mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Replaced old Vector class.
This commit is contained in:
parent
c8cb684299
commit
3e5a0a447d
13 changed files with 365 additions and 314 deletions
|
@ -1,13 +1,13 @@
|
||||||
// Camera object.
|
// Camera object.
|
||||||
|
|
||||||
#include "lc_global.h"
|
#include "lc_global.h"
|
||||||
|
#include "lc_math.h"
|
||||||
#include "lc_colors.h"
|
#include "lc_colors.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "opengl.h"
|
#include "opengl.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "vector.h"
|
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "lc_file.h"
|
#include "lc_file.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
@ -108,20 +108,21 @@ Camera::Camera (const float *eye, const float *target, const float *up, Camera*
|
||||||
: Object (LC_OBJECT_CAMERA)
|
: Object (LC_OBJECT_CAMERA)
|
||||||
{
|
{
|
||||||
// Fix the up vector
|
// Fix the up vector
|
||||||
Vector upvec(up), frontvec(eye[0]-target[0], eye[1]-target[1], eye[2]-target[2]), sidevec;
|
lcVector3 UpVector(up[0], up[1], up[2]);
|
||||||
frontvec.Normalize();
|
lcVector3 FrontVector(eye[0] - target[0], eye[1] - target[1], eye[2] - target[2]), SideVector;
|
||||||
sidevec.Cross(frontvec, upvec);
|
FrontVector.Normalize();
|
||||||
upvec.Cross(sidevec, frontvec);
|
SideVector = lcCross(FrontVector, UpVector);
|
||||||
upvec.Normalize();
|
UpVector = lcCross(SideVector, FrontVector);
|
||||||
|
UpVector.Normalize();
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
ChangeKey (1, false, true, eye, LC_CK_EYE);
|
ChangeKey (1, false, true, eye, LC_CK_EYE);
|
||||||
ChangeKey (1, false, true, target, LC_CK_TARGET);
|
ChangeKey (1, false, true, target, LC_CK_TARGET);
|
||||||
ChangeKey (1, false, true, upvec, LC_CK_UP);
|
ChangeKey (1, false, true, UpVector, LC_CK_UP);
|
||||||
ChangeKey (1, true, true, eye, LC_CK_EYE);
|
ChangeKey (1, true, true, eye, LC_CK_EYE);
|
||||||
ChangeKey (1, true, true, target, LC_CK_TARGET);
|
ChangeKey (1, true, true, target, LC_CK_TARGET);
|
||||||
ChangeKey (1, true, true, upvec, LC_CK_UP);
|
ChangeKey (1, true, true, UpVector, LC_CK_UP);
|
||||||
|
|
||||||
int i, max = 0;
|
int i, max = 0;
|
||||||
|
|
||||||
|
@ -150,14 +151,14 @@ Camera::Camera (float ex, float ey, float ez, float tx, float ty, float tz, Came
|
||||||
: Object (LC_OBJECT_CAMERA)
|
: Object (LC_OBJECT_CAMERA)
|
||||||
{
|
{
|
||||||
// Fix the up vector
|
// Fix the up vector
|
||||||
Vector upvec(0,0,1), frontvec(ex-tx, ey-ty, ez-tz), sidevec;
|
lcVector3 UpVector(0, 0, 1), FrontVector(ex - tx, ey - ty, ez - tz), SideVector;
|
||||||
frontvec.Normalize();
|
FrontVector.Normalize();
|
||||||
if (frontvec == upvec)
|
if (FrontVector == UpVector)
|
||||||
sidevec = Vector(1,0,0);
|
SideVector = lcVector3(1, 0, 0);
|
||||||
else
|
else
|
||||||
sidevec.Cross(frontvec, upvec);
|
SideVector = lcCross(FrontVector, UpVector);
|
||||||
upvec.Cross(sidevec, frontvec);
|
UpVector = lcCross(SideVector, FrontVector);
|
||||||
upvec.Normalize();
|
UpVector.Normalize();
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
|
@ -165,10 +166,10 @@ Camera::Camera (float ex, float ey, float ez, float tx, float ty, float tz, Came
|
||||||
|
|
||||||
ChangeKey (1, false, true, eye, LC_CK_EYE);
|
ChangeKey (1, false, true, eye, LC_CK_EYE);
|
||||||
ChangeKey (1, false, true, target, LC_CK_TARGET);
|
ChangeKey (1, false, true, target, LC_CK_TARGET);
|
||||||
ChangeKey (1, false, true, upvec, LC_CK_UP);
|
ChangeKey (1, false, true, UpVector, LC_CK_UP);
|
||||||
ChangeKey (1, true, true, eye, LC_CK_EYE);
|
ChangeKey (1, true, true, eye, LC_CK_EYE);
|
||||||
ChangeKey (1, true, true, target, LC_CK_TARGET);
|
ChangeKey (1, true, true, target, LC_CK_TARGET);
|
||||||
ChangeKey (1, true, true, upvec, LC_CK_UP);
|
ChangeKey (1, true, true, UpVector, LC_CK_UP);
|
||||||
|
|
||||||
int i, max = 0;
|
int i, max = 0;
|
||||||
|
|
||||||
|
@ -446,12 +447,12 @@ void Camera::Move (unsigned short nTime, bool bAnimation, bool bAddKey, float dx
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix the up vector
|
// Fix the up vector
|
||||||
Vector upvec(m_fUp), sidevec;
|
lcVector3 UpVector(m_fUp[0], m_fUp[1], m_fUp[2]), SideVector;
|
||||||
Vector frontvec(m_fTarget[0]-m_fEye[0], m_fTarget[1]-m_fEye[1], m_fTarget[2]-m_fEye[2]);
|
lcVector3 FrontVector(m_fTarget[0] - m_fEye[0], m_fTarget[1] - m_fEye[1], m_fTarget[2] - m_fEye[2]);
|
||||||
sidevec.Cross(frontvec, upvec);
|
SideVector = lcCross(FrontVector, UpVector);
|
||||||
upvec.Cross(sidevec, frontvec);
|
UpVector = lcCross(SideVector, FrontVector);
|
||||||
upvec.Normalize();
|
UpVector.Normalize();
|
||||||
upvec.ToFloat(m_fUp);
|
memcpy(m_fUp, UpVector, sizeof(m_fUp));
|
||||||
|
|
||||||
ChangeKey(nTime, bAnimation, bAddKey, m_fUp, LC_CK_UP);
|
ChangeKey(nTime, bAnimation, bAddKey, m_fUp, LC_CK_UP);
|
||||||
}
|
}
|
||||||
|
@ -519,15 +520,15 @@ void Camera::UpdatePosition(unsigned short nTime, bool bAnimation)
|
||||||
void Camera::UpdateBoundingBox()
|
void Camera::UpdateBoundingBox()
|
||||||
{
|
{
|
||||||
// Fix the up vector
|
// Fix the up vector
|
||||||
Vector frontvec(m_fEye[0]-m_fTarget[0], m_fEye[1]-m_fTarget[1], m_fEye[2]-m_fTarget[2]);
|
lcVector3 FrontVector(m_fEye[0] - m_fTarget[0], m_fEye[1] - m_fTarget[1], m_fEye[2] - m_fTarget[2]);
|
||||||
Vector upvec(m_fUp), sidevec;
|
lcVector3 UpVector(m_fUp[0], m_fUp[1], m_fUp[2]), SideVector;
|
||||||
|
|
||||||
sidevec.Cross(frontvec, upvec);
|
SideVector = lcCross(FrontVector, UpVector);
|
||||||
upvec.Cross(sidevec, frontvec);
|
UpVector = lcCross(SideVector, FrontVector);
|
||||||
upvec.Normalize();
|
UpVector.Normalize();
|
||||||
upvec.ToFloat(m_fUp);
|
memcpy(m_fUp, UpVector, sizeof(m_fUp));
|
||||||
|
|
||||||
float len = frontvec.Length();
|
float len = FrontVector.Length();
|
||||||
|
|
||||||
Matrix mat;
|
Matrix mat;
|
||||||
mat.CreateLookat (m_fEye, m_fTarget, m_fUp);
|
mat.CreateLookat (m_fEye, m_fTarget, m_fUp);
|
||||||
|
@ -656,8 +657,8 @@ void Camera::Render(float fLineWidth)
|
||||||
if (IsSelected())
|
if (IsSelected())
|
||||||
{
|
{
|
||||||
Matrix projection, modelview;
|
Matrix projection, modelview;
|
||||||
Vector frontvec(m_fTarget[0]-m_fEye[0], m_fTarget[1]-m_fEye[1], m_fTarget[2]-m_fEye[2]);
|
lcVector3 FrontVector(m_fTarget[0] - m_fEye[0], m_fTarget[1] - m_fEye[1], m_fTarget[2] - m_fEye[2]);
|
||||||
float len = frontvec.Length();
|
float len = FrontVector.Length();
|
||||||
|
|
||||||
glPushMatrix ();
|
glPushMatrix ();
|
||||||
|
|
||||||
|
@ -736,17 +737,17 @@ void Camera::LoadProjection(float fAspect)
|
||||||
|
|
||||||
void Camera::DoZoom(int dy, int mouse, unsigned short nTime, bool bAnimation, bool bAddKey)
|
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]);
|
lcVector3 FrontVector(m_fEye[0] - m_fTarget[0], m_fEye[1] - m_fTarget[1], m_fEye[2] - m_fTarget[2]);
|
||||||
frontvec.Normalize();
|
FrontVector.Normalize();
|
||||||
frontvec *= 2.0f*dy/(21-mouse);
|
FrontVector *= 2.0f * dy / (21 - mouse);
|
||||||
|
|
||||||
// TODO: option to move eye, target or both
|
// TODO: option to move eye, target or both
|
||||||
m_fEye[0] += frontvec[0];
|
m_fEye[0] += FrontVector[0];
|
||||||
m_fEye[1] += frontvec[1];
|
m_fEye[1] += FrontVector[1];
|
||||||
m_fEye[2] += frontvec[2];
|
m_fEye[2] += FrontVector[2];
|
||||||
m_fTarget[0] += frontvec[0];
|
m_fTarget[0] += FrontVector[0];
|
||||||
m_fTarget[1] += frontvec[1];
|
m_fTarget[1] += FrontVector[1];
|
||||||
m_fTarget[2] += frontvec[2];
|
m_fTarget[2] += FrontVector[2];
|
||||||
|
|
||||||
ChangeKey(nTime, bAnimation, bAddKey, m_fEye, LC_CK_EYE);
|
ChangeKey(nTime, bAnimation, bAddKey, m_fEye, LC_CK_EYE);
|
||||||
ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, LC_CK_TARGET);
|
ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, LC_CK_TARGET);
|
||||||
|
@ -755,19 +756,19 @@ void Camera::DoZoom(int dy, int mouse, unsigned short nTime, bool bAnimation, bo
|
||||||
|
|
||||||
void Camera::DoPan(int dx, int dy, int mouse, unsigned short nTime, bool bAnimation, bool bAddKey)
|
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;
|
lcVector3 UpVector(m_fUp[0], m_fUp[1], m_fUp[2]), FrontVector(m_fEye[0] - m_fTarget[0], m_fEye[1] - m_fTarget[1], m_fEye[2] - m_fTarget[2]), SideVector;
|
||||||
sidevec.Cross(frontvec, upvec);
|
SideVector = lcCross(FrontVector, UpVector);
|
||||||
sidevec.Normalize();
|
SideVector.Normalize();
|
||||||
sidevec *= 2.0f*dx/(21-mouse);
|
SideVector *= 2.0f*dx/(21-mouse);
|
||||||
upvec.Normalize();
|
UpVector.Normalize();
|
||||||
upvec *= -2.0f*dy/(21-mouse);
|
UpVector *= -2.0f*dy/(21-mouse);
|
||||||
|
|
||||||
m_fEye[0] += upvec[0] + sidevec[0];
|
m_fEye[0] += UpVector[0] + SideVector[0];
|
||||||
m_fEye[1] += upvec[1] + sidevec[1];
|
m_fEye[1] += UpVector[1] + SideVector[1];
|
||||||
m_fEye[2] += upvec[2] + sidevec[2];
|
m_fEye[2] += UpVector[2] + SideVector[2];
|
||||||
m_fTarget[0] += upvec[0] + sidevec[0];
|
m_fTarget[0] += UpVector[0] + SideVector[0];
|
||||||
m_fTarget[1] += upvec[1] + sidevec[1];
|
m_fTarget[1] += UpVector[1] + SideVector[1];
|
||||||
m_fTarget[2] += upvec[2] + sidevec[2];
|
m_fTarget[2] += UpVector[2] + SideVector[2];
|
||||||
|
|
||||||
ChangeKey(nTime, bAnimation, bAddKey, m_fEye, LC_CK_EYE);
|
ChangeKey(nTime, bAnimation, bAddKey, m_fEye, LC_CK_EYE);
|
||||||
ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, LC_CK_TARGET);
|
ChangeKey(nTime, bAnimation, bAddKey, m_fTarget, LC_CK_TARGET);
|
||||||
|
@ -776,28 +777,28 @@ void Camera::DoPan(int dx, int dy, int mouse, unsigned short nTime, bool bAnimat
|
||||||
|
|
||||||
void Camera::DoRotate(int dx, int dy, int mouse, unsigned short nTime, bool bAnimation, bool bAddKey, float* /*center*/)
|
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;
|
lcVector3 UpVector(m_fUp[0], m_fUp[1], m_fUp[2]), FrontVector(m_fEye[0] - m_fTarget[0], m_fEye[1] - m_fTarget[1], m_fEye[2] - m_fTarget[2]), SideVector;
|
||||||
sidevec.Cross(frontvec, upvec);
|
SideVector = lcCross(FrontVector, UpVector);
|
||||||
sidevec.Normalize();
|
SideVector.Normalize();
|
||||||
sidevec *= 2.0f*dx/(21-mouse);
|
SideVector *= 2.0f*dx/(21-mouse);
|
||||||
upvec.Normalize();
|
UpVector.Normalize();
|
||||||
upvec *= -2.0f*dy/(21-mouse);
|
UpVector *= -2.0f*dy/(21-mouse);
|
||||||
|
|
||||||
// TODO: option to move eye or target
|
// TODO: option to move eye or target
|
||||||
float len = frontvec.Length();
|
float len = FrontVector.Length();
|
||||||
frontvec += Vector(upvec[0] + sidevec[0], upvec[1] + sidevec[1], upvec[2] + sidevec[2]);
|
FrontVector += lcVector3(UpVector[0] + SideVector[0], UpVector[1] + SideVector[1], UpVector[2] + SideVector[2]);
|
||||||
frontvec.Normalize();
|
FrontVector.Normalize();
|
||||||
frontvec *= len;
|
FrontVector *= len;
|
||||||
frontvec += Vector(m_fTarget);
|
FrontVector += lcVector3(m_fTarget[0], m_fTarget[1], m_fTarget[2]);
|
||||||
frontvec.ToFloat(m_fEye);
|
memcpy(m_fEye, FrontVector, sizeof(m_fEye));
|
||||||
|
|
||||||
// Calculate new up
|
// Calculate new up
|
||||||
upvec = Vector(m_fUp[0], m_fUp[1], m_fUp[2]);
|
UpVector = lcVector3(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]);
|
FrontVector = lcVector3(m_fEye[0] - m_fTarget[0], m_fEye[1] - m_fTarget[1], m_fEye[2] - m_fTarget[2]);
|
||||||
sidevec.Cross(frontvec, upvec);
|
SideVector = lcCross(FrontVector, UpVector);
|
||||||
upvec.Cross(sidevec, frontvec);
|
UpVector = lcCross(SideVector, FrontVector);
|
||||||
upvec.Normalize();
|
UpVector.Normalize();
|
||||||
upvec.ToFloat(m_fUp);
|
memcpy(m_fUp, UpVector, sizeof(m_fUp));
|
||||||
|
|
||||||
ChangeKey(nTime, bAnimation, bAddKey, m_fEye, LC_CK_EYE);
|
ChangeKey(nTime, bAnimation, bAddKey, m_fEye, LC_CK_EYE);
|
||||||
ChangeKey(nTime, bAnimation, bAddKey, m_fUp, LC_CK_UP);
|
ChangeKey(nTime, bAnimation, bAddKey, m_fUp, LC_CK_UP);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "lc_global.h"
|
#include "lc_global.h"
|
||||||
|
#include "lc_math.h"
|
||||||
#include "lc_colors.h"
|
#include "lc_colors.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -9,7 +10,6 @@
|
||||||
#include "curve.h"
|
#include "curve.h"
|
||||||
#include "opengl.h"
|
#include "opengl.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "vector.h"
|
|
||||||
|
|
||||||
#define LC_CURVE_SAVE_VERSION 1 // LeoCAD 0.73
|
#define LC_CURVE_SAVE_VERSION 1 // LeoCAD 0.73
|
||||||
#define LC_CURVE_POINT_SAVE_VERSION 1 // LeoCAD 0.73
|
#define LC_CURVE_POINT_SAVE_VERSION 1 // LeoCAD 0.73
|
||||||
|
@ -545,28 +545,28 @@ void Curve::TesselateHose ()
|
||||||
b = 3*cy[0]*t2 + 2*cy[1]*t + cy[2];
|
b = 3*cy[0]*t2 + 2*cy[1]*t + cy[2];
|
||||||
c = 3*cz[0]*t2 + 2*cz[1]*t + cz[2];
|
c = 3*cz[0]*t2 + 2*cz[1]*t + cz[2];
|
||||||
|
|
||||||
Vector side, front (a, b, c);
|
lcVector3 SideVector, FrontVector(a, b, c);
|
||||||
Vector up (u);
|
lcVector3 UpVector(u[0], u[1], u[2]);
|
||||||
side.Cross (front, up);
|
SideVector = lcCross(FrontVector, UpVector);
|
||||||
up.Cross (side, front);
|
UpVector = lcCross(SideVector, FrontVector);
|
||||||
up.Normalize ();
|
UpVector.Normalize();
|
||||||
front.Normalize ();
|
FrontVector.Normalize();
|
||||||
side.Normalize ();
|
SideVector.Normalize();
|
||||||
|
|
||||||
if (angle_step != 0)
|
if (angle_step != 0)
|
||||||
{
|
{
|
||||||
Matrix rot;
|
Matrix rot;
|
||||||
rot.FromAxisAngle (front, angle_step);
|
rot.FromAxisAngle(FrontVector, angle_step);
|
||||||
rot.TransformPoint (u, up);
|
// rot.TransformPoint(u, UpVector);
|
||||||
}
|
}
|
||||||
else
|
// else
|
||||||
up.ToFloat (u);
|
// UpVector.ToFloat(u);
|
||||||
|
|
||||||
float f[16];
|
float f[16];
|
||||||
#define M(row,col) f[col*4+row]
|
#define M(row,col) f[col*4+row]
|
||||||
M(0,0) = side[0]; M(0,1) = up[0]; M(0,2) = front[0]; M(0,3) = x;
|
M(0,0) = SideVector[0]; M(0,1) = UpVector[0]; M(0,2) = FrontVector[0]; M(0,3) = x;
|
||||||
M(1,0) = side[1]; M(1,1) = up[1]; M(1,2) = front[1]; M(1,3) = y;
|
M(1,0) = SideVector[1]; M(1,1) = UpVector[1]; M(1,2) = FrontVector[1]; M(1,3) = y;
|
||||||
M(2,0) = side[2]; M(2,1) = up[2]; M(2,2) = front[2]; M(2,3) = z;
|
M(2,0) = SideVector[2]; M(2,1) = UpVector[2]; M(2,2) = FrontVector[2]; M(2,3) = z;
|
||||||
M(3,0) = 0.0; M(3,1) = 0.0; M(3,2) = 0.0; M(3,3) = 1.0;
|
M(3,0) = 0.0; M(3,1) = 0.0; M(3,2) = 0.0; M(3,3) = 1.0;
|
||||||
#undef M
|
#undef M
|
||||||
|
|
||||||
|
|
190
common/lc_math.h
Normal file
190
common/lc_math.h
Normal file
|
@ -0,0 +1,190 @@
|
||||||
|
#ifndef _LC_MATH_H_
|
||||||
|
#define _LC_MATH_H_
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
class lcVector3;
|
||||||
|
class lcVector4;
|
||||||
|
class lcMatrix33;
|
||||||
|
class lcMatrix44;
|
||||||
|
|
||||||
|
class lcVector3
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
lcVector3()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
lcVector3(const float _x, const float _y, const float _z)
|
||||||
|
: x(_x), y(_y), z(_z)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
lcVector3(const lcVector3& a)
|
||||||
|
: x(a.x), y(a.y), z(a.z)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
operator const float*() const
|
||||||
|
{
|
||||||
|
return (const float*)this;
|
||||||
|
}
|
||||||
|
|
||||||
|
float& operator[](int i) const
|
||||||
|
{
|
||||||
|
return ((float*)this)[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Normalize();
|
||||||
|
void Dot();
|
||||||
|
float Length() const;
|
||||||
|
|
||||||
|
float x, y, z;
|
||||||
|
};
|
||||||
|
|
||||||
|
class lcVector4
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
lcVector4()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
lcVector4(const float _x, const float _y, const float _z, const float _w)
|
||||||
|
: x(_x), y(_y), z(_z), w(_w)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
operator const float*() const
|
||||||
|
{
|
||||||
|
return (const float*)this;
|
||||||
|
}
|
||||||
|
|
||||||
|
float& operator[](int i) const
|
||||||
|
{
|
||||||
|
return ((float*)this)[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
float x, y, z, w;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline lcVector3 operator+(const lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
return lcVector3(a.x + b.x, a.y + b.y, a.z + b.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3 operator-(const lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
return lcVector3(a.x - b.x, a.y - b.y, a.z - b.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3 operator*(const lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
return lcVector3(a.x * b.x, a.y * b.y, a.z * b.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3 operator/(const lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
return lcVector3(a.x / b.x, a.y / b.y, a.z / b.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3 operator*(const lcVector3& a, float b)
|
||||||
|
{
|
||||||
|
return lcVector3(a.x * b, a.y * b, a.z * b);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3 operator/(const lcVector3& a, float b)
|
||||||
|
{
|
||||||
|
return lcVector3(a.x / b, a.y / b, a.z / b);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3 operator-(const lcVector3& a)
|
||||||
|
{
|
||||||
|
return lcVector3(-a.x, -a.y, -a.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3& operator+=(lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
a.x += b.x;
|
||||||
|
a.y += b.y;
|
||||||
|
a.z += b.z;
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3& operator-=(lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
a.x -= b.x;
|
||||||
|
a.y -= b.y;
|
||||||
|
a.z -= b.z;
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3& operator*=(lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
a.x *= b.x;
|
||||||
|
a.y *= b.y;
|
||||||
|
a.z *= b.z;
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3& operator/=(lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
a.x /= b.x;
|
||||||
|
a.y /= b.y;
|
||||||
|
a.z /= b.z;
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3& operator*=(lcVector3& a, float b)
|
||||||
|
{
|
||||||
|
a.x *= b;
|
||||||
|
a.y *= b;
|
||||||
|
a.z *= b;
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3& operator/=(lcVector3& a, float b)
|
||||||
|
{
|
||||||
|
a.x /= b;
|
||||||
|
a.y /= b;
|
||||||
|
a.z /= b;
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void lcVector3::Normalize()
|
||||||
|
{
|
||||||
|
float InvLength = 1.0f / Length();
|
||||||
|
|
||||||
|
x *= InvLength;
|
||||||
|
y *= InvLength;
|
||||||
|
z *= InvLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float lcVector3::Length() const
|
||||||
|
{
|
||||||
|
return sqrtf(x * x + y * y + z * z);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3 lcNormalize(const lcVector3& a)
|
||||||
|
{
|
||||||
|
lcVector3 Ret(a);
|
||||||
|
Ret.Normalize();
|
||||||
|
return Ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float lcDot(const lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline lcVector3 lcCross(const lcVector3& a, const lcVector3& b)
|
||||||
|
{
|
||||||
|
return lcVector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _LC_MATH_H_
|
|
@ -1,6 +1,7 @@
|
||||||
// Light object.
|
// Light object.
|
||||||
|
|
||||||
#include "lc_global.h"
|
#include "lc_global.h"
|
||||||
|
#include "lc_math.h"
|
||||||
#include "lc_colors.h"
|
#include "lc_colors.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -8,7 +9,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "vector.h"
|
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
|
|
||||||
GLuint Light::m_nSphereList = 0;
|
GLuint Light::m_nSphereList = 0;
|
||||||
|
@ -283,26 +283,27 @@ void Light::UpdatePosition (unsigned short nTime, bool bAnimation)
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(m_fPos[0], m_fPos[1], m_fPos[2]);
|
glTranslatef(m_fPos[0], m_fPos[1], m_fPos[2]);
|
||||||
|
|
||||||
Vector frontvec (m_fTarget[0]-m_fPos[0], m_fTarget[1]-m_fPos[1], m_fTarget[2]-m_fPos[2]);
|
lcVector3 FrontVector(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 };
|
lcVector3 UpVector(1, 1, 1);
|
||||||
|
float Length = FrontVector.Length();
|
||||||
|
|
||||||
if (fabs (frontvec[0]) < fabs (frontvec[1]))
|
if (fabs (FrontVector[0]) < fabs (FrontVector[1]))
|
||||||
{
|
{
|
||||||
if (fabs (frontvec[0]) < fabs (frontvec[2]))
|
if (fabs(FrontVector[0]) < fabs(FrontVector[2]))
|
||||||
up[0] = -(up[1]*frontvec[1] + up[2]*frontvec[2]);
|
UpVector[0] = -(UpVector[1] * FrontVector[1] + UpVector[2] * FrontVector[2]);
|
||||||
else
|
else
|
||||||
up[2] = -(up[0]*frontvec[0] + up[1]*frontvec[1]);
|
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (fabs (frontvec[1]) < fabs (frontvec[2]))
|
if (fabs(FrontVector[1]) < fabs(FrontVector[2]))
|
||||||
up[1] = -(up[0]*frontvec[0] + up[2]*frontvec[2]);
|
UpVector[1] = -(UpVector[0] * FrontVector[0] + UpVector[2] * FrontVector[2]);
|
||||||
else
|
else
|
||||||
up[2] = -(up[0]*frontvec[0] + up[1]*frontvec[1]);
|
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix mat;
|
Matrix mat;
|
||||||
mat.CreateLookat (m_fPos, m_fTarget, up);
|
mat.CreateLookat(m_fPos, m_fTarget, UpVector);
|
||||||
mat.Invert();
|
mat.Invert();
|
||||||
mat.SetTranslation(0, 0, 0);
|
mat.SetTranslation(0, 0, 0);
|
||||||
|
|
||||||
|
@ -331,7 +332,7 @@ void Light::UpdatePosition (unsigned short nTime, bool bAnimation)
|
||||||
glVertex3f (-0.5f, 0.5f, -0.3f);
|
glVertex3f (-0.5f, 0.5f, -0.3f);
|
||||||
glEnd ();
|
glEnd ();
|
||||||
|
|
||||||
glTranslatef(0, 0, -len);
|
glTranslatef(0, 0, -Length);
|
||||||
glEndList();
|
glEndList();
|
||||||
|
|
||||||
if (m_nTargetList == 0)
|
if (m_nTargetList == 0)
|
||||||
|
@ -471,31 +472,32 @@ void Light::Render (float fLineWidth)
|
||||||
if (IsSelected())
|
if (IsSelected())
|
||||||
{
|
{
|
||||||
Matrix projection, modelview;
|
Matrix projection, modelview;
|
||||||
Vector frontvec(m_fTarget[0]-m_fPos[0], m_fTarget[1]-m_fPos[1], m_fTarget[2]-m_fPos[2]);
|
lcVector3 FrontVector(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 };
|
lcVector3 UpVector(1, 1, 1);
|
||||||
|
float Length = FrontVector.Length();
|
||||||
|
|
||||||
if (fabs (frontvec[0]) < fabs (frontvec[1]))
|
if (fabs(FrontVector[0]) < fabs(FrontVector[1]))
|
||||||
{
|
{
|
||||||
if (fabs (frontvec[0]) < fabs (frontvec[2]))
|
if (fabs(FrontVector[0]) < fabs(FrontVector[2]))
|
||||||
up[0] = -(up[1]*frontvec[1] + up[2]*frontvec[2]);
|
UpVector[0] = -(UpVector[1] * FrontVector[1] + UpVector[2] * FrontVector[2]);
|
||||||
else
|
else
|
||||||
up[2] = -(up[0]*frontvec[0] + up[1]*frontvec[1]);
|
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (fabs (frontvec[1]) < fabs (frontvec[2]))
|
if (fabs(FrontVector[1]) < fabs(FrontVector[2]))
|
||||||
up[1] = -(up[0]*frontvec[0] + up[2]*frontvec[2]);
|
UpVector[1] = -(UpVector[0] * FrontVector[0] + UpVector[2] * FrontVector[2]);
|
||||||
else
|
else
|
||||||
up[2] = -(up[0]*frontvec[0] + up[1]*frontvec[1]);
|
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
modelview.CreateLookat (m_fPos, m_fTarget, up);
|
modelview.CreateLookat (m_fPos, m_fTarget, UpVector);
|
||||||
modelview.Invert ();
|
modelview.Invert ();
|
||||||
glMultMatrixf (modelview.m);
|
glMultMatrixf (modelview.m);
|
||||||
|
|
||||||
projection.CreatePerspective (2*m_fCutoff, 1.0f, 0.01f, len);
|
projection.CreatePerspective (2*m_fCutoff, 1.0f, 0.01f, Length);
|
||||||
projection.Invert ();
|
projection.Invert ();
|
||||||
glMultMatrixf (projection.m);
|
glMultMatrixf (projection.m);
|
||||||
|
|
||||||
|
@ -573,11 +575,11 @@ void Light::Setup (int index)
|
||||||
|
|
||||||
if (m_pTarget != NULL)
|
if (m_pTarget != NULL)
|
||||||
{
|
{
|
||||||
Vector dir (m_fTarget[0]-m_fPos[0], m_fTarget[1]-m_fPos[1], m_fTarget[2]-m_fPos[2]);
|
lcVector3 Dir(m_fTarget[0] - m_fPos[0], m_fTarget[1] - m_fPos[1], m_fTarget[2] - m_fPos[2]);
|
||||||
dir.Normalize ();
|
Dir.Normalize();
|
||||||
|
|
||||||
glLightf(light, GL_SPOT_CUTOFF, m_fCutoff);
|
glLightf(light, GL_SPOT_CUTOFF, m_fCutoff);
|
||||||
glLightf(light, GL_SPOT_EXPONENT, m_fExponent);
|
glLightf(light, GL_SPOT_EXPONENT, m_fExponent);
|
||||||
glLightfv (light, GL_SPOT_DIRECTION, dir);
|
glLightfv(light, GL_SPOT_DIRECTION, Dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ SRC += common/algebra.cpp common/camera.cpp common/console.cpp common/curve.cpp
|
||||||
common/matrix.cpp common/message.cpp common/minifig.cpp common/object.cpp common/opengl.cpp \
|
common/matrix.cpp common/message.cpp common/minifig.cpp common/object.cpp common/opengl.cpp \
|
||||||
common/piece.cpp common/pieceinf.cpp common/preview.cpp common/project.cpp common/quant.cpp \
|
common/piece.cpp common/pieceinf.cpp common/preview.cpp common/project.cpp common/quant.cpp \
|
||||||
common/str.cpp common/terrain.cpp common/texfont.cpp common/texture.cpp common/tr.cpp \
|
common/str.cpp common/terrain.cpp common/texfont.cpp common/texture.cpp common/tr.cpp \
|
||||||
common/vector.cpp common/view.cpp
|
common/view.cpp
|
||||||
|
|
||||||
ifeq ($(HAVE_JPEGLIB), yes)
|
ifeq ($(HAVE_JPEGLIB), yes)
|
||||||
LIBS += -ljpeg
|
LIBS += -ljpeg
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "lc_global.h"
|
#include "lc_global.h"
|
||||||
|
#include "lc_math.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
@ -9,7 +10,6 @@
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "vector.h"
|
|
||||||
#include "lc_file.h"
|
#include "lc_file.h"
|
||||||
#include "lc_application.h"
|
#include "lc_application.h"
|
||||||
|
|
||||||
|
@ -34,11 +34,11 @@ static void GetPolyCoeffs (float x1, float y1, float z1, float x2, float y2, flo
|
||||||
|
|
||||||
double LC_CLICKLINE::PointDistance (float *point)
|
double LC_CLICKLINE::PointDistance (float *point)
|
||||||
{
|
{
|
||||||
Vector op ((float)(point[0] - a1), (float)(point[1] - b1), (float)(point[2] - c1));
|
lcVector3 op((float)(point[0] - a1), (float)(point[1] - b1), (float)(point[2] - c1));
|
||||||
Vector d ((float)a2, (float)b2, (float)c2);
|
lcVector3 d((float)a2, (float)b2, (float)c2);
|
||||||
float len = d.Length();
|
float len = d.Length();
|
||||||
d.Normalize();
|
d.Normalize();
|
||||||
float t = op.Dot (d);
|
float t = lcDot(op, d);
|
||||||
|
|
||||||
if (t > 0)
|
if (t > 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "lc_global.h"
|
#include "lc_global.h"
|
||||||
|
#include "lc_math.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -12,7 +13,6 @@
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "vector.h"
|
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
#include "lc_application.h"
|
#include "lc_application.h"
|
||||||
|
|
||||||
|
@ -1711,14 +1711,14 @@ void PieceInfo::ZoomExtents(float Fov, float Aspect, float* EyePos) const
|
||||||
EyePos[2] = NewEye[2];
|
EyePos[2] = NewEye[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector FrontVec, RightVec, UpVec;
|
lcVector3 FrontVec, RightVec, UpVec;
|
||||||
|
|
||||||
// Calculate view matrix.
|
// Calculate view matrix.
|
||||||
UpVec = Vector(Top[0], Top[1], Top[2]);
|
UpVec = lcVector3(Top[0], Top[1], Top[2]);
|
||||||
UpVec.Normalize();
|
UpVec.Normalize();
|
||||||
FrontVec = Vector(Front[0], Front[1], Front[2]);
|
FrontVec = lcVector3(Front[0], Front[1], Front[2]);
|
||||||
FrontVec.Normalize();
|
FrontVec.Normalize();
|
||||||
RightVec = Vector(Side[0], Side[1], Side[2]);
|
RightVec = lcVector3(Side[0], Side[1], Side[2]);
|
||||||
RightVec.Normalize();
|
RightVec.Normalize();
|
||||||
|
|
||||||
float ViewMat[16];
|
float ViewMat[16];
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "lc_global.h"
|
#include "lc_global.h"
|
||||||
|
#include "lc_math.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -9,7 +10,6 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include "opengl.h"
|
#include "opengl.h"
|
||||||
#include "vector.h"
|
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "pieceinf.h"
|
#include "pieceinf.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
|
@ -418,17 +418,15 @@ bool Project::FileLoad(lcFile* file, bool bUndo, bool bMerge)
|
||||||
pCam->ChangeKey(1, true, false, tmp, LC_CK_TARGET);
|
pCam->ChangeKey(1, true, false, tmp, LC_CK_TARGET);
|
||||||
|
|
||||||
// Create up vector
|
// Create up vector
|
||||||
Vector upvec(0,0,1), frontvec((float)(eye[0]-target[0]), (float)(eye[1]-target[1]), (float)(eye[2]-target[2])), sidevec;
|
lcVector3 UpVector(0, 0, 1), FrontVector((float)(eye[0] - target[0]), (float)(eye[1] - target[1]), (float)(eye[2] - target[2])), SideVector;
|
||||||
frontvec.Normalize();
|
FrontVector.Normalize();
|
||||||
if (frontvec == upvec)
|
if (FrontVector == UpVector)
|
||||||
sidevec = Vector(1,0,0);
|
SideVector = lcVector3(1, 0, 0);
|
||||||
else
|
else
|
||||||
sidevec.Cross(frontvec, upvec);
|
SideVector = lcCross(FrontVector, UpVector);
|
||||||
upvec.Cross(sidevec, frontvec);
|
UpVector = lcNormalize(lcCross(SideVector, FrontVector));
|
||||||
upvec.Normalize();
|
pCam->ChangeKey(1, false, false, UpVector, LC_CK_UP);
|
||||||
upvec.ToFloat(tmp);
|
pCam->ChangeKey(1, true, false, UpVector, LC_CK_UP);
|
||||||
pCam->ChangeKey(1, false, false, tmp, LC_CK_UP);
|
|
||||||
pCam->ChangeKey(1, true, false, tmp, LC_CK_UP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bMerge)
|
if (bMerge)
|
||||||
|
|
|
@ -1,105 +0,0 @@
|
||||||
#include "lc_global.h"
|
|
||||||
#include <math.h>
|
|
||||||
#include "vector.h"
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
// Construction/Destruction
|
|
||||||
|
|
||||||
Vector::Vector()
|
|
||||||
{
|
|
||||||
m_fPoint[0] = 0;
|
|
||||||
m_fPoint[1] = 0;
|
|
||||||
m_fPoint[2] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
m_fPoint[0] = point[0];
|
|
||||||
m_fPoint[1] = point[1];
|
|
||||||
m_fPoint[2] = point[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
// Operations
|
|
||||||
|
|
||||||
Vector& Vector::operator*=(float scalar)
|
|
||||||
{
|
|
||||||
m_fPoint[0] *= scalar;
|
|
||||||
m_fPoint[1] *= scalar;
|
|
||||||
m_fPoint[2] *= scalar;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector& Vector::operator+=(const Vector& add)
|
|
||||||
{
|
|
||||||
m_fPoint[0] += add.m_fPoint[0];
|
|
||||||
m_fPoint[1] += add.m_fPoint[1];
|
|
||||||
m_fPoint[2] += add.m_fPoint[2];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector& Vector::operator-=(const Vector& sub)
|
|
||||||
{
|
|
||||||
m_fPoint[0] -= sub.m_fPoint[0];
|
|
||||||
m_fPoint[1] -= sub.m_fPoint[1];
|
|
||||||
m_fPoint[2] -= sub.m_fPoint[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]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vector::Normalize()
|
|
||||||
{
|
|
||||||
float inv = 1.0f / Length();
|
|
||||||
m_fPoint[0] *= inv;
|
|
||||||
m_fPoint[1] *= inv;
|
|
||||||
m_fPoint[2] *= inv;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector& Vector::Cross(const Vector& v1, const Vector& v2)
|
|
||||||
{
|
|
||||||
m_fPoint[0] = v1.m_fPoint[1]*v2.m_fPoint[2] - v1.m_fPoint[2]*v2.m_fPoint[1];
|
|
||||||
m_fPoint[1] = v1.m_fPoint[2]*v2.m_fPoint[0] - v1.m_fPoint[0]*v2.m_fPoint[2];
|
|
||||||
m_fPoint[2] = v1.m_fPoint[0]*v2.m_fPoint[1] - v1.m_fPoint[1]*v2.m_fPoint[0];
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Vector::Angle(const Vector& vec)
|
|
||||||
{
|
|
||||||
double d, m1, m2;
|
|
||||||
|
|
||||||
d = m_fPoint[0]*vec.m_fPoint[0]+m_fPoint[1]*vec.m_fPoint[1]+m_fPoint[2]*vec.m_fPoint[2];
|
|
||||||
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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
float Vector::Dot(const 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)
|
|
||||||
{
|
|
||||||
point[0] = m_fPoint[0];
|
|
||||||
point[1] = m_fPoint[1];
|
|
||||||
point[2] = m_fPoint[2];
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
#ifndef _VECTOR_H_
|
|
||||||
#define _VECTOR_H_
|
|
||||||
|
|
||||||
class Vector
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Vector();
|
|
||||||
Vector(float x, float y, float z);
|
|
||||||
Vector(const float *point);
|
|
||||||
Vector(const float *p1, const float *p2);
|
|
||||||
~Vector() { };
|
|
||||||
|
|
||||||
float Dot(const Vector& vec);
|
|
||||||
float Angle(const Vector& vec);
|
|
||||||
Vector& Cross(const Vector& v1, const Vector& v2);
|
|
||||||
Vector& operator+=(const Vector& add);
|
|
||||||
Vector& operator-=(const Vector& sub);
|
|
||||||
Vector& operator*=(float scalar);
|
|
||||||
|
|
||||||
operator const float*() const
|
|
||||||
{ return m_fPoint; }
|
|
||||||
void ToFloat(float *point);
|
|
||||||
float Length();
|
|
||||||
void Normalize();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
float m_fPoint[3];
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // _VECTOR_H_
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "Tools.h"
|
#include "Tools.h"
|
||||||
#include "Matrix.h"
|
#include "Matrix.h"
|
||||||
#include "Vector.h"
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define new DEBUG_NEW
|
#define new DEBUG_NEW
|
||||||
|
|
|
@ -200,7 +200,6 @@
|
||||||
<ClCompile Include="..\common\texfont.cpp" />
|
<ClCompile Include="..\common\texfont.cpp" />
|
||||||
<ClCompile Include="..\Common\texture.cpp" />
|
<ClCompile Include="..\Common\texture.cpp" />
|
||||||
<ClCompile Include="..\Common\Tr.cpp" />
|
<ClCompile Include="..\Common\Tr.cpp" />
|
||||||
<ClCompile Include="..\Common\vector.cpp" />
|
|
||||||
<ClCompile Include="..\common\view.cpp" />
|
<ClCompile Include="..\common\view.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -315,6 +314,7 @@
|
||||||
<ClInclude Include="..\common\lc_colors.h" />
|
<ClInclude Include="..\common\lc_colors.h" />
|
||||||
<ClInclude Include="..\common\lc_file.h" />
|
<ClInclude Include="..\common\lc_file.h" />
|
||||||
<ClInclude Include="..\common\lc_global.h" />
|
<ClInclude Include="..\common\lc_global.h" />
|
||||||
|
<ClInclude Include="..\common\lc_math.h" />
|
||||||
<ClInclude Include="AboutDlg.h" />
|
<ClInclude Include="AboutDlg.h" />
|
||||||
<ClInclude Include="ArrayDlg.h" />
|
<ClInclude Include="ArrayDlg.h" />
|
||||||
<ClInclude Include="CADBar.h" />
|
<ClInclude Include="CADBar.h" />
|
||||||
|
@ -396,7 +396,6 @@
|
||||||
<ClInclude Include="..\Common\texture.h" />
|
<ClInclude Include="..\Common\texture.h" />
|
||||||
<ClInclude Include="..\Common\Tr.h" />
|
<ClInclude Include="..\Common\Tr.h" />
|
||||||
<ClInclude Include="..\Common\typedefs.h" />
|
<ClInclude Include="..\Common\typedefs.h" />
|
||||||
<ClInclude Include="..\Common\vector.h" />
|
|
||||||
<ClInclude Include="..\common\view.h" />
|
<ClInclude Include="..\common\view.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
|
|
@ -266,9 +266,6 @@
|
||||||
<ClCompile Include="..\Common\Tr.cpp">
|
<ClCompile Include="..\Common\Tr.cpp">
|
||||||
<Filter>Common Source Files</Filter>
|
<Filter>Common Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\Common\vector.cpp">
|
|
||||||
<Filter>Common Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\common\view.cpp">
|
<ClCompile Include="..\common\view.cpp">
|
||||||
<Filter>Common Source Files</Filter>
|
<Filter>Common Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -810,9 +807,6 @@
|
||||||
<ClInclude Include="..\Common\typedefs.h">
|
<ClInclude Include="..\Common\typedefs.h">
|
||||||
<Filter>Common Header Files</Filter>
|
<Filter>Common Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\Common\vector.h">
|
|
||||||
<Filter>Common Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\common\view.h">
|
<ClInclude Include="..\common\view.h">
|
||||||
<Filter>Common Header Files</Filter>
|
<Filter>Common Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -834,6 +828,9 @@
|
||||||
<ClInclude Include="..\common\lc_colors.h">
|
<ClInclude Include="..\common\lc_colors.h">
|
||||||
<Filter>Common Header Files</Filter>
|
<Filter>Common Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\common\lc_math.h">
|
||||||
|
<Filter>Common Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CustomBuild Include="hlp\LeoCAD.hpj">
|
<CustomBuild Include="hlp\LeoCAD.hpj">
|
||||||
|
|
Loading…
Reference in a new issue