Code cleanup.

This commit is contained in:
leo 2012-06-21 00:41:53 +00:00
parent 9bc700a8f4
commit 8c04f52e14
12 changed files with 94 additions and 381 deletions

View file

@ -708,8 +708,7 @@ void Camera::LoadProjection(float fAspect)
else
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(m_fovy, fAspect, m_zNear, m_zFar);
glLoadMatrixf(lcMatrix44Perspective(m_fovy, fAspect, m_zNear, m_zFar));
/*
ymax = 10;//(m_zFar-m_zNear)*tan(DTOR*m_fovy)/3;
ymin = -ymax;

View file

@ -127,10 +127,6 @@ int stricmp(const char* str1, const char* str2);
#define LC_STR_VERSION "LeoCAD 0.7 Project\0\0" // char[20]
#define LC_MAXCOLORS 28 // Number of colors supported
#define LC_COL_EDGES 28 // Piece edges
#define LC_COL_DEFAULT 31 // Default piece color
// #define DET_BACKFACES 0x00001 // Draw backfaces
// #define DET_DEPTH 0x00002 // Enable depth test

View file

@ -844,8 +844,7 @@ void MinifigWizard::OnDraw()
float aspect = (float)m_nWidth/(float)m_nHeight;
glViewport(0, 0, m_nWidth, m_nHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f, aspect, 1.0f, 20.0f);
glLoadMatrixf(lcMatrix44Perspective(30.0f, aspect, 1.0f, 20.0f));
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(lcMatrix44LookAt(lcVector3(0, -9, 4), lcVector3(0, 5, 1), lcVector3(0, 0, 1)));

View file

@ -1140,66 +1140,3 @@ bool GL_InitializeExtensions()
return true;
}
// =============================================================================
// GLU functions
// Temporary, should be replaced with better versions in the code
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265
#endif
void gluLookAt(GLdouble ex, GLdouble ey, GLdouble ez, GLdouble cx, GLdouble cy, GLdouble cz, GLdouble ux, GLdouble uy, GLdouble uz)
{
GLdouble x[3], y[3], z[3] = { ex-cx, ey-cy, ez-cz };
GLdouble inv;
inv = sqrt (z[0]*z[0] + z[1]*z[1] + z[2]*z[2]);
if (inv)
{
inv = 1.0/inv;
z[0] *= inv;
z[1] *= inv;
z[2] *= inv;
}
x[0] = uy*z[2] - uz*z[1];
x[1] = -ux*z[2] + uz*z[0];
x[2] = ux*z[1] - uy*z[0];
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];
inv = sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
if (inv)
{
inv = 1.0/inv;
x[0] *= inv;
x[1] *= inv;
x[2] *= inv;
}
inv = sqrt(y[0]*y[0] + y[1]*y[1] + y[2]*y[2]);
if (inv)
{
inv = 1.0/inv;
y[0] *= inv;
y[1] *= inv;
y[2] *= inv;
}
{
GLdouble m[16] = { x[0], y[0], z[0], 0, x[1], y[1], z[1], 0, x[2], y[2], z[2], 0, 0, 0, 0, 1 };
glMultMatrixd(m);
glTranslated(-ex, -ey, -ez);
}
}
void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
{
GLdouble y = zNear * tan (fovy * M_PI / 360.0);
glFrustum (-y*aspect, y*aspect, -y, y, zNear, zFar);
}

View file

@ -17,11 +17,6 @@
#define APIENTRY
#endif
void gluLookAt (GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble centerx, GLdouble centery, GLdouble centerz,
GLdouble upx, GLdouble upy, GLdouble upz);
void gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);
bool GL_Initialize(const char* libname);
void GL_Shutdown();
bool GL_InitializeExtensions();

View file

@ -1,6 +1,3 @@
// Information about how to draw a piece and some more stuff.
//
#include "lc_global.h"
#include "lc_math.h"
#include "lc_mesh.h"
@ -13,8 +10,6 @@
#include "texture.h"
#include "pieceinf.h"
#include "project.h"
#include "globals.h"
#include "matrix.h"
#include "library.h"
#include "lc_application.h"
@ -40,81 +35,6 @@ static float costbl[SIDES];
#define LC_KNOB_RADIUS 0.32f
//#define LC_STUD_TECH_RADIUS (LC_FLAT_HEIGHT/2)
static void GetFrustumPlanes (float planes[6][4])
{
// Storage for the Modelview, Projection and their multiplication (Frustum) matrix.
float mv[16], pj[16], fm[16];
glGetFloatv(GL_MODELVIEW_MATRIX, mv);
glGetFloatv(GL_PROJECTION_MATRIX, pj);
fm[0] = pj[0] * mv[0] + pj[4] * mv[1] + pj[8] * mv[2] + pj[12] * mv[3];
fm[4] = pj[0] * mv[4] + pj[4] * mv[5] + pj[8] * mv[6] + pj[12] * mv[7];
fm[8] = pj[0] * mv[8] + pj[4] * mv[9] + pj[8] * mv[10] + pj[12] * mv[11];
fm[12] = pj[0] * mv[12] + pj[4] * mv[13] + pj[8] * mv[14] + pj[12] * mv[15];
fm[1] = pj[1] * mv[0] + pj[5] * mv[1] + pj[9] * mv[2] + pj[13] * mv[3];
fm[5] = pj[1] * mv[4] + pj[5] * mv[5] + pj[9] * mv[6] + pj[13] * mv[7];
fm[9] = pj[1] * mv[8] + pj[5] * mv[9] + pj[9] * mv[10] + pj[13] * mv[11];
fm[13] = pj[1] * mv[12] + pj[5] * mv[13] + pj[9] * mv[14] + pj[13] * mv[15];
fm[2] = pj[2] * mv[0] + pj[6] * mv[1] + pj[10] * mv[2] + pj[14] * mv[3];
fm[6] = pj[2] * mv[4] + pj[6] * mv[5] + pj[10] * mv[6] + pj[14] * mv[7];
fm[10] = pj[2] * mv[8] + pj[6] * mv[9] + pj[10] * mv[10] + pj[14] * mv[11];
fm[14] = pj[2] * mv[12] + pj[6] * mv[13] + pj[10] * mv[14] + pj[14] * mv[15];
fm[3] = pj[3] * mv[0] + pj[7] * mv[1] + pj[11] * mv[2] + pj[15] * mv[3];
fm[7] = pj[3] * mv[4] + pj[7] * mv[5] + pj[11] * mv[6] + pj[15] * mv[7];
fm[11] = pj[3] * mv[8] + pj[7] * mv[9] + pj[11] * mv[10] + pj[15] * mv[11];
fm[15] = pj[3] * mv[12] + pj[7] * mv[13] + pj[11] * mv[14] + pj[15] * mv[15];
planes[0][0] = (fm[0] - fm[3]) * -1;
planes[0][1] = (fm[4] - fm[7]) * -1;
planes[0][2] = (fm[8] - fm[11]) * -1;
planes[0][3] = (fm[12] - fm[15]) * -1;
planes[1][0] = fm[0] + fm[3];
planes[1][1] = fm[4] + fm[7];
planes[1][2] = fm[8] + fm[11];
planes[1][3] = fm[12] + fm[15];
planes[2][0] = (fm[1] - fm[3]) * -1;
planes[2][1] = (fm[5] - fm[7]) * -1;
planes[2][2] = (fm[9] - fm[11]) * -1;
planes[2][3] = (fm[13] - fm[15]) * -1;
planes[3][0] = fm[1] + fm[3];
planes[3][1] = fm[5] + fm[7];
planes[3][2] = fm[9] + fm[11];
planes[3][3] = fm[13] + fm[15];
planes[4][0] = (fm[2] - fm[3]) * -1;
planes[4][1] = (fm[6] - fm[7]) * -1;
planes[4][2] = (fm[10] - fm[11]) * -1;
planes[4][3] = (fm[14] - fm[15]) * -1;
planes[5][0] = fm[2] + fm[3];
planes[5][1] = fm[6] + fm[7];
planes[5][2] = fm[10] + fm[11];
planes[5][3] = fm[14] + fm[15];
}
bool BoxOutsideFrustum (float Dimensions[6])
{
float d, planes[6][4], verts[8][3] = {
{ Dimensions[0], Dimensions[1], Dimensions[5] },
{ Dimensions[3], Dimensions[1], Dimensions[5] },
{ Dimensions[0], Dimensions[1], Dimensions[2] },
{ Dimensions[3], Dimensions[4], Dimensions[5] },
{ Dimensions[3], Dimensions[4], Dimensions[2] },
{ Dimensions[0], Dimensions[4], Dimensions[2] },
{ Dimensions[0], Dimensions[4], Dimensions[5] },
{ Dimensions[3], Dimensions[1], Dimensions[2] } };
GetFrustumPlanes (planes);
for (int i = 0; i < 6; i++)
for (int j = 0; j < 8; j++)
{
d = verts[j][0]*planes[i][0] + verts[j][1]*planes[i][1] + verts[j][2]*planes[i][2] + planes[i][3];
if (d < -0.001f)
return true;
}
return false;
}
/////////////////////////////////////////////////////////////////////////////
// PieceInfo construction/destruction
@ -334,25 +254,25 @@ static void WriteMeshDrawInfo(lcuint32*& Data, lcMesh* Mesh, float*& OutVertex,
}
template<class DstType>
static void WriteStudDrawInfo(int ColorIdx, const Matrix44& Mat, lcMesh* Mesh, float*& OutVertex, float Radius, int* SectionIndices, lcMeshSection** DstSections)
static void WriteStudDrawInfo(int ColorIdx, const lcMatrix44& Mat, lcMesh* Mesh, float*& OutVertex, float Radius, int* SectionIndices, lcMeshSection** DstSections)
{
// Build vertices.
int BaseVertex = (OutVertex - (float*)Mesh->mVertexBuffer.mData) / 3;
Vector3 Vert;
lcVector3 Vert;
for (int i = 0; i < SIDES; i++)
{
Vert = Mul31(Vector3(Radius * costbl[i], Radius * sintbl[i], 0.0f), Mat);
Vert = lcMul31(lcVector3(Radius * costbl[i], Radius * sintbl[i], 0.0f), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
Vert = Mul31(Vector3(Radius * costbl[i], Radius * sintbl[i], LC_STUD_HEIGHT), Mat);
Vert = lcMul31(lcVector3(Radius * costbl[i], Radius * sintbl[i], LC_STUD_HEIGHT), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
}
Vert = Mul31(Vector3(0.0f, 0.0f, LC_STUD_HEIGHT), Mat);
Vert = lcMul31(lcVector3(0.0f, 0.0f, LC_STUD_HEIGHT), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
@ -413,30 +333,30 @@ static void WriteStudDrawInfo(int ColorIdx, const Matrix44& Mat, lcMesh* Mesh, f
}
template<class DstType>
static void WriteHollowStudDrawInfo(int ColorIdx, const Matrix44& Mat, lcMesh* Mesh, float*& OutVertex, float InnerRadius, float OuterRadius, int* SectionIndices, lcMeshSection** DstSections)
static void WriteHollowStudDrawInfo(int ColorIdx, const lcMatrix44& Mat, lcMesh* Mesh, float*& OutVertex, float InnerRadius, float OuterRadius, int* SectionIndices, lcMeshSection** DstSections)
{
// Build vertices.
int BaseVertex = (OutVertex - (float*)Mesh->mVertexBuffer.mData) / 3;
Vector3 Vert;
lcVector3 Vert;
for (int i = 0; i < SIDES; i++)
{
// Outside.
Vert = Mul31(Vector3(OuterRadius * costbl[i], OuterRadius * sintbl[i], 0.0f), Mat);
Vert = lcMul31(lcVector3(OuterRadius * costbl[i], OuterRadius * sintbl[i], 0.0f), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
Vert = Mul31(Vector3(OuterRadius * costbl[i], OuterRadius * sintbl[i], LC_STUD_HEIGHT), Mat);
Vert = lcMul31(lcVector3(OuterRadius * costbl[i], OuterRadius * sintbl[i], LC_STUD_HEIGHT), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
// Inside.
Vert = Mul31(Vector3(InnerRadius * costbl[i], InnerRadius * sintbl[i], LC_STUD_HEIGHT), Mat);
Vert = lcMul31(lcVector3(InnerRadius * costbl[i], InnerRadius * sintbl[i], LC_STUD_HEIGHT), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
Vert = Mul31(Vector3(InnerRadius * costbl[i], InnerRadius * sintbl[i], 0.0f), Mat);
Vert = lcMul31(lcVector3(InnerRadius * costbl[i], InnerRadius * sintbl[i], 0.0f), Mat);
*OutVertex++ = Vert[0];
*OutVertex++ = Vert[1];
*OutVertex++ = Vert[2];
@ -615,10 +535,10 @@ void PieceInfo::BuildMesh(void* Data, int* SectionIndices)
for (int i = 0; i < 12; i++)
MatFloats[i] = LCFLOAT(MatFloats[i]);
Matrix44 Mat(Vector4(MatFloats[0], MatFloats[1], MatFloats[2], 0.0f),
Vector4(MatFloats[3], MatFloats[4], MatFloats[5], 0.0f),
Vector4(MatFloats[6], MatFloats[7], MatFloats[8], 0.0f),
Vector4(MatFloats[9], MatFloats[10], MatFloats[11], 1.0f));
lcMatrix44 Mat(lcVector4(MatFloats[0], MatFloats[1], MatFloats[2], 0.0f),
lcVector4(MatFloats[3], MatFloats[4], MatFloats[5], 0.0f),
lcVector4(MatFloats[6], MatFloats[7], MatFloats[8], 0.0f),
lcVector4(MatFloats[9], MatFloats[10], MatFloats[11], 1.0f));
WriteStudDrawInfo<DstType>(ColorIdx, Mat, mMesh, OutVertex, LC_STUD_RADIUS, SectionIndices, DstSections);
} break;
@ -634,10 +554,10 @@ void PieceInfo::BuildMesh(void* Data, int* SectionIndices)
for (int i = 0; i < 12; i++)
MatFloats[i] = LCFLOAT(MatFloats[i]);
Matrix44 Mat(Vector4(MatFloats[0], MatFloats[1], MatFloats[2], 0.0f),
Vector4(MatFloats[3], MatFloats[4], MatFloats[5], 0.0f),
Vector4(MatFloats[6], MatFloats[7], MatFloats[8], 0.0f),
Vector4(MatFloats[9], MatFloats[10], MatFloats[11], 1.0f));
lcMatrix44 Mat(lcVector4(MatFloats[0], MatFloats[1], MatFloats[2], 0.0f),
lcVector4(MatFloats[3], MatFloats[4], MatFloats[5], 0.0f),
lcVector4(MatFloats[6], MatFloats[7], MatFloats[8], 0.0f),
lcVector4(MatFloats[9], MatFloats[10], MatFloats[11], 1.0f));
WriteHollowStudDrawInfo<DstType>(ColorIdx, Mat, mMesh, OutVertex, 0.16f, LC_STUD_RADIUS, SectionIndices, DstSections);
} break;
@ -882,155 +802,44 @@ void PieceInfo::FreeInformation()
// Zoom extents for the preview window and print catalog
void PieceInfo::ZoomExtents(float Fov, float Aspect, float* EyePos) const
{
float Eye[3] = { -100.0f, -100.0f, 50.0f };
lcVector3 Points[8] =
{
lcVector3(m_fDimensions[0], m_fDimensions[1], m_fDimensions[5]),
lcVector3(m_fDimensions[3], m_fDimensions[1], m_fDimensions[5]),
lcVector3(m_fDimensions[0], m_fDimensions[1], m_fDimensions[2]),
lcVector3(m_fDimensions[3], m_fDimensions[4], m_fDimensions[5]),
lcVector3(m_fDimensions[3], m_fDimensions[4], m_fDimensions[2]),
lcVector3(m_fDimensions[0], m_fDimensions[4], m_fDimensions[2]),
lcVector3(m_fDimensions[0], m_fDimensions[4], m_fDimensions[5]),
lcVector3(m_fDimensions[3], m_fDimensions[1], m_fDimensions[2])
};
lcVector3 Center(GetCenter());
lcVector3 Position;
if (EyePos)
{
Eye[0] = EyePos[0];
Eye[1] = EyePos[1];
Eye[2] = EyePos[2];
}
Position = lcVector3(EyePos[0], EyePos[1], EyePos[2]);
else
Position = lcVector3(-10.0f, -10.0f, 5.0f);
Position += Center;
// Get perspective information.
float Alpha = Fov / 2.0f;
float HalfFovY = Fov / 2.0f;
HalfFovY = HalfFovY * 3.1415f / 180.0f;
float HalfFovX = (float)atan(tan(HalfFovY) * Aspect);
HalfFovX = HalfFovX * 180.0f / 3.1415f;
float Beta = HalfFovX;
lcMatrix44 Projection = lcMatrix44Perspective(30.0f, Aspect, 1.0f, 100.0f);
lcMatrix44 ModelView = lcMatrix44LookAt(Position, Center, lcVector3(0, 0, 1));
Position = lcZoomExtents(Position, ModelView, Projection, Points, 8);
// Get vectors from the position.
float NonOrthoTop[3] = { 0.0f, 0.0f, 1.0f };
float Target[3] = { (m_fDimensions[0] + m_fDimensions[3])*0.5f, (m_fDimensions[1] + m_fDimensions[4])*0.5f,
(m_fDimensions[2] + m_fDimensions[5])*0.5f };
float Front[3] = { Target[0] - Eye[0], Target[1] - Eye[1], Target[2] - Eye[2]};
float Side[3];
Side[0] = NonOrthoTop[1]*Front[2] - NonOrthoTop[2]*Front[1];
Side[1] = NonOrthoTop[2]*Front[0] - NonOrthoTop[0]*Front[2];
Side[2] = NonOrthoTop[0]*Front[1] - NonOrthoTop[1]*Front[0];
// Make sure the up vector is orthogonal.
float Top[3];
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];
// Calculate the plane normals.
Matrix Mat;
float TopNormal[3] = { -Top[0], -Top[1], -Top[2] };
Mat.FromAxisAngle(Side, -Alpha);
Mat.TransformPoints(TopNormal, 1);
float BottomNormal[3] = { Top[0], Top[1], Top[2] };
Mat.FromAxisAngle(Side, Alpha);
Mat.TransformPoints(BottomNormal, 1);
float RightNormal[3] = { Side[0], Side[1], Side[2] };
Mat.FromAxisAngle(Top, -Beta);
Mat.TransformPoints(RightNormal, 1);
float LeftNormal[3] = { -Side[0], -Side[1], -Side[2] };
Mat.FromAxisAngle(Top, Beta);
Mat.TransformPoints(LeftNormal, 1);
// Calculate the plane offsets from the normals and the eye position.
float TopD = Eye[0]*-TopNormal[0] + Eye[1]*-TopNormal[1] + Eye[2]*-TopNormal[2];
float BottomD = Eye[0]*-BottomNormal[0] + Eye[1]*-BottomNormal[1] + Eye[2]*-BottomNormal[2];
float LeftD = Eye[0]*-LeftNormal[0] + Eye[1]*-LeftNormal[1] + Eye[2]*-LeftNormal[2];
float RightD = Eye[0]*-RightNormal[0] + Eye[1]*-RightNormal[1] + Eye[2]*-RightNormal[2];
// Now generate the planes
float Inv;
Inv = 1.0f/(float)sqrt(TopNormal[0]*TopNormal[0]+TopNormal[1]*TopNormal[1]+TopNormal[2]*TopNormal[2]);
float TopPlane[4] = { TopNormal[0]*Inv, TopNormal[1]*Inv, TopNormal[2]*Inv, TopD*Inv };
Inv = 1.0f/(float)sqrt(BottomNormal[0]*BottomNormal[0]+BottomNormal[1]*BottomNormal[1]+BottomNormal[2]*BottomNormal[2]);
float BottomPlane[4] = { BottomNormal[0]*Inv, BottomNormal[1]*Inv, BottomNormal[2]*Inv, BottomD*Inv };
Inv = 1.0f/(float)sqrt(LeftNormal[0]*LeftNormal[0]+LeftNormal[1]*LeftNormal[1]+LeftNormal[2]*LeftNormal[2]);
float LeftPlane[4] = { LeftNormal[0]*Inv, LeftNormal[1]*Inv, LeftNormal[2]*Inv, LeftD*Inv };
Inv = 1.0f/(float)sqrt(RightNormal[0]*RightNormal[0]+RightNormal[1]*RightNormal[1]+RightNormal[2]*RightNormal[2]);
float RightPlane[4] = { RightNormal[0]*Inv, RightNormal[1]*Inv, RightNormal[2]*Inv, RightD*Inv };
float Verts[8][3] = {
{ m_fDimensions[0], m_fDimensions[1], m_fDimensions[5] },
{ m_fDimensions[3], m_fDimensions[1], m_fDimensions[5] },
{ m_fDimensions[0], m_fDimensions[1], m_fDimensions[2] },
{ m_fDimensions[3], m_fDimensions[4], m_fDimensions[5] },
{ m_fDimensions[3], m_fDimensions[4], m_fDimensions[2] },
{ m_fDimensions[0], m_fDimensions[4], m_fDimensions[2] },
{ m_fDimensions[0], m_fDimensions[4], m_fDimensions[5] },
{ m_fDimensions[3], m_fDimensions[1], m_fDimensions[2] } };
float SmallestU = 10000.0f;
for (int i = 0; i < 4; i++)
{
float* Plane;
switch (i)
{
case 0: Plane = TopPlane; break;
case 1: Plane = BottomPlane; break;
case 2: Plane = LeftPlane; break;
case 3: Plane = RightPlane; break;
}
for (int j = 0; j < 8; j++)
{
Plane[3] = Verts[j][0]*-Plane[0] + Verts[j][1]*-Plane[1] + Verts[j][2]*-Plane[2];
// Intersect the eye line with the plane, NewEye = Eye + u * (Target - Eye)
float u = Eye[0] * Plane[0] + Eye[1] * Plane[1] + Eye[2] * Plane[2] + Plane[3];
u /= Front[0] * -Plane[0] + Front[1] * -Plane[1] + Front[2] * -Plane[2];
if (u < SmallestU)
SmallestU = u;
}
}
float NewEye[3];
NewEye[0] = Eye[0] + Front[0] * SmallestU;
NewEye[1] = Eye[1] + Front[1] * SmallestU;
NewEye[2] = Eye[2] + Front[2] * SmallestU;
if (EyePos)
{
EyePos[0] = NewEye[0];
EyePos[1] = NewEye[1];
EyePos[2] = NewEye[2];
}
lcVector3 FrontVec, RightVec, UpVec;
// Calculate view matrix.
UpVec = lcVector3(Top[0], Top[1], Top[2]);
UpVec.Normalize();
FrontVec = lcVector3(Front[0], Front[1], Front[2]);
FrontVec.Normalize();
RightVec = lcVector3(Side[0], Side[1], Side[2]);
RightVec.Normalize();
float ViewMat[16];
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_PROJECTION);
glLoadMatrixf(Projection);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(ViewMat);
glTranslatef(-NewEye[0], -NewEye[1], -NewEye[2]);
glLoadMatrixf(lcMatrix44LookAt(Position, Center, lcVector3(0, 0, 1)));
if (EyePos)
{
EyePos[0] = Position[0];
EyePos[1] = Position[1];
EyePos[2] = Position[2];
}
}
// Used by the print catalog and HTML instructions functions.
void PieceInfo::RenderOnce(int nColor)
{
AddRef();
RenderPiece(nColor);
DeRef();
}
// Called by the piece preview and from RenderOnce()
void PieceInfo::RenderPiece(int nColor)
{
mMesh->Render(nColor, false, false);

View file

@ -58,7 +58,6 @@ class PieceInfo
// Operations
void ZoomExtents(float Fov, float Aspect, float* EyePos = NULL) const;
void RenderOnce(int nColor);
void RenderPiece(int nColor);
// Implementation

View file

@ -47,11 +47,6 @@ void PiecePreview::OnDraw()
float aspect = (float)m_nWidth/(float)m_nHeight;
glViewport(0, 0, m_nWidth, m_nHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f, aspect, 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
lcVector3 Eye(0.0f, 0.0f, 1.0f);
@ -69,6 +64,9 @@ void PiecePreview::OnDraw()
}
else
{
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(lcMatrix44Perspective(30.0f, aspect, 1.0f, 100.0f));
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(lcMatrix44LookAt(Eye * m_Distance, m_PieceInfo->GetCenter(), lcVector3(0, 0, 1)));
}

View file

@ -3732,11 +3732,6 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
if (bSkip)
continue;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f, aspect, 1.0f, 50.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDepthFunc(GL_LEQUAL);
glClearColor(1,1,1,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

View file

@ -6,7 +6,28 @@
#include <math.h>
#include <memory.h>
#include <string.h>
#include "quant.h"
struct CUBE
{
unsigned long r, g, b;
unsigned long pixel_count;
unsigned long pixels_in_cube;
unsigned char children;
unsigned char palette_index;
};
struct FCUBE
{
unsigned char level;
unsigned short index;
};
struct CLOSEST_INFO
{
unsigned char palette_index, red, green, blue;
unsigned long distance;
unsigned long squares[255+255+1];
};
//#define FAST // improves speed but uses a lot of memory
#define QUAL1 // slightly improves quality
@ -218,16 +239,16 @@ static int build_table(unsigned char *image, unsigned long pixels)
return 1;
}
static void fixheap(unsigned long id)
static void fixheap(unsigned long heapid)
{
unsigned char thres_level = heap[id].level;
unsigned long thres_index = heap[id].index, index = 0;
unsigned char thres_level = heap[heapid].level;
unsigned long thres_index = heap[heapid].index, index = 0;
unsigned long half_totc = tot_colors >> 1;
unsigned long thres_val = rgb_table[thres_level][thres_index].pixels_in_cube;
while (id <= half_totc)
while (heapid <= half_totc)
{
index = id << 1;
index = heapid << 1;
if (index < (unsigned long)tot_colors)
if (rgb_table[heap[index].level][heap[index].index].pixels_in_cube
@ -237,12 +258,12 @@ static void fixheap(unsigned long id)
if (thres_val <= rgb_table[heap[index].level][heap[index].index].pixels_in_cube)
break;
else {
heap[id] = heap[index];
id = index;
heap[heapid] = heap[index];
heapid = index;
}
}
heap[id].level = thres_level;
heap[id].index = (unsigned short)thres_index;
heap[heapid].level = thres_level;
heap[heapid].index = (unsigned short)thres_index;
}
static void reduce_table(int num_colors)

View file

@ -1,31 +1,6 @@
///////////////////////////////////////
// DL1 Quantization
#ifndef _QUANT_H_
#define _QUANT_H_
typedef struct
{
unsigned long r, g, b;
unsigned long pixel_count;
unsigned long pixels_in_cube;
unsigned char children;
unsigned char palette_index;
} CUBE;
typedef struct
{
unsigned char level;
unsigned short index;
} FCUBE;
typedef struct
{
unsigned char palette_index, red, green, blue;
unsigned long distance;
unsigned long squares[255+255+1];
} CLOSEST_INFO;
bool dl1quant(unsigned char *inbuf, unsigned char *outbuf, int width, int height, int quant_to, int dither, unsigned char userpal[3][256]);
#endif // _QUANT_H_

View file

@ -275,17 +275,12 @@ static void PrintCatalogThread (CWnd* pParent, CFrameWndEx* pMainFrame)
{
if (node == NULL) continue;
printed++;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f, aspect, 1.0f, 200.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDepthFunc(GL_LEQUAL);
glClearColor(1,1,1,1);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) ;
glEnable(GL_COLOR_MATERIAL) ;
glDisable (GL_DITHER);
glShadeModel (GL_FLAT);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_DITHER);
glShadeModel(GL_FLAT);
lcSetColor(lcGetActiveProject()->GetCurrentColor());
@ -672,17 +667,12 @@ static void PrintPiecesThread(void* pv)
{
if (node == NULL) continue;
printed++;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f, aspect, 1.0f, 200.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDepthFunc(GL_LEQUAL);
glClearColor(1,1,1,1);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE) ;
glEnable(GL_COLOR_MATERIAL) ;
glDisable (GL_DITHER);
glShadeModel (GL_FLAT);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glDisable(GL_DITHER);
glShadeModel(GL_FLAT);
lcSetColor(project->m_nCurColor);