summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/camera.cpp1783
-rw-r--r--common/camera.h157
-rw-r--r--common/light.cpp18
-rw-r--r--common/light.h36
-rw-r--r--common/piece.cpp17
-rw-r--r--common/piece.h11
-rw-r--r--common/project.cpp561
-rw-r--r--common/project.h15
-rw-r--r--common/terrain.cpp17
9 files changed, 1345 insertions, 1270 deletions
diff --git a/common/camera.cpp b/common/camera.cpp
index 34893e8..1fbf576 100644
--- a/common/camera.cpp
+++ b/common/camera.cpp
@@ -1,18 +1,14 @@
// Camera object.
-#ifdef LC_WINDOWS
-#include "stdafx.h"
-#endif
-#include "GL/glu.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
+#include "opengl.h"
#include "globals.h"
#include "defines.h"
#include "vector.h"
#include "matrix.h"
#include "file.h"
-#include "boundbox.h"
#include "camera.h"
#include "tr.h"
@@ -21,292 +17,327 @@
static GLuint _nTargetList = 0;
-static CAMERA_KEY* AddNode (CAMERA_KEY *node, unsigned short nTime, unsigned char nType)
+static LC_CAMERA_KEY* AddNode (LC_CAMERA_KEY *node, unsigned short nTime, unsigned char nType)
{
- CAMERA_KEY* newnode = (CAMERA_KEY*)malloc(sizeof(CAMERA_KEY));
+ LC_CAMERA_KEY* newnode = (LC_CAMERA_KEY*)malloc (sizeof (LC_CAMERA_KEY));
- if (node)
- {
- newnode->next = node->next;
- node->next = newnode;
- }
- else
- newnode->next = NULL;
+ if (node)
+ {
+ newnode->next = node->next;
+ node->next = newnode;
+ }
+ else
+ newnode->next = NULL;
- newnode->type = nType;
- newnode->time = nTime;
- newnode->param[0] = newnode->param[1] = newnode->param[2] = 0;
+ newnode->type = nType;
+ newnode->time = nTime;
+ newnode->param[0] = newnode->param[1] = newnode->param[2] = 0;
- return newnode;
+ return newnode;
}
static bool invert(double src[16], double inverse[16])
{
- double t;
- int i, j, k, swap;
- double tmp[4][4];
+ double t;
+ int i, j, k, swap;
+ double tmp[4][4];
+
+ for (i = 0; i < 16; i++)
+ inverse[i] = 0.0;
+ inverse[0] = inverse[5] = inverse[10] = inverse[15] = 1.0;
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++)
+ tmp[i][j] = src[i*4+j];
+
+ for (i = 0; i < 4; i++)
+ {
+ // look for largest element in column.
+ swap = i;
+ for (j = i + 1; j < 4; j++)
+ if (fabs(tmp[j][i]) > fabs(tmp[i][i]))
+ swap = j;
+
+ if (swap != i)
+ {
+ // swap rows.
+ for (k = 0; k < 4; k++)
+ {
+ t = tmp[i][k];
+ tmp[i][k] = tmp[swap][k];
+ tmp[swap][k] = t;
+
+ t = inverse[i*4+k];
+ inverse[i*4+k] = inverse[swap*4+k];
+ inverse[swap*4+k] = t;
+ }
+ }
+
+ if (tmp[i][i] == 0)
+ {
+ // The matrix is singular, which shouldn't happen.
+ return false;
+ }
+
+ t = tmp[i][i];
+ for (k = 0; k < 4; k++)
+ {
+ tmp[i][k] /= t;
+ inverse[i*4+k] /= t;
+ }
+
+ for (j = 0; j < 4; j++)
+ {
+ if (j != i)
+ {
+ t = tmp[j][i];
+ for (k = 0; k < 4; k++)
+ {
+ tmp[j][k] -= tmp[i][k]*t;
+ inverse[j*4+k] -= inverse[i*4+k]*t;
+ }
+ }
+ }
+ }
- for (i = 0; i < 16; i++)
- inverse[i] = 0.0;
- inverse[0] = inverse[5] = inverse[10] = inverse[15] = 1.0;
+ return true;
+}
- for (i = 0; i < 4; i++)
- for (j = 0; j < 4; j++)
- tmp[i][j] = src[i*4+j];
+// =============================================================================
+// CameraTarget class
- for (i = 0; i < 4; i++)
- {
- // look for largest element in column.
- swap = i;
- for (j = i + 1; j < 4; j++)
- if (fabs(tmp[j][i]) > fabs(tmp[i][i]))
- swap = j;
-
- if (swap != i)
- {
- // swap rows.
- for (k = 0; k < 4; k++)
- {
- t = tmp[i][k];
- tmp[i][k] = tmp[swap][k];
- tmp[swap][k] = t;
-
- t = inverse[i*4+k];
- inverse[i*4+k] = inverse[swap*4+k];
- inverse[swap*4+k] = t;
- }
- }
-
- if (tmp[i][i] == 0)
- {
- // The matrix is singular, which shouldn't happen.
- return false;
- }
-
- t = tmp[i][i];
- for (k = 0; k < 4; k++)
- {
- tmp[i][k] /= t;
- inverse[i*4+k] /= t;
- }
- for (j = 0; j < 4; j++)
- {
- if (j != i)
- {
- t = tmp[j][i];
- for (k = 0; k < 4; k++)
- {
- tmp[j][k] -= tmp[i][k]*t;
- inverse[j*4+k] -= inverse[i*4+k]*t;
- }
- }
- }
- }
- return true;
+CameraTarget::CameraTarget (Camera *pParent)
+ : Object (LC_OBJECT_CAMERA_TARGET)
+{
+ m_pParent = pParent;
+ /*
+ strcpy (m_strName, pParent->GetName ());
+ m_strName[LC_OBJECT_NAME_LEN-8] = '\0';
+ strcat (m_strName, ".Target");
+ */
+}
+
+CameraTarget::~CameraTarget ()
+{
+}
+
+void CameraTarget::MinIntersectDist (LC_CLICKLINE* pLine)
+{
+ double dist = BoundingBoxIntersectDist (pLine);
+
+ if (dist < pLine->mindist)
+ {
+ pLine->mindist = dist;
+ pLine->pClosest = this;
+ }
}
/////////////////////////////////////////////////////////////////////////////
// Camera construction/destruction
-Camera::Camera()
+Camera::Camera ()
+ : Object (LC_OBJECT_CAMERA)
{
- Initialize();
+ Initialize();
}
// Start with a standard camera.
-Camera::Camera(unsigned char nType, Camera* pPrev)
+Camera::Camera (unsigned char nType, Camera* pPrev)
+ : Object (LC_OBJECT_CAMERA)
{
- if (nType > 7)
- nType = 8;
-
- char names[8][7] = { "Front", "Back", "Top", "Under", "Left", "Right", "Main", "User" };
- float eyes[8][3] = { { 50,0,0 }, { -50,0,0 }, { 0,0,50 }, { 0,0,-50 },
- { 0,50,0 }, { 0,-50,0 }, { 10,10,5}, { 0,5,0 }};
- float ups [8][3] = { { 0,0,1 }, { 0,0,1 }, { 1,0,0 }, { -1,0,0 }, { 0,0,1 },
- { 0,0,1 }, {-0.2357f, -0.2357f, 0.94281f }, { 0,0,1 }};
- CAMERA_KEY* node;
-
- Initialize();
- m_pAnimationKeys = AddNode (NULL, 1, CK_EYE);
- m_pAnimationKeys->param[0] = eyes[nType][0];
- m_pAnimationKeys->param[1] = eyes[nType][1];
- m_pAnimationKeys->param[2] = eyes[nType][2];
- node = AddNode (m_pAnimationKeys, 1, CK_TARGET);
- node = AddNode (node, 1, CK_UP);
- node->param[0] = ups[nType][0];
- node->param[1] = ups[nType][1];
- node->param[2] = ups[nType][2];
-
- m_pInstructionKeys = AddNode (NULL, 1, CK_EYE);
- m_pInstructionKeys->param[0] = eyes[nType][0];
- m_pInstructionKeys->param[1] = eyes[nType][1];
- m_pInstructionKeys->param[2] = eyes[nType][2];
- node = AddNode (m_pInstructionKeys, 1, CK_TARGET);
- node = AddNode (node, 1, CK_UP);
- node->param[0] = ups[nType][0];
- node->param[1] = ups[nType][1];
- node->param[2] = ups[nType][2];
-
- strcpy (m_strName, names[nType]);
- if (nType != 8)
- m_nState = LC_CAMERA_HIDDEN;
- m_nType = nType;
-
- if (pPrev)
- pPrev->m_pNext = this;
-
- UpdatePosition(1, false);
+ if (nType > 7)
+ nType = 8;
+
+ char names[8][7] = { "Front", "Back", "Top", "Under", "Left", "Right", "Main", "User" };
+ float eyes[8][3] = { { 50,0,0 }, { -50,0,0 }, { 0,0,50 }, { 0,0,-50 },
+ { 0,50,0 }, { 0,-50,0 }, { 10,10,5}, { 0,5,0 } };
+ float ups [8][3] = { { 0,0,1 }, { 0,0,1 }, { 1,0,0 }, { -1,0,0 }, { 0,0,1 },
+ { 0,0,1 }, {-0.2357f, -0.2357f, 0.94281f }, { 0,0,1 } };
+ LC_CAMERA_KEY* node;
+
+ Initialize();
+ m_pAnimationKeys = AddNode (NULL, 1, CK_EYE);
+ m_pAnimationKeys->param[0] = eyes[nType][0];
+ m_pAnimationKeys->param[1] = eyes[nType][1];
+ m_pAnimationKeys->param[2] = eyes[nType][2];
+ node = AddNode (m_pAnimationKeys, 1, CK_TARGET);
+ node = AddNode (node, 1, CK_UP);
+ node->param[0] = ups[nType][0];
+ node->param[1] = ups[nType][1];
+ node->param[2] = ups[nType][2];
+
+ m_pInstructionKeys = AddNode (NULL, 1, CK_EYE);
+ m_pInstructionKeys->param[0] = eyes[nType][0];
+ m_pInstructionKeys->param[1] = eyes[nType][1];
+ m_pInstructionKeys->param[2] = eyes[nType][2];
+ node = AddNode (m_pInstructionKeys, 1, CK_TARGET);
+ node = AddNode (node, 1, CK_UP);
+ node->param[0] = ups[nType][0];
+ node->param[1] = ups[nType][1];
+ node->param[2] = ups[nType][2];
+
+ strcpy (m_strName, names[nType]);
+ if (nType != 8)
+ m_nState = LC_CAMERA_HIDDEN;
+ m_nType = nType;
+
+ if (pPrev)
+ pPrev->m_pNext = this;
+
+ UpdatePosition(1, false);
}
// From OnMouseMove(), case LC_ACTION_ROTATE_VIEW
-Camera::Camera(float eye[3], float target[3], float up[3], Camera* pCamera)
+Camera::Camera (const float *eye, const float *target, const float *up, Camera* pCamera)
+ : Object (LC_OBJECT_CAMERA)
{
- CAMERA_KEY* node;
-
- // Fix the up vector
- Vector upvec(up), frontvec(eye[0]-target[0], eye[1]-target[1], eye[2]-target[2]), sidevec;
- frontvec.Normalize();
- sidevec.Cross(frontvec, upvec);
- upvec.Cross(sidevec, frontvec);
- upvec.Normalize();
-
- Initialize();
- m_pAnimationKeys = AddNode (NULL, 1, CK_EYE);
- m_pAnimationKeys->param[0] = eye[0];
- m_pAnimationKeys->param[1] = eye[1];
- m_pAnimationKeys->param[2] = eye[2];
- node = AddNode (m_pAnimationKeys, 1, CK_TARGET);
- node->param[0] = target[0];
- node->param[1] = target[1];
- node->param[2] = target[2];
- node = AddNode (node, 1, CK_UP);
- node->param[0] = upvec.X();
- node->param[1] = upvec.Y();
- node->param[2] = upvec.Z();
-
- m_pInstructionKeys = AddNode (NULL, 1, CK_EYE);
- m_pInstructionKeys->param[0] = eye[0];
- m_pInstructionKeys->param[1] = eye[1];
- m_pInstructionKeys->param[2] = eye[2];
- node = AddNode (m_pInstructionKeys, 1, CK_TARGET);
- node->param[0] = target[0];
- node->param[1] = target[1];
- node->param[2] = target[2];
- node = AddNode (node, 1, CK_UP);
- node->param[0] = upvec.X();
- node->param[1] = upvec.Y();
- node->param[2] = upvec.Z();
-
- int i, max = 0;
-
- for (;;)
- {
- if (strncmp (pCamera->m_strName, "Camera ", 7) == 0)
- if (sscanf(pCamera->m_strName, "Camera %d", &i) == 1)
- if (i > max)
- max = i;
-
- if (pCamera->m_pNext == NULL)
- {
- sprintf(m_strName, "Camera %d", max+1);
- pCamera->m_pNext = this;
- break;
- }
- else
- pCamera = pCamera->m_pNext;
- }
-
- UpdatePosition(1, false);
+ LC_CAMERA_KEY* node;
+
+ // Fix the up vector
+ Vector upvec(up), frontvec(eye[0]-target[0], eye[1]-target[1], eye[2]-target[2]), sidevec;
+ frontvec.Normalize();
+ sidevec.Cross(frontvec, upvec);
+ upvec.Cross(sidevec, frontvec);
+ upvec.Normalize();
+
+ Initialize();
+ m_pAnimationKeys = AddNode (NULL, 1, CK_EYE);
+ m_pAnimationKeys->param[0] = eye[0];
+ m_pAnimationKeys->param[1] = eye[1];
+ m_pAnimationKeys->param[2] = eye[2];
+ node = AddNode (m_pAnimationKeys, 1, CK_TARGET);
+ node->param[0] = target[0];
+ node->param[1] = target[1];
+ node->param[2] = target[2];
+ node = AddNode (node, 1, CK_UP);
+ node->param[0] = upvec.X();
+ node->param[1] = upvec.Y();
+ node->param[2] = upvec.Z();
+
+ m_pInstructionKeys = AddNode (NULL, 1, CK_EYE);
+ m_pInstructionKeys->param[0] = eye[0];
+ m_pInstructionKeys->param[1] = eye[1];
+ m_pInstructionKeys->param[2] = eye[2];
+ node = AddNode (m_pInstructionKeys, 1, CK_TARGET);
+ node->param[0] = target[0];
+ node->param[1] = target[1];
+ node->param[2] = target[2];
+ node = AddNode (node, 1, CK_UP);
+ node->param[0] = upvec.X();
+ node->param[1] = upvec.Y();
+ node->param[2] = upvec.Z();
+
+ int i, max = 0;
+
+ for (;;)
+ {
+ if (strncmp (pCamera->m_strName, "Camera ", 7) == 0)
+ if (sscanf(pCamera->m_strName, "Camera %d", &i) == 1)
+ if (i > max)
+ max = i;
+
+ if (pCamera->m_pNext == NULL)
+ {
+ sprintf(m_strName, "Camera %d", max+1);
+ pCamera->m_pNext = this;
+ break;
+ }
+ else
+ pCamera = pCamera->m_pNext;
+ }
+
+ UpdatePosition (1, false);
}
// From LC_ACTION_CAMERA
-Camera::Camera(float ex, float ey, float ez, float tx, float ty, float tz, Camera* pCamera)
+Camera::Camera (float ex, float ey, float ez, float tx, float ty, float tz, Camera* pCamera)
+ : Object (LC_OBJECT_CAMERA)
{
- CAMERA_KEY* node;
-
- // Fix the up vector
- Vector upvec(0,0,1), frontvec(ex-tx, ey-ty, ez-tz), sidevec;
- frontvec.Normalize();
- if (frontvec == upvec)
- sidevec.FromFloat(1,0,0);
- else
- sidevec.Cross(frontvec, upvec);
- upvec.Cross(sidevec, frontvec);
- upvec.Normalize();
-
- Initialize();
- m_pAnimationKeys = AddNode (NULL, 1, CK_EYE);
- m_pAnimationKeys->param[0] = ex;
- m_pAnimationKeys->param[1] = ey;
- m_pAnimationKeys->param[2] = ez;
- node = AddNode (m_pAnimationKeys, 1, CK_TARGET);
- node->param[0] = tx;
- node->param[1] = ty;
- node->param[2] = tz;
- node = AddNode (node, 1, CK_UP);
- node->param[0] = upvec.X();
- node->param[1] = upvec.Y();
- node->param[2] = upvec.Z();
-
- m_pInstructionKeys = AddNode (NULL, 1, CK_EYE);
- m_pInstructionKeys->param[0] = ex;
- m_pInstructionKeys->param[1] = ey;
- m_pInstructionKeys->param[2] = ez;
- node = AddNode (m_pInstructionKeys, 1, CK_TARGET);
- node->param[0] = tx;
- node->param[1] = ty;
- node->param[2] = tz;
- node = AddNode (node, 1, CK_UP);
- node->param[0] = upvec.X();
- node->param[1] = upvec.Y();
- node->param[2] = upvec.Z();
-
- int i, max = 0;
-
- if (pCamera)
- for (;;)
- {
- if (strncmp (pCamera->m_strName, "Camera ", 7) == 0)
- if (sscanf(pCamera->m_strName, "Camera %d", &i) == 1)
- if (i > max)
- max = i;
-
- if (pCamera->m_pNext == NULL)
- {
- sprintf(m_strName, "Camera %d", max+1);
- pCamera->m_pNext = this;
- break;
- }
- else
- pCamera = pCamera->m_pNext;
- }
-
- UpdatePosition(1, false);
+ LC_CAMERA_KEY* node;
+
+ // Fix the up vector
+ Vector upvec(0,0,1), frontvec(ex-tx, ey-ty, ez-tz), sidevec;
+ frontvec.Normalize();
+ if (frontvec == upvec)
+ sidevec.FromFloat(1,0,0);
+ else
+ sidevec.Cross(frontvec, upvec);
+ upvec.Cross(sidevec, frontvec);
+ upvec.Normalize();
+
+ Initialize();
+ m_pAnimationKeys = AddNode (NULL, 1, CK_EYE);
+ m_pAnimationKeys->param[0] = ex;
+ m_pAnimationKeys->param[1] = ey;
+ m_pAnimationKeys->param[2] = ez;
+ node = AddNode (m_pAnimationKeys, 1, CK_TARGET);
+ node->param[0] = tx;
+ node->param[1] = ty;
+ node->param[2] = tz;
+ node = AddNode (node, 1, CK_UP);
+ node->param[0] = upvec.X();
+ node->param[1] = upvec.Y();
+ node->param[2] = upvec.Z();
+
+ m_pInstructionKeys = AddNode (NULL, 1, CK_EYE);
+ m_pInstructionKeys->param[0] = ex;
+ m_pInstructionKeys->param[1] = ey;
+ m_pInstructionKeys->param[2] = ez;
+ node = AddNode (m_pInstructionKeys, 1, CK_TARGET);
+ node->param[0] = tx;
+ node->param[1] = ty;
+ node->param[2] = tz;
+ node = AddNode (node, 1, CK_UP);
+ node->param[0] = upvec.X();
+ node->param[1] = upvec.Y();
+ node->param[2] = upvec.Z();
+
+ int i, max = 0;
+
+ if (pCamera)
+ for (;;)
+ {
+ if (strncmp (pCamera->m_strName, "Camera ", 7) == 0)
+ if (sscanf(pCamera->m_strName, "Camera %d", &i) == 1)
+ if (i > max)
+ max = i;
+
+ if (pCamera->m_pNext == NULL)
+ {
+ sprintf(m_strName, "Camera %d", max+1);
+ pCamera->m_pNext = this;
+ break;
+ }
+ else
+ pCamera = pCamera->m_pNext;
+ }
+
+ UpdatePosition (1, false);
}
Camera::~Camera()
{
- RemoveKeys();
+ RemoveKeys();
}
void Camera::Initialize()
{
- m_fovy = 30;
- m_zNear = 1;
- m_zFar = 100;
-
- m_BoundingBox.Initialize(this, LC_CAMERA);
- m_TargetBoundingBox.Initialize(this, LC_CAMERA_TARGET);
- m_pNext = NULL;
- m_nState = 0;
- m_pAnimationKeys = NULL;
- m_pInstructionKeys = NULL;
- m_nList = 0;
- m_nType = LC_CAMERA_USER;
-
- m_pTR = NULL;
- for (unsigned char i = 0 ; i < sizeof(m_strName) ; i++ )
- m_strName[i] = 0;
+ m_fovy = 30;
+ m_zNear = 1;
+ m_zFar = 100;
+
+ m_pNext = NULL;
+ m_nState = 0;
+ m_pAnimationKeys = NULL;
+ m_pInstructionKeys = NULL;
+ m_nList = 0;
+ m_nType = LC_CAMERA_USER;
+
+ m_pTR = NULL;
+ for (unsigned char i = 0 ; i < sizeof(m_strName) ; i++ )
+ m_strName[i] = 0;
+
+ m_pTarget = new CameraTarget (this);
}
/////////////////////////////////////////////////////////////////////////////
@@ -314,600 +345,596 @@ void Camera::Initialize()
void Camera::FileLoad(File* file)
{
- RemoveKeys();
- unsigned char version, ch;
- CAMERA_KEY *node;
-
- file->Read(&version, 1);
-
- if (version == 4)
- {
- file->Read(m_strName, 80);
- m_strName[80] = 0;
- }
- else
- {
- file->Read(&ch, 1);
- if (ch == 0xFF)
- return; // don't read CString
- file->Read(m_strName, ch);
- m_strName[ch] = 0;
- }
-
- if (version < 3)
- {
- double d[3];
- file->Read(d, sizeof(d));
- m_pInstructionKeys = AddNode(NULL, 1, CK_EYE);
- m_pInstructionKeys->param[0] = (float)d[0];
- m_pInstructionKeys->param[1] = (float)d[1];
- m_pInstructionKeys->param[2] = (float)d[2];
- file->Read(d, sizeof(d));
- node = AddNode(m_pInstructionKeys, 1, CK_TARGET);
- node->param[0] = (float)d[0];
- node->param[1] = (float)d[1];
- node->param[2] = (float)d[2];
- file->Read (d, sizeof(d));
- node = AddNode(node, 1, CK_UP);
- node->param[0] = (float)d[0];
- node->param[1] = (float)d[1];
- node->param[2] = (float)d[2];
+ RemoveKeys();
+ unsigned char version, ch;
+ LC_CAMERA_KEY *node;
+
+ file->Read(&version, 1);
+
+ if (version == 4)
+ {
+ file->Read(m_strName, 80);
+ m_strName[80] = 0;
+ }
+ else
+ {
+ file->Read(&ch, 1);
+ if (ch == 0xFF)
+ return; // don't read CString
+ file->Read(m_strName, ch);
+ m_strName[ch] = 0;
+ }
+
+ if (version < 3)
+ {
+ double d[3];
+ file->Read(d, sizeof(d));
+ m_pInstructionKeys = AddNode(NULL, 1, CK_EYE);
+ m_pInstructionKeys->param[0] = (float)d[0];
+ m_pInstructionKeys->param[1] = (float)d[1];
+ m_pInstructionKeys->param[2] = (float)d[2];
+ file->Read(d, sizeof(d));
+ node = AddNode(m_pInstructionKeys, 1, CK_TARGET);
+ node->param[0] = (float)d[0];
+ node->param[1] = (float)d[1];
+ node->param[2] = (float)d[2];
+ file->Read (d, sizeof(d));
+ node = AddNode(node, 1, CK_UP);
+ node->param[0] = (float)d[0];
+ node->param[1] = (float)d[1];
+ node->param[2] = (float)d[2];
// m_Start.snapshot = FALSE;
- }
-
- if (version == 3)
- {
- file->Read(&ch, 1);
-
- node = NULL;
- while (ch--)
- {
- if (node == NULL)
- {
- m_pInstructionKeys = AddNode(NULL, 1, CK_EYE);
- node = m_pInstructionKeys;
- }
- else
- node = AddNode(node, 1, CK_EYE);
-
- unsigned char step;
- double eye[3], target[3], up[3];
- file->Read(eye, sizeof(double[3]));
- file->Read(target, sizeof(double[3]));
- file->Read(up, sizeof(double[3]));
- file->Read(&step, 1);
-
- if (up[0] == 0 && up[1] == 0 && up[2] == 0)
- up[2] = 1;
-
- node->time = step;
- node->param[0] = (float)eye[0];
- node->param[1] = (float)eye[1];
- node->param[2] = (float)eye[2];
- node = AddNode(node, step, CK_TARGET);
- node->param[0] = (float)target[0];
- node->param[1] = (float)target[1];
- node->param[2] = (float)target[2];
- node = AddNode(node, step, CK_UP);
- node->param[0] = (float)up[0];
- node->param[1] = (float)up[1];
- node->param[2] = (float)up[2];
-
- int snapshot; // BOOL under Windows
- int cam;
- file->Read(&snapshot, 4);
- file->Read(&cam, 4);
+ }
+
+ if (version == 3)
+ {
+ file->Read(&ch, 1);
+
+ node = NULL;
+ while (ch--)
+ {
+ if (node == NULL)
+ {
+ m_pInstructionKeys = AddNode(NULL, 1, CK_EYE);
+ node = m_pInstructionKeys;
+ }
+ else
+ node = AddNode(node, 1, CK_EYE);
+
+ unsigned char step;
+ double eye[3], target[3], up[3];
+ file->Read(eye, sizeof(double[3]));
+ file->Read(target, sizeof(double[3]));
+ file->Read(up, sizeof(double[3]));
+ file->Read(&step, 1);
+
+ if (up[0] == 0 && up[1] == 0 && up[2] == 0)
+ up[2] = 1;
+
+ node->time = step;
+ node->param[0] = (float)eye[0];
+ node->param[1] = (float)eye[1];
+ node->param[2] = (float)eye[2];
+ node = AddNode(node, step, CK_TARGET);
+ node->param[0] = (float)target[0];
+ node->param[1] = (float)target[1];
+ node->param[2] = (float)target[2];
+ node = AddNode(node, step, CK_UP);
+ node->param[0] = (float)up[0];
+ node->param[1] = (float)up[1];
+ node->param[2] = (float)up[2];
+
+ int snapshot; // BOOL under Windows
+ int cam;
+ file->Read(&snapshot, 4);
+ file->Read(&cam, 4);
// if (cam == -1)
// node->pCam = NULL;
// else
// node->pCam = pDoc->GetCamera(i);
- }
- }
-
- if (version < 4)
- {
- m_pAnimationKeys = AddNode (NULL, 1, CK_EYE);
- CAMERA_KEY* node = AddNode (m_pAnimationKeys, 1, CK_TARGET);
- node = AddNode (node, 1, CK_UP);
- memcpy(m_pAnimationKeys->param, m_pInstructionKeys->param, sizeof(float[3]));
- memcpy(m_pAnimationKeys->next->param, m_pInstructionKeys->next->param, sizeof(float[3]));
- memcpy(node->param, m_pInstructionKeys->next->next->param, sizeof(float[3]));
-
- double d;
- file->Read(&d, sizeof(d)); m_fovy = (float)d;
- file->Read(&d, sizeof(d)); m_zFar = (float)d;
- file->Read(&d, sizeof(d)); m_zNear= (float)d;
- }
- else
- {
- int n;
-
- file->Read(&n, 4);
- for (node = NULL; n--;)
- {
- if (node == NULL)
- {
- m_pInstructionKeys = AddNode(NULL, 1, CK_EYE);
- node = m_pInstructionKeys;
- }
- else
- node = AddNode(node, 1, CK_EYE);
- file->Read(&node->time, 2);
- file->Read(node->param, 12);
- file->Read(&node->type, 1);
- }
-
- file->Read(&n, 4);
- for (node = NULL; n--;)
- {
- if (node == NULL)
- {
- m_pAnimationKeys = AddNode(NULL, 1, CK_EYE);
- node = m_pAnimationKeys;
- }
- else
- node = AddNode(node, 1, CK_EYE);
- file->Read(&node->time, 2);
- file->Read(node->param, 12);
- file->Read(&node->type, 1);
- }
-
- file->Read(&m_fovy, 4);
- file->Read(&m_zFar, 4);
- file->Read(&m_zNear, 4);
-
- if (version < 5)
- {
- file->Read(&n, 4);
- if (n != 0)
- m_nState |= LC_CAMERA_HIDDEN;
- }
- else
- {
- file->Read(&m_nState, 1);
- file->Read(&m_nType, 1);
- }
- }
-
- if ((version > 1) && (version < 4))
- {
- unsigned long show;
- int user;
-
- file->Read(&show, 4);
+ }
+ }
+
+ if (version < 4)
+ {
+ m_pAnimationKeys = AddNode (NULL, 1, CK_EYE);
+ LC_CAMERA_KEY* node = AddNode (m_pAnimationKeys, 1, CK_TARGET);
+ node = AddNode (node, 1, CK_UP);
+ memcpy(m_pAnimationKeys->param, m_pInstructionKeys->param, sizeof(float[3]));
+ memcpy(m_pAnimationKeys->next->param, m_pInstructionKeys->next->param, sizeof(float[3]));
+ memcpy(node->param, m_pInstructionKeys->next->next->param, sizeof(float[3]));
+
+ double d;
+ file->Read(&d, sizeof(d)); m_fovy = (float)d;
+ file->Read(&d, sizeof(d)); m_zFar = (float)d;
+ file->Read(&d, sizeof(d)); m_zNear= (float)d;
+ }
+ else
+ {
+ int n;
+
+ file->Read(&n, 4);
+ for (node = NULL; n--;)
+ {
+ if (node == NULL)
+ {
+ m_pInstructionKeys = AddNode(NULL, 1, CK_EYE);
+ node = m_pInstructionKeys;
+ }
+ else
+ node = AddNode(node, 1, CK_EYE);
+ file->Read(&node->time, 2);
+ file->Read(node->param, 12);
+ file->Read(&node->type, 1);
+ }
+
+ file->Read(&n, 4);
+ for (node = NULL; n--;)
+ {
+ if (node == NULL)
+ {
+ m_pAnimationKeys = AddNode(NULL, 1, CK_EYE);
+ node = m_pAnimationKeys;
+ }
+ else
+ node = AddNode(node, 1, CK_EYE);
+ file->Read(&node->time, 2);
+ file->Read(node->param, 12);
+ file->Read(&node->type, 1);
+ }
+
+ file->Read(&m_fovy, 4);
+ file->Read(&m_zFar, 4);
+ file->Read(&m_zNear, 4);
+
+ if (version < 5)
+ {
+ file->Read(&n, 4);
+ if (n != 0)
+ m_nState |= LC_CAMERA_HIDDEN;
+ }
+ else
+ {
+ file->Read(&m_nState, 1);
+ file->Read(&m_nType, 1);
+ }
+ }
+
+ if ((version > 1) && (version < 4))
+ {
+ unsigned long show;
+ int user;
+
+ file->Read(&show, 4);
// if (version > 2)
- file->Read(&user, 4);
- if (show == 0)
- m_nState |= LC_CAMERA_HIDDEN;
- }
+ file->Read(&user, 4);
+ if (show == 0)
+ m_nState |= LC_CAMERA_HIDDEN;
+ }
}
void Camera::FileSave(File* file)
{
- int n;
- CAMERA_KEY *node;
- unsigned char ch = 5; // LeoCAD 0.70
-
- file->Write(&ch, 1);
- ch = (unsigned char)strlen(m_strName);
- file->Write(&ch, 1);
- file->Write(m_strName, ch);
-
- for (n = 0, node = m_pInstructionKeys; node; node = node->next)
- n++;
- file->Write(&n, 4);
-
- for (node = m_pInstructionKeys; node; node = node->next)
- {
- file->Write(&node->time, 2);
- file->Write(node->param, 12);
- file->Write(&node->type, 1);
- }
-
- for (n = 0, node = m_pAnimationKeys; node; node = node->next)
- n++;
- file->Write(&n, 4);
-
- for (node = m_pAnimationKeys; node; node = node->next)
- {
- file->Write(&node->time, 2);
- file->Write(node->param, 12);
- file->Write(&node->type, 1);
- }
-
- file->Write(&m_fovy, 4);
- file->Write(&m_zFar, 4);
- file->Write(&m_zNear, 4);
- // version 5
- file->Write(&m_nState, 1);
- file->Write(&m_nType, 1);
+ int n;
+ LC_CAMERA_KEY *node;
+ unsigned char ch = 5; // LeoCAD 0.70
+
+ file->Write(&ch, 1);
+ ch = (unsigned char)strlen(m_strName);
+ file->Write(&ch, 1);
+ file->Write(m_strName, ch);
+
+ for (n = 0, node = m_pInstructionKeys; node; node = node->next)
+ n++;
+ file->Write(&n, 4);
+
+ for (node = m_pInstructionKeys; node; node = node->next)
+ {
+ file->Write(&node->time, 2);
+ file->Write(node->param, 12);
+ file->Write(&node->type, 1);
+ }
+
+ for (n = 0, node = m_pAnimationKeys; node; node = node->next)
+ n++;
+ file->Write(&n, 4);
+
+ for (node = m_pAnimationKeys; node; node = node->next)
+ {
+ file->Write(&node->time, 2);
+ file->Write(node->param, 12);
+ file->Write(&node->type, 1);
+ }
+
+ file->Write(&m_fovy, 4);
+ file->Write(&m_zFar, 4);
+ file->Write(&m_zNear, 4);
+ // version 5
+ file->Write(&m_nState, 1);
+ file->Write(&m_nType, 1);
}
/////////////////////////////////////////////////////////////////////////////
// Camera operations
-void Camera::ChangeKey(unsigned short nTime, bool bAnimation, bool bAddKey, float param[3], unsigned char nKeyType)
+void Camera::ChangeKey (unsigned short nTime, bool bAnimation, bool bAddKey, float param[3], unsigned char nKeyType)
{
- CAMERA_KEY *node, *poskey = NULL, *newpos = NULL;
- if (bAnimation)
- node = m_pAnimationKeys;
- else
- node = m_pInstructionKeys;
-
- while (node)
- {
- if ((node->time <= nTime) &&
- (node->type == nKeyType))
- poskey = node;
-
- node = node->next;
- }
-
- if (bAddKey)
- {
- if (poskey)
- {
- if (poskey->time != nTime)
- newpos = AddNode(poskey, nTime, nKeyType);
- }
- else
- newpos = AddNode(poskey, nTime, nKeyType);
- }
-
- if (newpos == NULL)
- newpos = poskey;
-
- newpos->param[0] = param[0];
- newpos->param[1] = param[1];
- newpos->param[2] = param[2];
+ LC_CAMERA_KEY *node, *poskey = NULL, *newpos = NULL;
+ if (bAnimation)
+ node = m_pAnimationKeys;
+ else
+ node = m_pInstructionKeys;
+
+ while (node)
+ {
+ if ((node->time <= nTime) &&
+ (node->type == nKeyType))
+ poskey = node;
+
+ node = node->next;
+ }
+
+ if (bAddKey)
+ {
+ if (poskey)
+ {
+ if (poskey->time != nTime)
+ newpos = AddNode(poskey, nTime, nKeyType);
+ }
+ else
+ newpos = AddNode(poskey, nTime, nKeyType);
+ }
+
+ if (newpos == NULL)
+ newpos = poskey;
+
+ newpos->param[0] = param[0];
+ newpos->param[1] = param[1];
+ newpos->param[2] = param[2];
}
-void Camera::Move(unsigned short nTime, bool bAnimation, bool bAddKey, float x, float y, float z)
+void Camera::Move(unsigned short nTime, bool bAnimation, bool bAddKey, float dx, float dy, float dz)
{
- if (IsSide())
- {
- m_fEye[0] += x;
- m_fEye[1] += y;
- m_fEye[2] += z;
- m_fTarget[0] += x;
- m_fTarget[1] += y;
- m_fTarget[2] += z;
-
- ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
- ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, CK_TARGET);
- }
- else
- {
- if (IsEyeSelected())
- {
- m_fEye[0] += x;
- m_fEye[1] += y;
- m_fEye[2] += z;
-
- ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
- }
-
- if (IsTargetSelected())
- {
- m_fTarget[0] += x;
- m_fTarget[1] += y;
- m_fTarget[2] += z;
-
- ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, CK_TARGET);
- }
-
- // Fix the up vector
- Vector upvec(m_fUp), frontvec(m_fTarget[0]-m_fEye[0], m_fTarget[1]-m_fEye[1], m_fTarget[2]-m_fEye[2]), sidevec;
- sidevec.Cross(frontvec, upvec);
- upvec.Cross(sidevec, frontvec);
- upvec.Normalize();
- upvec.ToFloat(m_fUp);
-
- ChangeKey(nTime, bAnimation, bAddKey, m_fUp, CK_UP);
- }
+ if (IsSide())
+ {
+ m_fEye[0] += dx;
+ m_fEye[1] += dy;
+ m_fEye[2] += dz;
+ m_fTarget[0] += dx;
+ m_fTarget[1] += dy;
+ m_fTarget[2] += dz;
+
+ ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
+ ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, CK_TARGET);
+ }
+ else
+ {
+ if (IsEyeSelected())
+ {
+ m_fEye[0] += dx;
+ m_fEye[1] += dy;
+ m_fEye[2] += dz;
+
+ ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
+ }
+
+ if (IsTargetSelected())
+ {
+ m_fTarget[0] += dx;
+ m_fTarget[1] += dy;
+ m_fTarget[2] += dz;
+
+ ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, CK_TARGET);
+ }
+
+ // Fix the up vector
+ Vector upvec(m_fUp), sidevec;
+ Vector frontvec(m_fTarget[0]-m_fEye[0], m_fTarget[1]-m_fEye[1], m_fTarget[2]-m_fEye[2]);
+ sidevec.Cross(frontvec, upvec);
+ upvec.Cross(sidevec, frontvec);
+ upvec.Normalize();
+ upvec.ToFloat(m_fUp);
+
+ ChangeKey(nTime, bAnimation, bAddKey, m_fUp, CK_UP);
+ }
}
void Camera::RemoveKeys()
{
- CAMERA_KEY *node, *prev;
-
- for (node = m_pInstructionKeys; node;)
- {
- prev = node;
- node = node->next;
- free (prev);
- }
-
- for (node = m_pAnimationKeys; node;)
- {
- prev = node;
- node = node->next;
- free (prev);
- }
+ LC_CAMERA_KEY *node, *prev;
+
+ for (node = m_pInstructionKeys; node;)
+ {
+ prev = node;
+ node = node->next;
+ free (prev);
+ }
+
+ for (node = m_pAnimationKeys; node;)
+ {
+ prev = node;
+ node = node->next;
+ free (prev);
+ }
}
-void Camera::CalculatePosition(unsigned short nTime, bool bAnimation, float eye[3], float target[3], float up[3])
+void Camera::CalculatePosition (unsigned short nTime, bool bAnimation, float eye[3], float target[3], float up[3])
{
- CAMERA_KEY *node, *pe = NULL, *ne = NULL, *pt = NULL, *nt = NULL, *pu = NULL, *nu = NULL;
- if (bAnimation)
- node = m_pAnimationKeys;
- else
- node = m_pInstructionKeys;
-
- while (node && (!ne || !nt || !nu))
- {
- if (node->time <= nTime)
- {
- switch (node->type)
- {
- case CK_EYE: pe = node; break;
- case CK_TARGET: pt = node; break;
- case CK_UP: pu = node; break;
- }
- }
- else
- {
- switch (node->type)
- {
- case CK_EYE: if (ne == NULL) ne = node; break;
- case CK_TARGET: if (nt == NULL) nt = node; break;
- case CK_UP: if (nu == NULL) nu = node; break;
- }
- }
-
- node = node->next;
- }
-
- // TODO: USE KEY IN/OUT WEIGHTS
- if (bAnimation && (ne != NULL) && (pe->time != nTime))
- {
- float t = (float)(nTime - pe->time)/(ne->time - pe->time);
- eye[0] = pe->param[0] + (ne->param[0] - pe->param[0])*t;
- eye[1] = pe->param[1] + (ne->param[1] - pe->param[1])*t;
- eye[2] = pe->param[2] + (ne->param[2] - pe->param[2])*t;
- }
- else
- memcpy (eye, pe->param, sizeof(float[3]));
-
- if (bAnimation && (nt != NULL) && (pt->time != nTime))
- {
- float t = (float)(nTime - pt->time)/(nt->time - pt->time);
- target[0] = pt->param[0] + (nt->param[0] - pt->param[0])*t;
- target[1] = pt->param[1] + (nt->param[1] - pt->param[1])*t;
- target[2] = pt->param[2] + (nt->param[2] - pt->param[2])*t;
- }
- else
- memcpy (target, pt->param, sizeof(float[3]));
-
- if (bAnimation && (nu != NULL) && (pu->time != nTime))
- {
- float t = (float)(nTime - pu->time)/(nu->time - pu->time);
- up[0] = pu->param[0] + (nu->param[0] - pu->param[0])*t;
- up[1] = pu->param[1] + (nu->param[1] - pu->param[1])*t;
- up[2] = pu->param[2] + (nu->param[2] - pu->param[2])*t;
- }
- else
- memcpy (up, pu->param, sizeof(float[3]));
-
- // Fix the up vector
- Vector upvec(up), frontvec(eye[0]-target[0], eye[1]-target[1], eye[2]-target[2]), sidevec;
- sidevec.Cross(frontvec, upvec);
- upvec.Cross(sidevec, frontvec);
- upvec.Normalize();
- upvec.ToFloat(up);
+ LC_CAMERA_KEY *node, *pe = NULL, *ne = NULL, *pt = NULL, *nt = NULL, *pu = NULL, *nu = NULL;
+ if (bAnimation)
+ node = m_pAnimationKeys;
+ else
+ node = m_pInstructionKeys;
+
+ while (node && (!ne || !nt || !nu))
+ {
+ if (node->time <= nTime)
+ {
+ switch (node->type)
+ {
+ case CK_EYE: pe = node; break;
+ case CK_TARGET: pt = node; break;
+ case CK_UP: pu = node; break;
+ }
+ }
+ else
+ {
+ switch (node->type)
+ {
+ case CK_EYE: if (ne == NULL) ne = node; break;
+ case CK_TARGET: if (nt == NULL) nt = node; break;
+ case CK_UP: if (nu == NULL) nu = node; break;
+ }
+ }
+
+ node = node->next;
+ }
+
+ // TODO: USE KEY IN/OUT WEIGHTS
+ if (bAnimation && (ne != NULL) && (pe->time != nTime))
+ {
+ float t = (float)(nTime - pe->time)/(ne->time - pe->time);
+ eye[0] = pe->param[0] + (ne->param[0] - pe->param[0])*t;
+ eye[1] = pe->param[1] + (ne->param[1] - pe->param[1])*t;
+ eye[2] = pe->param[2] + (ne->param[2] - pe->param[2])*t;
+ }
+ else
+ memcpy (eye, pe->param, sizeof(float[3]));
+
+ if (bAnimation && (nt != NULL) && (pt->time != nTime))
+ {
+ float t = (float)(nTime - pt->time)/(nt->time - pt->time);
+ target[0] = pt->param[0] + (nt->param[0] - pt->param[0])*t;
+ target[1] = pt->param[1] + (nt->param[1] - pt->param[1])*t;
+ target[2] = pt->param[2] + (nt->param[2] - pt->param[2])*t;
+ }
+ else
+ memcpy (target, pt->param, sizeof(float[3]));
+
+ if (bAnimation && (nu != NULL) && (pu->time != nTime))
+ {
+ float t = (float)(nTime - pu->time)/(nu->time - pu->time);
+ up[0] = pu->param[0] + (nu->param[0] - pu->param[0])*t;
+ up[1] = pu->param[1] + (nu->param[1] - pu->param[1])*t;
+ up[2] = pu->param[2] + (nu->param[2] - pu->param[2])*t;
+ }
+ else
+ memcpy (up, pu->param, sizeof(float[3]));
+
+ // Fix the up vector
+ Vector upvec(up), frontvec(eye[0]-target[0], eye[1]-target[1], eye[2]-target[2]), sidevec;
+ sidevec.Cross(frontvec, upvec);
+ upvec.Cross(sidevec, frontvec);
+ upvec.Normalize();
+ upvec.ToFloat(up);
}
void Camera::UpdatePosition(unsigned short nTime, bool bAnimation)
{
- CalculatePosition(nTime, bAnimation, m_fEye, m_fTarget, m_fUp);
-
- float len;
- Vector upvec(m_fUp), frontvec(m_fTarget[0]-m_fEye[0], m_fTarget[1]-m_fEye[1], m_fTarget[2]-m_fEye[2]), sidevec;
- len = frontvec.Length();
- sidevec.Cross(frontvec, upvec);
- sidevec.Normalize();
- upvec.Normalize();
- frontvec.Normalize();
-
- double m[16], inverse[16];
+ CalculatePosition(nTime, bAnimation, m_fEye, m_fTarget, m_fUp);
+
+ float len;
+ Vector upvec(m_fUp), sidevec;
+ Vector frontvec(m_fTarget[0]-m_fEye[0], m_fTarget[1]-m_fEye[1], m_fTarget[2]-m_fEye[2]);
+ len = frontvec.Length();
+ sidevec.Cross(frontvec, upvec);
+ sidevec.Normalize();
+ upvec.Normalize();
+ frontvec.Normalize();
+
+ double m[16], inverse[16];
#define M(row,col) m[col*4+row]
- M(0,0) = sidevec.X(); M(0,1) = sidevec.Y(); M(0,2) = sidevec.Z(); M(0,3) = 0.0;
- M(1,0) = upvec.X(); M(1,1) = upvec.Y(); M(1,2) = upvec.Z(); M(1,3) = 0.0;
- M(2,0) = frontvec.X(); M(2,1) = frontvec.Y(); M(2,2) = frontvec.Z(); M(2,3) = 0.0;
- M(3,0) = 0.0; M(3,1) = 0.0; M(3,2) = 0.0; M(3,3) = 1.0;
+ M(0,0) = sidevec.X(); M(0,1) = sidevec.Y(); M(0,2) = sidevec.Z(); M(0,3) = 0.0;
+ M(1,0) = upvec.X(); M(1,1) = upvec.Y(); M(1,2) = upvec.Z(); M(1,3) = 0.0;
+ M(2,0) = frontvec.X(); M(2,1) = frontvec.Y(); M(2,2) = frontvec.Z(); M(2,3) = 0.0;
+ M(3,0) = 0.0; M(3,1) = 0.0; M(3,2) = 0.0; M(3,3) = 1.0;
#undef M
- invert(m, inverse);
+ invert(m, inverse);
- Matrix mat(inverse);
- mat.SetTranslation(m_fEye[0], m_fEye[1], m_fEye[2]);
- m_BoundingBox.CalculateBoundingBox(&mat);
- mat.SetTranslation(m_fTarget[0], m_fTarget[1], m_fTarget[2]);
- m_TargetBoundingBox.CalculateBoundingBox(&mat);
+ Matrix mat(inverse);
+ mat.SetTranslation(m_fEye[0], m_fEye[1], m_fEye[2]);
+ BoundingBoxCalculate (&mat);
+ mat.SetTranslation(m_fTarget[0], m_fTarget[1], m_fTarget[2]);
+ m_pTarget->BoundingBoxCalculate (&mat);
- if (m_nList == 0)
- m_nList = glGenLists(1);
+ if (m_nList == 0)
+ m_nList = glGenLists(1);
- glNewList(m_nList, GL_COMPILE);
+ glNewList(m_nList, GL_COMPILE);
- glPushMatrix();
- glTranslatef(m_fEye[0], m_fEye[1], m_fEye[2]);
- glMultMatrixd(inverse);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- float verts[34][3] = {
- { 0.3f, 0.3f, 0.3f }, { -0.3f, 0.3f, 0.3f },
- { -0.3f, 0.3f, 0.3f }, { -0.3f, -0.3f, 0.3f },
- { -0.3f, -0.3f, 0.3f }, { 0.3f, -0.3f, 0.3f },
- { 0.3f, -0.3f, 0.3f }, { 0.3f, 0.3f, 0.3f },
- { 0.3f, 0.3f, -0.3f }, { -0.3f, 0.3f, -0.3f },
- { -0.3f, 0.3f, -0.3f }, { -0.3f, -0.3f, -0.3f },
- { -0.3f, -0.3f, -0.3f }, { 0.3f, -0.3f, -0.3f },
- { 0.3f, -0.3f, -0.3f }, { 0.3f, 0.3f, -0.3f },
- { 0.3f, 0.3f, 0.3f }, { 0.3f, 0.3f, -0.3f },
- { -0.3f, 0.3f, 0.3f }, { -0.3f, 0.3f, -0.3f },
- { -0.3f, -0.3f, 0.3f }, { -0.3f, -0.3f, -0.3f },
- { 0.3f, -0.3f, 0.3f }, { 0.3f, -0.3f, -0.3f },
- { -0.3f, -0.3f, 0.6f }, { -0.3f, 0.3f, 0.6f },
- { 0.0f, 0.0f, 0.3f }, { -0.3f, -0.3f, 0.6f },
- { 0.3f, -0.3f, 0.6f }, { 0.0f, 0.0f, 0.3f },
- { 0.3f, 0.3f, 0.6f }, { 0.3f, -0.3f, 0.6f },
- { 0.3f, 0.3f, 0.6f }, { -0.3f, 0.3f, 0.6f } };
- glVertexPointer (3, GL_FLOAT, 0, verts);
- glDrawArrays(GL_LINES, 0, 24);
- glDrawArrays(GL_LINE_STRIP, 24, 10);
+ glPushMatrix();
+ glTranslatef(m_fEye[0], m_fEye[1], m_fEye[2]);
+ glMultMatrixd(inverse);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ float verts[34][3] = {
+ { 0.3f, 0.3f, 0.3f }, { -0.3f, 0.3f, 0.3f },
+ { -0.3f, 0.3f, 0.3f }, { -0.3f, -0.3f, 0.3f },
+ { -0.3f, -0.3f, 0.3f }, { 0.3f, -0.3f, 0.3f },
+ { 0.3f, -0.3f, 0.3f }, { 0.3f, 0.3f, 0.3f },
+ { 0.3f, 0.3f, -0.3f }, { -0.3f, 0.3f, -0.3f },
+ { -0.3f, 0.3f, -0.3f }, { -0.3f, -0.3f, -0.3f },
+ { -0.3f, -0.3f, -0.3f }, { 0.3f, -0.3f, -0.3f },
+ { 0.3f, -0.3f, -0.3f }, { 0.3f, 0.3f, -0.3f },
+ { 0.3f, 0.3f, 0.3f }, { 0.3f, 0.3f, -0.3f },
+ { -0.3f, 0.3f, 0.3f }, { -0.3f, 0.3f, -0.3f },
+ { -0.3f, -0.3f, 0.3f }, { -0.3f, -0.3f, -0.3f },
+ { 0.3f, -0.3f, 0.3f }, { 0.3f, -0.3f, -0.3f },
+ { -0.3f, -0.3f, 0.6f }, { -0.3f, 0.3f, 0.6f },
+ { 0.0f, 0.0f, 0.3f }, { -0.3f, -0.3f, 0.6f },
+ { 0.3f, -0.3f, 0.6f }, { 0.0f, 0.0f, 0.3f },
+ { 0.3f, 0.3f, 0.6f }, { 0.3f, -0.3f, 0.6f },
+ { 0.3f, 0.3f, 0.6f }, { -0.3f, 0.3f, 0.6f } };
+ glVertexPointer (3, GL_FLOAT, 0, verts);
+ glDrawArrays(GL_LINES, 0, 24);
+ glDrawArrays(GL_LINE_STRIP, 24, 10);
// glBegin(GL_LINES);
// glVertex3f(0,0,0);
// glVertex3f(0,0,len);
// glEnd();
- glTranslatef(0, 0, len);
-
- glEndList();
-
- if (_nTargetList == 0)
- {
- _nTargetList = glGenLists(1);
- glNewList(_nTargetList, GL_COMPILE);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- float box[24][3] = {
- { 0.2f, 0.2f, 0.2f }, { -0.2f, 0.2f, 0.2f },
- { -0.2f, 0.2f, 0.2f }, { -0.2f, -0.2f, 0.2f },
- { -0.2f, -0.2f, 0.2f }, { 0.2f, -0.2f, 0.2f },
- { 0.2f, -0.2f, 0.2f }, { 0.2f, 0.2f, 0.2f },
- { 0.2f, 0.2f, -0.2f }, { -0.2f, 0.2f, -0.2f },
- { -0.2f, 0.2f, -0.2f }, { -0.2f, -0.2f, -0.2f },
- { -0.2f, -0.2f, -0.2f }, { 0.2f, -0.2f, -0.2f },
- { 0.2f, -0.2f, -0.2f }, { 0.2f, 0.2f, -0.2f },
- { 0.2f, 0.2f, 0.2f }, { 0.2f, 0.2f, -0.2f },
- { -0.2f, 0.2f, 0.2f }, { -0.2f, 0.2f, -0.2f },
- { -0.2f, -0.2f, 0.2f }, { -0.2f, -0.2f, -0.2f },
- { 0.2f, -0.2f, 0.2f }, { 0.2f, -0.2f, -0.2f } };
- glVertexPointer (3, GL_FLOAT, 0, box);
- glDrawArrays(GL_LINES, 0, 24);
- glPopMatrix();
- glEndList();
- }
+ glTranslatef(0, 0, len);
+
+ glEndList();
+
+ if (_nTargetList == 0)
+ {
+ _nTargetList = glGenLists(1);
+ glNewList(_nTargetList, GL_COMPILE);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ float box[24][3] = {
+ { 0.2f, 0.2f, 0.2f }, { -0.2f, 0.2f, 0.2f },
+ { -0.2f, 0.2f, 0.2f }, { -0.2f, -0.2f, 0.2f },
+ { -0.2f, -0.2f, 0.2f }, { 0.2f, -0.2f, 0.2f },
+ { 0.2f, -0.2f, 0.2f }, { 0.2f, 0.2f, 0.2f },
+ { 0.2f, 0.2f, -0.2f }, { -0.2f, 0.2f, -0.2f },
+ { -0.2f, 0.2f, -0.2f }, { -0.2f, -0.2f, -0.2f },
+ { -0.2f, -0.2f, -0.2f }, { 0.2f, -0.2f, -0.2f },
+ { 0.2f, -0.2f, -0.2f }, { 0.2f, 0.2f, -0.2f },
+ { 0.2f, 0.2f, 0.2f }, { 0.2f, 0.2f, -0.2f },
+ { -0.2f, 0.2f, 0.2f }, { -0.2f, 0.2f, -0.2f },
+ { -0.2f, -0.2f, 0.2f }, { -0.2f, -0.2f, -0.2f },
+ { 0.2f, -0.2f, 0.2f }, { 0.2f, -0.2f, -0.2f } };
+ glVertexPointer (3, GL_FLOAT, 0, box);
+ glDrawArrays(GL_LINES, 0, 24);
+ glPopMatrix();
+ glEndList();
+ }
}
void Camera::Render(float fLineWidth)
{
- if (IsEyeSelected())
- {
- glLineWidth(fLineWidth*2);
- glColor3ubv(FlatColorArray[(m_nState & LC_CAMERA_FOCUSED) != 0 ? LC_COL_FOCUSED : LC_COL_SELECTED]);
- glCallList(m_nList);
- glLineWidth(fLineWidth);
- }
- else
- {
- glColor3f(0.5f, 0.8f, 0.5f);
- glCallList(m_nList);
- }
-
- if (IsTargetSelected())
- {
- glLineWidth(fLineWidth*2);
- glColor3ubv(FlatColorArray[(m_nState & LC_CAMERA_TARGET_FOCUSED) != 0 ? LC_COL_FOCUSED : LC_COL_SELECTED]);
- glCallList(_nTargetList);
- glLineWidth(fLineWidth);
- }
- else
- {
- glColor3f(0.5f, 0.8f, 0.5f);
- glCallList(_nTargetList);
- }
-
- glColor3f(0.5f, 0.8f, 0.5f);
- glBegin(GL_LINES);
- glVertex3fv(m_fEye);
- glVertex3fv(m_fTarget);
- glEnd();
-
- if (IsSelected())
- {
- double projection[16], modelview[16], inverse[16];
-
- float len;
- Vector frontvec(m_fTarget[0]-m_fEye[0], m_fTarget[1]-m_fEye[1], m_fTarget[2]-m_fEye[2]);
- len = frontvec.Length();
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- gluPerspective(m_fovy, 1.33f, 0.01, len);
- glGetDoublev(GL_PROJECTION_MATRIX, projection);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- gluLookAt(m_fEye[0], m_fEye[1], m_fEye[2], m_fTarget[0], m_fTarget[1], m_fTarget[2], m_fUp[0], m_fUp[1], m_fUp[2]);
- glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
- glPopMatrix();
-
- glPushMatrix();
- invert(modelview, inverse);
- glMultMatrixd(inverse);
- invert(projection, inverse);
- glMultMatrixd(inverse);
-
- // draw the viewing frustum
- glBegin(GL_LINE_LOOP);
- glVertex3i(1, 1, 1);
- glVertex3i(-1, 1, 1);
- glVertex3i(-1, -1, 1);
- glVertex3i(1, -1, 1);
- glEnd();
-
- glBegin(GL_LINES);
- glVertex3i(1, 1, -1);
- glVertex3i(1, 1, 1);
- glVertex3i(-1, 1, -1);
- glVertex3i(-1, 1, 1);
- glVertex3i(-1, -1, -1);
- glVertex3i(-1, -1, 1);
- glVertex3i(1, -1, -1);
- glVertex3i(1, -1, 1);
- glEnd();
-
- glPopMatrix();
- }
+ if (IsEyeSelected())
+ {
+ glLineWidth(fLineWidth*2);
+ glColor3ubv(FlatColorArray[(m_nState & LC_CAMERA_FOCUSED) != 0 ? LC_COL_FOCUSED : LC_COL_SELECTED]);
+ glCallList(m_nList);
+ glLineWidth(fLineWidth);
+ }
+ else
+ {
+ glColor3f(0.5f, 0.8f, 0.5f);
+ glCallList(m_nList);
+ }
+
+ if (IsTargetSelected())
+ {
+ glLineWidth(fLineWidth*2);
+ glColor3ubv(FlatColorArray[(m_nState & LC_CAMERA_TARGET_FOCUSED) != 0 ? LC_COL_FOCUSED : LC_COL_SELECTED]);
+ glCallList(_nTargetList);
+ glLineWidth(fLineWidth);
+ }
+ else
+ {
+ glColor3f(0.5f, 0.8f, 0.5f);
+ glCallList(_nTargetList);
+ }
+
+ glColor3f(0.5f, 0.8f, 0.5f);
+ glBegin(GL_LINES);
+ glVertex3fv(m_fEye);
+ glVertex3fv(m_fTarget);
+ glEnd();
+
+ if (IsSelected())
+ {
+ double projection[16], modelview[16], inverse[16];
+
+ float len;
+ Vector frontvec(m_fTarget[0]-m_fEye[0], m_fTarget[1]-m_fEye[1], m_fTarget[2]-m_fEye[2]);
+ len = frontvec.Length();
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+ gluPerspective(m_fovy, 1.33f, 0.01, len);
+ glGetDoublev(GL_PROJECTION_MATRIX, projection);
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ gluLookAt(m_fEye[0], m_fEye[1], m_fEye[2], m_fTarget[0], m_fTarget[1], m_fTarget[2], m_fUp[0], m_fUp[1], m_fUp[2]);
+ glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
+ glPopMatrix();
+
+ glPushMatrix();
+ invert(modelview, inverse);
+ glMultMatrixd(inverse);
+ invert(projection, inverse);
+ glMultMatrixd(inverse);
+
+ // draw the viewing frustum
+ glBegin(GL_LINE_LOOP);
+ glVertex3i(1, 1, 1);
+ glVertex3i(-1, 1, 1);
+ glVertex3i(-1, -1, 1);
+ glVertex3i(1, -1, 1);
+ glEnd();
+
+ glBegin(GL_LINES);
+ glVertex3i(1, 1, -1);
+ glVertex3i(1, 1, 1);
+ glVertex3i(-1, 1, -1);
+ glVertex3i(-1, 1, 1);
+ glVertex3i(-1, -1, -1);
+ glVertex3i(-1, -1, 1);
+ glVertex3i(1, -1, -1);
+ glVertex3i(1, -1, 1);
+ glEnd();
+
+ glPopMatrix();
+ }
}
-void Camera::MinIntersectDist(CLICKLINE* pLine)
+void Camera::MinIntersectDist(LC_CLICKLINE* pLine)
{
- double dist;
+ double dist;
- if (m_nState & LC_CAMERA_HIDDEN)
- return;
+ if (m_nState & LC_CAMERA_HIDDEN)
+ return;
- dist = m_BoundingBox.FindIntersectDist(pLine);
+ dist = BoundingBoxIntersectDist (pLine);
- if (dist < pLine->mindist)
- {
- pLine->mindist = dist;
- pLine->pClosest = &m_BoundingBox;
- }
-
- dist = m_TargetBoundingBox.FindIntersectDist(pLine);
+ if (dist < pLine->mindist)
+ {
+ pLine->mindist = dist;
+ pLine->pClosest = this;
+ }
- if (dist < pLine->mindist)
- {
- pLine->mindist = dist;
- pLine->pClosest = &m_TargetBoundingBox;
- }
+ m_pTarget->MinIntersectDist (pLine);
}
void Camera::LoadProjection(float fAspect)
{
- if (m_pTR != NULL)
- m_pTR->BeginTile();
- else
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(m_fovy, fAspect, m_zNear, m_zFar);
+ if (m_pTR != NULL)
+ m_pTR->BeginTile();
+ else
+ {
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluPerspective(m_fovy, fAspect, m_zNear, m_zFar);
/*
ymax = 10;//(m_zFar-m_zNear)*tan(DTOR*m_fovy)/3;
ymin = -ymax;
@@ -917,124 +944,124 @@ void Camera::LoadProjection(float fAspect)
zfar = 60;
glOrtho(xmin, xmax, ymin, ymax, znear, zfar);
*/
- }
+ }
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(m_fEye[0], m_fEye[1], m_fEye[2], m_fTarget[0], m_fTarget[1], m_fTarget[2], m_fUp[0], m_fUp[1], m_fUp[2]);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ gluLookAt(m_fEye[0], m_fEye[1], m_fEye[2], m_fTarget[0], m_fTarget[1], m_fTarget[2], m_fUp[0], m_fUp[1], m_fUp[2]);
}
void Camera::DoZoom(int dy, int mouse, unsigned short nTime, bool bAnimation, bool bAddKey)
{
- Vector frontvec(m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2]);
- frontvec.Normalize();
- frontvec *= 2.0f*dy/(21-mouse);
-
- // TODO: option to move eye, target or both
- m_fEye[0] += frontvec.X();
- m_fEye[1] += frontvec.Y();
- m_fEye[2] += frontvec.Z();
- m_fTarget[0] += frontvec.X();
- m_fTarget[1] += frontvec.Y();
- m_fTarget[2] += frontvec.Z();
-
- ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
- ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, CK_TARGET);
- UpdatePosition(nTime, bAnimation);
+ Vector frontvec(m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2]);
+ frontvec.Normalize();
+ frontvec *= 2.0f*dy/(21-mouse);
+
+ // TODO: option to move eye, target or both
+ m_fEye[0] += frontvec.X();
+ m_fEye[1] += frontvec.Y();
+ m_fEye[2] += frontvec.Z();
+ m_fTarget[0] += frontvec.X();
+ m_fTarget[1] += frontvec.Y();
+ m_fTarget[2] += frontvec.Z();
+
+ ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
+ ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, CK_TARGET);
+ UpdatePosition(nTime, bAnimation);
}
void Camera::DoPan(int dx, int dy, int mouse, unsigned short nTime, bool bAnimation, bool bAddKey)
{
- Vector upvec(m_fUp), frontvec(m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2]), sidevec;
- sidevec.Cross(frontvec, upvec);
- sidevec.Normalize();
- sidevec *= 2.0f*dx/(21-mouse);
- upvec.Normalize();
- upvec *= -2.0f*dy/(21-mouse);
-
- m_fEye[0] += upvec.X() + sidevec.X();
- m_fEye[1] += upvec.Y() + sidevec.Y();
- m_fEye[2] += upvec.Z() + sidevec.Z();
- m_fTarget[0] += upvec.X() + sidevec.X();
- m_fTarget[1] += upvec.Y() + sidevec.Y();
- m_fTarget[2] += upvec.Z() + sidevec.Z();
-
- ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
- ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, CK_TARGET);
- UpdatePosition(nTime, bAnimation);
+ Vector upvec(m_fUp), frontvec(m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2]), sidevec;
+ sidevec.Cross(frontvec, upvec);
+ sidevec.Normalize();
+ sidevec *= 2.0f*dx/(21-mouse);
+ upvec.Normalize();
+ upvec *= -2.0f*dy/(21-mouse);
+
+ m_fEye[0] += upvec.X() + sidevec.X();
+ m_fEye[1] += upvec.Y() + sidevec.Y();
+ m_fEye[2] += upvec.Z() + sidevec.Z();
+ m_fTarget[0] += upvec.X() + sidevec.X();
+ m_fTarget[1] += upvec.Y() + sidevec.Y();
+ m_fTarget[2] += upvec.Z() + sidevec.Z();
+
+ ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
+ ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, CK_TARGET);
+ UpdatePosition(nTime, bAnimation);
}
void Camera::DoRotate(int dx, int dy, int mouse, unsigned short nTime, bool bAnimation, bool bAddKey, float* /*center*/)
{
- Vector upvec(m_fUp), frontvec(m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2]), sidevec;
- sidevec.Cross(frontvec, upvec);
- sidevec.Normalize();
- sidevec *= 2.0f*dx/(21-mouse);
- upvec.Normalize();
- upvec *= -2.0f*dy/(21-mouse);
-
- // TODO: option to move eye or target
- float len = frontvec.Length();
- frontvec.Add(upvec.X() + sidevec.X(), upvec.Y() + sidevec.Y(), upvec.Z() + sidevec.Z());
- frontvec.Normalize();
- frontvec *= len;
- frontvec.Add(m_fTarget);
- frontvec.ToFloat(m_fEye);
-
- // Calculate new up
- upvec.FromFloat(m_fUp);
- frontvec.FromFloat(m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2]);
- sidevec.Cross(frontvec, upvec);
- upvec.Cross(sidevec, frontvec);
- upvec.Normalize();
- upvec.ToFloat(m_fUp);
-
- ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
- ChangeKey(nTime, bAnimation, bAddKey, m_fUp, CK_UP);
- UpdatePosition(nTime, bAnimation);
+ Vector upvec(m_fUp), frontvec(m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2]), sidevec;
+ sidevec.Cross(frontvec, upvec);
+ sidevec.Normalize();
+ sidevec *= 2.0f*dx/(21-mouse);
+ upvec.Normalize();
+ upvec *= -2.0f*dy/(21-mouse);
+
+ // TODO: option to move eye or target
+ float len = frontvec.Length();
+ frontvec.Add(upvec.X() + sidevec.X(), upvec.Y() + sidevec.Y(), upvec.Z() + sidevec.Z());
+ frontvec.Normalize();
+ frontvec *= len;
+ frontvec.Add(m_fTarget);
+ frontvec.ToFloat(m_fEye);
+
+ // Calculate new up
+ upvec.FromFloat(m_fUp);
+ frontvec.FromFloat(m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2]);
+ sidevec.Cross(frontvec, upvec);
+ upvec.Cross(sidevec, frontvec);
+ upvec.Normalize();
+ upvec.ToFloat(m_fUp);
+
+ ChangeKey(nTime, bAnimation, bAddKey, m_fEye, CK_EYE);
+ ChangeKey(nTime, bAnimation, bAddKey, m_fUp, CK_UP);
+ UpdatePosition(nTime, bAnimation);
}
void Camera::DoRoll(int dx, int mouse, unsigned short nTime, bool bAnimation, bool bAddKey)
{
- Matrix mat;
- float front[3] = { m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2] };
+ Matrix mat;
+ float front[3] = { m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2] };
- mat.FromAxisAngle(front, 2.0f*dx/(21-mouse));
- mat.TransformPoints(m_fUp, 1);
+ mat.FromAxisAngle(front, 2.0f*dx/(21-mouse));
+ mat.TransformPoints(m_fUp, 1);
- ChangeKey(nTime, bAnimation, bAddKey, m_fUp, CK_UP);
- UpdatePosition(nTime, bAnimation);
+ ChangeKey(nTime, bAnimation, bAddKey, m_fUp, CK_UP);
+ UpdatePosition(nTime, bAnimation);
}
void Camera::StartTiledRendering(int tw, int th, int iw, int ih, float fAspect)
{
- m_pTR = new TiledRender();
- m_pTR->TileSize(tw, th, 0);
- m_pTR->ImageSize(iw, ih);
- m_pTR->Perspective(m_fovy, fAspect, m_zNear, m_zFar);
+ m_pTR = new TiledRender();
+ m_pTR->TileSize(tw, th, 0);
+ m_pTR->ImageSize(iw, ih);
+ m_pTR->Perspective(m_fovy, fAspect, m_zNear, m_zFar);
}
void Camera::GetTileInfo(int* row, int* col, int* width, int* height)
{
- if (m_pTR != NULL)
- {
- *row = m_pTR->m_Rows - m_pTR->m_CurrentRow - 1;
- *col = m_pTR->m_CurrentColumn;
- *width = m_pTR->m_CurrentTileWidth;
- *height = m_pTR->m_CurrentTileHeight;
- }
+ if (m_pTR != NULL)
+ {
+ *row = m_pTR->m_Rows - m_pTR->m_CurrentRow - 1;
+ *col = m_pTR->m_CurrentColumn;
+ *width = m_pTR->m_CurrentTileWidth;
+ *height = m_pTR->m_CurrentTileHeight;
+ }
}
bool Camera::EndTile()
{
- if (m_pTR != NULL)
- {
- if (m_pTR->EndTile())
- return true;
+ if (m_pTR != NULL)
+ {
+ if (m_pTR->EndTile())
+ return true;
- delete m_pTR;
- m_pTR = NULL;
- }
+ delete m_pTR;
+ m_pTR = NULL;
+ }
- return false;
+ return false;
}
diff --git a/common/camera.h b/common/camera.h
index b492954..2f4acde 100644
--- a/common/camera.h
+++ b/common/camera.h
@@ -1,47 +1,86 @@
-//
-// camera.h
-////////////////////////////////////////////////////
-
#ifndef _CAMERA_H_
#define _CAMERA_H_
-#ifndef GLuint
-#include "GL/gl.h"
-#endif
-#include "boundbox.h"
+#include "opengl.h"
+#include "object.h"
-#define LC_CAMERA_HIDDEN 0x01
-#define LC_CAMERA_SELECTED 0x02
-#define LC_CAMERA_FOCUSED 0x04
+#define LC_CAMERA_HIDDEN 0x01
+#define LC_CAMERA_SELECTED 0x02
+#define LC_CAMERA_FOCUSED 0x04
#define LC_CAMERA_TARGET_SELECTED 0x08
#define LC_CAMERA_TARGET_FOCUSED 0x10
-typedef enum { LC_CAMERA_FRONT,LC_CAMERA_BACK,
- LC_CAMERA_TOP, LC_CAMERA_UNDER,
- LC_CAMERA_LEFT, LC_CAMERA_RIGHT,
- LC_CAMERA_MAIN, LC_CAMERA_USER } LC_CAMERA_TYPES;
+class Camera;
+class CameraTarget;
+class File;
+class TiledRender;
-typedef enum { CK_EYE, CK_TARGET, CK_UP } CK_TYPES;
+typedef enum
+{
+ LC_CAMERA_FRONT,LC_CAMERA_BACK,
+ LC_CAMERA_TOP, LC_CAMERA_UNDER,
+ LC_CAMERA_LEFT, LC_CAMERA_RIGHT,
+ LC_CAMERA_MAIN, LC_CAMERA_USER
+} LC_CAMERA_TYPES;
-typedef struct CAMERA_KEY {
- unsigned short time;
- float param[3];
- unsigned char type;
- CAMERA_KEY* next;
-} CAMERA_KEY;
+typedef enum { CK_EYE, CK_TARGET, CK_UP } CK_TYPES;
-class File;
-class TiledRender;
+typedef struct LC_CAMERA_KEY
+{
+ unsigned short time;
+ float param[3];
+ unsigned char type;
+ LC_CAMERA_KEY* next;
+} LC_CAMERA_KEY;
-class Camera
+class CameraTarget : public Object
{
-public:
- Camera();
- Camera(unsigned char nType, Camera* pPrev);
- Camera(float ex, float ey, float ez, float tx, float ty, float tz, Camera* pCamera);
- Camera(float eye[3], float target[3], float up[3], Camera* pCamera);
- ~Camera();
+ public:
+ CameraTarget (Camera *pParent);
+ ~CameraTarget ();
+
+ public:
+ void MinIntersectDist (LC_CLICKLINE* pLine);
+ Camera* GetParent () const
+ { return m_pParent; }
+
+ protected:
+ Camera* m_pParent;
+
+ friend class Camera; // FIXME: needed for BoundingBoxCalculate ()
+ // remove and use UpdatePosition instead
+};
+
+class Camera : public Object
+{
+ public:
+ Camera ();
+ Camera (unsigned char nType, Camera* pPrev);
+ Camera (float ex, float ey, float ez, float tx, float ty, float tz, Camera* pCamera);
+ Camera (const float *eye, const float *target, const float *up, Camera* pCamera);
+ virtual ~Camera ();
+
+ // Query current position
+ const float* GetEyePos () const
+ { return m_fEye; };
+ void GetEyePos (float* eye) const
+ { memcpy(eye, m_fEye, sizeof(m_fEye)); };
+ const float* GetTargetPos () const
+ { return m_fTarget; };
+ void GetTargetPos (float* target) const
+ { memcpy(target, m_fTarget, sizeof(m_fTarget)); };
+ const float* GetUpVec () const
+ { return m_fUp; };
+ void GetUpVec (float* up) const
+ { memcpy(up, m_fUp, sizeof(m_fUp)); };
+
+
+
+
+
+
+public:
Camera* m_pNext;
void Hide()
{ m_nState = LC_CAMERA_HIDDEN; }
@@ -76,15 +115,8 @@ public:
void FocusTarget()
{ m_nState |= (LC_CAMERA_TARGET_FOCUSED|LC_CAMERA_TARGET_SELECTED); }
- void GetEye(float* eye)
- { memcpy(eye, m_fEye, sizeof(m_fEye)); };
- void GetTarget(float* target)
- { memcpy(target, m_fTarget, sizeof(m_fTarget)); };
- void GetUp(float* up)
- { memcpy(up, m_fUp, sizeof(m_fUp)); };
-
public:
- void MinIntersectDist(CLICKLINE* Line);
+ void MinIntersectDist (LC_CLICKLINE* pLine);
void ChangeKey(unsigned short nTime, bool bAnimation, bool bAddKey, float param[3], unsigned char nKeyType);
void UpdatePosition(unsigned short nTime, bool bAnimation);
void Render(float fLineWidth);
@@ -106,30 +138,29 @@ public:
float m_zNear;
float m_zFar;
-protected:
- void CalculatePosition(unsigned short nTime, bool bAnimation, float eye[3], float target[3], float up[3]);
- void RemoveKeys();
- void Initialize();
-
- // For using the mouse
- BoundingBox m_BoundingBox;
- BoundingBox m_TargetBoundingBox;
-
- // Position
- CAMERA_KEY* m_pAnimationKeys;
- CAMERA_KEY* m_pInstructionKeys;
-
- // Attributes
- char m_strName[81];
- unsigned char m_nState;
- unsigned char m_nType;
- GLuint m_nList;
-
- // Temporary position
- float m_fEye[3];
- float m_fTarget[3];
- float m_fUp[3];
- TiledRender* m_pTR;
+ protected:
+ void CalculatePosition(unsigned short nTime, bool bAnimation, float eye[3], float target[3], float up[3]);
+ void RemoveKeys();
+ void Initialize();
+
+ // Camera target
+ CameraTarget* m_pTarget;
+
+ // Position
+ LC_CAMERA_KEY* m_pAnimationKeys;
+ LC_CAMERA_KEY* m_pInstructionKeys;
+
+ // Attributes
+ char m_strName[81];
+ unsigned char m_nState;
+ unsigned char m_nType;
+ GLuint m_nList;
+
+ // Temporary position
+ float m_fEye[3];
+ float m_fTarget[3];
+ float m_fUp[3];
+ TiledRender* m_pTR;
};
#endif // _CAMERA_H_
diff --git a/common/light.cpp b/common/light.cpp
index b546e4b..5638b35 100644
--- a/common/light.cpp
+++ b/common/light.cpp
@@ -1,10 +1,6 @@
// Light object.
-#ifdef LC_WINDOWS
-#include "stdafx.h"
-#endif
#include <stdlib.h>
-#include "boundbox.h"
#include "light.h"
#include "defines.h"
@@ -12,9 +8,10 @@
// Camera construction/destruction
Light::Light()
+ : Object (LC_OBJECT_LIGHT)
{
- m_BoundingBox.Initialize(this, LC_LIGHT);
- m_TargetBoundingBox.Initialize(this, LC_LIGHT_TARGET);
+ // m_BoundingBox.Initialize(this, LC_LIGHT);
+ // m_TargetBoundingBox.Initialize(this, LC_LIGHT_TARGET);
m_pNext = NULL;
m_nState = 0;
}
@@ -29,21 +26,21 @@ void Light::RemoveKeys()
}
-void Light::MinIntersectDist(CLICKLINE* pLine)
+void Light::MinIntersectDist(LC_CLICKLINE* pLine)
{
double dist;
if (m_nState & LC_LIGHT_HIDDEN)
return;
- dist = m_BoundingBox.FindIntersectDist(pLine);
+ dist = BoundingBoxIntersectDist (pLine);
if (dist < pLine->mindist)
{
pLine->mindist = dist;
- pLine->pClosest = &m_BoundingBox;
+ pLine->pClosest = this;
}
-
+ /*
dist = m_TargetBoundingBox.FindIntersectDist(pLine);
if (dist < pLine->mindist)
@@ -51,6 +48,7 @@ void Light::MinIntersectDist(CLICKLINE* pLine)
pLine->mindist = dist;
pLine->pClosest = &m_TargetBoundingBox;
}
+ */
}
void Light::UpdatePosition(unsigned short nTime, bool bAnimation)
diff --git a/common/light.h b/common/light.h
index bd656d2..e110799 100644
--- a/common/light.h
+++ b/common/light.h
@@ -1,10 +1,8 @@
-//
-// light.h
-////////////////////////////////////////////////////
-
#ifndef _LIGHT_H_
#define _LIGHT_H_
+#include "object.h"
+
#define LC_LIGHT_HIDDEN 0x01
#define LC_LIGHT_SELECTED 0x02
#define LC_LIGHT_FOCUSED 0x04
@@ -12,7 +10,29 @@
#define LC_LIGHT_TARGET_FOCUSED 0x10
#define LC_LIGHT_ENABLED 0x20
-class Light
+class Light;
+class LightTarget;
+
+class LightTarget : public Object
+{
+ public:
+ LightTarget (Light *pParent);
+ ~LightTarget ();
+
+ public:
+ void MinIntersectDist (LC_CLICKLINE* pLine);
+
+ Light* GetParent () const
+ { return m_pParent; }
+
+ protected:
+ Light* m_pParent;
+
+ friend class Light; // FIXME: needed for BoundingBoxCalculate ()
+ // remove and use UpdatePosition instead
+};
+
+class Light : public Object
{
public:
Light();
@@ -37,14 +57,14 @@ public:
const char* GetName()
{ return m_strName; }
- void MinIntersectDist(CLICKLINE* Line);
+ void MinIntersectDist(LC_CLICKLINE* Line);
void UpdatePosition(unsigned short nTime, bool bAnimation);
protected:
void RemoveKeys();
- BoundingBox m_BoundingBox;
- BoundingBox m_TargetBoundingBox;
+ // BoundingBox m_BoundingBox;
+ // BoundingBox m_TargetBoundingBox;
unsigned char m_nState;
char m_strName[81];
diff --git a/common/piece.cpp b/common/piece.cpp
index 91573bc..1f14020 100644
--- a/common/piece.cpp
+++ b/common/piece.cpp
@@ -1,16 +1,13 @@
// A piece object in the LeoCAD world.
//
-#ifdef LC_WINDOWS
-#include "stdafx.h"
-#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
+#include "opengl.h"
#include "matrix.h"
#include "pieceinf.h"
-#include "boundbox.h"
#include "texture.h"
#include "piece.h"
#include "group.h"
@@ -122,6 +119,7 @@ static bool lockarrays = true;
#endif
Piece::Piece(PieceInfo* pPieceInfo)
+ : Object (LC_OBJECT_PIECE)
{
#if ! (defined (GL_EXT_compiled_vertex_array))
@@ -141,7 +139,6 @@ Piece::Piece(PieceInfo* pPieceInfo)
}
#endif
- m_BoundingBox.Initialize(this, LC_PIECE);
m_pNext = NULL;
m_pPieceInfo = pPieceInfo;
m_nState = 0;
@@ -466,7 +463,7 @@ void Piece::CreateName(Piece* pPiece)
sprintf (m_strName, "%s #%.2d", m_pPieceInfo->m_strDescription, max+1);
}
-void Piece::LineFacet(float* p1, float* p2, float* p3, float* p4, CLICKLINE* pLine)
+void Piece::LineFacet(float* p1, float* p2, float* p3, float* p4, LC_CLICKLINE* pLine)
{
double t, t1, t2, x, y, z, plane[4];
plane[0] = ((p1[1]-p2[1])*(p3[2]-p2[2])) - ((p1[2]-p2[2])*(p3[1]-p2[1]));
@@ -542,18 +539,18 @@ void Piece::LineFacet(float* p1, float* p2, float* p3, float* p4, CLICKLINE* pLi
}
pLine->mindist = dist;
- pLine->pClosest = &m_BoundingBox;
+ pLine->pClosest = this;
}
}
}
}
}
-void Piece::MinIntersectDist(CLICKLINE* pLine)
+void Piece::MinIntersectDist(LC_CLICKLINE* pLine)
{
double dist;
- dist = m_BoundingBox.FindIntersectDist(pLine);
+ dist = BoundingBoxIntersectDist(pLine);
if (dist >= pLine->mindist)
return;
@@ -825,7 +822,7 @@ void Piece::UpdatePosition(unsigned short nTime, bool bAnimation)
// if (CalculatePositionRotation(nTime, bAnimation, m_fPosition, m_fRotation))
{
Matrix mat(m_fRotation, m_fPosition);
- m_BoundingBox.CalculateBoundingBox(&mat, m_pPieceInfo->m_fDimensions);
+ BoundingBoxCalculate(&mat, m_pPieceInfo->m_fDimensions);
for (int i = 0; i < m_pPieceInfo->m_nConnectionCount; i++)
{
mat.TransformPoint(m_pConnections[i].center, m_pPieceInfo->m_pConnections[i].center);
diff --git a/common/piece.h b/common/piece.h
index c163480..849ec23 100644
--- a/common/piece.h
+++ b/common/piece.h
@@ -10,7 +10,7 @@ class Piece;
class Group;
class PieceInfo;
-#include "boundbox.h"
+#include "object.h"
#include "globals.h"
#include "typedefs.h"
#include "defines.h"
@@ -28,8 +28,10 @@ typedef struct PIECE_KEY {
PIECE_KEY* next;
} PIECE_KEY;
-class Piece
+class Piece : public Object
{
+
+
public:
Piece(PieceInfo* pPieceInfo);
~Piece();
@@ -56,7 +58,7 @@ public:
bool IsFocused()
{ return (m_nState & LC_PIECE_FOCUSED) != 0; }
- void MinIntersectDist(CLICKLINE* pLine);
+ void MinIntersectDist(LC_CLICKLINE* pLine);
bool IsVisible(unsigned short nTime, bool bAnimation);
void Initialize(float x, float y, float z, unsigned char nStep, unsigned short nFrame, unsigned char nColor);
void CreateName(Piece* pPiece);
@@ -152,7 +154,7 @@ public:
}
*/
protected:
- void LineFacet(float* p1, float* p2, float* p3, float* p4, CLICKLINE* pLine);
+ void LineFacet(float* p1, float* p2, float* p3, float* p4, LC_CLICKLINE* pLine);
void RemoveKeys();
void BuildDrawInfo();
@@ -162,7 +164,6 @@ protected:
// Atributes
PieceInfo* m_pPieceInfo;
- BoundingBox m_BoundingBox;
Group* m_pGroup;
unsigned short m_nFrameShow;
diff --git a/common/project.cpp b/common/project.cpp
index 85ec7cb..c76af9e 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -1,16 +1,12 @@
// Everything that is a part of a LeoCAD project goes here.
//
-#ifdef LC_WINDOWS
-#include "stdafx.h"
-#endif
-#include <GL/gl.h>
-#include <GL/glu.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <math.h>
+#include "opengl.h"
#include "vector.h"
#include "matrix.h"
#include "pieceinf.h"
@@ -79,9 +75,9 @@ Project::Project()
m_nCurClipboard = 0;
m_pTerrain = new Terrain();
m_pBackground = new Texture();
- m_nAutosave = SystemGetProfileInt("Settings", "Autosave", 10);
- m_nMouse = SystemGetProfileInt("Default", "Mouse", 11);
- strcpy(m_strModelsPath, SystemGetProfileString("Default", "Projects", ""));
+ m_nAutosave = Sys_ProfileLoadInt ("Settings", "Autosave", 10);
+ m_nMouse = Sys_ProfileLoadInt ("Default", "Mouse", 11);
+ strcpy(m_strModelsPath, Sys_ProfileLoadString ("Default", "Projects", ""));
int i;
for (i = 0; i < LC_CONNECTIONS; i++)
@@ -97,7 +93,7 @@ Project::Project()
for (i = 0; i < 4; i++)
{
sprintf(entry, "File%d", i+1);
- strcpy(m_strRecentFiles[i], SystemGetProfileString("RecentFiles", entry, ""));
+ strcpy(m_strRecentFiles[i], Sys_ProfileLoadString ("RecentFiles", entry, ""));
}
// Create font table
@@ -165,7 +161,7 @@ Project::~Project()
{
sprintf(entry, "File%d", i+1);
// if (strlen(m_strRecentFiles[i]) > 0)
- SystemSetProfileString("RecentFiles", entry, m_strRecentFiles[i]);
+ Sys_ProfileSaveString("RecentFiles", entry, m_strRecentFiles[i]);
}
for (i = 0; i < 10; i++)
@@ -190,12 +186,12 @@ bool Project::Initialize(int argc, char *argv[], char* libpath)
char picture[LC_MAXPATH];
picture[0] = 0;
- unsigned long image = SystemGetProfileInt ("Default", "Image Options", 1|LC_IMAGE_TRANSPARENT);
- int width = SystemGetProfileInt("Default", "Image Width", 640);
- int height = SystemGetProfileInt("Default", "Image Height", 480);
-// int width = SystemGetProfileInt("Default", "Image Width", GetSystemMetrics(SM_CXSCREEN));
-// int height = SystemGetProfileInt("Default", "Image Height", GetSystemMetrics(SM_CYSCREEN));
- imopts.quality = SystemGetProfileInt("Default", "JPEG Quality", 70);
+ unsigned long image = Sys_ProfileLoadInt ("Default", "Image Options", 1|LC_IMAGE_TRANSPARENT);
+ int width = Sys_ProfileLoadInt ("Default", "Image Width", 640);
+ int height = Sys_ProfileLoadInt ("Default", "Image Height", 480);
+// int width = Sys_ProfileLoadInt ("Default", "Image Width", GetSystemMetrics(SM_CXSCREEN));
+// int height = Sys_ProfileLoadInt ("Default", "Image Height", GetSystemMetrics(SM_CYSCREEN));
+ imopts.quality = Sys_ProfileLoadInt ("Default", "JPEG Quality", 70);
imopts.interlaced = (image & LC_IMAGE_PROGRESSIVE) != 0;
imopts.transparent = (image & LC_IMAGE_TRANSPARENT) != 0;
imopts.truecolor = (image & LC_IMAGE_HIGHCOLOR) != 0;
@@ -572,49 +568,49 @@ void Project::LoadDefaults(bool cameras)
SystemUpdateAnimation(m_bAnimation, m_bAddKeys);
m_bUndoOriginal = true;
SystemUpdateUndoRedo(NULL, NULL);
- m_nDetail = SystemGetProfileInt("Default", "Detail", LC_DET_BRICKEDGES);
+ m_nDetail = Sys_ProfileLoadInt ("Default", "Detail", LC_DET_BRICKEDGES);
SystemUpdateRenderingMode((m_nDetail & LC_DET_BACKGROUND) != 0, (m_nDetail & LC_DET_FAST) != 0);
- m_nAngleSnap = (unsigned short)SystemGetProfileInt("Default", "Angle", 30);
- m_nSnap = SystemGetProfileInt("Default", "Snap", LC_DRAW_SNAP_A | LC_DRAW_SNAP_X | LC_DRAW_SNAP_Y | LC_DRAW_SNAP_Z | LC_DRAW_MOVE | LC_DRAW_PREVIEW);
+ m_nAngleSnap = (unsigned short)Sys_ProfileLoadInt ("Default", "Angle", 30);
+ m_nSnap = Sys_ProfileLoadInt ("Default", "Snap", LC_DRAW_SNAP_A | LC_DRAW_SNAP_X | LC_DRAW_SNAP_Y | LC_DRAW_SNAP_Z | LC_DRAW_MOVE | LC_DRAW_PREVIEW);
SystemUpdateSnap(m_nSnap);
m_nMoveSnap = 0;
SystemUpdateMoveSnap(m_nMoveSnap);
- m_fLineWidth = (float)SystemGetProfileInt("Default", "Line", 100)/100;
- m_fFogDensity = (float)SystemGetProfileInt("Default", "Density", 10)/100;
- rgb = SystemGetProfileInt("Default", "Fog", 0xFFFFFF);
+ m_fLineWidth = (float)Sys_ProfileLoadInt ("Default", "Line", 100)/100;
+ m_fFogDensity = (float)Sys_ProfileLoadInt ("Default", "Density", 10)/100;
+ rgb = Sys_ProfileLoadInt ("Default", "Fog", 0xFFFFFF);
m_fFogColor[0] = (float)((unsigned char) (rgb))/255;
m_fFogColor[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
m_fFogColor[2] = (float)((unsigned char) ((rgb) >> 16))/255;
m_fFogColor[3] = 1.0f;
- m_nGridSize = (unsigned short)SystemGetProfileInt("Default", "Grid", 20);
- rgb = SystemGetProfileInt("Default", "Ambient", 0x4B4B4B);
+ m_nGridSize = (unsigned short)Sys_ProfileLoadInt ("Default", "Grid", 20);
+ rgb = Sys_ProfileLoadInt ("Default", "Ambient", 0x4B4B4B);
m_fAmbient[0] = (float)((unsigned char) (rgb))/255;
m_fAmbient[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
m_fAmbient[2] = (float)((unsigned char) ((rgb) >> 16))/255;
m_fAmbient[3] = 1.0f;
- rgb = SystemGetProfileInt("Default", "Background", 0xFFFFFF);
+ rgb = Sys_ProfileLoadInt ("Default", "Background", 0xFFFFFF);
m_fBackground[0] = (float)((unsigned char) (rgb))/255;
m_fBackground[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
m_fBackground[2] = (float)((unsigned char) ((rgb) >> 16))/255;
m_fBackground[3] = 1.0f;
- rgb = SystemGetProfileInt("Default", "Gradient1", 0xBF0000);
+ rgb = Sys_ProfileLoadInt ("Default", "Gradient1", 0xBF0000);
m_fGradient1[0] = (float)((unsigned char) (rgb))/255;
m_fGradient1[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
m_fGradient1[2] = (float)((unsigned char) ((rgb) >> 16))/255;
- rgb = SystemGetProfileInt("Default", "Gradient2", 0xFFFFFF);
+ rgb = Sys_ProfileLoadInt ("Default", "Gradient2", 0xFFFFFF);
m_fGradient2[0] = (float)((unsigned char) (rgb))/255;
m_fGradient2[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
m_fGradient2[2] = (float)((unsigned char) ((rgb) >> 16))/255;
- m_nFPS = SystemGetProfileInt("Default", "FPS", 24);
+ m_nFPS = Sys_ProfileLoadInt ("Default", "FPS", 24);
m_nCurStep = 1;
m_nCurFrame = 1;
m_nTotalFrames = 100;
SystemUpdateTime(false, 1, 255);
- m_nScene = SystemGetProfileInt("Default", "Scene", 0);
+ m_nScene = Sys_ProfileLoadInt ("Default", "Scene", 0);
m_nSaveTimer = 0;
- strcpy(m_strHeader, SystemGetProfileString("Default", "Header", ""));
- strcpy(m_strFooter, SystemGetProfileString("Default", "Footer", "Page &P"));
- strcpy(m_strBackground, SystemGetProfileString("Default", "BMP", ""));
+ strcpy(m_strHeader, Sys_ProfileLoadString ("Default", "Header", ""));
+ strcpy(m_strFooter, Sys_ProfileLoadString ("Default", "Footer", "Page &P"));
+ strcpy(m_strBackground, Sys_ProfileLoadString ("Default", "BMP", ""));
m_pTerrain->LoadDefaults((m_nDetail & LC_DET_LINEAR) != 0);
RenderInitialize();
@@ -1194,7 +1190,7 @@ void Project::FileSave(File* file, bool bUndo)
{
unsigned long pos = 0;
- i = SystemGetProfileInt("Default", "Save Preview", 0);
+ i = Sys_ProfileLoadInt ("Default", "Save Preview", 0);
if (i != 0)
{
pos = file->GetPosition();
@@ -2099,7 +2095,7 @@ glLightfv(GL_LIGHT0, GL_SPECULAR, one);
if (pList)
{
float eye[3];
- m_pViewCameras[vp]->GetEye(eye);
+ m_pViewCameras[vp]->GetEyePos (eye);
BuildBSP(&tree, pList);
RenderBSP(&tree, eye, &bSel,
(m_nDetail & LC_DET_LIGHTING) != 0, (m_nDetail & LC_DET_SCREENDOOR) != 0, (m_nDetail & LC_DET_BRICKEDGES) != 0, &nLastColor, &bTrans);
@@ -2803,7 +2799,7 @@ void Project::CreateImages(LC_IMAGE** images, int width, int height, unsigned sh
{
int oldx, oldy;
unsigned short oldtime;
- void* render = SystemStartRender(width, height);
+ void* render = Sys_StartMemoryRender(width, height);
oldtime = m_bAnimation ? m_nCurFrame : m_nCurStep;
oldx = m_nViewX;
oldy = m_nViewY;
@@ -2839,7 +2835,14 @@ void Project::CreateImages(LC_IMAGE** images, int width, int height, unsigned sh
CalculateStep();
Render(true);
- images[i-from] = SystemGetRenderImage(render);
+ LC_IMAGE* image = (LC_IMAGE*)malloc(width*height*3+sizeof(LC_IMAGE));
+ image->width = width;
+ image->height = height;
+ image->bits = (unsigned char*)image + sizeof(LC_IMAGE);
+ glPixelStorei (GL_PACK_ALIGNMENT, 1);
+ glReadPixels (0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,image->bits);
+
+ images[i-from] = image;
}
// pDoc->m_ViewCameras[pDoc->m_nActiveViewport] = pOld;
m_nViewX = oldx;
@@ -2849,7 +2852,7 @@ void Project::CreateImages(LC_IMAGE** images, int width, int height, unsigned sh
else
m_nCurStep = (unsigned char)oldtime;
CalculateStep();
- SystemFinishRender(render);
+ Sys_FinishMemoryRender (render);
}
void Project::CreateHTMLPieceList(FILE* f, int nStep, bool bImages, char* ext)
@@ -3017,7 +3020,7 @@ void Project::HandleNotify(LC_NOTIFY id, unsigned long param)
else
pCamera->UnHide();
- pCamera->GetUp(tmp);
+ pCamera->GetUpVec(tmp);
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, CK_EYE);
@@ -3205,16 +3208,16 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
*ptr = 0;
}
}
- unsigned long image = SystemGetProfileInt ("Default", "HTML Options", 1|LC_IMAGE_TRANSPARENT);
+ unsigned long image = Sys_ProfileLoadInt ("Default", "HTML Options", 1|LC_IMAGE_TRANSPARENT);
opts.imdlg.imopts.background[0] = (unsigned char)(m_fBackground[0]*255);
opts.imdlg.imopts.background[1] = (unsigned char)(m_fBackground[1]*255);
opts.imdlg.imopts.background[2] = (unsigned char)(m_fBackground[2]*255);
opts.imdlg.from = 1;
opts.imdlg.to = 1;
opts.imdlg.multiple = false;
- opts.imdlg.width = SystemGetProfileInt("Default", "HTML Width", 256);
- opts.imdlg.height = SystemGetProfileInt("Default", "HTML Height", 160);
- opts.imdlg.imopts.quality = SystemGetProfileInt("Default", "JPEG Quality", 70);
+ opts.imdlg.width = Sys_ProfileLoadInt ("Default", "HTML Width", 256);
+ opts.imdlg.height = Sys_ProfileLoadInt ("Default", "HTML Height", 160);
+ opts.imdlg.imopts.quality = Sys_ProfileLoadInt ("Default", "JPEG Quality", 70);
opts.imdlg.imopts.interlaced = (image & LC_IMAGE_PROGRESSIVE) != 0;
opts.imdlg.imopts.transparent = (image & LC_IMAGE_TRANSPARENT) != 0;
opts.imdlg.imopts.truecolor = (image & LC_IMAGE_HIGHCOLOR) != 0;
@@ -3278,7 +3281,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if (opts.listend)
CreateHTMLPieceList(f, 0, opts.images, ext);
- fputs("</CENTER>\n<BR><HR><BR><B><I>Created by <A HREF=\"http://www.geocities.com/Colosseum/3479/leocad.htm\">LeoCAD</A></B></I><BR></HTML>\n", f);
+ fputs("</CENTER>\n<BR><HR><BR><B><I>Created by <A HREF=\"http://www.leocad.org\">LeoCAD</A></B></I><BR></HTML>\n", f);
fclose(f);
}
else
@@ -3298,7 +3301,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if (opts.listend)
fprintf(f, "<A HREF=\"%s-pieces.htm\">Pieces Used</A><BR>\n", m_strTitle);
- fputs("</CENTER>\n<BR><HR><BR><B><I>Created by <A HREF=\"http://www.geocities.com/Colosseum/3479/leocad.htm\">LeoCAD</A></B></I><BR></HTML>\n", f);
+ fputs("</CENTER>\n<BR><HR><BR><B><I>Created by <A HREF=\"http://www.leocad.org\">LeoCAD</A></B></I><BR></HTML>\n", f);
fclose(f);
}
@@ -3369,7 +3372,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if (opts.images)
{
int cx = 120, cy = 100;
- void* render = SystemStartRender(cx, cy);
+ void* render = Sys_StartMemoryRender (cx, cy);
float aspect = (float)cx/(float)cy;
glViewport(0, 0, cx, cy);
@@ -3418,12 +3421,18 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
pInfo->RenderPiece(m_nCurColor);
glFinish();
- LC_IMAGE* image = SystemGetRenderImage(render);
+ LC_IMAGE* image = (LC_IMAGE*)malloc(cx*cy*3+sizeof(LC_IMAGE));
+ image->width = cx;
+ image->height = cy;
+ image->bits = (unsigned char*)image + sizeof(LC_IMAGE);
+ glPixelStorei (GL_PACK_ALIGNMENT, 1);
+ glReadPixels (0,0,cx,cy,GL_RGB,GL_UNSIGNED_BYTE,image->bits);
+
sprintf(fn, "%s%s%s", opts.path, pInfo->m_strName, ext);
SaveImage(fn, image, &opts.imdlg.imopts);
free(image);
}
- SystemFinishRender(render);
+ Sys_FinishMemoryRender (render);
}
}
} break;
@@ -3714,9 +3723,9 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
fprintf(f, "// File created by LeoCAD\n//\n\n#include \"%s.inc\"\n", ptr);
float eye[3], target[3], up[3];
- m_pViewCameras[m_nActiveViewport]->GetEye(eye);
- m_pViewCameras[m_nActiveViewport]->GetTarget(target);
- m_pViewCameras[m_nActiveViewport]->GetUp(up);
+ m_pViewCameras[m_nActiveViewport]->GetEyePos (eye);
+ m_pViewCameras[m_nActiveViewport]->GetTargetPos (target);
+ m_pViewCameras[m_nActiveViewport]->GetUpVec (up);
fprintf(f, "\ncamera {\n sky<%1g,%1g,%1g>\n location <%1g, %1g, %1g>\n look_at <%1g, %1g, %1g>\n angle %.0f\n}\n\n",
up[0], up[1], up[2], eye[1], eye[0], eye[2], target[1], target[0], target[2], m_pViewCameras[m_nActiveViewport]->m_fovy);
@@ -5113,8 +5122,8 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if (!bControl)
vp = 4;
- pCam->GetTarget(target);
- pCam->GetEye(eye);
+ pCam->GetTargetPos (target);
+ pCam->GetEyePos (eye);
up[0] = (bs[0] + bs[3])/2 - target[0];
up[1] = (bs[1] + bs[4])/2 - target[1];
@@ -5130,7 +5139,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
target[1] += up[1];
target[2] += up[2];
- pCam->GetUp(up);
+ pCam->GetUpVec (up);
Vector upvec(up), frontvec(eye[0]-target[0], eye[1]-target[1], eye[2]-target[2]), sidevec;
frontvec.Normalize();
sidevec.Cross(frontvec, upvec);
@@ -5685,7 +5694,7 @@ void Project::GetFocusPosition(float* pos)
{
if (pCamera->IsEyeFocused())
{
- pCamera->GetEye(pos);
+ pCamera->GetEyePos (pos);
if ((m_nSnap & LC_DRAW_CM_UNITS) == 0)
{
pos[0] /= 0.8f;
@@ -5697,7 +5706,7 @@ void Project::GetFocusPosition(float* pos)
if (pCamera->IsTargetFocused())
{
- pCamera->GetTarget(pos);
+ pCamera->GetTargetPos (pos);
if ((m_nSnap & LC_DRAW_CM_UNITS) == 0)
{
pos[0] /= 0.8f;
@@ -5747,7 +5756,7 @@ PieceInfo* Project::FindPieceInfo (const char* name) const
return NULL;
}
-BoundingBox* Project::FindObjectFromPoint(int x, int y)
+void Project::FindObjectFromPoint(int x, int y, LC_CLICKLINE* pLine)
{
GLdouble px, py, pz, rx, ry, rz;
GLdouble modelMatrix[16], projMatrix[16];
@@ -5765,20 +5774,25 @@ BoundingBox* Project::FindObjectFromPoint(int x, int y)
gluUnProject(x, y, 0, modelMatrix, projMatrix, viewport, &px, &py, &pz);
gluUnProject(x, y, 1, modelMatrix, projMatrix, viewport, &rx, &ry, &rz);
- CLICKLINE ClickLine = { px, py, pz, rx-px, ry-py, rz-pz, DBL_MAX, NULL };
+ pLine->a1 = px;
+ pLine->b1 = py;
+ pLine->c1 = pz;
+ pLine->a2 = rx-px;
+ pLine->b2 = ry-py;
+ pLine->c2 = rz-pz;
+ pLine->mindist = DBL_MAX;
+ pLine->pClosest = NULL;
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
if (pPiece->IsVisible(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation))
- pPiece->MinIntersectDist(&ClickLine);
+ pPiece->MinIntersectDist(pLine);
for (pCamera = m_pCameras; pCamera; pCamera = pCamera->m_pNext)
if (pCamera != m_pViewCameras[m_nActiveViewport])
- pCamera->MinIntersectDist(&ClickLine);
+ pCamera->MinIntersectDist(pLine);
for (pLight = m_pLights; pLight; pLight = pLight->m_pNext)
- pLight->MinIntersectDist(&ClickLine);
-
- return ClickLine.pClosest;
+ pLight->MinIntersectDist(pLine);
}
/////////////////////////////////////////////////////////////////////////////
@@ -6480,163 +6494,167 @@ bool Project::OnKeyDown(char nKey, bool bControl, bool bShift)
void Project::OnLeftButtonDown(int x, int y, bool bControl, bool bShift)
{
- GLdouble modelMatrix[16], projMatrix[16], point[3];
- GLint viewport[4];
-
- if (IsDrawing())
- return;
-
- if (m_nTracking != LC_TRACK_NONE)
- if (StopTracking(false))
- return;
-
- if (SetActiveViewport(x, y))
- return;
-
- m_bTrackCancel = false;
- m_nDownX = x;
- m_nDownY = y;
-
- LoadViewportProjection();
- glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
- glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
- glGetIntegerv(GL_VIEWPORT, viewport);
+ GLdouble modelMatrix[16], projMatrix[16], point[3];
+ GLint viewport[4];
+
+ if (IsDrawing())
+ return;
+
+ if (m_nTracking != LC_TRACK_NONE)
+ if (StopTracking(false))
+ return;
+
+ if (SetActiveViewport(x, y))
+ return;
+
+ m_bTrackCancel = false;
+ m_nDownX = x;
+ m_nDownY = y;
+
+ LoadViewportProjection();
+ glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
+ glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
+ glGetIntegerv(GL_VIEWPORT, viewport);
+
+ gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]);
+ m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2];
+
+ switch (m_nCurAction)
+ {
+ case LC_ACTION_SELECT:
+ case LC_ACTION_ERASER:
+ case LC_ACTION_PAINT:
+ {
+ LC_CLICKLINE ClickLine;
+ FindObjectFromPoint (x, y, &ClickLine);
+
+ if (m_nCurAction == LC_ACTION_SELECT)
+ {
+ SelectAndFocusNone(bControl);
+
+ if (ClickLine.pClosest != NULL)
+ switch (ClickLine.pClosest->GetType ())
+ {
+ case LC_OBJECT_PIECE:
+ {
+ Piece* pPiece = (Piece*)ClickLine.pClosest;
+ pPiece->Focus();
+ Group* pGroup = pPiece->GetTopGroup();
+
+ if (pGroup != NULL)
+ for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
+ if (pPiece->GetTopGroup() == pGroup)
+ pPiece->Select();
+ } break;
+
+ case LC_OBJECT_CAMERA:
+ {
+ ((Camera*)ClickLine.pClosest)->FocusEye();
+ } break;
+
+ case LC_OBJECT_CAMERA_TARGET:
+ {
+ ((CameraTarget*)ClickLine.pClosest)->GetParent()->FocusTarget();
+ } break;
+
+ case LC_OBJECT_LIGHT:
+ {
+ ((Light*)ClickLine.pClosest)->FocusEye();
+ } break;
+
+ case LC_OBJECT_LIGHT_TARGET:
+ {
+ ((LightTarget*)ClickLine.pClosest)->GetParent()->FocusTarget();
+ } break;
+ }
- gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]);
- m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2];
+ UpdateSelection();
+ SystemRedrawView();
+ if (ClickLine.pClosest)
+ SystemUpdateFocus(ClickLine.pClosest, ClickLine.pClosest->GetType()|LC_UPDATE_OBJECT|LC_UPDATE_TYPE);
+ else
+ SystemUpdateFocus(NULL, LC_UPDATE_OBJECT);
+ }
- switch (m_nCurAction)
+ if ((m_nCurAction == LC_ACTION_ERASER) && (ClickLine.pClosest != NULL))
+ {
+ switch (ClickLine.pClosest->GetType ())
{
- case LC_ACTION_SELECT:
- case LC_ACTION_ERASER:
- case LC_ACTION_PAINT:
- {
- BoundingBox* pBox;
- pBox = FindObjectFromPoint(x, y);
-
- if (m_nCurAction == LC_ACTION_SELECT)
- {
- SelectAndFocusNone(bControl);
-
- if (pBox != NULL)
- switch (pBox->GetOwnerType())
- {
- case LC_PIECE:
- {
- Piece* pPiece = (Piece*)pBox->GetOwner();
- pPiece->Focus();
- Group* pGroup = pPiece->GetTopGroup();
-
- if (pGroup != NULL)
- for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
- if (pPiece->GetTopGroup() == pGroup)
- pPiece->Select();
- } break;
-
- case LC_CAMERA:
- {
- ((Camera*)pBox->GetOwner())->FocusEye();
- } break;
-
- case LC_CAMERA_TARGET:
- {
- ((Camera*)pBox->GetOwner())->FocusTarget();
- } break;
-
- case LC_LIGHT:
- {
- ((Light*)pBox->GetOwner())->FocusEye();
- } break;
-
- case LC_LIGHT_TARGET:
- {
- ((Light*)pBox->GetOwner())->FocusTarget();
- } break;
- }
-
- UpdateSelection();
- SystemRedrawView();
- if (pBox)
- SystemUpdateFocus(pBox->GetOwner(), pBox->GetOwnerType()|LC_UPDATE_OBJECT|LC_UPDATE_TYPE);
- else
- SystemUpdateFocus(NULL, LC_UPDATE_OBJECT);
- }
-
- if ((m_nCurAction == LC_ACTION_ERASER) && (pBox != NULL))
- {
- switch (pBox->GetOwnerType())
- {
- case LC_PIECE:
- {
- Piece* pPiece = (Piece*)pBox->GetOwner();
- RemovePiece(pPiece);
- delete pPiece;
+ case LC_OBJECT_PIECE:
+ {
+ Piece* pPiece = (Piece*)ClickLine.pClosest;
+ RemovePiece(pPiece);
+ delete pPiece;
// CalculateStep();
- RemoveEmptyGroups();
- } break;
-
- case LC_CAMERA:
- case LC_CAMERA_TARGET:
- {
- Camera* pCamera = (Camera*)pBox->GetOwner();
- bool bCanDelete = pCamera->IsUser();
-
- for (int i = 0; i < 4; i++)
- if (pCamera == m_pViewCameras[i])
- bCanDelete = false;
-
- if (bCanDelete)
- {
- Camera* pPrev;
- for (pPrev = m_pCameras; pPrev; pPrev = pPrev->m_pNext)
- if (pPrev->m_pNext == pCamera)
- {
- pPrev->m_pNext = pCamera->m_pNext;
- delete pCamera;
- SystemUpdateCameraMenu(m_pCameras);
- SystemUpdateCurrentCamera(NULL, m_pViewCameras[m_nActiveViewport], m_pCameras);
- break;
- }
- }
- } break;
+ RemoveEmptyGroups();
+ } break;
+
+ case LC_OBJECT_CAMERA:
+ case LC_OBJECT_CAMERA_TARGET:
+ {
+ Camera* pCamera;
+ if (ClickLine.pClosest->GetType () == LC_OBJECT_CAMERA)
+ pCamera = (Camera*)ClickLine.pClosest;
+ else
+ pCamera = ((CameraTarget*)ClickLine.pClosest)->GetParent();
+ bool bCanDelete = pCamera->IsUser();
+
+ for (int i = 0; i < 4; i++)
+ if (pCamera == m_pViewCameras[i])
+ bCanDelete = false;
+
+ if (bCanDelete)
+ {
+ Camera* pPrev;
+ for (pPrev = m_pCameras; pPrev; pPrev = pPrev->m_pNext)
+ if (pPrev->m_pNext == pCamera)
+ {
+ pPrev->m_pNext = pCamera->m_pNext;
+ delete pCamera;
+ SystemUpdateCameraMenu(m_pCameras);
+ SystemUpdateCurrentCamera(NULL, m_pViewCameras[m_nActiveViewport], m_pCameras);
+ break;
+ }
+ }
+ } break;
- case LC_LIGHT:
- case LC_LIGHT_TARGET:
- {
+ case LC_OBJECT_LIGHT:
+ case LC_OBJECT_LIGHT_TARGET:
+ {
/* pos = m_Lights.Find(pObject->m_pParent);
m_Lights.RemoveAt(pos);
delete pObject->m_pParent;
-*/ } break;
- }
+*/ } break;
+ }
- UpdateSelection();
- SystemRedrawView();
- SetModifiedFlag(true);
- CheckPoint("Deleting");
+ UpdateSelection();
+ SystemRedrawView();
+ SetModifiedFlag(true);
+ CheckPoint("Deleting");
// AfxGetMainWnd()->PostMessage(WM_LC_UPDATE_INFO, NULL, OT_PIECE);
- }
+ }
- if ((m_nCurAction == LC_ACTION_PAINT) && (pBox != NULL) &&
- (pBox->GetOwnerType() == LC_PIECE))
- {
- Piece* pPiece = (Piece*)pBox->GetOwner();
-
- if (pPiece->GetColor() != m_nCurColor)
- {
- bool bTrans = pPiece->IsTransparent();
- pPiece->SetColor(m_nCurColor);
- if (bTrans != pPiece->IsTransparent())
- pPiece->CalculateConnections(m_pConnections, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, true, true);
+ if ((m_nCurAction == LC_ACTION_PAINT) && (ClickLine.pClosest != NULL) &&
+ (ClickLine.pClosest->GetType() == LC_OBJECT_PIECE))
+ {
+ Piece* pPiece = (Piece*)ClickLine.pClosest;
- SetModifiedFlag(true);
- CheckPoint("Painting");
- SystemUpdateFocus(NULL, 0);
- SystemRedrawView();
- }
- }
- } break;
+ if (pPiece->GetColor() != m_nCurColor)
+ {
+ bool bTrans = pPiece->IsTransparent();
+ pPiece->SetColor(m_nCurColor);
+ if (bTrans != pPiece->IsTransparent())
+ pPiece->CalculateConnections(m_pConnections, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, true, true);
+
+ SetModifiedFlag(true);
+ CheckPoint("Painting");
+ SystemUpdateFocus(NULL, 0);
+ SystemRedrawView();
+ }
+ }
+ } break;
- case LC_ACTION_INSERT:
+ case LC_ACTION_INSERT:
// case LC_ACTION_LIGHT:
{
if (m_nCurAction == LC_ACTION_INSERT)
@@ -6756,73 +6774,73 @@ void Project::OnLeftButtonDown(int x, int y, bool bControl, bool bShift)
void Project::OnLeftButtonDoubleClick(int x, int y, bool bControl, bool bShift)
{
- GLdouble modelMatrix[16], projMatrix[16], point[3];
- GLint viewport[4];
+ GLdouble modelMatrix[16], projMatrix[16], point[3];
+ GLint viewport[4];
- if (IsDrawing())
- return;
+ if (IsDrawing())
+ return;
- if (SetActiveViewport(x, y))
- return;
+ if (SetActiveViewport(x, y))
+ return;
- LoadViewportProjection();
- glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
- glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
- glGetIntegerv(GL_VIEWPORT, viewport);
+ LoadViewportProjection();
+ glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
+ glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
+ glGetIntegerv(GL_VIEWPORT, viewport);
- gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]);
- m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2];
+ gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]);
+ m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2];
- BoundingBox* pBox;
- pBox = FindObjectFromPoint(x, y);
+ LC_CLICKLINE ClickLine;
+ FindObjectFromPoint (x, y, &ClickLine);
-// if (m_nCurAction == LC_ACTION_SELECT)
- {
- SelectAndFocusNone(bControl);
+// if (m_nCurAction == LC_ACTION_SELECT)
+ {
+ SelectAndFocusNone(bControl);
- if (pBox != NULL)
- switch (pBox->GetOwnerType())
- {
- case LC_PIECE:
- {
- Piece* pPiece = (Piece*)pBox->GetOwner();
- pPiece->Focus();
- Group* pGroup = pPiece->GetTopGroup();
+ if (ClickLine.pClosest != NULL)
+ switch (ClickLine.pClosest->GetType ())
+ {
+ case LC_OBJECT_PIECE:
+ {
+ Piece* pPiece = (Piece*)ClickLine.pClosest;
+ pPiece->Focus();
+ Group* pGroup = pPiece->GetTopGroup();
- if (pGroup != NULL)
- for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
- if (pPiece->GetTopGroup() == pGroup)
- pPiece->Select();
- } break;
+ if (pGroup != NULL)
+ for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
+ if (pPiece->GetTopGroup() == pGroup)
+ pPiece->Select();
+ } break;
- case LC_CAMERA:
- {
- ((Camera*)pBox->GetOwner())->FocusEye();
- } break;
-
- case LC_CAMERA_TARGET:
- {
- ((Camera*)pBox->GetOwner())->FocusTarget();
- } break;
+ case LC_OBJECT_CAMERA:
+ {
+ ((Camera*)ClickLine.pClosest)->FocusEye();
+ } break;
- case LC_LIGHT:
- {
- ((Light*)pBox->GetOwner())->FocusEye();
- } break;
+ case LC_OBJECT_CAMERA_TARGET:
+ {
+ ((CameraTarget*)ClickLine.pClosest)->GetParent()->FocusTarget();
+ } break;
- case LC_LIGHT_TARGET:
- {
- ((Light*)pBox->GetOwner())->FocusTarget();
- } break;
- }
+ case LC_OBJECT_LIGHT:
+ {
+ ((Light*)ClickLine.pClosest)->FocusEye();
+ } break;
- UpdateSelection();
- SystemRedrawView();
- if (pBox)
- SystemUpdateFocus(pBox->GetOwner(), pBox->GetOwnerType()|LC_UPDATE_OBJECT|LC_UPDATE_TYPE);
- else
- SystemUpdateFocus(NULL, LC_UPDATE_OBJECT);
- }
+ case LC_OBJECT_LIGHT_TARGET:
+ {
+ ((LightTarget*)ClickLine.pClosest)->GetParent()->FocusTarget();
+ } break;
+ }
+
+ UpdateSelection();
+ SystemRedrawView();
+ if (ClickLine.pClosest)
+ SystemUpdateFocus(ClickLine.pClosest, ClickLine.pClosest->GetType()|LC_UPDATE_OBJECT|LC_UPDATE_TYPE);
+ else
+ SystemUpdateFocus(NULL, LC_UPDATE_OBJECT);
+ }
}
void Project::OnLeftButtonUp(int x, int y, bool bControl, bool bShift)
@@ -6957,7 +6975,7 @@ void Project::OnMouseMove(int x, int y, bool bControl, bool bShift)
pCamera = pCamera->m_pNext;
float target[3];
- pCamera->GetTarget(target);
+ pCamera->GetTargetPos (target);
target[0] += delta[0];
target[1] += delta[1];
target[2] += delta[2];
@@ -7100,9 +7118,9 @@ void Project::OnMouseMove(int x, int y, bool bControl, bool bShift)
if (m_pViewCameras[m_nActiveViewport]->IsSide())
{
float eye[3], target[3], up[3];
- m_pViewCameras[m_nActiveViewport]->GetEye(eye);
- m_pViewCameras[m_nActiveViewport]->GetTarget(target);
- m_pViewCameras[m_nActiveViewport]->GetUp(up);
+ m_pViewCameras[m_nActiveViewport]->GetEyePos(eye);
+ m_pViewCameras[m_nActiveViewport]->GetTargetPos(target);
+ m_pViewCameras[m_nActiveViewport]->GetUpVec(up);
Camera* pCamera = new Camera(eye, target, up, m_pCameras);
m_pViewCameras[m_nActiveViewport] = pCamera;
@@ -7138,16 +7156,3 @@ void Project::OnMouseMove(int x, int y, bool bControl, bool bShift)
} break;
}
}
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/common/project.h b/common/project.h
index 181982c..651c199 100644
--- a/common/project.h
+++ b/common/project.h
@@ -1,17 +1,15 @@
#ifndef _PROJECT_H_
#define _PROJECT_H_
+#include "object.h"
#include "defines.h"
#include "typedefs.h"
-#ifdef LC_WINDOWS
-#include "stdafx.h"
-#endif
-#include <GL/gl.h>
+#include "opengl.h"
typedef enum
{
- LC_TRACK_NONE, LC_TRACK_START_LEFT, LC_TRACK_LEFT,
- LC_TRACK_START_RIGHT, LC_TRACK_RIGHT
+ LC_TRACK_NONE, LC_TRACK_START_LEFT, LC_TRACK_LEFT,
+ LC_TRACK_START_RIGHT, LC_TRACK_RIGHT
} LC_MOUSE_TRACK;
class Piece;
@@ -19,7 +17,6 @@ class Camera;
class Light;
class Group;
class Texture;
-class BoundingBox;
class Terrain;
class PieceInfo;
class Matrix;
@@ -55,6 +52,8 @@ public:
unsigned char GetLastStep();
bool IsAnimation()
{ return m_bAnimation; }
+ unsigned short GetCurrentTime ()
+ { return m_bAnimation ? m_nCurFrame : m_nCurStep; }
int GetPieceLibraryCount()
{ return m_nPieceCount; }
const char* GetLibraryPath()
@@ -138,7 +137,7 @@ protected:
void AddPiece(Piece* pPiece);
void RemovePiece(Piece* pPiece);
bool RemoveSelectedObjects();
- BoundingBox* FindObjectFromPoint(int x, int y);
+ void FindObjectFromPoint(int x, int y, LC_CLICKLINE* pLine);
void SelectAndFocusNone(bool bFocusOnly);
void CalculateStep();
void MoveSelectedObjects(float x, float y, float z);
diff --git a/common/terrain.cpp b/common/terrain.cpp
index b43cf6a..072b865 100644
--- a/common/terrain.cpp
+++ b/common/terrain.cpp
@@ -1,14 +1,11 @@
// Terrain: a Bezier surface.
//
-#ifdef LC_WINDOWS
-#include "stdafx.h"
-#endif
-#include <GL/gl.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
+#include "opengl.h"
#include "defines.h"
#include "terrain.h"
#include "file.h"
@@ -578,7 +575,7 @@ void Terrain::Render(Camera* pCam, float aspect)
if (m_nOptions & LC_TERRAIN_FLAT)
{
float eye[3];
- pCam->GetEye(eye);
+ pCam->GetEyePos(eye);
glPushMatrix();
glTranslatef(eye[0], eye[1], 0);
glScalef(pCam->m_zFar, pCam->m_zFar, 1);
@@ -672,7 +669,7 @@ void Terrain::FindVisiblePatches(Camera* pCam, float aspect)
{
// Get camera position information.
float eye[3];
- pCam->GetEye(eye);
+ pCam->GetEyePos(eye);
// Get perspective information.
float alpha = pCam->m_fovy / 2.0f;
@@ -684,8 +681,8 @@ void Terrain::FindVisiblePatches(Camera* pCam, float aspect)
// Get vector stuff from the position.
float nonOrthoTop[3], target[3];
- pCam->GetUp(nonOrthoTop);
- pCam->GetTarget(target);
+ pCam->GetUpVec(nonOrthoTop);
+ pCam->GetTargetPos(target);
float front[3] = { target[0] - eye[0], target[1] - eye[1], target[2] - eye[2]};
float side[3];
side[0] = nonOrthoTop[1]*front[2] - nonOrthoTop[2]*front[1];
@@ -790,7 +787,7 @@ void Terrain::FindVisiblePatches(Camera* pCam, float aspect)
void Terrain::LoadDefaults(bool bLinear)
{
- unsigned long rgb = SystemGetProfileInt("Default", "Floor", RGB (0,191,0));
+ unsigned long rgb = Sys_ProfileLoadInt ("Default", "Floor", RGB (0,191,0));
m_fColor[0] = (float)((unsigned char) (rgb))/255;
m_fColor[1] = (float)((unsigned char) (((unsigned short) (rgb)) >> 8))/255;
m_fColor[2] = (float)((unsigned char) ((rgb) >> 16))/255;
@@ -798,7 +795,7 @@ void Terrain::LoadDefaults(bool bLinear)
m_uSize = 50;
m_vSize = 50;
- strcpy(m_strTexture, SystemGetProfileString("Default", "FloorBMP", ""));
+ strcpy (m_strTexture, Sys_ProfileLoadString ("Default", "FloorBMP", ""));
m_pTexture->Unload();
m_nOptions = LC_TERRAIN_FLAT;