Removed old matrix class functions.

This commit is contained in:
leo 2012-06-07 00:08:59 +00:00
parent 7b5377af70
commit 0596ad829f
9 changed files with 197 additions and 222 deletions

View file

@ -519,7 +519,7 @@ void Camera::UpdateBoundingBox()
lcVector3 FrontVector(mPosition - mTargetPosition);
float len = FrontVector.Length();
lcMatrix44 Mat = lcMatrix44AffineInverse(mWorldView);
lcMatrix44 Mat = lcMatrix44Inverse(mWorldView);
Mat.SetTranslation(mPosition);
BoundingBoxCalculate((Matrix*)&Mat);
@ -655,7 +655,7 @@ void Camera::Render(float fLineWidth)
glPushMatrix ();
lcMatrix44 ViewWorld = lcMatrix44AffineInverse(mWorldView);
lcMatrix44 ViewWorld = lcMatrix44Inverse(mWorldView);
glMultMatrixf(ViewWorld);
lcMatrix44 InvProjection = lcMatrix44Inverse(lcMatrix44Perspective(m_fovy, 1.33f, 0.01f, len));

View file

@ -9,7 +9,6 @@
#include "globals.h"
#include "curve.h"
#include "opengl.h"
#include "matrix.h"
#define LC_CURVE_SAVE_VERSION 1 // LeoCAD 0.73
#define LC_CURVE_POINT_SAVE_VERSION 1 // LeoCAD 0.73
@ -555,32 +554,22 @@ void Curve::TesselateHose ()
if (angle_step != 0)
{
Matrix rot;
rot.FromAxisAngle(FrontVector, angle_step);
// Matrix rot;
// rot.FromAxisAngle(FrontVector, angle_step);
// rot.TransformPoint(u, UpVector);
}
// else
// UpVector.ToFloat(u);
float f[16];
#define M(row,col) f[col*4+row]
M(0,0) = SideVector[0]; M(0,1) = UpVector[0]; M(0,2) = FrontVector[0]; M(0,3) = x;
M(1,0) = SideVector[1]; M(1,1) = UpVector[1]; M(1,2) = FrontVector[1]; M(1,3) = y;
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;
#undef M
float v[3];
Matrix m;
m.FromFloat (f);
lcMatrix44 m(lcVector4(SideVector, 0.0f), lcVector4(UpVector, 0.0f), lcVector4(FrontVector, 0.0f), lcVector4(x, y, z, 1.0f));
for (int k = 0; k < steps2; k++)
{
float *o = &verts[(j*steps2+k)*3];
v[0] = (float)(cos (2.0 * M_PI * k / steps2) * 0.15);
v[1] = (float)(sin (2.0 * M_PI * k / steps2) * 0.15);
v[2] = 0;
m.TransformPoint (o, v);
lcVector3 Pos((float)(cos (2.0 * M_PI * k / steps2) * 0.15), (float)(sin (2.0 * M_PI * k / steps2) * 0.15), 0.0f);
Pos = lcMul31(Pos, m);
verts[(j*steps2+k)*3+0] = Pos[0];
verts[(j*steps2+k)*3+1] = Pos[1];
verts[(j*steps2+k)*3+2] = Pos[2];
}
}

View file

