summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/algebra.h3
-rw-r--r--common/piece.h2
-rw-r--r--common/project.cpp84
-rw-r--r--common/project.h8
-rw-r--r--common/typedefs.h16
5 files changed, 58 insertions, 55 deletions
diff --git a/common/algebra.h b/common/algebra.h
index 826fe7a..4a34b36 100644
--- a/common/algebra.h
+++ b/common/algebra.h
@@ -299,6 +299,9 @@ public:
friend inline Vector3 operator*=(Vector3& a, float b)
{ a.m_Value = a.m_Value * b; return a; }
+ friend inline Vector3 operator/=(Vector3& a, float b)
+ { a.m_Value = a.m_Value / b; return a; }
+
// Other functions.
inline float Length() const
{ return m_Value.Length3(); }
diff --git a/common/piece.h b/common/piece.h
index 91dfc74..6304681 100644
--- a/common/piece.h
+++ b/common/piece.h
@@ -100,6 +100,8 @@ public:
{ return m_nFrameHide; }
const float* GetConstPosition()
{ return m_fPosition; }
+ inline Vector3 GetPosition() const
+ { return Vector3(m_fPosition[0], m_fPosition[1], m_fPosition[2]); }
void GetPosition (float* position)
{ memcpy(position, m_fPosition, sizeof(m_fPosition)); }
void GetRotation (float* rotation)
diff --git a/common/project.cpp b/common/project.cpp
index 36f109b..2426cd5 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -3496,18 +3496,18 @@ void Project::HandleNotify(LC_NOTIFY id, unsigned long param)
LC_PIECE_MODIFY* mod = (LC_PIECE_MODIFY*)param;
Piece* pPiece = (Piece*)mod->piece;
- float pos[3], rot[4];
- pPiece->GetPosition(pos);
+ float rot[4];
+ Vector3 Pos = pPiece->GetPosition();
pPiece->GetRotation(rot);
- Matrix mat(rot, pos);
+ Matrix mat(rot, Pos);
mat.ToEulerAngles(rot);
- if (mod->pos[0] != pos[0] || mod->pos[1] != pos[1] || mod->pos[2] != pos[2])
- pPiece->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, mod->pos, LC_PK_POSITION);
+ if (Pos != mod->Position)
+ pPiece->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, mod->Position, LC_PK_POSITION);
- if (mod->rot[0] != rot[0] || mod->rot[1] != rot[1] || mod->rot[2] != rot[2])
+ if (mod->Rotation[0] != rot[0] || mod->Rotation[1] != rot[1] || mod->Rotation[2] != rot[2])
{
- mat.FromEulerAngles (mod->rot[0], mod->rot[1], mod->rot[2]);
+ mat.FromEulerAngles(mod->Rotation[0], mod->Rotation[1], mod->Rotation[2]);
mat.ToAxisAngle(rot);
pPiece->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, rot, LC_PK_ROTATION);
}
@@ -3543,21 +3543,20 @@ void Project::HandleNotify(LC_NOTIFY id, unsigned long param)
{
LC_CAMERA_MODIFY* mod = (LC_CAMERA_MODIFY*)param;
Camera* pCamera = (Camera*)mod->camera;
- float tmp[3];
if (mod->hidden)
pCamera->Hide();
else
pCamera->UnHide();
- pCamera->GetUpVec(tmp);
+ if (pCamera->GetEyePosition() != mod->Eye)
+ pCamera->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, mod->Eye, LC_CK_EYE);
+
+ if (pCamera->GetTargetPosition() != mod->Target)
+ pCamera->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, mod->Target, LC_CK_TARGET);
- if (tmp[0] != mod->eye[0] || tmp[1] != mod->eye[1] || tmp[2] != mod->eye[2])
- pCamera->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, mod->eye, LC_CK_EYE);
- if (tmp[0] != mod->target[0] || tmp[1] != mod->target[1] || tmp[2] != mod->target[2])
- pCamera->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, mod->target, LC_CK_TARGET);
- if (tmp[0] != mod->up[0] || tmp[1] != mod->up[1] || tmp[2] != mod->up[2])
- pCamera->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, mod->up, LC_CK_UP);
+ if (pCamera->GetUpVector() != mod->Up)
+ pCamera->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, mod->Up, LC_CK_UP);
pCamera->m_fovy = mod->fovy;
pCamera->m_zNear = mod->znear;
@@ -6513,54 +6512,51 @@ void Project::GetActiveViewportMatrices(Matrix44& ModelView, Matrix44& Projectio
Projection.CreatePerspective(Cam->m_fovy, Aspect, Cam->m_zNear, Cam->m_zFar);
}
-void Project::GetFocusPosition(float* pos)
+void Project::ConvertToUserUnits(Vector3& Value) const
+{
+ if ((m_nSnap & LC_DRAW_CM_UNITS) == 0)
+ Value /= 0.08f;
+}
+
+void Project::ConvertFromUserUnits(Vector3& Value) const
+{
+ if ((m_nSnap & LC_DRAW_CM_UNITS) == 0)
+ Value *= 0.08f;
+}
+
+bool Project::GetFocusPosition(Vector3& Position) const
{
Piece* pPiece;
Camera* pCamera;
+ float* pos = &Position[0];
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
if (pPiece->IsFocused())
{
pPiece->GetPosition(pos);
- if ((m_nSnap & LC_DRAW_CM_UNITS) == 0)
- {
- pos[0] /= 0.08f;
- pos[1] /= 0.08f;
- pos[2] /= 0.08f;
- }
- return;
+ return true;
}
for (pCamera = m_pCameras; pCamera; pCamera = pCamera->m_pNext)
{
if (pCamera->IsEyeFocused())
{
- pCamera->GetEyePos (pos);
- if ((m_nSnap & LC_DRAW_CM_UNITS) == 0)
- {
- pos[0] /= 0.08f;
- pos[1] /= 0.08f;
- pos[2] /= 0.08f;
- }
- return;
+ pCamera->GetEyePos(pos);
+ return true;
}
if (pCamera->IsTargetFocused())
{
- pCamera->GetTargetPos (pos);
- if ((m_nSnap & LC_DRAW_CM_UNITS) == 0)
- {
- pos[0] /= 0.08f;
- pos[1] /= 0.08f;
- pos[2] /= 0.08f;
- }
- return;
+ pCamera->GetTargetPos(pos);
+ return true;
}
}
// TODO: light
pos[0] = pos[1] = pos[2] = 0.0f;
+
+ return false;
}
// Returns the object that currently has focus.
@@ -8897,16 +8893,16 @@ void Project::MouseUpdateOverlays(int x, int y)
}
}
- for (int i = 1; i < 4; i++)
+ int i, Mode = -1;
+ Vector3 Pt((float)x, (float)y, 0);
+
+ for (i = 1; i < 4; i++)
Points[i] += Points[0];
ProjectPoints(Points, 4, ModelView, Projection, Viewport);
- int Mode = -1;
- Vector3 Pt((float)x, (float)y, 0);
-
// Check if the mouse is over an arrow.
- for (int i = 1; i < 4; i++)
+ for (i = 1; i < 4; i++)
{
Vector3 Line = Points[i] - Points[0];
Vector3 Vec = Pt - Points[0];
diff --git a/common/project.h b/common/project.h
index 870bfce..dd495c6 100644
--- a/common/project.h
+++ b/common/project.h
@@ -73,8 +73,6 @@ public:
{ m_bAnimation = Anim; } // only to be called from lcApplication::Initialize()
unsigned short GetCurrentTime ()
{ return m_bAnimation ? m_nCurFrame : m_nCurStep; }
- unsigned long GetSnapFlags() const
- { return m_nSnap; }
void SetCurrentPiece(PieceInfo* pInfo)
{ m_pCurPiece = pInfo; }
int GetCurrentColor () const
@@ -96,6 +94,8 @@ public:
unsigned short GetTotalFrames () const
{ return m_nTotalFrames; }
+ void ConvertToUserUnits(Vector3& Value) const;
+ void ConvertFromUserUnits(Vector3& Value) const;
void GetArrays(Piece** ppPiece, Camera** ppCamera, Light** ppLight)
{
*ppPiece = m_pPieces;
@@ -116,7 +116,8 @@ public:
void Render(bool bToMemory);
void SetViewSize(int cx, int cy);
void CheckAutoSave();
- void GetFocusPosition(float* pos);
+ bool GetSelectionCenter(Vector3& Center) const;
+ bool GetFocusPosition(Vector3& Position) const;
Object* GetFocusObject() const;
Group* AddGroup (const char* name, Group* pParent, float x, float y, float z);
@@ -166,7 +167,6 @@ protected:
void FindObjectFromPoint(int x, int y, LC_CLICKLINE* pLine, bool PiecesOnly = false);
void FindObjectsInBox(float x1, float y1, float x2, float y2, PtrArray<Object>& Objects);
void SelectAndFocusNone(bool bFocusOnly);
- bool GetSelectionCenter(Vector3& Center) const;
void GetActiveViewportMatrices(Matrix44& ModelView, Matrix44& Projection, int Viewport[4]);
void CalculateStep();
diff --git a/common/typedefs.h b/common/typedefs.h
index a12882c..ce68b1f 100644
--- a/common/typedefs.h
+++ b/common/typedefs.h
@@ -7,9 +7,11 @@
class Group;
class Piece;
class PieceInfo;
+class Camera;
#include "defines.h"
#include "str.h"
+#include "algebra.h"
typedef enum
{
@@ -225,10 +227,10 @@ typedef struct
typedef struct
{
- void* piece;
+ Piece* piece;
+ Vector3 Position;
+ Vector3 Rotation;
char name[81];
- float pos[3];
- float rot[3];
int from;
int to;
bool hidden;
@@ -237,11 +239,11 @@ typedef struct
typedef struct
{
- void* camera;
+ Camera* camera;
+ Vector3 Eye;
+ Vector3 Target;
+ Vector3 Up;
char name[81];
- float eye[3];
- float target[3];
- float up[3];
float fovy;
float znear;
float zfar;