summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/camera.cpp34
-rw-r--r--common/light.cpp28
-rwxr-xr-xcommon/object.cpp2
-rw-r--r--common/pieceinf.cpp14
-rw-r--r--common/project.cpp16
-rw-r--r--common/vector.cpp84
-rw-r--r--common/vector.h59
7 files changed, 74 insertions, 163 deletions
diff --git a/common/camera.cpp b/common/camera.cpp
index a663037..8381cb0 100644
--- a/common/camera.cpp
+++ b/common/camera.cpp
@@ -152,7 +152,7 @@ Camera::Camera (float ex, float ey, float ez, float tx, float ty, float tz, Came
Vector upvec(0,0,1), frontvec(ex-tx, ey-ty, ez-tz), sidevec;
frontvec.Normalize();
if (frontvec == upvec)
- sidevec.FromFloat(1,0,0);
+ sidevec = Vector(1,0,0);
else
sidevec.Cross(frontvec, upvec);
upvec.Cross(sidevec, frontvec);
@@ -730,12 +730,12 @@ void Camera::DoZoom(int dy, int mouse, unsigned short nTime, bool bAnimation, bo
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();
+ m_fEye[0] += frontvec[0];
+ m_fEye[1] += frontvec[1];
+ m_fEye[2] += frontvec[2];
+ m_fTarget[0] += frontvec[0];
+ m_fTarget[1] += frontvec[1];
+ m_fTarget[2] += frontvec[2];
ChangeKey(nTime, bAnimation, bAddKey, m_fEye, LC_CK_EYE);
ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, LC_CK_TARGET);
@@ -751,12 +751,12 @@ void Camera::DoPan(int dx, int dy, int mouse, unsigned short nTime, bool bAnimat
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();
+ m_fEye[0] += upvec[0] + sidevec[0];
+ m_fEye[1] += upvec[1] + sidevec[1];
+ m_fEye[2] += upvec[2] + sidevec[2];
+ m_fTarget[0] += upvec[0] + sidevec[0];
+ m_fTarget[1] += upvec[1] + sidevec[1];
+ m_fTarget[2] += upvec[2] + sidevec[2];
ChangeKey(nTime, bAnimation, bAddKey, m_fEye, LC_CK_EYE);
ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, LC_CK_TARGET);
@@ -774,15 +774,15 @@ void Camera::DoRotate(int dx, int dy, int mouse, unsigned short nTime, bool bAni
// 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 += Vector(upvec[0] + sidevec[0], upvec[1] + sidevec[1], upvec[2] + sidevec[2]);
frontvec.Normalize();
frontvec *= len;
- frontvec.Add(m_fTarget);
+ frontvec += Vector(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]);
+ upvec = Vector(m_fUp[0], m_fUp[1], m_fUp[2]);
+ frontvec = Vector(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();
diff --git a/common/light.cpp b/common/light.cpp
index 11bf8ad..2e545a4 100644
--- a/common/light.cpp
+++ b/common/light.cpp
@@ -285,19 +285,19 @@ void Light::UpdatePosition (unsigned short nTime, bool bAnimation)
Vector frontvec (m_fTarget[0]-m_fPos[0], m_fTarget[1]-m_fPos[1], m_fTarget[2]-m_fPos[2]);
float len = frontvec.Length (), up[3] = { 1, 1, 1 };
- if (fabs (frontvec.X ()) < fabs (frontvec.Y ()))
+ if (fabs (frontvec[0]) < fabs (frontvec[1]))
{
- if (fabs (frontvec.X ()) < fabs (frontvec.Z ()))
- up[0] = -(up[1]*frontvec.Y () + up[2]*frontvec.Z ());
+ if (fabs (frontvec[0]) < fabs (frontvec[2]))
+ up[0] = -(up[1]*frontvec[1] + up[2]*frontvec[2]);
else
- up[2] = -(up[0]*frontvec.X () + up[1]*frontvec.Y ());
+ up[2] = -(up[0]*frontvec[0] + up[1]*frontvec[1]);
}
else
{
- if (fabs (frontvec.Y ()) < fabs (frontvec.Z ()))
- up[1] = -(up[0]*frontvec.X () + up[2]*frontvec.Z ());
+ if (fabs (frontvec[1]) < fabs (frontvec[2]))
+ up[1] = -(up[0]*frontvec[0] + up[2]*frontvec[2]);
else
- up[2] = -(up[0]*frontvec.X () + up[1]*frontvec.Y ());
+ up[2] = -(up[0]*frontvec[0] + up[1]*frontvec[1]);
}
Matrix mat;
@@ -467,19 +467,19 @@ void Light::Render (float fLineWidth)
Vector frontvec(m_fTarget[0]-m_fPos[0], m_fTarget[1]-m_fPos[1], m_fTarget[2]-m_fPos[2]);
float len = frontvec.Length (), up[3] = { 1, 1, 1 };
- if (fabs (frontvec.X ()) < fabs (frontvec.Y ()))
+ if (fabs (frontvec[0]) < fabs (frontvec[1]))
{
- if (fabs (frontvec.X ()) < fabs (frontvec.Z ()))
- up[0] = -(up[1]*frontvec.Y () + up[2]*frontvec.Z ());
+ if (fabs (frontvec[0]) < fabs (frontvec[2]))
+ up[0] = -(up[1]*frontvec[1] + up[2]*frontvec[2]);
else
- up[2] = -(up[0]*frontvec.X () + up[1]*frontvec.Y ());
+ up[2] = -(up[0]*frontvec[0] + up[1]*frontvec[1]);
}
else
{
- if (fabs (frontvec.Y ()) < fabs (frontvec.Z ()))
- up[1] = -(up[0]*frontvec.X () + up[2]*frontvec.Z ());
+ if (fabs (frontvec[1]) < fabs (frontvec[2]))
+ up[1] = -(up[0]*frontvec[0] + up[2]*frontvec[2]);
else
- up[2] = -(up[0]*frontvec.X () + up[1]*frontvec.Y ());
+ up[2] = -(up[0]*frontvec[0] + up[1]*frontvec[1]);
}
glPushMatrix ();
diff --git a/common/object.cpp b/common/object.cpp
index 489ad12..1b8a91c 100755
--- a/common/object.cpp
+++ b/common/object.cpp
@@ -46,7 +46,7 @@ double LC_CLICKLINE::PointDistance (float *point)
else
t /= len;
- d.Scale (t*len);
+ d *= (t*len);
op -= d;
}
diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp
index 5aca46d..a31d414 100644
--- a/common/pieceinf.cpp
+++ b/common/pieceinf.cpp
@@ -1663,18 +1663,18 @@ void PieceInfo::ZoomExtents(float Fov, float Aspect, float* EyePos) const
Vector FrontVec, RightVec, UpVec;
// Calculate view matrix.
- UpVec.FromFloat(Top);
+ UpVec = Vector(Top[0], Top[1], Top[2]);
UpVec.Normalize();
- FrontVec.FromFloat(Front);
+ FrontVec = Vector(Front[0], Front[1], Front[2]);
FrontVec.Normalize();
- RightVec.FromFloat(Side);
+ RightVec = Vector(Side[0], Side[1], Side[2]);
RightVec.Normalize();
float ViewMat[16];
- ViewMat[0] = -RightVec.X(); ViewMat[4] = -RightVec.Y(); ViewMat[8] = -RightVec.Z(); ViewMat[12] = 0.0;
- ViewMat[1] = UpVec.X(); ViewMat[5] = UpVec.Y(); ViewMat[9] = UpVec.Z(); ViewMat[13] = 0.0;
- ViewMat[2] = -FrontVec.X(); ViewMat[6] = -FrontVec.Y(); ViewMat[10] = -FrontVec.Z(); ViewMat[14] = 0.0;
- ViewMat[3] = 0.0; ViewMat[7] = 0.0; ViewMat[11] = 0.0; ViewMat[15] = 1.0;
+ ViewMat[0] = -RightVec[0]; ViewMat[4] = -RightVec[1]; ViewMat[8] = -RightVec[2]; ViewMat[12] = 0.0;
+ ViewMat[1] = UpVec[0]; ViewMat[5] = UpVec[1]; ViewMat[9] = UpVec[2]; ViewMat[13] = 0.0;
+ ViewMat[2] = -FrontVec[0]; ViewMat[6] = -FrontVec[1]; ViewMat[10] = -FrontVec[2]; ViewMat[14] = 0.0;
+ ViewMat[3] = 0.0; ViewMat[7] = 0.0; ViewMat[11] = 0.0; ViewMat[15] = 1.0;
// Load ViewMatrix
glMatrixMode(GL_MODELVIEW);
diff --git a/common/project.cpp b/common/project.cpp
index b5ae75c..7b61352 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -460,7 +460,7 @@ bool Project::FileLoad(File* file, bool bUndo, bool bMerge)
Vector upvec(0,0,1), frontvec((float)(eye[0]-target[0]), (float)(eye[1]-target[1]), (float)(eye[2]-target[2])), sidevec;
frontvec.Normalize();
if (frontvec == upvec)
- sidevec.FromFloat(1,0,0);
+ sidevec = Vector(1,0,0);
else
sidevec.Cross(frontvec, upvec);
upvec.Cross(sidevec, frontvec);
@@ -5743,7 +5743,7 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
upvec.Cross(sidevec, frontvec);
upvec.Normalize();
upvec.ToFloat(up);
- frontvec.Scale(0.25f);
+ frontvec *= 0.25f;
glMatrixMode(GL_MODELVIEW);
glGetDoublev(GL_PROJECTION_MATRIX,projMatrix);
@@ -5751,9 +5751,9 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
for (out = 0; out < 10000; out++) // Zoom in
{
- eye[0] -= frontvec.X();
- eye[1] -= frontvec.Y();
- eye[2] -= frontvec.Z();
+ eye[0] -= frontvec[0];
+ eye[1] -= frontvec[1];
+ eye[2] -= frontvec[2];
glLoadIdentity();
gluLookAt(eye[0], eye[1], eye[2], target[0], target[1], target[2], up[0], up[1], up[2]);
glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
@@ -5775,9 +5775,9 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
for (out = 0; out < 10000 && !stp; out++) // zoom out
{
stp = true;
- eye[0] += frontvec.X();
- eye[1] += frontvec.Y();
- eye[2] += frontvec.Z();
+ eye[0] += frontvec[0];
+ eye[1] += frontvec[1];
+ eye[2] += frontvec[2];
glLoadIdentity();
gluLookAt(eye[0], eye[1], eye[2], target[0], target[1], target[2], up[0], up[1], up[2]);
glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix);
diff --git a/common/vector.cpp b/common/vector.cpp
index e0cfd4f..0495163 100644
--- a/common/vector.cpp
+++ b/common/vector.cpp
@@ -1,7 +1,3 @@
-// Vector.cpp: implementation of the Vector class.
-//
-//////////////////////////////////////////////////////////////////////
-
#include <math.h>
#include "vector.h"
#include "defines.h"
@@ -9,52 +5,37 @@
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
-Vector::Vector ()
+Vector::Vector()
{
m_fPoint[0] = 0;
m_fPoint[1] = 0;
m_fPoint[2] = 0;
}
-Vector::Vector (float x, float y, float z)
+Vector::Vector(float x, float y, float z)
{
m_fPoint[0] = x;
m_fPoint[1] = y;
m_fPoint[2] = z;
}
-Vector::Vector (const float *point)
+Vector::Vector(const float *point)
{
m_fPoint[0] = point[0];
m_fPoint[1] = point[1];
m_fPoint[2] = point[2];
}
-Vector::Vector (const float *p1, const float *p2)
+Vector::Vector(const float *p1, const float *p2)
{
m_fPoint[0] = p2[0] - p1[0];
m_fPoint[1] = p2[1] - p1[1];
m_fPoint[2] = p2[2] - p1[2];
}
-Vector::~Vector ()
-{
-}
-
//////////////////////////////////////////////////////////////////////
// Operations
-bool Vector::operator==(Vector& vec)
-{
- if (m_fPoint[0] != vec.m_fPoint[0])
- return false;
- if (m_fPoint[1] != vec.m_fPoint[1])
- return false;
- if (m_fPoint[2] != vec.m_fPoint[2])
- return false;
- return true;
-}
-
Vector& Vector::operator*=(float scalar)
{
m_fPoint[0] *= scalar;
@@ -79,22 +60,6 @@ Vector& Vector::operator-=(Vector& sub)
return *this;
}
-Vector& Vector::operator=(Vector& source)
-{
- m_fPoint[0] = source.m_fPoint[0];
- m_fPoint[1] = source.m_fPoint[1];
- m_fPoint[2] = source.m_fPoint[2];
- return *this;
-}
-
-Vector& Vector::operator=(const float *point)
-{
- m_fPoint[0] = point[0];
- m_fPoint[1] = point[1];
- m_fPoint[2] = point[2];
- return *this;
-}
-
float Vector::Length()
{
return (float)sqrt(m_fPoint[0]*m_fPoint[0] + m_fPoint[1]*m_fPoint[1] + m_fPoint[2]*m_fPoint[2]);
@@ -102,33 +67,12 @@ float Vector::Length()
void Vector::Normalize()
{
- float inv = 1.0f/(float)sqrt(m_fPoint[0]*m_fPoint[0] + m_fPoint[1]*m_fPoint[1] + m_fPoint[2]*m_fPoint[2]);
+ float inv = 1.0f / Length();
m_fPoint[0] *= inv;
m_fPoint[1] *= inv;
m_fPoint[2] *= inv;
}
-void Vector::Add (const float *point)
-{
- m_fPoint[0] += point[0];
- m_fPoint[1] += point[1];
- m_fPoint[2] += point[2];
-}
-
-void Vector::Add (float x, float y, float z)
-{
- m_fPoint[0] += x;
- m_fPoint[1] += y;
- m_fPoint[2] += z;
-}
-
-void Vector::Scale(float scale)
-{
- m_fPoint[0] *= scale;
- m_fPoint[1] *= scale;
- m_fPoint[2] *= scale;
-}
-
Vector& Vector::Cross(Vector& v1, Vector& v2)
{
m_fPoint[0] = v1.m_fPoint[1]*v2.m_fPoint[2] - v1.m_fPoint[2]*v2.m_fPoint[1];
@@ -145,7 +89,7 @@ float Vector::Angle(Vector& vec)
m1 = sqrt(m_fPoint[0]*m_fPoint[0]+m_fPoint[1]*m_fPoint[1]+m_fPoint[2]*m_fPoint[2]);
m2 = sqrt(vec.m_fPoint[0]*vec.m_fPoint[0]+vec.m_fPoint[1]*vec.m_fPoint[1]+vec.m_fPoint[2]*vec.m_fPoint[2]);
- return (float) (RTOD * acos (d / (m1*m2)));
+ return (float)(RTOD * acos(d / (m1*m2)));
}
float Vector::Dot(Vector& vec)
@@ -153,23 +97,9 @@ float Vector::Dot(Vector& vec)
return m_fPoint[0]*vec.m_fPoint[0]+m_fPoint[1]*vec.m_fPoint[1]+m_fPoint[2]*vec.m_fPoint[2];
}
-void Vector::ToFloat (float *point)
+void Vector::ToFloat(float *point)
{
point[0] = m_fPoint[0];
point[1] = m_fPoint[1];
point[2] = m_fPoint[2];
}
-
-void Vector::FromFloat (const float *point)
-{
- m_fPoint[0] = point[0];
- m_fPoint[1] = point[1];
- m_fPoint[2] = point[2];
-}
-
-void Vector::FromFloat(float x, float y, float z)
-{
- m_fPoint[0] = x;
- m_fPoint[1] = y;
- m_fPoint[2] = z;
-}
diff --git a/common/vector.h b/common/vector.h
index defce45..2458e30 100644
--- a/common/vector.h
+++ b/common/vector.h
@@ -1,49 +1,30 @@
-// Vector.h: interface for the Vector class.
-//
-//////////////////////////////////////////////////////////////////////
-
#ifndef _VECTOR_H_
#define _VECTOR_H_
-class Vector
+class Vector
{
- public:
- Vector ();
- Vector (float x, float y, float z);
- Vector (const float *point);
- Vector (const float *p1, const float *p2);
- virtual ~Vector ();
-
- float X ()
- { return m_fPoint[0]; }
- float Y ()
- { return m_fPoint[1]; }
- float Z ()
- { return m_fPoint[2]; }
+public:
+ Vector();
+ Vector(float x, float y, float z);
+ Vector(const float *point);
+ Vector(const float *p1, const float *p2);
+ ~Vector() { };
- float Dot (Vector& vec);
- float Angle (Vector& vec);
- Vector& Cross (Vector& v1, Vector& v2);
- void Add (const float *point);
- void Add (float x, float y, float z);
- Vector& operator+=(Vector& add);
- Vector& operator-=(Vector& sub);
- Vector& operator*=(float scalar);
- Vector& operator=(Vector& source);
- Vector& operator=(const float *point);
- bool operator==(Vector& vec);
+ float Dot(Vector& vec);
+ float Angle(Vector& vec);
+ Vector& Cross(Vector& v1, Vector& v2);
+ Vector& operator+=(Vector& add);
+ Vector& operator-=(Vector& sub);
+ Vector& operator*=(float scalar);
- operator const float* () const
- { return m_fPoint; }
- void ToFloat (float *point);
- void FromFloat (const float *point);
- void FromFloat (float x, float y, float z);
- float Length ();
- void Normalize ();
- void Scale (float scale);
+ operator const float*() const
+ { return m_fPoint; }
+ void ToFloat(float *point);
+ float Length();
+ void Normalize();
- protected:
- float m_fPoint[3];
+protected:
+ float m_fPoint[3];
};
#endif // _VECTOR_H_