Draw trackball hover indicator.

This commit is contained in:
Leonardo Zide committed 2026-09-13 15:28:18 -07:00
1 parent f5ace52543
commit 4ddeab6a0b
3 files changed
+37 -10

No files matched your search

+4 -4
View File
@@ -1938,11 +1938,11 @@ lcCursor lcView::GetCursor() const
lcCursor::Move, // lcTrackTool::MoveXZ
lcCursor::Move, // lcTrackTool::MoveYZ
lcCursor::Move, // lcTrackTool::MoveXYZ
lcCursor::Rotate, // lcTrackTool::RotateX
lcCursor::Rotate, // lcTrackTool::RotateY
lcCursor::Rotate, // lcTrackTool::RotateZ
lcCursor::Default, // lcTrackTool::RotateX
lcCursor::Default, // lcTrackTool::RotateY
lcCursor::Default, // lcTrackTool::RotateZ
lcCursor::Default, // lcTrackTool::RotateTrackBall
lcCursor::Rotate, // lcTrackTool::RotateCamera
lcCursor::Default, // lcTrackTool::RotateCamera
lcCursor::Select, // lcTrackTool::RotateTrainTrackRight
lcCursor::Select, // lcTrackTool::RotateTrainTrackLeft
lcCursor::Select, // lcTrackTool::InsertTrainTrack
+31 -5
View File
@@ -628,6 +628,31 @@ void lcViewManipulator::DrawRotate(lcTrackButton TrackButton, lcTrackTool TrackT
if (ActiveModel != mView->GetModel())
WorldMatrix = lcMul(WorldMatrix, mView->GetActiveSubmodelTransform());
// Show the trackball's active area while the pointer is inside it.
if (TrackButton == lcTrackButton::None && TrackTool == lcTrackTool::RotateTrackBall)
{
lcMatrix44 Mat = lcMatrix44AffineInverse(Camera->mWorldView);
Mat.SetTranslation(WorldMatrix.GetTranslation());
constexpr int SegmentCount = 32;
lcVector3 Verts[SegmentCount + 2];
Verts[0] = lcVector3(0.0f, 0.0f, 0.0f);
for (int SegmentIndex = 0; SegmentIndex <= SegmentCount; SegmentIndex++)
{
const float Angle = LC_2PI * SegmentIndex / SegmentCount;
Verts[SegmentIndex + 1] = lcVector3(cosf(Angle) * OverlayRotateRadius * OverlayScale, sinf(Angle) * OverlayRotateRadius * OverlayScale, 0.0f);
}
Context->SetColor(mColorTrackball);
Context->SetWorldMatrix(Mat);
Context->EnableColorBlend(true);
Context->SetVertexBufferPointer(Verts);
Context->SetVertexFormatPosition(3);
Context->DrawPrimitives(GL_TRIANGLE_FAN, 0, SegmentCount + 2);
Context->EnableColorBlend(false);
}
// Draw a disc showing the rotation amount.
if (MouseToolDistance.LengthSquared() != 0.0f && (TrackButton != lcTrackButton::None))
{
@@ -861,7 +886,7 @@ void lcViewManipulator::DrawRotate(lcTrackButton TrackButton, lcTrackTool TrackT
}
}
const float HalfWidth = OverlayScale * 0.035f;
const float HalfWidth = OverlayScale * 0.035f;
constexpr int SegmentCount = 32;
lcVector3 Verts[SegmentCount * 6];
int NumVerts = 0;
@@ -930,7 +955,7 @@ void lcViewManipulator::DrawRotate(lcTrackButton TrackButton, lcTrackTool TrackT
Context->DrawPrimitives(GL_TRIANGLES, 0, NumVerts);
}
// Draw tangent arrow and text.
// Draw rotation and text.
if (TrackButton != lcTrackButton::None && ((TrackTool == lcTrackTool::RotateX) || (TrackTool == lcTrackTool::RotateY) || (TrackTool == lcTrackTool::RotateZ) || (TrackTool == lcTrackTool::RotateCamera)))
{
lcVector4 Rotation;
@@ -1387,7 +1412,7 @@ lcTrackTool lcViewManipulator::UpdateRotate()
lcMatrix33 RelativeRotation;
if (!ActiveModel->GetMoveRotateTransform(OverlayCenter, RelativeRotation))
return lcTrackTool::RotateTrackBall;
return lcTrackTool::None;
lcMatrix44 WorldMatrix = lcMatrix44(RelativeRotation, OverlayCenter);
@@ -1402,7 +1427,8 @@ lcTrackTool lcViewManipulator::UpdateRotate()
lcVector3 Intersection;
if (lcSphereRayIntersection(OverlayCenter, OverlayRotateRadius * OverlayScale, StartEnd[0], StartEnd[1], Intersection))
const bool TrackballHit = lcSphereRayIntersection(OverlayCenter, OverlayRotateRadius * OverlayScale, StartEnd[0], StartEnd[1], Intersection);
if (TrackballHit)
{
const lcVector3 LocalIntersection = lcMul(Intersection - OverlayCenter, lcMatrix33AffineInverse(lcMatrix33(WorldMatrix)));
const float Epsilon = 0.25f * OverlayScale;
@@ -1454,5 +1480,5 @@ lcTrackTool lcViewManipulator::UpdateRotate()
return lcTrackTool::RotateCamera;
}
return lcTrackTool::RotateTrackBall;
return TrackballHit ? lcTrackTool::RotateTrackBall : lcTrackTool::None;
}
+2 -1
View File
@@ -30,7 +30,8 @@ protected:
static constexpr lcVector4 mColorXAxis = lcVector4(200.0f / 255.0f, 40.0f / 255.0f, 60.0f / 255.0f, 255.0f / 255.0f);
static constexpr lcVector4 mColorYAxis = lcVector4(120.0f / 255.0f, 200.0f / 255.0f, 20.0f / 255.0f, 255.0f / 255.0f);
static constexpr lcVector4 mColorZAxis = lcVector4( 70.0f / 255.0f, 130.0f / 255.0f, 240.0f / 255.0f, 255.0f / 255.0f);
static constexpr lcVector4 mColorCamera = lcVector4(200.0f / 255.0f, 200.0f / 255.0f, 200.0f / 255.0f, 255.0f / 255.0f);
static constexpr lcVector4 mColorCamera = lcVector4(190.0f / 255.0f, 190.0f / 255.0f, 190.0f / 255.0f, 255.0f / 255.0f);
static constexpr lcVector4 mColorTrackball = lcVector4(120.0f / 255.0f, 120.0f / 255.0f, 120.0f / 255.0f, 30.0f / 255.0f);
static constexpr lcVector4 mColorXAxisSelected = lcVector4(219.0f / 255.0f, 72.0f / 255.0f, 89.0f / 255.0f, 255.0f / 255.0f);
static constexpr lcVector4 mColorYAxisSelected = lcVector4(145.0f / 255.0f, 233.0f / 255.0f, 37.0f / 255.0f, 255.0f / 255.0f);
static constexpr lcVector4 mColorZAxisSelected = lcVector4(118.0f / 255.0f, 162.0f / 255.0f, 244.0f / 255.0f, 255.0f / 255.0f);