@ -9,7 +9,6 @@
#include <math.h>
#include "light.h"
#include "globals.h"
#include "matrix.h"
GLuint Light::m_nSphereList = 0;
GLuint Light::m_nTargetList = 0;
@ -83,8 +82,6 @@ Light::Light (float px, float py, float pz)
ChangeKey (1, true, true, pos, LC_LK_POSITION);
ChangeKey (1, true, true, target, LC_LK_TARGET);
m_fPos[3] = 0.0f;
UpdatePosition (1, false);
}
@ -102,7 +99,6 @@ Light::Light (float px, float py, float pz, float tx, float ty, float tz)
ChangeKey (1, true, true, target, LC_LK_TARGET);
m_pTarget = new LightTarget (this);
m_fPos[3] = 1.0f;
UpdatePosition (1, false);
}
@ -120,7 +116,7 @@ void Light::Initialize ()
m_fDiffuse[3] = 1.0f;
m_fSpecular[3] = 1.0f;
float *values[] = { m_fPos, m_fTarget, m_fAmbient, m_fDiffuse, m_fSpecular,
float *values[] = { mPosition, mTargetPosition, m_fAmbient, m_fDiffuse, m_fSpecular,
&m_fConstant, &m_fLinear, &m_fQuadratic, &m_fCutoff, &m_fExponent };
RegisterKeys (values, light_key_info, LC_LK_COUNT);
@ -247,33 +243,31 @@ void Light::MinIntersectDist (LC_CLICKLINE* pLine)
void Light::Move (unsigned short nTime, bool bAnimation, bool bAddKey, float dx, float dy, float dz)
{
if (IsEyeSelected())
{
m_fPos[0] += dx;
m_fPos[1] += dy;
m_fPos[2] += dz;
lcVector3 Move(dx, dy, dz);
ChangeKey (nTime, bAnimation, bAddKey, m_fPos, LC_LK_POSITION);
}
if (IsEyeSelected())
{
mPosition += Move;
if (IsTargetSelected())
{
m_fTarget[0] += dx;
m_fTarget[1] += dy;
m_fTarget[2] += dz;
ChangeKey (nTime, bAnimation, bAddKey, mPosition, LC_LK_POSITION);
}
ChangeKey (nTime, bAnimation, bAddKey, m_fTarget, LC_LK_TARGET);
}
if (IsTargetSelected())
{
mTargetPosition += Move;
ChangeKey (nTime, bAnimation, bAddKey, mTargetPosition, LC_LK_TARGET);
}
}
void Light::UpdatePosition (unsigned short nTime, bool bAnimation)
{
CalculateKeys(nTime, bAnimation);
BoundingBoxCalculate(m_fPos);
BoundingBoxCalculate(mPosition);
if (m_pTarget != NULL)
{
m_pTarget->BoundingBoxCalculate(m_fTarget);
m_pTarget->BoundingBoxCalculate(mTargetPosition);
if (m_nList == 0)
m_nList = glGenLists(1);
@ -281,9 +275,9 @@ void Light::UpdatePosition (unsigned short nTime, bool bAnimation)
glNewList(m_nList, GL_COMPILE);
glPushMatrix();
glTranslatef(m_fPos[0], m_fPos[1], m_fPos[2]);
glTranslatef(mPosition[0], mPosition[1], mPosition[2]);
lcVector3 FrontVector(m_fTarget[0] - m_fPos[0], m_fTarget[1] - m_fPos[1], m_fTarget[2] - m_fPos[2]);
lcVector3 FrontVector(mTargetPosition - mPosition);
lcVector3 UpVector(1, 1, 1);
float Length = FrontVector.Length();
@ -302,12 +296,11 @@ void Light::UpdatePosition (unsigned short nTime, bool bAnimation)
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
}
Matrix mat;
mat.CreateLookat(m_fPos, m_fTarget, UpVector);
mat.Invert();
mat.SetTranslation(0, 0, 0);
lcMatrix44 mat = lcMatrix44LookAt(mPosition, mTargetPosition, UpVector);
mat = lcMatrix44AffineInverse(mat);
mat.SetTranslation(lcVector3(0, 0, 0));
glMultMatrixf(mat.m);
glMultMatrixf(mat);
glEnableClientState (GL_VERTEX_ARRAY);
float verts[16*3];
@ -429,157 +422,157 @@ void Light::UpdatePosition (unsigned short nTime, bool bAnimation)
void Light::Render (float fLineWidth)
{
if (m_pTarget != NULL)
{
if (IsEyeSelected())
{
glLineWidth(fLineWidth*2);
if (m_nState & LC_LIGHT_FOCUSED)
lcSetColorFocused();
else
lcSetColorSelected();
glCallList(m_nList);
glLineWidth(fLineWidth);
}
else
{
lcSetColorLight();
glCallList(m_nList);
}
if (m_pTarget != NULL)
{
if (IsEyeSelected())
{
glLineWidth(fLineWidth*2);
if (m_nState & LC_LIGHT_FOCUSED)
lcSetColorFocused();
else
lcSetColorSelected();
glCallList(m_nList);
glLineWidth(fLineWidth);
}
else
{
lcSetColorLight();
glCallList(m_nList);
}
if (IsTargetSelected())
{
glLineWidth(fLineWidth*2);
if (m_nState & LC_LIGHT_TARGET_FOCUSED)
lcSetColorFocused();
else
lcSetColorSelected();
glCallList(m_nTargetList);
glLineWidth(fLineWidth);
}
else
{
lcSetColorLight();
glCallList(m_nTargetList);
}
if (IsTargetSelected())
{
glLineWidth(fLineWidth*2);
if (m_nState & LC_LIGHT_TARGET_FOCUSED)
lcSetColorFocused();
else
lcSetColorSelected();
glCallList(m_nTargetList);
glLineWidth(fLineWidth);
}
else
{
lcSetColorLight();
glCallList(m_nTargetList);
}
lcSetColorLight();
glBegin(GL_LINES);
glVertex3fv(m_fPos);
glVertex3fv(m_fTarget);
glEnd();
lcSetColorLight();
glBegin(GL_LINES);
glVertex3fv(mPosition);
glVertex3fv(mTargetPosition);
glEnd();
if (IsSelected())
{
Matrix projection, modelview;
lcVector3 FrontVector(m_fTarget[0] - m_fPos[0], m_fTarget[1] - m_fPos[1], m_fTarget[2] - m_fPos[2]);
lcVector3 UpVector(1, 1, 1);
float Length = FrontVector.Length();
if (IsSelected())
{
lcMatrix44 projection, modelview;
lcVector3 FrontVector(mTargetPosition - mPosition);
lcVector3 UpVector(1, 1, 1);
float Length = FrontVector.Length();
if (fabs(FrontVector[0]) < fabs(FrontVector[1]))
{
if (fabs(FrontVector[0]) < fabs(FrontVector[2]))
UpVector[0] = -(UpVector[1] * FrontVector[1] + UpVector[2] * FrontVector[2]);
else
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
}
else
{
if (fabs(FrontVector[1]) < fabs(FrontVector[2]))
UpVector[1] = -(UpVector[0] * FrontVector[0] + UpVector[2] * FrontVector[2]);
else
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
}
if (fabs(FrontVector[0]) < fabs(FrontVector[1]))
{
if (fabs(FrontVector[0]) < fabs(FrontVector[2]))
UpVector[0] = -(UpVector[1] * FrontVector[1] + UpVector[2] * FrontVector[2]);
else
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
}
else
{
if (fabs(FrontVector[1]) < fabs(FrontVector[2]))
UpVector[1] = -(UpVector[0] * FrontVector[0] + UpVector[2] * FrontVector[2]);
else
UpVector[2] = -(UpVector[0] * FrontVector[0] + UpVector[1] * FrontVector[1]);
}
glPushMatrix();
glPushMatrix();
modelview.CreateLookat (m_fPos, m_fTarget, UpVector);
modelview.Invert ();
glMultMatrixf (modelview.m);
modelview = lcMatrix44LookAt(mPosition, mTargetPosition, UpVector);
modelview = lcMatrix44AffineInverse(modelview);
glMultMatrixf(modelview);
projection.CreatePerspective (2*m_fCutoff, 1.0f, 0.01f, Length);
projection.Invert ();
glMultMatrixf (projection.m);
projection = lcMatrix44Perspective(2*m_fCutoff, 1.0f, 0.01f, Length);
projection = lcMatrix44Inverse(projection);
glMultMatrixf(projection);
// draw the viewing frustum
glBegin (GL_LINE_LOOP);
glVertex3f ( 0.5f, 1.0f, 1.0f);
glVertex3f ( 1.0f, 0.5f, 1.0f);
glVertex3f ( 1.0f, -0.5f, 1.0f);
glVertex3f ( 0.5f, -1.0f, 1.0f);
glVertex3f (-0.5f, -1.0f, 1.0f);
glVertex3f (-1.0f, -0.5f, 1.0f);
glVertex3f (-1.0f, 0.5f, 1.0f);
glVertex3f (-0.5f, 1.0f, 1.0f);
glEnd ();
// draw the viewing frustum
glBegin (GL_LINE_LOOP);
glVertex3f ( 0.5f, 1.0f, 1.0f);
glVertex3f ( 1.0f, 0.5f, 1.0f);
glVertex3f ( 1.0f, -0.5f, 1.0f);
glVertex3f ( 0.5f, -1.0f, 1.0f);
glVertex3f (-0.5f, -1.0f, 1.0f);
glVertex3f (-1.0f, -0.5f, 1.0f);
glVertex3f (-1.0f, 0.5f, 1.0f);
glVertex3f (-0.5f, 1.0f, 1.0f);
glEnd ();
glBegin (GL_LINES);
glVertex3f (1, 1, -1);
glVertex3f (0.75f, 0.75f, 1);
glVertex3f (-1, 1, -1);
glVertex3f (-0.75f, 0.75f, 1);
glVertex3f (-1, -1, -1);
glVertex3f (-0.75f, -0.75f, 1);
glVertex3f (1, -1, -1);
glVertex3f (0.75f, -0.75f, 1);
glEnd ();
glBegin (GL_LINES);
glVertex3f (1, 1, -1);
glVertex3f (0.75f, 0.75f, 1);
glVertex3f (-1, 1, -1);
glVertex3f (-0.75f, 0.75f, 1);
glVertex3f (-1, -1, -1);
glVertex3f (-0.75f, -0.75f, 1);
glVertex3f (1, -1, -1);
glVertex3f (0.75f, -0.75f, 1);
glEnd ();
glPopMatrix();
}
}
else
{
glPushMatrix ();
glTranslatef (m_fPos[0], m_fPos[1], m_fPos[2]);
glPopMatrix();
}
}
else
{
glPushMatrix ();
glTranslatef (mPosition[0], mPosition[1], mPosition[2]);
if (IsEyeSelected ())
{
glLineWidth (fLineWidth*2);
if (m_nState & LC_LIGHT_FOCUSED)
lcSetColorFocused();
else
lcSetColorSelected();
glCallList (m_nSphereList);
glLineWidth (fLineWidth);
}
else
{
lcSetColorLight();
glCallList (m_nSphereList);
}
if (IsEyeSelected ())
{
glLineWidth (fLineWidth*2);
if (m_nState & LC_LIGHT_FOCUSED)
lcSetColorFocused();
else
lcSetColorSelected();
glCallList (m_nSphereList);
glLineWidth (fLineWidth);
}
else
{
lcSetColorLight();
glCallList (m_nSphereList);
}
glPopMatrix ();
}
glPopMatrix ();
}
}
void Light::Setup (int index)
{
GLenum light = (GLenum)(GL_LIGHT0+index);
GLenum light = (GLenum)(GL_LIGHT0+index);
if (!m_bEnabled)
{
glDisable (light);
return;
}
if (!m_bEnabled)
{
glDisable (light);
return;
}
glEnable (light);
glLightfv (light, GL_POSITION, m_fPos);
glEnable (light);
glLightfv (light, GL_POSITION, lcVector4(mPosition, m_pTarget ? 1.0f : 0.0f));
glLightfv (light, GL_AMBIENT, m_fAmbient);
glLightfv (light, GL_DIFFUSE, m_fDiffuse);
glLightfv (light, GL_SPECULAR, m_fSpecular);
glLightfv (light, GL_AMBIENT, m_fAmbient);
glLightfv (light, GL_DIFFUSE, m_fDiffuse);
glLightfv (light, GL_SPECULAR, m_fSpecular);
glLightf (light, GL_CONSTANT_ATTENUATION, m_fConstant);
glLightf (light, GL_LINEAR_ATTENUATION, m_fLinear);
glLightf (light, GL_QUADRATIC_ATTENUATION, m_fQuadratic);
glLightf (light, GL_CONSTANT_ATTENUATION, m_fConstant);
glLightf (light, GL_LINEAR_ATTENUATION, m_fLinear);
glLightf (light, GL_QUADRATIC_ATTENUATION, m_fQuadratic);
if (m_pTarget != NULL)
{
lcVector3 Dir(m_fTarget[0] - m_fPos[0], m_fTarget[1] - m_fPos[1], m_fTarget[2] - m_fPos[2]);
Dir.Normalize();
if (m_pTarget != NULL)
{
lcVector3 Dir(mTargetPosition - mPosition);
Dir.Normalize();
glLightf(light, GL_SPOT_CUTOFF, m_fCutoff);
glLightf(light, GL_SPOT_EXPONENT, m_fExponent);
glLightfv(light, GL_SPOT_DIRECTION, Dir);
}
glLightf(light, GL_SPOT_CUTOFF, m_fCutoff);
glLightf(light, GL_SPOT_EXPONENT, m_fExponent);
glLightfv(light, GL_SPOT_DIRECTION, Dir);
}
}

View file

@ -3,6 +3,7 @@
#include "opengl.h"
#include "object.h"
#include "lc_math.h"
#define LC_LIGHT_HIDDEN 0x01
#define LC_LIGHT_SELECTED 0x02
@ -89,23 +90,24 @@ public:
{ m_nState |= (LC_LIGHT_TARGET_FOCUSED|LC_LIGHT_TARGET_SELECTED); }
const char* GetName()
{ return m_strName; }
void GetTargetPos (float *pos) const
{ memcpy (pos, m_fTarget, sizeof (float[3])); }
LightTarget* GetTarget () const
{ return m_pTarget; }
const char* GetName() const
{ return m_strName; };
void Render (float fLineWidth);
void MinIntersectDist (LC_CLICKLINE* Line);
void Render (float fLineWidth);
void MinIntersectDist (LC_CLICKLINE* Line);
bool IntersectsVolume(const Vector4* Planes, int NumPlanes)
{ return false; }
void UpdatePosition (unsigned short nTime, bool bAnimation);
void Move (unsigned short nTime, bool bAnimation, bool bAddKey, float dx, float dy, float dz);
void Setup (int index);
void UpdatePosition (unsigned short nTime, bool bAnimation);
void Move (unsigned short nTime, bool bAnimation, bool bAddKey, float dx, float dy, float dz);
void Setup (int index);
void CreateName(const Light* pLight);
lcVector3 mPosition;
lcVector3 mTargetPosition;
protected:
void Initialize ();
@ -123,8 +125,6 @@ protected:
static GLuint m_nTargetList;
// Temporary parameters
float m_fPos[4];
float m_fTarget[3];
float m_fAmbient[4];
float m_fDiffuse[4];
float m_fSpecular[4];

View file

@ -5,7 +5,7 @@
#ifndef GLuint
#include "opengl.h"
#endif
#include "algebra.h"
#include "lc_math.h"
#define LC_PIECE_COUNT 0x001 // Count this piece in the totals ?
#define LC_PIECE_LONGDATA_FILE 0x002 // unsigned long/short index

View file

@ -2329,7 +2329,7 @@ void Project::RenderOverlays(View* view)
}
}
lcMatrix44 Mat = lcMatrix44AffineInverse(Cam->mWorldView);
lcMatrix44 Mat = lcMatrix44Inverse(Cam->mWorldView);
Mat.SetTranslation(m_OverlayCenter);
// Draw the circles.
@ -7165,7 +7165,7 @@ bool Project::OnKeyDown(char nKey, bool bControl, bool bShift)
if (camera->IsSide ())
{
lcMatrix44 mat = lcMatrix44AffineInverse(camera->mWorldView);
lcMatrix44 mat = lcMatrix44Inverse(camera->mWorldView);
switch (nKey)
{

View file

@ -10,7 +10,6 @@
#include "terrain.h"
#include "lc_file.h"
#include "camera.h"
#include "matrix.h"
#include "system.h"
#include "texture.h"
@ -671,45 +670,43 @@ void Terrain::FindVisiblePatches(Camera* pCam, float aspect)
const lcVector3& eye = pCam->mPosition;
// Get perspective information.
float alpha = pCam->m_fovy / 2.0f;
float halfFovY = pCam->m_fovy / 2.0f;
halfFovY = halfFovY * 3.1415f / 180.0f;
float alpha = pCam->m_fovy / 2.0f * LC_DTOR;
float halfFovY = pCam->m_fovy / 2.0f * LC_DTOR;
float halfFovX = (float)atan(tan(halfFovY) * aspect);
halfFovX = halfFovX * 180.0f / 3.1415f;
float beta = 2.0f * halfFovX;
// Get vector stuff from the position.
const lcVector3& nonOrthoTop = pCam->mUpVector;
const lcVector3& target = pCam->mTargetPosition;
float front[3] = { target[0] - eye[0], target[1] - eye[1], target[2] - eye[2]};
float side[3];
lcVector3 side;
side[0] = nonOrthoTop[1]*front[2] - nonOrthoTop[2]*front[1];
side[1] = nonOrthoTop[2]*front[0] - nonOrthoTop[0]*front[2];
side[2] = nonOrthoTop[0]*front[1] - nonOrthoTop[1]*front[0];
// Make sure our up vector is orthogonal.
float top[3];
lcVector3 top;
top[0] = front[1]*side[2] - front[2]*side[1];
top[1] = front[2]*side[0] - front[0]*side[2];
top[2] = front[0]*side[1] - front[1]*side[0];
// Get our plane normals.
Matrix mat;
float topNormal[3] = { -top[0], -top[1], -top[2] };
mat.FromAxisAngle(side, -alpha);
mat.TransformPoints(topNormal, 1);
lcMatrix44 mat;
lcVector3 topNormal(-top[0], -top[1], -top[2]);
mat = lcMatrix44FromAxisAngle(side, -alpha);
topNormal = lcMul30(topNormal, mat);
float bottomNormal[3] = { top[0], top[1], top[2] };
mat.FromAxisAngle(side, alpha);
mat.TransformPoints(bottomNormal, 1);
lcVector3 bottomNormal(top);
mat = lcMatrix44FromAxisAngle(side, alpha);
bottomNormal = lcMul30(bottomNormal, mat);
float rightNormal[3] = { side[0], side[1], side[2] };
mat.FromAxisAngle(top, -beta);
mat.TransformPoints(rightNormal, 1);
lcVector3 rightNormal(side);
mat = lcMatrix44FromAxisAngle(top, -beta);
rightNormal = lcMul30(rightNormal, mat);
float leftNormal[3] = { -side[0], -side[1], -side[2] };
mat.FromAxisAngle(top, beta);
mat.TransformPoints(leftNormal, 1);
lcVector3 leftNormal(-side[0], -side[1], -side[2]);
mat = lcMatrix44FromAxisAngle(top, beta);
leftNormal = lcMul30(leftNormal, mat);
float nearNormal[3] = { front[0], front[1], front[2] };

View file

@ -5,7 +5,6 @@
#include "camera.h"
#include "Tools.h"
#include "Matrix.h"
#ifdef _DEBUG
#define new DEBUG_NEW

View file

@ -257,7 +257,6 @@ BOOL FolderBrowse(CString *strFolder, LPCSTR lpszTitle, HWND hWndOwner)
#include "project.h"
#include "piece.h"
#include "pieceinf.h"
#include "matrix.h"
void Export3DStudio()
{
@ -475,18 +474,16 @@ void Export3DStudio()
sprintf(mobj->name, "Piece%d", objcount);
objcount++;
float tmp[3], pos[3], rot[4];
pPiece->GetPosition(pos);
pPiece->GetRotation(rot);
Matrix mat(rot, pos);
const lcMatrix44& ModelWorld = pPiece->mModelWorld;
float* Verts = (float*)pInfo->mMesh->mVertexBuffer.mData;
for (int c = 0; c < pInfo->mMesh->mNumVertices; c++)
{
mat.TransformPoint(tmp, &Verts[c*3]);
mobj->vertexarray[c].x = tmp[0];
mobj->vertexarray[c].y = tmp[1];
mobj->vertexarray[c].z = tmp[2];
lcVector3 Pos(Verts[c*3], Verts[c*3+1], Verts[c*3+2]);
Pos = lcMul31(Pos, ModelWorld);
mobj->vertexarray[c].x = Pos[0];
mobj->vertexarray[c].y = Pos[1];
mobj->vertexarray[c].z = Pos[2];
}
int NumFaces = 0;