mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Removed some old vector code.
This commit is contained in:
parent
b5c74b8a10
commit
a42fe600ca
9 changed files with 244 additions and 188 deletions
|
@ -166,6 +166,16 @@ inline lcVector3 operator/(const lcVector3& a, float b)
|
||||||
return lcVector3(a.x / b, a.y / b, a.z / b);
|
return lcVector3(a.x / b, a.y / b, a.z / b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline lcVector3 operator*(float a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
return lcVector3(b.x * a, b.y * a, b.z * a);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3 operator/(float a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
return lcVector3(b.x / a, b.y / a, b.z / a);
|
||||||
|
}
|
||||||
|
|
||||||
inline lcVector3 operator-(const lcVector3& a)
|
inline lcVector3 operator-(const lcVector3& a)
|
||||||
{
|
{
|
||||||
return lcVector3(-a.x, -a.y, -a.z);
|
return lcVector3(-a.x, -a.y, -a.z);
|
||||||
|
@ -876,4 +886,77 @@ inline lcVector3 lcZoomExtents(const lcVector3& Position, const lcMatrix44& Worl
|
||||||
return Position - (Front * SmallestDistance);
|
return Position - (Front * SmallestDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the intersection of a line segment and a plane and returns false
|
||||||
|
// if they are parallel or the intersection is outside the line segment.
|
||||||
|
inline bool lcLinePlaneIntersection(lcVector3& Intersection, const lcVector3& Start, const lcVector3& End, const lcVector4& Plane)
|
||||||
|
{
|
||||||
|
lcVector3 Dir = End - Start;
|
||||||
|
lcVector3 PlaneNormal(Plane[0], Plane[1], Plane[2]);
|
||||||
|
|
||||||
|
float t1 = lcDot(PlaneNormal, Start) + Plane[3];
|
||||||
|
float t2 = lcDot(PlaneNormal, Dir);
|
||||||
|
|
||||||
|
if (t2 == 0.0f)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
float t = -t1 / t2;
|
||||||
|
|
||||||
|
Intersection = Start + t * Dir;
|
||||||
|
|
||||||
|
if ((t < 0.0f) || (t > 1.0f))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool lcLineTriangleMinIntersection(const lcVector3& p1, const lcVector3& p2, const lcVector3& p3, const lcVector3& Start, const lcVector3& End, float& MinDist, lcVector3& Intersection)
|
||||||
|
{
|
||||||
|
// Calculate the polygon plane.
|
||||||
|
lcVector3 PlaneNormal = lcCross(p1 - p2, p3 - p2);
|
||||||
|
float PlaneD = -lcDot(PlaneNormal, p1);
|
||||||
|
|
||||||
|
// Check if the line is parallel to the plane.
|
||||||
|
lcVector3 Dir = End - Start;
|
||||||
|
|
||||||
|
float t1 = lcDot(PlaneNormal, Start) + PlaneD;
|
||||||
|
float t2 = lcDot(PlaneNormal, Dir);
|
||||||
|
|
||||||
|
if (t2 == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
float t = -(t1 / t2);
|
||||||
|
|
||||||
|
if (t < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Intersection of the plane and line segment.
|
||||||
|
Intersection = Start - (t1 / t2) * Dir;
|
||||||
|
|
||||||
|
float Dist = (Start - Intersection).Length();
|
||||||
|
|
||||||
|
if (Dist > MinDist)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check if we're inside the triangle.
|
||||||
|
lcVector3 pa1, pa2, pa3;
|
||||||
|
pa1 = lcNormalize(p1 - Intersection);
|
||||||
|
pa2 = lcNormalize(p2 - Intersection);
|
||||||
|
pa3 = lcNormalize(p3 - Intersection);
|
||||||
|
|
||||||
|
float a1, a2, a3;
|
||||||
|
a1 = lcDot(pa1, pa2);
|
||||||
|
a2 = lcDot(pa2, pa3);
|
||||||
|
a3 = lcDot(pa3, pa1);
|
||||||
|
|
||||||
|
float total = (acosf(a1) + acosf(a2) + acosf(a3)) * RTOD;
|
||||||
|
|
||||||
|
if (fabs(total - 360) <= 0.001f)
|
||||||
|
{
|
||||||
|
MinDist = Dist;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _LC_MATH_H_
|
#endif // _LC_MATH_H_
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include "lc_mesh.h"
|
#include "lc_mesh.h"
|
||||||
#include "lc_colors.h"
|
#include "lc_colors.h"
|
||||||
#include "lc_file.h"
|
#include "lc_file.h"
|
||||||
#include "globals.h"
|
#include "lc_math.h"
|
||||||
|
|
||||||
struct lcVertex
|
struct lcVertex
|
||||||
{
|
{
|
||||||
|
@ -44,8 +44,8 @@ void lcMesh::CreateBox()
|
||||||
{
|
{
|
||||||
Create(2, 8, 36 + 24);
|
Create(2, 8, 36 + 24);
|
||||||
|
|
||||||
Vector3 Min(-0.4f, -0.4f, -0.96f);
|
lcVector3 Min(-0.4f, -0.4f, -0.96f);
|
||||||
Vector3 Max(0.4f, 0.4f, 0.16f);
|
lcVector3 Max(0.4f, 0.4f, 0.16f);
|
||||||
|
|
||||||
float* Verts = (float*)mVertexBuffer.mData;
|
float* Verts = (float*)mVertexBuffer.mData;
|
||||||
lcuint16* Indices = (lcuint16*)mIndexBuffer.mData;
|
lcuint16* Indices = (lcuint16*)mIndexBuffer.mData;
|
||||||
|
@ -177,7 +177,7 @@ void lcMesh::Render(int DefaultColorIdx, bool Selected, bool Focused)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename IndexType>
|
template<typename IndexType>
|
||||||
bool lcMesh::MinIntersectDist(const Vector3& Start, const Vector3& End, float& MinDist, Vector3& Intersection)
|
bool lcMesh::MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDist, lcVector3& Intersection)
|
||||||
{
|
{
|
||||||
float* Verts = (float*)mVertexBuffer.mData;
|
float* Verts = (float*)mVertexBuffer.mData;
|
||||||
bool Hit = false;
|
bool Hit = false;
|
||||||
|
@ -196,11 +196,11 @@ bool lcMesh::MinIntersectDist(const Vector3& Start, const Vector3& End, float& M
|
||||||
float* p1 = Verts + Indices[Idx + 0] * 3;
|
float* p1 = Verts + Indices[Idx + 0] * 3;
|
||||||
float* p2 = Verts + Indices[Idx + 1] * 3;
|
float* p2 = Verts + Indices[Idx + 1] * 3;
|
||||||
float* p3 = Verts + Indices[Idx + 2] * 3;
|
float* p3 = Verts + Indices[Idx + 2] * 3;
|
||||||
Vector3 v1(p1[0], p1[1], p1[2]);
|
lcVector3 v1(p1[0], p1[1], p1[2]);
|
||||||
Vector3 v2(p2[0], p2[1], p2[2]);
|
lcVector3 v2(p2[0], p2[1], p2[2]);
|
||||||
Vector3 v3(p3[0], p3[1], p3[2]);
|
lcVector3 v3(p3[0], p3[1], p3[2]);
|
||||||
|
|
||||||
if (LineTriangleMinIntersection(v1, v2, v3, Start, End, MinDist, Intersection))
|
if (lcLineTriangleMinIntersection(v1, v2, v3, Start, End, MinDist, Intersection))
|
||||||
Hit = true;
|
Hit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ bool lcMesh::MinIntersectDist(const Vector3& Start, const Vector3& End, float& M
|
||||||
return Hit;
|
return Hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool lcMesh::MinIntersectDist(const Vector3& Start, const Vector3& End, float& MinDist, Vector3& Intersection)
|
bool lcMesh::MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDist, lcVector3& Intersection)
|
||||||
{
|
{
|
||||||
if (mIndexType == GL_UNSIGNED_SHORT)
|
if (mIndexType == GL_UNSIGNED_SHORT)
|
||||||
return MinIntersectDist<GLushort>(Start, End, MinDist, Intersection);
|
return MinIntersectDist<GLushort>(Start, End, MinDist, Intersection);
|
||||||
|
|
|
@ -125,8 +125,8 @@ public:
|
||||||
void ExportWavefrontIndices(lcFile& File, int DefaultColorIndex, int VertexOffset);
|
void ExportWavefrontIndices(lcFile& File, int DefaultColorIndex, int VertexOffset);
|
||||||
|
|
||||||
template<typename IndexType>
|
template<typename IndexType>
|
||||||
bool MinIntersectDist(const Vector3& Start, const Vector3& End, float& MinDist, Vector3& Intersection);
|
bool MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDist, lcVector3& Intersection);
|
||||||
bool MinIntersectDist(const Vector3& Start, const Vector3& End, float& MinDist, Vector3& Intersection);
|
bool MinIntersectDist(const lcVector3& Start, const lcVector3& End, float& MinDist, lcVector3& Intersection);
|
||||||
|
|
||||||
template<typename IndexType>
|
template<typename IndexType>
|
||||||
bool IntersectsPlanes(const Vector4* Planes, int NumPlanes);
|
bool IntersectsPlanes(const Vector4* Planes, int NumPlanes);
|
||||||
|
|
|
@ -401,13 +401,12 @@ void Piece::MinIntersectDist(LC_CLICKLINE* pLine)
|
||||||
if (dist >= pLine->mindist)
|
if (dist >= pLine->mindist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Matrix44 WorldToLocal;
|
lcMatrix44 WorldToLocal = lcMatrix44FromAxisAngle(lcVector3(mRotation[0], mRotation[1], mRotation[2]), -mRotation[3] * LC_DTOR);
|
||||||
WorldToLocal.CreateFromAxisAngle(Vector3(mRotation[0], mRotation[1], mRotation[2]), -mRotation[3] * LC_DTOR);
|
WorldToLocal.SetTranslation(lcMul31(lcVector3(-mPosition[0], -mPosition[1], -mPosition[2]), WorldToLocal));
|
||||||
WorldToLocal.SetTranslation(Mul31(Vector3(-mPosition[0], -mPosition[1], -mPosition[2]), WorldToLocal));
|
|
||||||
|
|
||||||
Vector3 Start = Mul31(Vector3(pLine->a1, pLine->b1, pLine->c1), WorldToLocal);
|
lcVector3 Start = lcMul31(lcVector3(pLine->a1, pLine->b1, pLine->c1), WorldToLocal);
|
||||||
Vector3 End = Mul31(Vector3(pLine->a1 + pLine->a2, pLine->b1 + pLine->b2, pLine->c1 + pLine->c2), WorldToLocal);
|
lcVector3 End = lcMul31(lcVector3(pLine->a1 + pLine->a2, pLine->b1 + pLine->b2, pLine->c1 + pLine->c2), WorldToLocal);
|
||||||
Vector3 Intersection;
|
lcVector3 Intersection;
|
||||||
|
|
||||||
if (mPieceInfo->mMesh->MinIntersectDist(Start, End, pLine->mindist, Intersection))
|
if (mPieceInfo->mMesh->MinIntersectDist(Start, End, pLine->mindist, Intersection))
|
||||||
pLine->pClosest = this;
|
pLine->pClosest = this;
|
||||||
|
|
|
@ -90,14 +90,6 @@ public:
|
||||||
{ m_nFrameHide = frame; }
|
{ m_nFrameHide = frame; }
|
||||||
const unsigned short GetFrameHide()
|
const unsigned short GetFrameHide()
|
||||||
{ return m_nFrameHide; }
|
{ return m_nFrameHide; }
|
||||||
inline Vector3 GetPosition() const
|
|
||||||
{ return Vector3(mPosition[0], mPosition[1], mPosition[2]); }
|
|
||||||
inline Vector4 GetRotation() const
|
|
||||||
{ return Vector4(mRotation[0], mRotation[1], mRotation[2], mRotation[3]); }
|
|
||||||
void GetPosition (float* position)
|
|
||||||
{ memcpy(position, mPosition, sizeof(mPosition)); }
|
|
||||||
void GetRotation (float* rotation)
|
|
||||||
{ memcpy(rotation, mRotation, sizeof(mRotation)); }
|
|
||||||
|
|
||||||
void Render(bool bLighting, bool bEdges);
|
void Render(bool bLighting, bool bEdges);
|
||||||
void RenderBox(bool bHilite, float fLineWidth);
|
void RenderBox(bool bHilite, float fLineWidth);
|
||||||
|
|
|
@ -1228,9 +1228,9 @@ bool Project::DoSave(char* lpszPathName, bool bReplace)
|
||||||
{
|
{
|
||||||
if ((pPiece->IsVisible(i, false)) && (pPiece->GetStepShow() == i))
|
if ((pPiece->IsVisible(i, false)) && (pPiece->GetStepShow() == i))
|
||||||
{
|
{
|
||||||
float f[12], position[3], rotation[4];
|
float f[12];
|
||||||
pPiece->GetPosition(position);
|
const lcVector3& position = pPiece->mPosition;
|
||||||
pPiece->GetRotation(rotation);
|
const lcVector4& rotation = pPiece->mRotation;
|
||||||
Matrix mat(rotation, position);
|
Matrix mat(rotation, position);
|
||||||
mat.ToLDraw(f);
|
mat.ToLDraw(f);
|
||||||
sprintf (buf, " 1 %d %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %s.DAT\r\n",
|
sprintf (buf, " 1 %d %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %s.DAT\r\n",
|
||||||
|
@ -1964,8 +1964,8 @@ void Project::RenderSceneObjects(View* view)
|
||||||
// Draw cameras & lights
|
// Draw cameras & lights
|
||||||
if (m_nCurAction == LC_ACTION_INSERT)
|
if (m_nCurAction == LC_ACTION_INSERT)
|
||||||
{
|
{
|
||||||
Vector3 Pos;
|
lcVector3 Pos;
|
||||||
Vector4 Rot;
|
lcVector4 Rot;
|
||||||
GetPieceInsertPosition(view, m_nDownX, m_nDownY, Pos, Rot);
|
GetPieceInsertPosition(view, m_nDownX, m_nDownY, Pos, Rot);
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
@ -2003,17 +2003,18 @@ void Project::RenderSceneObjects(View* view)
|
||||||
{
|
{
|
||||||
// glClear(GL_DEPTH_BUFFER_BIT);
|
// glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
Matrix Mats[3];
|
lcMatrix44 Mats[3];
|
||||||
Mats[0].CreateLookat(view->m_Camera->mPosition, view->m_Camera->mTargetPosition, view->m_Camera->mUpVector);
|
Mats[0] = view->m_Camera->mWorldView;
|
||||||
Mats[0].SetTranslation(0, 0, 0);
|
Mats[0].SetTranslation(lcVector3(0, 0, 0));
|
||||||
|
Mats[1] = lcMul(lcMatrix44(lcVector4(0, 1, 0, 0), lcVector4(1, 0, 0, 0), lcVector4(0, 0, 1, 0), lcVector4(0, 0, 0, 1)), Mats[0]);
|
||||||
|
Mats[2] = lcMul(lcMatrix44(lcVector4(0, 0, 1, 0), lcVector4(0, 1, 0, 0), lcVector4(1, 0, 0, 0), lcVector4(0, 0, 0, 1)), Mats[0]);
|
||||||
|
|
||||||
float m1[] = { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
|
lcVector3 pts[3] =
|
||||||
float m2[] = { 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 };
|
{
|
||||||
Mats[1].Multiply(Mats[0], Matrix(m1));
|
lcMul30(lcVector3(20, 0, 0), Mats[0]),
|
||||||
Mats[2].Multiply(Mats[0], Matrix(m2));
|
lcMul30(lcVector3(0, 20, 0), Mats[0]),
|
||||||
|
lcMul30(lcVector3(0, 0, 20), Mats[0]),
|
||||||
float pts[3][3] = { { 20, 0, 0 }, { 0, 20, 0 }, { 0, 0, 20 } };
|
};
|
||||||
Mats[0].TransformPoints(&pts[0][0], 3);
|
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
@ -2047,8 +2048,7 @@ void Project::RenderSceneObjects(View* view)
|
||||||
glVertex3f(pts[i][0], pts[i][1], pts[i][2]);
|
glVertex3f(pts[i][0], pts[i][1], pts[i][2]);
|
||||||
for (int j = 0; j < 9; j++)
|
for (int j = 0; j < 9; j++)
|
||||||
{
|
{
|
||||||
float pt[3] = { 12.0f, cosf(LC_2PI * j / 8) * 3.0f, sinf(LC_2PI * j / 8) * 3.0f };
|
lcVector3 pt = lcMul30(lcVector3(12.0f, cosf(LC_2PI * j / 8) * 3.0f, sinf(LC_2PI * j / 8) * 3.0f), Mats[i]);
|
||||||
Mats[i].TransformPoints(pt, 1);
|
|
||||||
glVertex3f(pt[0], pt[1], pt[2]);
|
glVertex3f(pt[0], pt[1], pt[2]);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
|
@ -2122,14 +2122,14 @@ void Project::RenderOverlays(View* view)
|
||||||
|
|
||||||
// Find the rotation from the focused piece if relative snap is enabled.
|
// Find the rotation from the focused piece if relative snap is enabled.
|
||||||
Object* Focus = NULL;
|
Object* Focus = NULL;
|
||||||
float Rot[4];
|
lcVector4 Rot;
|
||||||
|
|
||||||
if ((m_nSnap & LC_DRAW_GLOBAL_SNAP) == 0)
|
if ((m_nSnap & LC_DRAW_GLOBAL_SNAP) == 0)
|
||||||
{
|
{
|
||||||
Focus = GetFocusObject();
|
Focus = GetFocusObject();
|
||||||
|
|
||||||
if ((Focus != NULL) && Focus->IsPiece())
|
if ((Focus != NULL) && Focus->IsPiece())
|
||||||
((Piece*)Focus)->GetRotation(Rot);
|
Rot = ((Piece*)Focus)->mRotation;
|
||||||
else
|
else
|
||||||
Focus = NULL;
|
Focus = NULL;
|
||||||
}
|
}
|
||||||
|
@ -2231,14 +2231,14 @@ void Project::RenderOverlays(View* view)
|
||||||
|
|
||||||
// Find the rotation from the focused piece if relative snap is enabled.
|
// Find the rotation from the focused piece if relative snap is enabled.
|
||||||
Object* Focus = NULL;
|
Object* Focus = NULL;
|
||||||
float Rot[4];
|
lcVector4 Rot;
|
||||||
|
|
||||||
if ((m_nSnap & LC_DRAW_GLOBAL_SNAP) == 0)
|
if ((m_nSnap & LC_DRAW_GLOBAL_SNAP) == 0)
|
||||||
{
|
{
|
||||||
Focus = GetFocusObject();
|
Focus = GetFocusObject();
|
||||||
|
|
||||||
if ((Focus != NULL) && Focus->IsPiece())
|
if ((Focus != NULL) && Focus->IsPiece())
|
||||||
((Piece*)Focus)->GetRotation(Rot);
|
Rot = ((Piece*)Focus)->mRotation;
|
||||||
else
|
else
|
||||||
Focus = NULL;
|
Focus = NULL;
|
||||||
}
|
}
|
||||||
|
@ -2246,7 +2246,7 @@ void Project::RenderOverlays(View* view)
|
||||||
// Draw a disc showing the rotation amount.
|
// Draw a disc showing the rotation amount.
|
||||||
if (m_MouseTotalDelta.LengthSquared() != 0.0f && (m_nTracking != LC_TRACK_NONE))
|
if (m_MouseTotalDelta.LengthSquared() != 0.0f && (m_nTracking != LC_TRACK_NONE))
|
||||||
{
|
{
|
||||||
Vector4 Rotation;
|
lcVector4 Rotation;
|
||||||
float Angle, Step;
|
float Angle, Step;
|
||||||
|
|
||||||
switch (m_OverlayMode)
|
switch (m_OverlayMode)
|
||||||
|
@ -2254,17 +2254,17 @@ void Project::RenderOverlays(View* view)
|
||||||
case LC_OVERLAY_X:
|
case LC_OVERLAY_X:
|
||||||
glColor4f(0.8f, 0.0f, 0.0f, 0.3f);
|
glColor4f(0.8f, 0.0f, 0.0f, 0.3f);
|
||||||
Angle = m_MouseTotalDelta[0];
|
Angle = m_MouseTotalDelta[0];
|
||||||
Rotation = Vector4(0.0f, 0.0f, 0.0f, 0.0f);
|
Rotation = lcVector4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_Y:
|
case LC_OVERLAY_Y:
|
||||||
glColor4f(0.0f, 0.8f, 0.0f, 0.3f);
|
glColor4f(0.0f, 0.8f, 0.0f, 0.3f);
|
||||||
Angle = m_MouseTotalDelta[1];
|
Angle = m_MouseTotalDelta[1];
|
||||||
Rotation = Vector4(90.0f, 0.0f, 0.0f, 1.0f);
|
Rotation = lcVector4(90.0f, 0.0f, 0.0f, 1.0f);
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_Z:
|
case LC_OVERLAY_Z:
|
||||||
glColor4f(0.0f, 0.0f, 0.8f, 0.3f);
|
glColor4f(0.0f, 0.0f, 0.8f, 0.3f);
|
||||||
Angle = m_MouseTotalDelta[2];
|
Angle = m_MouseTotalDelta[2];
|
||||||
Rotation = Vector4(90.0f, 0.0f, -1.0f, 0.0f);
|
Rotation = lcVector4(90.0f, 0.0f, -1.0f, 0.0f);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Angle = 0.0f;
|
Angle = 0.0f;
|
||||||
|
@ -3263,9 +3263,8 @@ void Project::HandleNotify(LC_NOTIFY id, unsigned long param)
|
||||||
LC_PIECE_MODIFY* mod = (LC_PIECE_MODIFY*)param;
|
LC_PIECE_MODIFY* mod = (LC_PIECE_MODIFY*)param;
|
||||||
Piece* pPiece = (Piece*)mod->piece;
|
Piece* pPiece = (Piece*)mod->piece;
|
||||||
|
|
||||||
float rot[4];
|
const lcVector3& Pos = pPiece->mPosition;
|
||||||
Vector3 Pos = pPiece->GetPosition();
|
lcVector4 rot = pPiece->mRotation;
|
||||||
pPiece->GetRotation(rot);
|
|
||||||
Matrix mat(rot, Pos);
|
Matrix mat(rot, Pos);
|
||||||
mat.ToEulerAngles(rot);
|
mat.ToEulerAngles(rot);
|
||||||
|
|
||||||
|
@ -3998,14 +3997,14 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
||||||
for (Piece* piece = m_pPieces; piece; piece = piece->m_pNext)
|
for (Piece* piece = m_pPieces; piece; piece = piece->m_pNext)
|
||||||
{
|
{
|
||||||
int Index = Library->GetPieceIndex(piece->mPieceInfo);
|
int Index = Library->GetPieceIndex(piece->mPieceInfo);
|
||||||
float fl[12], pos[3], rot[4];
|
float fl[12];
|
||||||
int Color;
|
int Color;
|
||||||
|
|
||||||
Color = piece->mColorIndex;
|
Color = piece->mColorIndex;
|
||||||
const char* Suffix = lcIsColorTranslucent(Color) ? "_clear" : "";
|
const char* Suffix = lcIsColorTranslucent(Color) ? "_clear" : "";
|
||||||
|
|
||||||
piece->GetPosition(pos);
|
const lcVector3& pos = piece->mPosition;
|
||||||
piece->GetRotation(rot);
|
const lcVector4& rot = piece->mRotation;
|
||||||
Matrix mat(rot, pos);
|
Matrix mat(rot, pos);
|
||||||
mat.ToLDraw(fl);
|
mat.ToLDraw(fl);
|
||||||
|
|
||||||
|
@ -4149,9 +4148,9 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
||||||
|
|
||||||
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
|
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
|
||||||
{
|
{
|
||||||
float pos[3], rot[4], tmp[3];
|
float tmp[3];
|
||||||
pPiece->GetPosition(pos);
|
const lcVector3& pos = pPiece->mPosition;
|
||||||
pPiece->GetRotation(rot);
|
const lcVector4& rot = pPiece->mRotation;
|
||||||
Matrix mat(rot, pos);
|
Matrix mat(rot, pos);
|
||||||
PieceInfo* pInfo = pPiece->mPieceInfo;
|
PieceInfo* pInfo = pPiece->mPieceInfo;
|
||||||
float* Verts = (float*)pInfo->mMesh->mVertexBuffer.mData;
|
float* Verts = (float*)pInfo->mMesh->mVertexBuffer.mData;
|
||||||
|
@ -4676,8 +4675,8 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
||||||
|
|
||||||
if (pLast != NULL)
|
if (pLast != NULL)
|
||||||
{
|
{
|
||||||
Vector3 Pos;
|
lcVector3 Pos;
|
||||||
Vector4 Rot;
|
lcVector4 Rot;
|
||||||
|
|
||||||
GetPieceInsertPosition(pLast, Pos, Rot);
|
GetPieceInsertPosition(pLast, Pos, Rot);
|
||||||
|
|
||||||
|
@ -4839,9 +4838,8 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
|
||||||
|
|
||||||
for (i = 0; i < opts.n1DCount; i++)
|
for (i = 0; i < opts.n1DCount; i++)
|
||||||
{
|
{
|
||||||
float pos[3], param[4];
|
lcVector3 pos = pPiece->mPosition;
|
||||||
pPiece->GetRotation(param);
|
lcVector4 param = pPiece->mRotation;
|
||||||
pPiece->GetPosition(pos);
|
|
||||||
Matrix mat(param, pos);
|
Matrix mat(param, pos);
|
||||||
|
|
||||||
if (sel == 1)
|
if (sel == 1)
|
||||||
|
@ -6142,25 +6140,24 @@ Object* Project::GetFocusObject() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a good starting position/orientation relative to an existing piece.
|
// Find a good starting position/orientation relative to an existing piece.
|
||||||
void Project::GetPieceInsertPosition(Piece* OffsetPiece, Vector3& Position, Vector4& Rotation)
|
void Project::GetPieceInsertPosition(Piece* OffsetPiece, lcVector3& Position, lcVector4& Rotation)
|
||||||
{
|
{
|
||||||
Vector3 Dist(0, 0, OffsetPiece->mPieceInfo->m_fDimensions[2] - m_pCurPiece->m_fDimensions[5]);
|
lcVector3 Dist(0, 0, OffsetPiece->mPieceInfo->m_fDimensions[2] - m_pCurPiece->m_fDimensions[5]);
|
||||||
SnapVector(Dist);
|
SnapVector(Dist);
|
||||||
|
|
||||||
float pos[3], rot[4];
|
lcVector3 pos = OffsetPiece->mPosition;
|
||||||
OffsetPiece->GetPosition(pos);
|
const lcVector4& rot = OffsetPiece->mRotation;
|
||||||
OffsetPiece->GetRotation(rot);
|
|
||||||
|
|
||||||
Matrix mat(rot, pos);
|
Matrix mat(rot, pos);
|
||||||
mat.Translate(Dist[0], Dist[1], Dist[2]);
|
mat.Translate(Dist[0], Dist[1], Dist[2]);
|
||||||
mat.GetTranslation(pos);
|
mat.GetTranslation(pos);
|
||||||
|
|
||||||
Position = Vector3(pos[0], pos[1], pos[2]);
|
Position = lcVector3(pos[0], pos[1], pos[2]);
|
||||||
Rotation = Vector4(rot[0], rot[1], rot[2], rot[3]);
|
Rotation = lcVector4(rot[0], rot[1], rot[2], rot[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find a good starting position/orientation for a new piece.
|
// Try to find a good starting position/orientation for a new piece.
|
||||||
void Project::GetPieceInsertPosition(View* view, int MouseX, int MouseY, Vector3& Position, Vector4& Rotation)
|
void Project::GetPieceInsertPosition(View* view, int MouseX, int MouseY, lcVector3& Position, lcVector4& Rotation)
|
||||||
{
|
{
|
||||||
// Check if the mouse is over a piece.
|
// Check if the mouse is over a piece.
|
||||||
Piece* HitPiece = (Piece*)FindObjectFromPoint(view, MouseX, MouseY, true);
|
Piece* HitPiece = (Piece*)FindObjectFromPoint(view, MouseX, MouseY, true);
|
||||||
|
@ -6183,18 +6180,18 @@ void Project::GetPieceInsertPosition(View* view, int MouseX, int MouseY, Vector3
|
||||||
lcVector3 ClickPoints[2] = { lcVector3((float)m_nDownX, (float)m_nDownY, 0.0f), lcVector3((float)m_nDownX, (float)m_nDownY, 1.0f) };
|
lcVector3 ClickPoints[2] = { lcVector3((float)m_nDownX, (float)m_nDownY, 0.0f), lcVector3((float)m_nDownX, (float)m_nDownY, 1.0f) };
|
||||||
lcUnprojectPoints(ClickPoints, 2, ModelView, Projection, Viewport);
|
lcUnprojectPoints(ClickPoints, 2, ModelView, Projection, Viewport);
|
||||||
|
|
||||||
Vector3 Intersection;
|
lcVector3 Intersection;
|
||||||
if (LinePlaneIntersection(Intersection, Vector3(ClickPoints[0]), Vector3(ClickPoints[1]), Vector4(0, 0, 1, 0)))
|
if (lcLinePlaneIntersection(Intersection, ClickPoints[0], ClickPoints[1], lcVector4(0, 0, 1, 0)))
|
||||||
{
|
{
|
||||||
SnapVector(Intersection);
|
SnapVector(Intersection);
|
||||||
Position = Intersection;
|
Position = Intersection;
|
||||||
Rotation = Vector4(0, 0, 1, 0);
|
Rotation = lcVector4(0, 0, 1, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Couldn't find a good position, so just place the piece somewhere near the camera.
|
// Couldn't find a good position, so just place the piece somewhere near the camera.
|
||||||
Position = Vector3(lcUnprojectPoint(lcVector3((float)m_nDownX, (float)m_nDownY, 0.9f), ModelView, Projection, Viewport));
|
Position = lcUnprojectPoint(lcVector3((float)m_nDownX, (float)m_nDownY, 0.9f), ModelView, Projection, Viewport);
|
||||||
Rotation = Vector4(0, 0, 1, 0);
|
Rotation = lcVector4(0, 0, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object* Project::FindObjectFromPoint(View* view, int x, int y, bool PiecesOnly)
|
Object* Project::FindObjectFromPoint(View* view, int x, int y, bool PiecesOnly)
|
||||||
|
@ -6615,7 +6612,7 @@ void Project::GetSnapDistanceText(char* SnapXY, char* SnapZ) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::SnapVector(Vector3& Delta, Vector3& Leftover) const
|
void Project::SnapVector(lcVector3& Delta, lcVector3& Leftover) const
|
||||||
{
|
{
|
||||||
float SnapXY, SnapZ;
|
float SnapXY, SnapZ;
|
||||||
GetSnapDistance(&SnapXY, &SnapZ);
|
GetSnapDistance(&SnapXY, &SnapZ);
|
||||||
|
@ -6678,7 +6675,7 @@ void Project::SnapVector(Vector3& Delta, Vector3& Leftover) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::SnapRotationVector(Vector3& Delta, Vector3& Leftover) const
|
void Project::SnapRotationVector(lcVector3& Delta, lcVector3& Leftover) const
|
||||||
{
|
{
|
||||||
if (m_nSnap & LC_DRAW_SNAP_A)
|
if (m_nSnap & LC_DRAW_SNAP_A)
|
||||||
{
|
{
|
||||||
|
@ -6689,13 +6686,13 @@ void Project::SnapRotationVector(Vector3& Delta, Vector3& Leftover) const
|
||||||
Snap[i] = (int)(Delta[i] / (float)m_nAngleSnap);
|
Snap[i] = (int)(Delta[i] / (float)m_nAngleSnap);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 NewDelta((float)(m_nAngleSnap * Snap[0]), (float)(m_nAngleSnap * Snap[1]), (float)(m_nAngleSnap * Snap[2]));
|
lcVector3 NewDelta((float)(m_nAngleSnap * Snap[0]), (float)(m_nAngleSnap * Snap[1]), (float)(m_nAngleSnap * Snap[2]));
|
||||||
Leftover = Delta - NewDelta;
|
Leftover = Delta - NewDelta;
|
||||||
Delta = NewDelta;
|
Delta = NewDelta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Project::MoveSelectedObjects(Vector3& Move, Vector3& Remainder, bool Snap)
|
bool Project::MoveSelectedObjects(lcVector3& Move, lcVector3& Remainder, bool Snap)
|
||||||
{
|
{
|
||||||
// Don't move along locked directions.
|
// Don't move along locked directions.
|
||||||
if (m_nSnap & LC_DRAW_LOCK_X)
|
if (m_nSnap & LC_DRAW_LOCK_X)
|
||||||
|
@ -6722,15 +6719,7 @@ bool Project::MoveSelectedObjects(Vector3& Move, Vector3& Remainder, bool Snap)
|
||||||
Object* Focus = GetFocusObject();
|
Object* Focus = GetFocusObject();
|
||||||
|
|
||||||
if ((Focus != NULL) && Focus->IsPiece())
|
if ((Focus != NULL) && Focus->IsPiece())
|
||||||
{
|
Move = lcMul30(Move, ((Piece*)Focus)->mModelWorld);
|
||||||
float Rot[4];
|
|
||||||
((Piece*)Focus)->GetRotation(Rot);
|
|
||||||
|
|
||||||
Matrix33 RotMat;
|
|
||||||
RotMat.CreateFromAxisAngle(Vector3(Rot[0], Rot[1], Rot[2]), Rot[3] * LC_DTOR);
|
|
||||||
|
|
||||||
Move = Mul(Move, RotMat);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Piece* pPiece;
|
Piece* pPiece;
|
||||||
|
@ -6770,7 +6759,7 @@ bool Project::MoveSelectedObjects(Vector3& Move, Vector3& Remainder, bool Snap)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Project::RotateSelectedObjects(Vector3& Delta, Vector3& Remainder)
|
bool Project::RotateSelectedObjects(lcVector3& Delta, lcVector3& Remainder)
|
||||||
{
|
{
|
||||||
// Don't move along locked directions.
|
// Don't move along locked directions.
|
||||||
if (m_nSnap & LC_DRAW_LOCK_X)
|
if (m_nSnap & LC_DRAW_LOCK_X)
|
||||||
|
@ -6789,7 +6778,8 @@ bool Project::RotateSelectedObjects(Vector3& Delta, Vector3& Remainder)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 };
|
float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 };
|
||||||
float pos[3], rot[4];
|
lcVector3 pos;
|
||||||
|
lcVector4 rot;
|
||||||
int nSel = 0;
|
int nSel = 0;
|
||||||
Piece *pPiece, *pFocus = NULL;
|
Piece *pPiece, *pFocus = NULL;
|
||||||
|
|
||||||
|
@ -6807,7 +6797,7 @@ bool Project::RotateSelectedObjects(Vector3& Delta, Vector3& Remainder)
|
||||||
|
|
||||||
if (pFocus != NULL)
|
if (pFocus != NULL)
|
||||||
{
|
{
|
||||||
pFocus->GetPosition(pos);
|
pos = pFocus->mPosition;
|
||||||
bs[0] = bs[3] = pos[0];
|
bs[0] = bs[3] = pos[0];
|
||||||
bs[1] = bs[4] = pos[1];
|
bs[1] = bs[4] = pos[1];
|
||||||
bs[2] = bs[5] = pos[2];
|
bs[2] = bs[5] = pos[2];
|
||||||
|
@ -6846,8 +6836,8 @@ bool Project::RotateSelectedObjects(Vector3& Delta, Vector3& Remainder)
|
||||||
|
|
||||||
if (pFocus != NULL)
|
if (pFocus != NULL)
|
||||||
{
|
{
|
||||||
float Rot[4];
|
lcVector4 Rot;
|
||||||
((Piece*)pFocus)->GetRotation(Rot);
|
Rot = ((Piece*)pFocus)->mRotation;
|
||||||
|
|
||||||
WorldToFocus.FromAxisAngle(Vector4(Rot[0], Rot[1], Rot[2], -Rot[3] * LC_DTOR));
|
WorldToFocus.FromAxisAngle(Vector4(Rot[0], Rot[1], Rot[2], -Rot[3] * LC_DTOR));
|
||||||
FocusToWorld.FromAxisAngle(Vector4(Rot[0], Rot[1], Rot[2], Rot[3] * LC_DTOR));
|
FocusToWorld.FromAxisAngle(Vector4(Rot[0], Rot[1], Rot[2], Rot[3] * LC_DTOR));
|
||||||
|
@ -6860,8 +6850,8 @@ bool Project::RotateSelectedObjects(Vector3& Delta, Vector3& Remainder)
|
||||||
if (!pPiece->IsSelected())
|
if (!pPiece->IsSelected())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pPiece->GetPosition(pos);
|
pos = pPiece->mPosition;
|
||||||
pPiece->GetRotation(rot);
|
rot = pPiece->mRotation;
|
||||||
|
|
||||||
Vector4 NewRotation;
|
Vector4 NewRotation;
|
||||||
|
|
||||||
|
@ -7271,13 +7261,13 @@ bool Project::OnKeyDown(char nKey, bool bControl, bool bShift)
|
||||||
|
|
||||||
if (bShift)
|
if (bShift)
|
||||||
{
|
{
|
||||||
Vector3 tmp;
|
lcVector3 tmp;
|
||||||
RotateSelectedObjects(Vector3(axis), tmp);
|
RotateSelectedObjects(axis, tmp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Vector3 tmp;
|
lcVector3 tmp;
|
||||||
MoveSelectedObjects(Vector3(axis), tmp, false);
|
MoveSelectedObjects(axis, tmp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateOverlayScale();
|
UpdateOverlayScale();
|
||||||
|
@ -7323,8 +7313,8 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
|
||||||
m_bTrackCancel = false;
|
m_bTrackCancel = false;
|
||||||
m_nDownX = x;
|
m_nDownX = x;
|
||||||
m_nDownY = y;
|
m_nDownY = y;
|
||||||
m_MouseTotalDelta = Vector3(0, 0, 0);
|
m_MouseTotalDelta = lcVector3(0, 0, 0);
|
||||||
m_MouseSnapLeftover = Vector3(0, 0, 0);
|
m_MouseSnapLeftover = lcVector3(0, 0, 0);
|
||||||
|
|
||||||
int Viewport[4] = { 0, 0, view->GetWidth(), view->GetHeight() };
|
int Viewport[4] = { 0, 0, view->GetWidth(), view->GetHeight() };
|
||||||
float Aspect = (float)Viewport[2]/(float)Viewport[3];
|
float Aspect = (float)Viewport[2]/(float)Viewport[3];
|
||||||
|
@ -7475,8 +7465,8 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
|
||||||
{
|
{
|
||||||
if (m_nCurAction == LC_ACTION_INSERT)
|
if (m_nCurAction == LC_ACTION_INSERT)
|
||||||
{
|
{
|
||||||
Vector3 Pos;
|
lcVector3 Pos;
|
||||||
Vector4 Rot;
|
lcVector4 Rot;
|
||||||
|
|
||||||
GetPieceInsertPosition(view, x, y, Pos, Rot);
|
GetPieceInsertPosition(view, x, y, Pos, Rot);
|
||||||
|
|
||||||
|
@ -7609,7 +7599,7 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
|
||||||
{
|
{
|
||||||
StartTracking(LC_TRACK_START_LEFT);
|
StartTracking(LC_TRACK_START_LEFT);
|
||||||
m_OverlayDelta = lcVector3(0.0f, 0.0f, 0.0f);
|
m_OverlayDelta = lcVector3(0.0f, 0.0f, 0.0f);
|
||||||
m_MouseSnapLeftover = Vector3(0.0f, 0.0f, 0.0f);
|
m_MouseSnapLeftover = lcVector3(0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
@ -7706,8 +7696,8 @@ void Project::OnLeftButtonUp(View* view, int x, int y, bool bControl, bool bShif
|
||||||
{
|
{
|
||||||
if ((x > 0) && (x < view->GetWidth()) && (y > 0) && (y < view->GetHeight()))
|
if ((x > 0) && (x < view->GetWidth()) && (y > 0) && (y < view->GetHeight()))
|
||||||
{
|
{
|
||||||
Vector3 Pos;
|
lcVector3 Pos;
|
||||||
Vector4 Rot;
|
lcVector4 Rot;
|
||||||
|
|
||||||
GetPieceInsertPosition(view, x, y, Pos, Rot);
|
GetPieceInsertPosition(view, x, y, Pos, Rot);
|
||||||
|
|
||||||
|
@ -7988,10 +7978,9 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
|
|
||||||
if ((m_OverlayActive && (m_OverlayMode != LC_OVERLAY_XYZ)) || (!Camera->IsSide()))
|
if ((m_OverlayActive && (m_OverlayMode != LC_OVERLAY_XYZ)) || (!Camera->IsSide()))
|
||||||
{
|
{
|
||||||
Vector3 ScreenX = Cross3(Vector3(Camera->mTargetPosition) - Vector3(Camera->mPosition), Vector3(Camera->mUpVector));
|
lcVector3 ScreenX = lcNormalize(lcCross(Camera->mTargetPosition - Camera->mPosition, Camera->mUpVector));
|
||||||
Vector3 ScreenY = Vector3(Camera->mUpVector);
|
lcVector3 ScreenY = Camera->mUpVector;
|
||||||
ScreenX.Normalize();
|
lcVector3 Dir1, Dir2;
|
||||||
Vector3 Dir1, Dir2;
|
|
||||||
bool SingleDir = true;
|
bool SingleDir = true;
|
||||||
|
|
||||||
int OverlayMode;
|
int OverlayMode;
|
||||||
|
@ -8006,34 +7995,34 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
switch (OverlayMode)
|
switch (OverlayMode)
|
||||||
{
|
{
|
||||||
case LC_OVERLAY_X:
|
case LC_OVERLAY_X:
|
||||||
Dir1 = Vector3(1, 0, 0);
|
Dir1 = lcVector3(1, 0, 0);
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_Y:
|
case LC_OVERLAY_Y:
|
||||||
Dir1 = Vector3(0, 1, 0);
|
Dir1 = lcVector3(0, 1, 0);
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_Z:
|
case LC_OVERLAY_Z:
|
||||||
Dir1 = Vector3(0, 0, 1);
|
Dir1 = lcVector3(0, 0, 1);
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_XY:
|
case LC_OVERLAY_XY:
|
||||||
Dir1 = Vector3(1, 0, 0);
|
Dir1 = lcVector3(1, 0, 0);
|
||||||
Dir2 = Vector3(0, 1, 0);
|
Dir2 = lcVector3(0, 1, 0);
|
||||||
SingleDir = false;
|
SingleDir = false;
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_XZ:
|
case LC_OVERLAY_XZ:
|
||||||
Dir1 = Vector3(1, 0, 0);
|
Dir1 = lcVector3(1, 0, 0);
|
||||||
Dir2 = Vector3(0, 0, 1);
|
Dir2 = lcVector3(0, 0, 1);
|
||||||
SingleDir = false;
|
SingleDir = false;
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_YZ:
|
case LC_OVERLAY_YZ:
|
||||||
Dir1 = Vector3(0, 1, 0);
|
Dir1 = lcVector3(0, 1, 0);
|
||||||
Dir2 = Vector3(0, 0, 1);
|
Dir2 = lcVector3(0, 0, 1);
|
||||||
SingleDir = false;
|
SingleDir = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform the translation axis.
|
// Transform the translation axis.
|
||||||
Vector3 Axis1 = Dir1;
|
lcVector3 Axis1 = Dir1;
|
||||||
Vector3 Axis2 = Dir2;
|
lcVector3 Axis2 = Dir2;
|
||||||
|
|
||||||
if ((m_nSnap & LC_DRAW_GLOBAL_SNAP) == 0)
|
if ((m_nSnap & LC_DRAW_GLOBAL_SNAP) == 0)
|
||||||
{
|
{
|
||||||
|
@ -8041,24 +8030,20 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
|
|
||||||
if ((Focus != NULL) && Focus->IsPiece())
|
if ((Focus != NULL) && Focus->IsPiece())
|
||||||
{
|
{
|
||||||
float Rot[4];
|
const lcMatrix44& ModelWorld = ((Piece*)Focus)->mModelWorld;
|
||||||
((Piece*)Focus)->GetRotation(Rot);
|
|
||||||
|
|
||||||
Matrix33 RotMat;
|
Axis1 = lcMul30(Dir1, ModelWorld);
|
||||||
RotMat.CreateFromAxisAngle(Vector3(Rot[0], Rot[1], Rot[2]), Rot[3] * LC_DTOR);
|
Axis2 = lcMul30(Dir2, ModelWorld);
|
||||||
|
|
||||||
Axis1 = Mul(Dir1, RotMat);
|
|
||||||
Axis2 = Mul(Dir2, RotMat);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out what direction the mouse is going to move stuff.
|
// Find out what direction the mouse is going to move stuff.
|
||||||
Vector3 MoveX, MoveY;
|
lcVector3 MoveX, MoveY;
|
||||||
|
|
||||||
if (SingleDir)
|
if (SingleDir)
|
||||||
{
|
{
|
||||||
float dx1 = Dot3(ScreenX, Axis1);
|
float dx1 = lcDot(ScreenX, Axis1);
|
||||||
float dy1 = Dot3(ScreenY, Axis1);
|
float dy1 = lcDot(ScreenY, Axis1);
|
||||||
|
|
||||||
if (fabsf(dx1) > fabsf(dy1))
|
if (fabsf(dx1) > fabsf(dy1))
|
||||||
{
|
{
|
||||||
|
@ -8067,11 +8052,11 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
else
|
else
|
||||||
MoveX = -Dir1;
|
MoveX = -Dir1;
|
||||||
|
|
||||||
MoveY = Vector3(0, 0, 0);
|
MoveY = lcVector3(0, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MoveX = Vector3(0, 0, 0);
|
MoveX = lcVector3(0, 0, 0);
|
||||||
|
|
||||||
if (dy1 > 0.0f)
|
if (dy1 > 0.0f)
|
||||||
MoveY = Dir1;
|
MoveY = Dir1;
|
||||||
|
@ -8081,10 +8066,10 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float dx1 = Dot3(ScreenX, Axis1);
|
float dx1 = lcDot(ScreenX, Axis1);
|
||||||
float dy1 = Dot3(ScreenY, Axis1);
|
float dy1 = lcDot(ScreenY, Axis1);
|
||||||
float dx2 = Dot3(ScreenX, Axis2);
|
float dx2 = lcDot(ScreenX, Axis2);
|
||||||
float dy2 = Dot3(ScreenY, Axis2);
|
float dy2 = lcDot(ScreenY, Axis2);
|
||||||
|
|
||||||
if (fabsf(dx1) > fabsf(dx2))
|
if (fabsf(dx1) > fabsf(dx2))
|
||||||
{
|
{
|
||||||
|
@ -8118,22 +8103,22 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
m_nDownX = x;
|
m_nDownX = x;
|
||||||
m_nDownY = y;
|
m_nDownY = y;
|
||||||
|
|
||||||
Vector3 Delta = MoveX + MoveY + m_MouseSnapLeftover;
|
lcVector3 Delta = MoveX + MoveY + m_MouseSnapLeftover;
|
||||||
Redraw = MoveSelectedObjects(Delta, m_MouseSnapLeftover, true);
|
Redraw = MoveSelectedObjects(Delta, m_MouseSnapLeftover, true);
|
||||||
m_MouseTotalDelta += Delta;
|
m_MouseTotalDelta += Delta;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 3D movement.
|
// 3D movement.
|
||||||
Vector3 ScreenZ = (Vector3(Camera->mTargetPosition) - Vector3(Camera->mPosition)).Normalize();
|
lcVector3 ScreenZ = lcNormalize(Camera->mTargetPosition - Camera->mPosition);
|
||||||
Vector3 ScreenX = Cross3(ScreenZ, Vector3(Camera->mUpVector));
|
lcVector3 ScreenX = lcCross(ScreenZ, Camera->mUpVector);
|
||||||
Vector3 ScreenY = Vector3(Camera->mUpVector);
|
lcVector3 ScreenY = Camera->mUpVector;
|
||||||
|
|
||||||
Vector3 TotalMove;
|
lcVector3 TotalMove;
|
||||||
|
|
||||||
if (m_nTracking == LC_TRACK_LEFT)
|
if (m_nTracking == LC_TRACK_LEFT)
|
||||||
{
|
{
|
||||||
Vector3 MoveX, MoveY;
|
lcVector3 MoveX, MoveY;
|
||||||
|
|
||||||
MoveX = ScreenX * (float)(x - m_nDownX) * 0.25f / (float)(21 - m_nMouse);
|
MoveX = ScreenX * (float)(x - m_nDownX) * 0.25f / (float)(21 - m_nMouse);
|
||||||
MoveY = ScreenY * (float)(y - m_nDownY) * 0.25f / (float)(21 - m_nMouse);
|
MoveY = ScreenY * (float)(y - m_nDownY) * 0.25f / (float)(21 - m_nMouse);
|
||||||
|
@ -8142,7 +8127,7 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Vector3 MoveZ;
|
lcVector3 MoveZ;
|
||||||
|
|
||||||
MoveZ = ScreenZ * (float)(y - m_nDownY) * 0.25f / (float)(21 - m_nMouse);
|
MoveZ = ScreenZ * (float)(y - m_nDownY) * 0.25f / (float)(21 - m_nMouse);
|
||||||
|
|
||||||
|
@ -8167,10 +8152,9 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
|
|
||||||
if ((m_OverlayActive && (m_OverlayMode != LC_OVERLAY_XYZ)) || (!Camera->IsSide()))
|
if ((m_OverlayActive && (m_OverlayMode != LC_OVERLAY_XYZ)) || (!Camera->IsSide()))
|
||||||
{
|
{
|
||||||
Vector3 ScreenX = Cross3(Vector3(Camera->mTargetPosition) - Vector3(Camera->mPosition), Vector3(Camera->mUpVector));
|
lcVector3 ScreenX = lcNormalize(lcCross(Camera->mTargetPosition - Camera->mPosition, Camera->mUpVector));
|
||||||
Vector3 ScreenY = Vector3(Camera->mUpVector);
|
lcVector3 ScreenY = Camera->mUpVector;
|
||||||
ScreenX.Normalize();
|
lcVector3 Dir1, Dir2;
|
||||||
Vector3 Dir1, Dir2;
|
|
||||||
bool SingleDir = true;
|
bool SingleDir = true;
|
||||||
|
|
||||||
int OverlayMode;
|
int OverlayMode;
|
||||||
|
@ -8185,38 +8169,38 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
switch (OverlayMode)
|
switch (OverlayMode)
|
||||||
{
|
{
|
||||||
case LC_OVERLAY_X:
|
case LC_OVERLAY_X:
|
||||||
Dir1 = Vector3(1, 0, 0);
|
Dir1 = lcVector3(1, 0, 0);
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_Y:
|
case LC_OVERLAY_Y:
|
||||||
Dir1 = Vector3(0, 1, 0);
|
Dir1 = lcVector3(0, 1, 0);
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_Z:
|
case LC_OVERLAY_Z:
|
||||||
Dir1 = Vector3(0, 0, 1);
|
Dir1 = lcVector3(0, 0, 1);
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_XY:
|
case LC_OVERLAY_XY:
|
||||||
Dir1 = Vector3(1, 0, 0);
|
Dir1 = lcVector3(1, 0, 0);
|
||||||
Dir2 = Vector3(0, 1, 0);
|
Dir2 = lcVector3(0, 1, 0);
|
||||||
SingleDir = false;
|
SingleDir = false;
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_XZ:
|
case LC_OVERLAY_XZ:
|
||||||
Dir1 = Vector3(1, 0, 0);
|
Dir1 = lcVector3(1, 0, 0);
|
||||||
Dir2 = Vector3(0, 0, 1);
|
Dir2 = lcVector3(0, 0, 1);
|
||||||
SingleDir = false;
|
SingleDir = false;
|
||||||
break;
|
break;
|
||||||
case LC_OVERLAY_YZ:
|
case LC_OVERLAY_YZ:
|
||||||
Dir1 = Vector3(0, 1, 0);
|
Dir1 = lcVector3(0, 1, 0);
|
||||||
Dir2 = Vector3(0, 0, 1);
|
Dir2 = lcVector3(0, 0, 1);
|
||||||
SingleDir = false;
|
SingleDir = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find out what direction the mouse is going to move stuff.
|
// Find out what direction the mouse is going to move stuff.
|
||||||
Vector3 MoveX, MoveY;
|
lcVector3 MoveX, MoveY;
|
||||||
|
|
||||||
if (SingleDir)
|
if (SingleDir)
|
||||||
{
|
{
|
||||||
float dx1 = Dot3(ScreenX, Dir1);
|
float dx1 = lcDot(ScreenX, Dir1);
|
||||||
float dy1 = Dot3(ScreenY, Dir1);
|
float dy1 = lcDot(ScreenY, Dir1);
|
||||||
|
|
||||||
if (fabsf(dx1) > fabsf(dy1))
|
if (fabsf(dx1) > fabsf(dy1))
|
||||||
{
|
{
|
||||||
|
@ -8225,11 +8209,11 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
else
|
else
|
||||||
MoveX = -Dir1;
|
MoveX = -Dir1;
|
||||||
|
|
||||||
MoveY = Vector3(0, 0, 0);
|
MoveY = lcVector3(0, 0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MoveX = Vector3(0, 0, 0);
|
MoveX = lcVector3(0, 0, 0);
|
||||||
|
|
||||||
if (dy1 > 0.0f)
|
if (dy1 > 0.0f)
|
||||||
MoveY = Dir1;
|
MoveY = Dir1;
|
||||||
|
@ -8239,10 +8223,10 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
float dx1 = Dot3(ScreenX, Dir1);
|
float dx1 = lcDot(ScreenX, Dir1);
|
||||||
float dy1 = Dot3(ScreenY, Dir1);
|
float dy1 = lcDot(ScreenY, Dir1);
|
||||||
float dx2 = Dot3(ScreenX, Dir2);
|
float dx2 = lcDot(ScreenX, Dir2);
|
||||||
float dy2 = Dot3(ScreenY, Dir2);
|
float dy2 = lcDot(ScreenY, Dir2);
|
||||||
|
|
||||||
if (fabsf(dx1) > fabsf(dx2))
|
if (fabsf(dx1) > fabsf(dx2))
|
||||||
{
|
{
|
||||||
|
@ -8276,22 +8260,22 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
m_nDownX = x;
|
m_nDownX = x;
|
||||||
m_nDownY = y;
|
m_nDownY = y;
|
||||||
|
|
||||||
Vector3 Delta = MoveX + MoveY + m_MouseSnapLeftover;
|
lcVector3 Delta = MoveX + MoveY + m_MouseSnapLeftover;
|
||||||
Redraw = RotateSelectedObjects(Delta, m_MouseSnapLeftover);
|
Redraw = RotateSelectedObjects(Delta, m_MouseSnapLeftover);
|
||||||
m_MouseTotalDelta += Delta;
|
m_MouseTotalDelta += Delta;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 3D movement.
|
// 3D movement.
|
||||||
Vector3 ScreenZ = (Vector3(Camera->mTargetPosition) - Vector3(Camera->mPosition)).Normalize();
|
lcVector3 ScreenZ = lcNormalize(Camera->mTargetPosition - Camera->mPosition);
|
||||||
Vector3 ScreenX = Cross3(ScreenZ, Vector3(Camera->mUpVector));
|
lcVector3 ScreenX = lcCross(ScreenZ, Camera->mUpVector);
|
||||||
Vector3 ScreenY = Vector3(Camera->mUpVector);
|
lcVector3 ScreenY = Camera->mUpVector;
|
||||||
|
|
||||||
Vector3 Delta;
|
lcVector3 Delta;
|
||||||
|
|
||||||
if (m_nTracking == LC_TRACK_LEFT)
|
if (m_nTracking == LC_TRACK_LEFT)
|
||||||
{
|
{
|
||||||
Vector3 MoveX, MoveY;
|
lcVector3 MoveX, MoveY;
|
||||||
|
|
||||||
MoveX = ScreenX * (float)(x - m_nDownX) * 36.0f / (float)(21 - m_nMouse);
|
MoveX = ScreenX * (float)(x - m_nDownX) * 36.0f / (float)(21 - m_nMouse);
|
||||||
MoveY = ScreenY * (float)(y - m_nDownY) * 36.0f / (float)(21 - m_nMouse);
|
MoveY = ScreenY * (float)(y - m_nDownY) * 36.0f / (float)(21 - m_nMouse);
|
||||||
|
@ -8300,7 +8284,7 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Vector3 MoveZ;
|
lcVector3 MoveZ;
|
||||||
|
|
||||||
MoveZ = ScreenZ * (float)(y - m_nDownY) * 36.0f / (float)(21 - m_nMouse);
|
MoveZ = ScreenZ * (float)(y - m_nDownY) * 36.0f / (float)(21 - m_nMouse);
|
||||||
|
|
||||||
|
|
|
@ -178,23 +178,23 @@ protected:
|
||||||
void AddPiece(Piece* pPiece);
|
void AddPiece(Piece* pPiece);
|
||||||
void RemovePiece(Piece* pPiece);
|
void RemovePiece(Piece* pPiece);
|
||||||
bool RemoveSelectedObjects();
|
bool RemoveSelectedObjects();
|
||||||
void GetPieceInsertPosition(Piece* OffsetPiece, Vector3& Position, Vector4& Rotation);
|
void GetPieceInsertPosition(Piece* OffsetPiece, lcVector3& Position, lcVector4& Rotation);
|
||||||
void GetPieceInsertPosition(View* view, int MouseX, int MouseY, Vector3& Position, Vector4& Orientation);
|
void GetPieceInsertPosition(View* view, int MouseX, int MouseY, lcVector3& Position, lcVector4& Orientation);
|
||||||
Object* FindObjectFromPoint(View* view, int x, int y, bool PiecesOnly = false);
|
Object* FindObjectFromPoint(View* view, int x, int y, bool PiecesOnly = false);
|
||||||
void FindObjectsInBox(float x1, float y1, float x2, float y2, PtrArray<Object>& Objects);
|
void FindObjectsInBox(float x1, float y1, float x2, float y2, PtrArray<Object>& Objects);
|
||||||
void SelectAndFocusNone(bool bFocusOnly);
|
void SelectAndFocusNone(bool bFocusOnly);
|
||||||
void CalculateStep();
|
void CalculateStep();
|
||||||
|
|
||||||
// Movement.
|
// Movement.
|
||||||
bool MoveSelectedObjects(Vector3& Move, Vector3& Remainder, bool Snap);
|
bool MoveSelectedObjects(lcVector3& Move, lcVector3& Remainder, bool Snap);
|
||||||
bool RotateSelectedObjects(Vector3& Delta, Vector3& Remainder);
|
bool RotateSelectedObjects(lcVector3& Delta, lcVector3& Remainder);
|
||||||
void SnapVector(Vector3& Delta) const
|
void SnapVector(lcVector3& Delta) const
|
||||||
{
|
{
|
||||||
Vector3 Dummy;
|
lcVector3 Dummy;
|
||||||
SnapVector(Delta, Dummy);
|
SnapVector(Delta, Dummy);
|
||||||
}
|
}
|
||||||
void SnapVector(Vector3& Delta, Vector3& Leftover) const;
|
void SnapVector(lcVector3& Delta, lcVector3& Leftover) const;
|
||||||
void SnapRotationVector(Vector3& Delta, Vector3& Leftover) const;
|
void SnapRotationVector(lcVector3& Delta, lcVector3& Leftover) const;
|
||||||
|
|
||||||
// Rendering functions.
|
// Rendering functions.
|
||||||
void RenderBackground(View* view);
|
void RenderBackground(View* view);
|
||||||
|
@ -215,8 +215,8 @@ protected:
|
||||||
int m_nDownY;
|
int m_nDownY;
|
||||||
float m_fTrack[3];
|
float m_fTrack[3];
|
||||||
int m_nMouse;
|
int m_nMouse;
|
||||||
Vector3 m_MouseSnapLeftover;
|
lcVector3 m_MouseSnapLeftover;
|
||||||
Vector3 m_MouseTotalDelta;
|
lcVector3 m_MouseTotalDelta;
|
||||||
|
|
||||||
int m_OverlayMode;
|
int m_OverlayMode;
|
||||||
bool m_OverlayActive;
|
bool m_OverlayActive;
|
||||||
|
|
|
@ -10,7 +10,6 @@ class PieceInfo;
|
||||||
class Camera;
|
class Camera;
|
||||||
|
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "algebra.h"
|
|
||||||
#include "lc_math.h"
|
#include "lc_math.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|
|
@ -203,10 +203,9 @@ void CPropertiesPane::SetPiece(Object* Focus)
|
||||||
m_wndPropList.AddProperty(Appearence);
|
m_wndPropList.AddProperty(Appearence);
|
||||||
}
|
}
|
||||||
|
|
||||||
float Rot[4];
|
|
||||||
Piece* pPiece = (Piece*)Focus;
|
Piece* pPiece = (Piece*)Focus;
|
||||||
lcVector3 Pos = pPiece->mPosition;
|
lcVector3 Pos = pPiece->mPosition;
|
||||||
pPiece->GetRotation(Rot);
|
lcVector4 Rot = pPiece->mRotation;
|
||||||
Matrix mat(Rot, Pos);
|
Matrix mat(Rot, Pos);
|
||||||
mat.ToEulerAngles(Rot);
|
mat.ToEulerAngles(Rot);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue