summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorleo2005-02-16 20:13:34 +0000
committerleo2005-02-16 20:13:34 +0000
commit5d8f2105f7408c8178d48bb1de3c12e191e270a5 (patch)
treeb96f1dd9d642576b54e71c2e060c2b68ec47c4b5 /common
parent42ec485e88f797276f05afb90ed43decb81c2744 (diff)
Render rotation tangent arrow, re-scale mouse overlays.
git-svn-id: http://svn.leocad.org/trunk@380 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'common')
-rw-r--r--common/algebra.h197
-rw-r--r--common/project.cpp57
2 files changed, 162 insertions, 92 deletions
diff --git a/common/algebra.h b/common/algebra.h
index ecc714f..36d5b7b 100644
--- a/common/algebra.h
+++ b/common/algebra.h
@@ -364,6 +364,84 @@ protected:
// ============================================================================
+// Point3 and Vector3 Operators.
+
+// Comparison.
+inline bool operator==(const Point3& a, const Point3& b)
+{ return Compare3(a.GetValue(), b.GetValue()); }
+
+inline bool operator==(const Vector3& a, const Vector3& b)
+{ return Compare3(a.GetValue(), b.GetValue()); }
+
+// Multiply by a scalar.
+inline Vector3 operator*(const Vector3& a, float f)
+{ return Vector3(Multiply34(a.GetValue(), f)); }
+
+inline Vector3 operator*(float f, const Vector3& a)
+{ return Vector3(Multiply34(a.GetValue(), f)); }
+
+inline Point3 operator*(const Point3& a, float f)
+{ return Point3(Multiply34(a.GetValue(), f)); }
+
+inline Point3 operator*(float f, const Point3& a)
+{ return Point3(Multiply34(a.GetValue(), f)); }
+
+// Divide by a scalar.
+inline Vector3 operator/(const Vector3& a, float f)
+{ return Vector3(Divide34(a.GetValue(), f)); }
+
+inline Vector3 operator/(float f, const Vector3& a)
+{ return Vector3(Divide34(a.GetValue(), f)); }
+
+inline Point3 operator/(const Point3& a, float f)
+{ return Point3(Divide34(a.GetValue(), f)); }
+
+inline Point3 operator/(float f, const Point3& a)
+{ return Point3(Divide34(a.GetValue(), f)); }
+
+// Add vectors/points (return a point if either is a point).
+inline Point3 operator+(const Point3& a, const Point3& b)
+{ return Point3(Add34(a.GetValue(), b.GetValue())); }
+
+inline Point3 operator+(const Point3& a, const Vector3& b)
+{ return Point3(Add34(a.GetValue(), b.GetValue())); }
+
+inline Point3 operator+(const Vector3& a, const Point3& b)
+{ return Point3(Add34(a.GetValue(), b.GetValue())); }
+
+inline Vector3 operator+(const Vector3& a, const Vector3& b)
+{ return Vector3(Add34(a.GetValue(), b.GetValue())); }
+
+// Subtract vectors/points (return a vector if both arguments are the same type).
+inline Vector3 operator-(const Point3& a, const Point3& b)
+{ return Vector3(Subtract34(a.GetValue(), b.GetValue())); }
+
+inline Point3 operator-(const Point3& a, const Vector3& b)
+{ return Point3(Subtract34(a.GetValue(), b.GetValue())); }
+
+inline Point3 operator-(const Vector3& a, const Point3& b)
+{ return Point3(Subtract34(a.GetValue(), b.GetValue())); }
+
+inline Vector3 operator-(const Vector3& a, const Vector3& b)
+{ return Vector3(Subtract34(a.GetValue(), b.GetValue())); }
+
+// Negate.
+inline Vector3 operator-(const Vector3& a)
+{ return Vector3(Negate34(a.GetValue())); }
+
+inline Point3 operator-(const Point3& a)
+{ return Point3(Negate34(a.GetValue())); }
+
+// Dot product.
+inline float Dot3(const Vector3& a, const Vector3& b)
+{ return Dot3(a.GetValue(), b.GetValue()); }
+
+// Cross product.
+inline Vector3 Cross3(const Vector3& a, const Vector3& b)
+{ return Vector3(Cross3(a.GetValue(), b.GetValue())); }
+
+
+// ============================================================================
// Quaternion class.
class Quaternion
@@ -464,6 +542,48 @@ public:
inline Matrix33(const Vector3& Row0, const Vector3& Row1, const Vector3& Row2)
{ m_Rows[0] = Row0; m_Rows[1] = Row1; m_Rows[2] = Row2; }
+ inline void LoadIdentity()
+ {
+ m_Rows[0] = Vector3(1, 0, 0);
+ m_Rows[1] = Vector3(0, 1, 0);
+ m_Rows[2] = Vector3(0, 0, 1);
+ }
+
+ inline void FromAxisAngle(const Vector3& Axis, const float Radians)
+ {
+ float s, c, mag, xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;
+
+ s = sinf(Radians);
+ c = cosf(Radians);
+ mag = Axis.Length();
+
+ if (mag == 0.0f)
+ {
+ LoadIdentity();
+ return;
+ }
+
+ Vector3 Normal = Axis * (1.0f / mag);
+
+ xx = Normal[0] * Normal[0];
+ yy = Normal[1] * Normal[1];
+ zz = Normal[2] * Normal[2];
+ xy = Normal[0] * Normal[1];
+ yz = Normal[1] * Normal[2];
+ zx = Normal[2] * Normal[0];
+ xs = Normal[0] * s;
+ ys = Normal[1] * s;
+ zs = Normal[2] * s;
+ one_c = 1.0f - c;
+
+ m_Rows[0] = Vector3((one_c * xx) + c, (one_c * xy) - zs, (one_c * zx) + ys);
+ m_Rows[1] = Vector3((one_c * xy) + zs, (one_c * yy) + c, (one_c * yz) - xs);
+ m_Rows[2] = Vector3((one_c * zx) - ys, (one_c * yz) + xs, (one_c * zz) + c);
+ }
+
+ friend inline Vector3 operator*(const Vector3& a, const Matrix33& b)
+ { return Vector3(b.m_Rows[0]*a.GetX() + b.m_Rows[1]*a.GetY() + b.m_Rows[2]*a.GetZ()); }
+
protected:
Vector3 m_Rows[3];
};
@@ -503,83 +623,6 @@ protected:
// ============================================================================
-// Operators.
-
-// Comparison.
-inline bool operator==(const Point3& a, const Point3& b)
-{ return Compare3(a.GetValue(), b.GetValue()); }
-
-inline bool operator==(const Vector3& a, const Vector3& b)
-{ return Compare3(a.GetValue(), b.GetValue()); }
-
-// Multiply by a scalar.
-inline Vector3 operator*(const Vector3& a, float f)
-{ return Vector3(Multiply34(a.GetValue(), f)); }
-
-inline Vector3 operator*(float f, const Vector3& a)
-{ return Vector3(Multiply34(a.GetValue(), f)); }
-
-inline Point3 operator*(const Point3& a, float f)
-{ return Point3(Multiply34(a.GetValue(), f)); }
-
-inline Point3 operator*(float f, const Point3& a)
-{ return Point3(Multiply34(a.GetValue(), f)); }
-
-// Divide by a scalar.
-inline Vector3 operator/(const Vector3& a, float f)
-{ return Vector3(Divide34(a.GetValue(), f)); }
-
-inline Vector3 operator/(float f, const Vector3& a)
-{ return Vector3(Divide34(a.GetValue(), f)); }
-
-inline Point3 operator/(const Point3& a, float f)
-{ return Point3(Divide34(a.GetValue(), f)); }
-
-inline Point3 operator/(float f, const Point3& a)
-{ return Point3(Divide34(a.GetValue(), f)); }
-
-// Add vectors/points (return a point if either is a point).
-inline Point3 operator+(const Point3& a, const Point3& b)
-{ return Point3(Add34(a.GetValue(), b.GetValue())); }
-
-inline Point3 operator+(const Point3& a, const Vector3& b)
-{ return Point3(Add34(a.GetValue(), b.GetValue())); }
-
-inline Point3 operator+(const Vector3& a, const Point3& b)
-{ return Point3(Add34(a.GetValue(), b.GetValue())); }
-
-inline Vector3 operator+(const Vector3& a, const Vector3& b)
-{ return Vector3(Add34(a.GetValue(), b.GetValue())); }
-
-// Subtract vectors/points (return a vector if both arguments are the same type).
-inline Vector3 operator-(const Point3& a, const Point3& b)
-{ return Vector3(Subtract34(a.GetValue(), b.GetValue())); }
-
-inline Point3 operator-(const Point3& a, const Vector3& b)
-{ return Point3(Subtract34(a.GetValue(), b.GetValue())); }
-
-inline Point3 operator-(const Vector3& a, const Point3& b)
-{ return Point3(Subtract34(a.GetValue(), b.GetValue())); }
-
-inline Vector3 operator-(const Vector3& a, const Vector3& b)
-{ return Vector3(Subtract34(a.GetValue(), b.GetValue())); }
-
-// Negate.
-inline Vector3 operator-(const Vector3& a)
-{ return Vector3(Negate34(a.GetValue())); }
-
-inline Point3 operator-(const Point3& a)
-{ return Point3(Negate34(a.GetValue())); }
-
-// Dot product.
-inline float Dot3(const Vector3& a, const Vector3& b)
-{ return Dot3(a.GetValue(), b.GetValue()); }
-
-// Cross product.
-inline Vector3 Cross3(const Vector3& a, const Vector3& b)
-{ return Vector3(Cross3(a.GetValue(), b.GetValue())); }
-
-// ============================================================================
// Other Functions.
Point3 ProjectPoint(const Point3& Pt, const Matrix44& ModelView, const Matrix44& Projection, const int Viewport[4]);
diff --git a/common/project.cpp b/common/project.cpp
index 2cef5cf..6318635 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -2562,7 +2562,7 @@ void Project::RenderOverlays(int Viewport)
Pt = Pt * Mat;
- glVertex3f(Pt.GetX(), Pt.GetY(), Pt.GetZ());
+ glVertex3f(Pt[0], Pt[1], Pt[2]);
}
glEnd();
@@ -2617,7 +2617,7 @@ void Project::RenderOverlays(int Viewport)
break;
}
- if (Dot3(ViewDir, v1+v2) < 0.0f)
+ if (Dot3(ViewDir, v1+v2) <= 0.0f)
{
Point3 Pt1 = m_OverlayCenter + v1 * OverlayRotateRadius * OverlayScale;
Point3 Pt2 = m_OverlayCenter + v2 * OverlayRotateRadius * OverlayScale;
@@ -2643,15 +2643,15 @@ void Project::RenderOverlays(int Viewport)
{
case LC_OVERLAY_X:
Angle = m_MouseTotalDelta[0];
- Tangent = Vector3(0.0f, -Normal.GetZ(), Normal.GetY());
+ Tangent = Vector3(0.0f, -Normal[2], Normal[1]);
break;
case LC_OVERLAY_Y:
Angle = m_MouseTotalDelta[1];
- Tangent = Vector3(Normal.GetZ(), 0.0f, -Normal.GetX());
+ Tangent = Vector3(Normal[2], 0.0f, -Normal[0]);
break;
case LC_OVERLAY_Z:
Angle = m_MouseTotalDelta[2];
- Tangent = Vector3(-Normal.GetY(), Normal.GetX(), 0.0f);
+ Tangent = Vector3(-Normal[1], Normal[0], 0.0f);
break;
}
@@ -2661,17 +2661,35 @@ void Project::RenderOverlays(int Viewport)
Angle = -Angle;
}
+ // Draw tangent arrow.
if (Angle > 0.0f)
{
- Point3 Pt = m_OverlayCenter + Normal * m_OverlayScale[Viewport] * OverlayRotateRadius;
+ const float OverlayRotateArrowSize = 1.5f;
+ const float OverlayRotateArrowCapSize = 0.25f;
- // TODO: scale
- // TODO: draw cap
+ Point3 Pt = m_OverlayCenter + Normal * OverlayScale * OverlayRotateRadius;
+ Point3 Tip = Pt + Tangent * OverlayScale * OverlayRotateArrowSize;
+ Vector3 Arrow;
+ Matrix33 Rot;
glBegin(GL_LINES);
glColor3f(0.8f, 0.8f, 0.0f);
+
glVertex3f(Pt[0], Pt[1], Pt[2]);
- glVertex3f(Pt[0] + Tangent[0], Pt[1] + Tangent[1], Pt[2] + Tangent[2]);
+ glVertex3f(Tip[0], Tip[1], Tip[2]);
+
+ Rot.FromAxisAngle(Normal, LC_PI * 0.15f);
+ Arrow = Tangent * Rot * OverlayRotateArrowCapSize;
+
+ glVertex3f(Tip[0], Tip[1], Tip[2]);
+ glVertex3f(Tip[0] - Arrow[0], Tip[1] - Arrow[1], Tip[2] - Arrow[2]);
+
+ Rot.FromAxisAngle(Normal, -LC_PI * 0.15f);
+ Arrow = Tangent * Rot * OverlayRotateArrowCapSize;
+
+ glVertex3f(Tip[0], Tip[1], Tip[2]);
+ glVertex3f(Tip[0] - Arrow[0], Tip[1] - Arrow[1], Tip[2] - Arrow[2]);
+
glEnd();
}
@@ -5642,6 +5660,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
{
m_pViewCameras[m_nActiveViewport]->DoZoom(nParam, m_nMouse, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys);
SystemUpdateFocus(NULL);
+ UpdateOverlayScale();
UpdateAllViews();
} break;
@@ -5649,6 +5668,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
{
m_pViewCameras[m_nActiveViewport]->DoZoom(-1, m_nMouse, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys);
SystemUpdateFocus(NULL);
+ UpdateOverlayScale();
UpdateAllViews();
} break;
@@ -5656,6 +5676,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
{
m_pViewCameras[m_nActiveViewport]->DoZoom(1, m_nMouse, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys);
SystemUpdateFocus(NULL);
+ UpdateOverlayScale();
UpdateAllViews();
} break;
@@ -5789,6 +5810,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
}
SystemUpdateFocus(NULL);
+ UpdateOverlayScale();
UpdateAllViews();
} break;
@@ -5803,6 +5825,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
SystemUpdateViewport(nParam, m_nViewportMode);
m_nViewportMode = (unsigned char)nParam;
+ UpdateOverlayScale();
UpdateAllViews();
} break;
@@ -5997,6 +6020,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
SystemUpdateCurrentCamera(m_pViewCameras[m_nActiveViewport], pCamera, m_pCameras);
m_pViewCameras[m_nActiveViewport] = pCamera;
+ UpdateOverlayScale();
UpdateAllViews();
} break;
@@ -6030,6 +6054,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
SystemUpdateCameraMenu(m_pCameras);
SystemUpdateCurrentCamera(NULL, m_pViewCameras[m_nActiveViewport], m_pCameras);
SystemUpdateFocus(NULL);
+ UpdateOverlayScale();
UpdateAllViews();
SetModifiedFlag(true);
CheckPoint("Reset Cameras");
@@ -6049,6 +6074,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
m_pViewCameras[m_nActiveViewport]->DoPan(x/4, y/4, 1, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys);
m_nDownX = x;
m_nDownY = y;
+ UpdateOverlayScale();
SystemUpdateFocus(NULL);
UpdateAllViews();
} break;
@@ -6832,9 +6858,9 @@ void Project::MoveSelectedObjects(const Vector3& Delta)
void Project::RotateSelectedObjects(const Vector3& Delta)
{
- float x = Delta.GetX();
- float y = Delta.GetY();
- float z = Delta.GetZ();
+ float x = Delta[0];
+ float y = Delta[1];
+ float z = Delta[2];
if (m_nSnap & LC_DRAW_LOCK_X)
x = 0;
@@ -7368,6 +7394,7 @@ bool Project::OnKeyDown(char nKey, bool bControl, bool bShift)
RotateSelectedObjects(axis[0], axis[1], axis[2]);
else
MoveSelectedObjects(axis[0], axis[1], axis[2]);
+ UpdateOverlayScale();
UpdateAllViews();
SetModifiedFlag(true);
CheckPoint((bShift) ? "Rotating" : "Moving");
@@ -8634,9 +8661,9 @@ void Project::MouseUpdateOverlays(int x, int y)
Dist.Normalize();
Dist.Abs();
- float dx = Dist.GetX();
- float dy = Dist.GetY();
- float dz = Dist.GetZ();
+ float dx = Dist[0];
+ float dy = Dist[1];
+ float dz = Dist[2];
if (dx < dy)
{