mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Removed old functions.
This commit is contained in:
parent
c2b4837ab9
commit
7c6242bd27
10 changed files with 122 additions and 342 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "lc_global.h"
|
||||
#include <float.h>
|
||||
#include "algebra.h"
|
||||
#include "lc_math.h"
|
||||
|
||||
// ============================================================================
|
||||
// 4x4 Matrix class.
|
||||
|
@ -432,7 +433,7 @@ bool LineTriangleMinIntersection(const Vector3& p1, const Vector3& p2, const Vec
|
|||
a2 = Dot3(pa2, pa3);
|
||||
a3 = Dot3(pa3, pa1);
|
||||
|
||||
float total = (acosf(a1) + acosf(a2) + acosf(a3)) * RTOD;
|
||||
float total = (acosf(a1) + acosf(a2) + acosf(a3)) * LC_RTOD;
|
||||
|
||||
if (fabs(total - 360) <= 0.001f)
|
||||
{
|
||||
|
@ -483,7 +484,7 @@ bool LineQuadMinIntersection(const Vector3& p1, const Vector3& p2, const Vector3
|
|||
a2 = Dot3(pa2, pa3);
|
||||
a3 = Dot3(pa3, pa1);
|
||||
|
||||
float total = (acosf(a1) + acosf(a2) + acosf(a3)) * RTOD;
|
||||
float total = (acosf(a1) + acosf(a2) + acosf(a3)) * LC_RTOD;
|
||||
|
||||
if (fabs(total - 360) <= 0.001f)
|
||||
{
|
||||
|
@ -498,7 +499,7 @@ bool LineQuadMinIntersection(const Vector3& p1, const Vector3& p2, const Vector3
|
|||
a2 = Dot3(pa2, pa3);
|
||||
a3 = Dot3(pa3, pa1);
|
||||
|
||||
total = (acosf(a1) + acosf(a2) + acosf(a3)) * RTOD;
|
||||
total = (acosf(a1) + acosf(a2) + acosf(a3)) * LC_RTOD;
|
||||
|
||||
if (fabs(total - 360) <= 0.001f)
|
||||
{
|
||||
|
|
|
@ -565,7 +565,7 @@ void Curve::TesselateHose ()
|
|||
|
||||
for (int k = 0; k < steps2; k++)
|
||||
{
|
||||
lcVector3 Pos((float)(cos (2.0 * M_PI * k / steps2) * 0.15), (float)(sin (2.0 * M_PI * k / steps2) * 0.15), 0.0f);
|
||||
lcVector3 Pos((float)(cos (2.0 * LC_PI * k / steps2) * 0.15), (float)(sin (2.0 * LC_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];
|
||||
|
|
|
@ -86,40 +86,12 @@ int stricmp(const char* str1, const char* str2);
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// LeoCAD constants
|
||||
|
||||
// Math numbers.
|
||||
#define LC_DTOR 0.017453f
|
||||
#define LC_RTOD 57.29578f
|
||||
#define LC_PI 3.141592f
|
||||
#define LC_2PI 6.283185f
|
||||
|
||||
|
||||
#define DTOR 0.017453f
|
||||
#define RTOD 57.29578f
|
||||
#define PI 3.14159265
|
||||
#define PI2 6.28318530
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef max
|
||||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#ifndef ABS
|
||||
#define ABS(a) (((a) > 0) ? (a) : -(a))
|
||||
#endif
|
||||
|
||||
#ifndef LC_WINDOWS
|
||||
#define RGB(r, g, b) ((unsigned long)(((unsigned char) (r) | ((unsigned short) (g) << 8))|(((unsigned long) (unsigned char) (b)) << 16)))
|
||||
#endif
|
||||
|
||||
#define FLOATRGB(f) RGB(f[0]*255, f[1]*255, f[2]*255)
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
#define LC_FOURCC(ch0, ch1, ch2, ch3) (lcuint32)((lcuint32)(lcuint8)(ch0) | ((lcuint32)(lcuint8)(ch1) << 8) | \
|
||||
((lcuint32)(lcuint8)(ch2) << 16) | ((lcuint32)(lcuint8)(ch3) << 24 ))
|
||||
|
||||
|
|
106
common/lc_math.h
106
common/lc_math.h
|
@ -4,6 +4,34 @@
|
|||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#define LC_DTOR 0.017453f
|
||||
#define LC_RTOD 57.29578f
|
||||
#define LC_PI 3.141592f
|
||||
#define LC_2PI 6.283185f
|
||||
|
||||
template <typename T, typename U>
|
||||
inline T lcMin(const T& a, const U& b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline T lcMax(const T& a, const U& b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
template <typename T, typename U, typename V>
|
||||
inline T lcClamp(const T& Value, const U& Min, const V& Max)
|
||||
{
|
||||
if (Value > Max)
|
||||
return Max;
|
||||
else if (Value < Min)
|
||||
return Min;
|
||||
else
|
||||
return Value;
|
||||
}
|
||||
|
||||
class lcVector3;
|
||||
class lcVector4;
|
||||
class lcMatrix33;
|
||||
|
@ -486,6 +514,18 @@ inline lcMatrix44 lcMatrix44Perspective(float FoVy, float Aspect, float Near, fl
|
|||
return m;
|
||||
}
|
||||
|
||||
inline lcMatrix44 lcMatrix44Ortho(float Left, float Right, float Bottom, float Top, float Near, float Far)
|
||||
{
|
||||
lcMatrix44 m;
|
||||
|
||||
m.r[0] = lcVector4(2.0f / (Right-Left), 0.0f, 0.0f, 0.0f),
|
||||
m.r[1] = lcVector4(0.0f, 2.0f / (Top-Bottom), 0.0f, 0.0f),
|
||||
m.r[2] = lcVector4(0.0f, 0.0f, -2.0f / (Far-Near), 0.0f),
|
||||
m.r[3] = lcVector4(-(Right+Left) / (Right-Left), -(Top+Bottom) / (Top-Bottom), -(Far+Near) / (Far-Near), 1.0f);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline lcMatrix44 lcMatrix44FromAxisAngle(const lcVector3& Axis, const float Radians)
|
||||
{
|
||||
float s, c, mag, xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;
|
||||
|
@ -539,15 +579,11 @@ inline lcVector4 lcMatrix44ToAxisAngle(const lcMatrix44& m)
|
|||
float Cos = 0.5f * (Trace - 1.0f);
|
||||
lcVector4 rot;
|
||||
|
||||
if (Cos < -1.0f)
|
||||
Cos = -1.0f;
|
||||
else if (Cos > 1.0f)
|
||||
Cos = 1.0f;
|
||||
rot[3] = acosf(Cos); // in [0,PI]
|
||||
rot[3] = acosf(lcClamp(Cos, -1.0f, 1.0f)); // in [0,PI]
|
||||
|
||||
if (rot[3] > 0.01f)
|
||||
{
|
||||
if (fabsf(3.141592f - rot[3]) > 0.01f)
|
||||
if (fabsf(LC_PI - rot[3]) > 0.01f)
|
||||
{
|
||||
rot[0] = Rows[1][2] - Rows[2][1];
|
||||
rot[1] = Rows[2][0] - Rows[0][2];
|
||||
|
@ -616,6 +652,58 @@ inline lcVector4 lcMatrix44ToAxisAngle(const lcMatrix44& m)
|
|||
return rot;
|
||||
}
|
||||
|
||||
inline lcMatrix44 lcMatrix44FromEulerAngles(const lcVector3& Radians)
|
||||
{
|
||||
float CosYaw, SinYaw, CosPitch, SinPitch, CosRoll, SinRoll;
|
||||
|
||||
CosRoll = cosf(Radians[0]);
|
||||
SinRoll = sinf(Radians[0]);
|
||||
CosPitch = cosf(Radians[1]);
|
||||
SinPitch = sinf(Radians[1]);
|
||||
CosYaw = cosf(Radians[2]);
|
||||
SinYaw = sinf(Radians[2]);
|
||||
|
||||
lcMatrix44 m;
|
||||
|
||||
m.r[0] = lcVector4(CosYaw * CosPitch, SinYaw * CosPitch, -SinPitch, 0.0f);
|
||||
m.r[1] = lcVector4(CosYaw * SinPitch * SinRoll - SinYaw * CosRoll, CosYaw * CosRoll + SinYaw * SinPitch * SinRoll, CosPitch * SinRoll, 0.0f);
|
||||
m.r[2] = lcVector4(CosYaw * SinPitch * CosRoll + SinYaw * SinRoll, SinYaw * SinPitch * CosRoll - CosYaw * SinRoll, CosPitch * CosRoll, 0.0f);
|
||||
m.r[3] = lcVector4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
inline lcVector3 lcMatrix44ToEulerAngles(const lcMatrix44& RotMat)
|
||||
{
|
||||
float SinPitch, CosPitch, SinRoll, CosRoll, SinYaw, CosYaw;
|
||||
|
||||
SinPitch = -RotMat.r[0][2];
|
||||
CosPitch = sqrtf(1 - SinPitch*SinPitch);
|
||||
|
||||
if (fabsf(CosPitch) > 0.0005f)
|
||||
{
|
||||
SinRoll = RotMat.r[1][2] / CosPitch;
|
||||
CosRoll = RotMat.r[2][2] / CosPitch;
|
||||
SinYaw = RotMat.r[0][1] / CosPitch;
|
||||
CosYaw = RotMat.r[0][0] / CosPitch;
|
||||
}
|
||||
else
|
||||
{
|
||||
SinRoll = -RotMat.r[2][1];
|
||||
CosRoll = RotMat.r[1][1];
|
||||
SinYaw = 0.0f;
|
||||
CosYaw = 1.0f;
|
||||
}
|
||||
|
||||
lcVector3 Rot(atan2f(SinRoll, CosRoll), atan2f(SinPitch, CosPitch), atan2f(SinYaw, CosYaw));
|
||||
|
||||
if (Rot[0] < 0) Rot[0] += LC_2PI;
|
||||
if (Rot[1] < 0) Rot[1] += LC_2PI;
|
||||
if (Rot[2] < 0) Rot[2] += LC_2PI;
|
||||
|
||||
return Rot;
|
||||
}
|
||||
|
||||
inline lcMatrix44 lcMatrix44Transpose(const lcMatrix44& m)
|
||||
{
|
||||
lcMatrix44 t;
|
||||
|
@ -849,8 +937,8 @@ inline void lcGetFrustumPlanes(const lcMatrix44& WorldView, const lcMatrix44& Pr
|
|||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
lcVector3 Normal(Planes[i][0], Planes[i][1], Planes[i][2]);
|
||||
float Len = Normal.Length();
|
||||
Planes[i] /= -Len;
|
||||
float Length = Normal.Length();
|
||||
Planes[i] /= -Length;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -948,7 +1036,7 @@ inline bool lcLineTriangleMinIntersection(const lcVector3& p1, const lcVector3&
|
|||
a2 = lcDot(pa2, pa3);
|
||||
a3 = lcDot(pa3, pa1);
|
||||
|
||||
float total = (acosf(a1) + acosf(a2) + acosf(a3)) * RTOD;
|
||||
float total = (acosf(a1) + acosf(a2) + acosf(a3)) * LC_RTOD;
|
||||
|
||||
if (fabs(total - 360) <= 0.001f)
|
||||
{
|
||||
|
|
|
@ -306,8 +306,8 @@ void Light::UpdatePosition (unsigned short nTime, bool bAnimation)
|
|||
float verts[16*3];
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
verts[i*6] = verts[i*6+3] = (float)cos ((float)i/4 * PI) * 0.3f;
|
||||
verts[i*6+1] = verts[i*6+4] = (float)sin ((float)i/4 * PI) * 0.3f;
|
||||
verts[i*6] = verts[i*6+3] = (float)cos ((float)i/4 * LC_PI) * 0.3f;
|
||||
verts[i*6+1] = verts[i*6+4] = (float)sin ((float)i/4 * LC_PI) * 0.3f;
|
||||
verts[i*6+2] = 0.3f;
|
||||
verts[i*6+5] = -0.3f;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "matrix.h"
|
||||
#include "lc_math.h"
|
||||
|
||||
// =============================================================================
|
||||
// static functions
|
||||
|
@ -42,8 +43,8 @@ static void rotation_matrix (double angle, float x, float y, float z, float m[]
|
|||
{
|
||||
float s, c, mag, xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;
|
||||
|
||||
s = (float)sin (angle * DTOR);
|
||||
c = (float)cos (angle * DTOR);
|
||||
s = (float)sin (angle * LC_DTOR);
|
||||
c = (float)cos (angle * LC_DTOR);
|
||||
mag = (float)sqrt(x*x + y*y + z*z);
|
||||
|
||||
if (mag == 0)
|
||||
|
@ -97,15 +98,10 @@ Matrix::Matrix ()
|
|||
LoadIdentity();
|
||||
}
|
||||
|
||||
Matrix::Matrix (const float* mat)
|
||||
{
|
||||
memcpy (&m[0], mat, sizeof(float[16]));
|
||||
}
|
||||
|
||||
// Create a matrix from axis-angle and a point
|
||||
Matrix::Matrix (const float *rot, const float *pos)
|
||||
{
|
||||
float tmp[4] = { rot[0], rot[1], rot[2], rot[3]*DTOR };
|
||||
float tmp[4] = { rot[0], rot[1], rot[2], rot[3]*LC_DTOR };
|
||||
float q[4];
|
||||
float length, cosA, sinA;
|
||||
length = (float)sqrt(tmp[0]*tmp[0] + tmp[1]*tmp[1] + tmp[2]*tmp[2]);
|
||||
|
@ -306,58 +302,6 @@ void Matrix::ToLDraw (float *f) const
|
|||
f[9] = tmp[2]; f[10]= tmp[6]; f[11]= tmp[10];
|
||||
}
|
||||
|
||||
void Matrix::ToEulerAngles (float *rot) const
|
||||
{
|
||||
double sinPitch, cosPitch, sinRoll, cosRoll, sinYaw, cosYaw;
|
||||
float colMatrix[4][4];
|
||||
|
||||
colMatrix[0][0] = m[0];
|
||||
colMatrix[0][1] = m[4];
|
||||
colMatrix[0][2] = m[8];
|
||||
colMatrix[0][3] = m[12];
|
||||
|
||||
colMatrix[1][0] = m[1];
|
||||
colMatrix[1][1] = m[5];
|
||||
colMatrix[1][2] = m[9];
|
||||
colMatrix[1][3] = m[13];
|
||||
|
||||
colMatrix[2][0] = m[2];
|
||||
colMatrix[2][1] = m[6];
|
||||
colMatrix[2][2] = m[10];
|
||||
colMatrix[2][3] = m[14];
|
||||
|
||||
colMatrix[3][0] = 0.0f;
|
||||
colMatrix[3][1] = 0.0f;
|
||||
colMatrix[3][2] = 0.0f;
|
||||
colMatrix[3][3] = 1.0f;
|
||||
|
||||
sinPitch = -colMatrix[2][0];
|
||||
cosPitch = sqrt(1 - sinPitch*sinPitch);
|
||||
|
||||
if (fabs(cosPitch) > 0.0005)
|
||||
{
|
||||
sinRoll = colMatrix[2][1] / cosPitch;
|
||||
cosRoll = colMatrix[2][2] / cosPitch;
|
||||
sinYaw = colMatrix[1][0] / cosPitch;
|
||||
cosYaw = colMatrix[0][0] / cosPitch;
|
||||
}
|
||||
else
|
||||
{
|
||||
sinRoll = -colMatrix[1][2];
|
||||
cosRoll = colMatrix[1][1];
|
||||
sinYaw = 0;
|
||||
cosYaw = 1;
|
||||
}
|
||||
|
||||
rot[2] = (float)(RTOD*atan2 (sinYaw, cosYaw));
|
||||
rot[1] = (float)(RTOD*atan2 (sinPitch, cosPitch));
|
||||
rot[0] = (float)(RTOD*atan2 (sinRoll, cosRoll));
|
||||
|
||||
if (rot[2] < 0) rot[2] += 360;
|
||||
if (rot[1] < 0) rot[1] += 360;
|
||||
if (rot[0] < 0) rot[0] += 360;
|
||||
}
|
||||
|
||||
void Matrix::ToAxisAngle(float *rot) const
|
||||
{
|
||||
Matrix tmp(*this);
|
||||
|
@ -386,7 +330,7 @@ void Matrix::ToAxisAngle(float *rot) const
|
|||
|
||||
if (rot[3] > 0.01f)
|
||||
{
|
||||
if (fabs (M_PI - rot[3]) > 0.01f)
|
||||
if (fabs (LC_PI - rot[3]) > 0.01f)
|
||||
{
|
||||
rot[0] = tmp.m[6] - tmp.m[9];
|
||||
rot[1] = tmp.m[8] - tmp.m[2];
|
||||
|
@ -453,215 +397,5 @@ void Matrix::ToAxisAngle(float *rot) const
|
|||
rot[2] = 1.0f;
|
||||
}
|
||||
|
||||
rot[3] *= RTOD;
|
||||
}
|
||||
|
||||
void Matrix::FromEulerAngles (float roll, float pitch, float yaw)
|
||||
{
|
||||
float cosYaw, sinYaw, cosPitch, sinPitch, cosRoll, sinRoll;
|
||||
|
||||
cosYaw = (float)cos(yaw*DTOR);
|
||||
sinYaw = (float)sin(yaw*DTOR);
|
||||
cosPitch = (float)cos(pitch*DTOR);
|
||||
sinPitch = (float)sin(pitch*DTOR);
|
||||
cosRoll = (float)cos(roll*DTOR);
|
||||
sinRoll = (float)sin(roll*DTOR);
|
||||
|
||||
m[0] = cosYaw * cosPitch;
|
||||
m[4] = cosYaw * sinPitch * sinRoll - sinYaw * cosRoll;
|
||||
m[8] = cosYaw * sinPitch * cosRoll + sinYaw * sinRoll;
|
||||
m[12] = 0.0f;
|
||||
|
||||
m[1] = sinYaw * cosPitch;
|
||||
m[5] = cosYaw * cosRoll + sinYaw * sinPitch * sinRoll;
|
||||
m[9] = sinYaw * sinPitch * cosRoll - cosYaw * sinRoll;
|
||||
m[13] = 0.0f;
|
||||
|
||||
m[2] = -sinPitch;
|
||||
m[6] = cosPitch * sinRoll;
|
||||
m[10] = cosPitch * cosRoll;
|
||||
m[14] = 0.0f;
|
||||
|
||||
m[3] = 0.0f;
|
||||
m[7] = 0.0f;
|
||||
m[11] = 0.0f;
|
||||
m[15] = 1.0f;
|
||||
}
|
||||
|
||||
// Create a rotation matrix (angle is in degrees)
|
||||
void Matrix::FromAxisAngle (const float *axis, float angle)
|
||||
{
|
||||
if (angle == 0.0f)
|
||||
return;
|
||||
rotation_matrix (angle, axis[0], axis[1], axis[2], m);
|
||||
}
|
||||
|
||||
void Matrix::Transpose3()
|
||||
{
|
||||
float tmp;
|
||||
|
||||
tmp = m[1]; m[1] = m[4]; m[4] = tmp;
|
||||
tmp = m[2]; m[2] = m[8]; m[8] = tmp;
|
||||
tmp = m[6]; m[6] = m[9]; m[9] = tmp;
|
||||
}
|
||||
|
||||
bool Matrix::Invert ()
|
||||
{
|
||||
double t, inverse[16];
|
||||
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] = m[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++)
|
||||
m[i] = (float)inverse[i];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Matrix::CreatePerspective (float fovy, float aspect, float nearval, float farval)
|
||||
{
|
||||
float left, right, bottom, top;
|
||||
float x, y, a, b, c, d;
|
||||
|
||||
LoadIdentity ();
|
||||
|
||||
top = nearval * (float)tan (fovy * M_PI / 360.0);
|
||||
bottom = -top;
|
||||
|
||||
left = bottom * aspect;
|
||||
right = top * aspect;
|
||||
|
||||
if ((nearval<=0.0 || farval<=0.0) || (nearval == farval) || (left == right) || (top == bottom))
|
||||
return;
|
||||
|
||||
x = (2.0f*nearval) / (right-left);
|
||||
y = (2.0f*nearval) / (top-bottom);
|
||||
a = (right+left) / (right-left);
|
||||
b = (top+bottom) / (top-bottom);
|
||||
c = -(farval+nearval) / ( farval-nearval);
|
||||
d = -(2.0f*farval*nearval) / (farval-nearval);
|
||||
|
||||
#define M(row,col) m[col*4+row]
|
||||
M(0,0) = x; M(0,1) = 0.0F; M(0,2) = a; M(0,3) = 0.0F;
|
||||
M(1,0) = 0.0F; M(1,1) = y; M(1,2) = b; M(1,3) = 0.0F;
|
||||
M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = c; M(2,3) = d;
|
||||
M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = -1.0F; M(3,3) = 0.0F;
|
||||
#undef M
|
||||
}
|
||||
|
||||
void Matrix::CreateLookat (const float *eye, const float *target, const float *up)
|
||||
{
|
||||
float x[3], y[3], z[3];
|
||||
float mag;
|
||||
|
||||
z[0] = eye[0] - target[0];
|
||||
z[1] = eye[1] - target[1];
|
||||
z[2] = eye[2] - target[2];
|
||||
mag = (float)sqrt (z[0]*z[0] + z[1]*z[1] + z[2]*z[2]);
|
||||
if (mag)
|
||||
{
|
||||
z[0] /= mag;
|
||||
z[1] /= mag;
|
||||
z[2] /= mag;
|
||||
}
|
||||
|
||||
y[0] = up[0];
|
||||
y[1] = up[1];
|
||||
y[2] = up[2];
|
||||
|
||||
// X vector = Y cross Z
|
||||
x[0] = y[1]*z[2] - y[2]*z[1];
|
||||
x[1] = -y[0]*z[2] + y[2]*z[0];
|
||||
x[2] = y[0]*z[1] - y[1]*z[0];
|
||||
|
||||
// Recompute Y = Z cross X
|
||||
y[0] = z[1]*x[2] - z[2]*x[1];
|
||||
y[1] = -z[0]*x[2] + z[2]*x[0];
|
||||
y[2] = z[0]*x[1] - z[1]*x[0];
|
||||
|
||||
mag = (float)sqrt (x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
|
||||
if (mag)
|
||||
{
|
||||
x[0] /= mag;
|
||||
x[1] /= mag;
|
||||
x[2] /= mag;
|
||||
}
|
||||
|
||||
mag = (float)sqrt (y[0]*y[0] + y[1]*y[1] + y[2]*y[2]);
|
||||
if (mag)
|
||||
{
|
||||
y[0] /= mag;
|
||||
y[1] /= mag;
|
||||
y[2] /= mag;
|
||||
}
|
||||
|
||||
#define M(row,col) m[col*4+row]
|
||||
M(0,0) = x[0]; M(0,1) = x[1]; M(0,2) = x[2]; M(0,3) = 0.0;
|
||||
M(1,0) = y[0]; M(1,1) = y[1]; M(1,2) = y[2]; M(1,3) = 0.0;
|
||||
M(2,0) = z[0]; M(2,1) = z[1]; M(2,2) = z[2]; 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
|
||||
|
||||
// Translate Eye to Origin
|
||||
m[12] = m[0] * -eye[0] + m[4] * -eye[1] + m[8] * -eye[2] + m[12];
|
||||
m[13] = m[1] * -eye[0] + m[5] * -eye[1] + m[9] * -eye[2] + m[13];
|
||||
m[14] = m[2] * -eye[0] + m[6] * -eye[1] + m[10] * -eye[2] + m[14];
|
||||
m[15] = m[3] * -eye[0] + m[7] * -eye[1] + m[11] * -eye[2] + m[15];
|
||||
rot[3] *= LC_RTOD;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
// Matrix class
|
||||
//
|
||||
|
||||
#ifndef _MATRIX_H_
|
||||
#define _MATRIX_H_
|
||||
|
||||
|
@ -8,24 +5,18 @@ class Matrix
|
|||
{
|
||||
public:
|
||||
Matrix();
|
||||
Matrix(const float *mat);
|
||||
Matrix(const float *rot, const float *pos);
|
||||
~Matrix() { };
|
||||
|
||||
void FromFloat(const float* mat);
|
||||
void FromLDraw(const float *f);
|
||||
void FromEulerAngles(float yaw, float pitch, float roll);
|
||||
void FromAxisAngle(const float *axis, float angle);
|
||||
|
||||
void ToLDraw(float *f) const;
|
||||
void ToEulerAngles(float *rot) const;
|
||||
void ToAxisAngle(float *rot) const;
|
||||
|
||||
void LoadIdentity();
|
||||
void Translate(float x, float y, float z);
|
||||
void Multiply(const Matrix& m1, const Matrix& m2);
|
||||
bool Invert();
|
||||
void Transpose3();
|
||||
float Determinant() const;
|
||||
|
||||
void GetTranslation(float *x, float *y, float *z);
|
||||
|
@ -38,8 +29,6 @@ public:
|
|||
void CreateOld(float mx, float my, float mz, float rx, float ry, float rz);
|
||||
void Rotate(float angle, float x, float y, float z);
|
||||
void RotateCenter(float angle, float x, float y, float z, float px, float py, float pz);
|
||||
void CreatePerspective(float fovy, float aspect, float nearval, float farval);
|
||||
void CreateLookat(const float *eye, const float *target, const float *up);
|
||||
|
||||
public:
|
||||
float m[16];
|
||||
|
|
|
@ -62,8 +62,8 @@ void PieceInfo::LoadIndex(lcFile& file)
|
|||
{
|
||||
for (int i = 0; i < SIDES; i++)
|
||||
{
|
||||
sintbl[i] = (float)sin((PI2*i)/(SIDES));
|
||||
costbl[i] = (float)cos((PI2*i)/(SIDES));
|
||||
sintbl[i] = (float)sin((LC_2PI*i)/(SIDES));
|
||||
costbl[i] = (float)cos((LC_2PI*i)/(SIDES));
|
||||
}
|
||||
init = true;
|
||||
}
|
||||
|
|
|
@ -2309,8 +2309,8 @@ void Project::RenderOverlays(View* view)
|
|||
|
||||
do
|
||||
{
|
||||
float x = cosf((Step * i - StartAngle) * DTOR) * OverlayRotateRadius * OverlayScale;
|
||||
float y = sinf((Step * i - StartAngle) * DTOR) * OverlayRotateRadius * OverlayScale;
|
||||
float x = cosf((Step * i - StartAngle) * LC_DTOR) * OverlayRotateRadius * OverlayScale;
|
||||
float y = sinf((Step * i - StartAngle) * LC_DTOR) * OverlayRotateRadius * OverlayScale;
|
||||
|
||||
glVertex3f(0.0f, x, y);
|
||||
|
||||
|
@ -3268,17 +3268,15 @@ void Project::HandleNotify(LC_NOTIFY id, unsigned long param)
|
|||
Piece* pPiece = (Piece*)mod->piece;
|
||||
|
||||
const lcVector3& Pos = pPiece->mPosition;
|
||||
lcVector4 rot = pPiece->mRotation;
|
||||
Matrix mat(rot, Pos);
|
||||
mat.ToEulerAngles(rot);
|
||||
lcVector3 Angles = lcMatrix44ToEulerAngles(pPiece->mModelWorld) * LC_RTOD;
|
||||
|
||||
if (Pos != mod->Position)
|
||||
pPiece->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, mod->Position, LC_PK_POSITION);
|
||||
|
||||
if (mod->Rotation[0] != rot[0] || mod->Rotation[1] != rot[1] || mod->Rotation[2] != rot[2])
|
||||
if (mod->Rotation != Angles)
|
||||
{
|
||||
mat.FromEulerAngles(mod->Rotation[0], mod->Rotation[1], mod->Rotation[2]);
|
||||
mat.ToAxisAngle(rot);
|
||||
lcVector4 rot = lcMatrix44ToAxisAngle(lcMatrix44FromEulerAngles(mod->Rotation * LC_DTOR));
|
||||
rot[3] *= LC_RTOD;
|
||||
pPiece->ChangeKey(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys, rot, LC_PK_ROTATION);
|
||||
}
|
||||
|
||||
|
|
|
@ -205,9 +205,7 @@ void CPropertiesPane::SetPiece(Object* Focus)
|
|||
|
||||
Piece* pPiece = (Piece*)Focus;
|
||||
lcVector3 Pos = pPiece->mPosition;
|
||||
lcVector4 Rot = pPiece->mRotation;
|
||||
Matrix mat(Rot, Pos);
|
||||
mat.ToEulerAngles(Rot);
|
||||
lcVector3 Angles = lcMatrix44ToEulerAngles(pPiece->mModelWorld) * LC_RTOD;
|
||||
|
||||
lcGetActiveProject()->ConvertToUserUnits(Pos);
|
||||
|
||||
|
@ -217,9 +215,9 @@ void CPropertiesPane::SetPiece(Object* Focus)
|
|||
UpdateProperty(Position->GetSubItem(2), Pos[2]);
|
||||
|
||||
CMFCPropertyGridProperty* Rotation = m_wndPropList.GetProperty(1);
|
||||
UpdateProperty(Rotation->GetSubItem(0), Rot[0]);
|
||||
UpdateProperty(Rotation->GetSubItem(1), Rot[1]);
|
||||
UpdateProperty(Rotation->GetSubItem(2), Rot[2]);
|
||||
UpdateProperty(Rotation->GetSubItem(0), Angles[0]);
|
||||
UpdateProperty(Rotation->GetSubItem(1), Angles[1]);
|
||||
UpdateProperty(Rotation->GetSubItem(2), Angles[2]);
|
||||
|
||||
lcuint32 From, To;
|
||||
if (lcGetActiveProject()->IsAnimation())
|
||||
|
|
Loading…
Reference in a new issue