LOD, model reorganisation

git-svn-id: https://pioneer.svn.sourceforge.net/svnroot/pioneer/trunk@24 e632f14b-6550-0410-b89e-a82653faca30
master
jaj22 2008-06-29 05:40:11 +00:00
parent d5313a51bd
commit 0031d247e5
10 changed files with 276 additions and 151 deletions

View File

@ -62,7 +62,7 @@
<Tool
Name="VCLinkerTool"
AdditionalDependencies="sdl.lib sdlmain.lib ode.lib sigc-2.0d.lib opengl32.lib glu32.lib SDL_image.lib freetype236MT.lib"
OutputFile="..\data_win32\$(ProjectName)_debug.exe"
OutputFile="..\$(ProjectName)_debug.exe"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
@ -142,7 +142,7 @@
<Tool
Name="VCLinkerTool"
AdditionalDependencies="sdl.lib sdlmain.lib ode.lib sigc-2.0.lib opengl32.lib glu32.lib SDL_image.lib freetype236MT.lib"
OutputFile="..\data_win32\$(ProjectName)_release.exe"
OutputFile="..\$(ProjectName)_release.exe"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="2"
@ -566,11 +566,11 @@
>
</File>
<File
RelativePath="..\src\sbre\sbre_anim.h"
RelativePath="..\src\sbre\sbre_int.h"
>
</File>
<File
RelativePath="..\src\sbre\sbre_int.h"
RelativePath="..\src\sbre\sbre_models.h"
>
</File>
<File

View File

@ -5,7 +5,7 @@ const ShipType ShipType::types[] = {
// besides running a wicked corporatist regime in the
// sirius system, Sirius corporation make a range of
// lovely starships
"Sirius Interdictor", 10,
"Sirius Interdictor", 61,
{ 1e7,-1e7,1e6,-1e6,-1e6,1e6 },
1e7,
{
@ -17,7 +17,7 @@ const ShipType ShipType::types[] = {
}, {
// john - you should pick names yourself or this happens
"Ladybird Starfighter",
13,
62,
{ 1e7,-1e7,1e6,-1e6,-1e6,1e6 },
1e7,
{
@ -28,7 +28,7 @@ const ShipType ShipType::types[] = {
60, 15,
}, {
"Flowerfairy Heavy Trader",
14,
63,
{ 1e7,-1e7,1e6,-1e6,-1e6,1e6 },
1e7,
{

View File

@ -52,5 +52,5 @@ static ObjParams params = {
void SpaceStation::Render(const Frame *camFrame)
{
RenderSbreModel(camFrame, 12, &params);
RenderSbreModel(camFrame, 65, &params);
}

View File

@ -4,7 +4,7 @@
#include <malloc.h>
#include "sbre.h"
#include "sbre_int.h"
#include "sbre_anim.h"
#include "sbre_models.h"
float ResolveAnim (ObjParams *pObjParam, uint16 type)
{
@ -101,10 +101,10 @@ static void ResolveVertices (Model *pMod, Vector *pRes, ObjParams *pObjParam)
}
}
static float g_dn, g_df;
static float g_dn, g_df, g_sd;
static int g_wireframe = 0;
void sbreSetViewport (int w, int h, int d, float zn, float zf, float dn, float df)
void sbreSetViewport (int w, int h, float d, float zn, float zf, float dn, float df)
{
glViewport (0, 0, w, h);
@ -121,7 +121,7 @@ void sbreSetViewport (int w, int h, int d, float zn, float zf, float dn, float d
glMatrixMode (GL_PROJECTION);
glLoadMatrixf (pProjMat);
glDepthRange (dn+SBRE_ZBIAS, df);
g_dn = dn; g_df = df;
g_dn = dn; g_df = df; g_sd = d;
}
void sbreSetDirLight (float *pColor, float *pDir)
@ -189,6 +189,80 @@ void SetTransState ()
}
void sbreRenderModel (Vector *pPos, Matrix *pOrient, int model, ObjParams *pParam, float s, Vector *pCompos)
{
Model *pModel = ppModel[model];
s *= pModel->scale;
float pMV[16];
pMV[0] = s*pOrient->x1; pMV[1] = s*pOrient->y1; pMV[2] = s*pOrient->z1; pMV[3] = 0.0f;
pMV[4] = s*pOrient->x2; pMV[5] = s*pOrient->y2; pMV[6] = s*pOrient->z2; pMV[7] = 0.0f;
pMV[8] = s*pOrient->x3; pMV[9] = s*pOrient->y3; pMV[10] = s*pOrient->z3; pMV[11] = 0.0f;
pMV[12] = pPos->x; pMV[13] = pPos->y; pMV[14] = pPos->z; pMV[15] = 1.0f;
glMatrixMode (GL_MODELVIEW);
glLoadMatrixf (pMV);
Vector *pVtx = (Vector *) alloca (sizeof(Vector)*(pModel->cvStart+pModel->numCVtx));
ResolveVertices (pModel, pVtx, pParam);
RState rstate;
rstate.pVtx = pVtx;
rstate.objpos = *pPos;
rstate.objorient = *pOrient;
rstate.scale = s;
rstate.pModel = pModel;
rstate.pObjParam = pParam;
rstate.dn = g_dn;
rstate.df = g_df;
MatTVecMult (pOrient, pPos, &rstate.campos);
VecInv (&rstate.campos, &rstate.campos);
if (pCompos) rstate.compos = *pCompos;
else rstate.compos = zero_vector;
if (pModel->numCache && !pModel->ppVCache)
{
pModel->pNumVtx = (int *) calloc (pModel->numCache, sizeof(int));
pModel->pNumIdx = (int *) calloc (pModel->numCache, sizeof(int));
pModel->ppVCache = (Vector **) calloc (pModel->numCache, sizeof(Vector *));
pModel->ppICache = (uint16 **) calloc (pModel->numCache, sizeof(uint16 *));
}
SetGeneralState ();
SetOpaqueState ();
// Find suitable LOD
float dist = sqrt(VecDot(pPos, pPos));
float pixrad = g_sd * pModel->radius*s / dist;
int i; for (i=0; i<4; i++)
{
if (pModel->pLOD[i].pixrad <= 0.0f) break;
if (pixrad <= pModel->pLOD[i].pixrad) break;
}
uint16 *pData = pModel->pLOD[i].pData1;
if (pData) while (*pData != PTYPE_END) {
pData += pPrimFuncTable[*pData & 0xff] (pData, pModel, &rstate);
}
pData = pModel->pLOD[i].pData2;
if (pData) while (*pData != PTYPE_END) {
pData += pPrimFuncTable[*pData & 0xff] (pData, pModel, &rstate);
}
// glDepthRange (g_dn+SBRE_ZBIAS, g_df);
if (pModel->pLOD[i].numThrusters)
{
SetTransState ();
RenderThrusters (&rstate, pModel->pLOD[i].numThrusters, pModel->pLOD[i].pThruster);
}
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glEnable (GL_CULL_FACE);
}
// fuck, needs to recurse too...
/*
void sbreRenderModel (Vector *pPos, Matrix *pOrient, int model, ObjParams *pParam, float s, Vector *pCompos)
{
Model *pModel = ppModel[model];
@ -230,7 +304,15 @@ void sbreRenderModel (Vector *pPos, Matrix *pOrient, int model, ObjParams *pPara
SetGeneralState ();
SetOpaqueState ();
uint16 *pData = pModel->pData;
float dist = sqrt(VecDot(pPos, pPos));
float pixrad = g_sd * pModel->radius*s / dist;
int i; for (i=0; i<4; i++)
{
if (pModel->pLOD[i].pixrad >= 1000.0f) break;
if (pixrad <= pModel->pLOD[i].pixrad) break;
}
uint16 *pData = pModel->pLOD[i].pData;
while (*pData != PTYPE_END)
{
pData += pPrimFuncTable[*pData & 0xff] (pData, pModel, &rstate);
@ -242,4 +324,4 @@ void sbreRenderModel (Vector *pPos, Matrix *pOrient, int model, ObjParams *pPara
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glEnable (GL_CULL_FACE);
}
}*/

View File

@ -1,14 +1,6 @@
#include "sbre_int.h"
#include "sbre_anim.h"
#include "sbre_models.h"
const int SUB_WING2 = 1;
const int SUB_DISH = 2;
const int SUB_NOSEWHEEL = 3;
const int SUB_WING = 4;
const int SUB_NACELLE = 5;
const int SUB_NWUNIT = 6;
const int SUB_MAINWHEEL = 7;
const int SUB_MWUNIT = 8;
enum AxisIndex {
A_X = 0, A_Y, A_Z, A_NX, A_NY, A_NZ,
@ -34,8 +26,8 @@ static uint16 tetradata[] = {
PTYPE_SUBOBJECT, 0x8000, SUB_NOSEWHEEL, 10, 0, 4, 100,
PTYPE_END,
};
static Model tetramodel = { 1.0f, 11, tetravtx1, 20, 0, tetravtx2,
0, 0, 0, 0, tetradata, 0 };
Model tetramodel = { 1.0f, 66.0f, 11, tetravtx1, 20, 0, tetravtx2, 0,
{ { 0, tetradata, 0, 0, 0 } } };
static PlainVertex circlevtx1[] = {
@ -51,8 +43,8 @@ static uint16 circledata[] = {
PTYPE_CIRCLE, 0, 12, 6, 5, 1, 2000,
PTYPE_END,
};
static Model circlemodel = { 1.0f, 7, circlevtx1, 20, 0, circlevtx2,
0, 0, 0, 0, circledata, 1 };
Model circlemodel = { 1.0f, 20.0f, 7, circlevtx1, 20, 0, circlevtx2, 1,
{ { 0, circledata, 0, 0, 0 } } };
static PlainVertex cylvtx1[] = {
@ -69,8 +61,8 @@ static uint16 cyldata[] = {
PTYPE_TUBE, 0, 8, 6, 7, 20, 2000, 1000,
PTYPE_END,
};
static Model cylmodel = { 1.0f, 9, cylvtx1, 20, 1, cylvtx2,
0, 0, 0, 0, cyldata, 1 };
Model cylmodel = { 1.0f, 120.0f, 9, cylvtx1, 20, 1, cylvtx2, 1,
{ { 0, cyldata, 0, 0, 0 } } };
static PlainVertex nwunitvtx1[] = {
@ -106,8 +98,8 @@ static uint16 nwunitdata[] = {
PTYPE_END,
};
static Model nwunitmodel = { 1.0f, 15, nwunitvtx1, 20, 4, nwunitvtx2,
0, 0, 0, 0, nwunitdata, 0 };
Model nwunitmodel = { 1.0f, 7.0f, 15, nwunitvtx1, 20, 4, nwunitvtx2, 0,
{ { 0, nwunitdata, 0, 0, 0 } } };
static PlainVertex nosewheelvtx1[] = {
@ -128,8 +120,8 @@ static uint16 nosewheeldata[] = {
PTYPE_CYLINDER | RFLAG_XREF, 2, 8, 9, 10, 2, 100,
PTYPE_END,
};
static Model nosewheelmodel = { 1.0f, 11, nosewheelvtx1, 20, 0, nosewheelvtx2,
0, 0, 0, 0, nosewheeldata, 4 };
Model nosewheelmodel = { 1.0f, 7.0f, 11, nosewheelvtx1, 20, 0, nosewheelvtx2, 3,
{ { 0, nosewheeldata, 0, 0, 0 } } };
static PlainVertex mwunitvtx1[] = {
@ -165,8 +157,8 @@ static uint16 mwunitdata[] = {
PTYPE_END,
};
static Model mwunitmodel = { 1.0f, 15, mwunitvtx1, 20, 4, mwunitvtx2,
0, 0, 0, 0, mwunitdata, 0 };
Model mwunitmodel = { 1.0f, 8.0f, 15, mwunitvtx1, 20, 4, mwunitvtx2, 0,
{ { 0, mwunitdata, 0, 0, 0 } } };
static PlainVertex mainwheelvtx1[] = {
@ -194,8 +186,8 @@ static uint16 mainwheeldata[] = {
PTYPE_CYLINDER | RFLAG_XREF, 3, 8, 11, 12, 2, 100,
PTYPE_END,
};
static Model mainwheelmodel = { 1.0f, 15, mainwheelvtx1, 20, 0, mainwheelvtx2,
0, 0, 0, 0, mainwheeldata, 5 };
Model mainwheelmodel = { 1.0f, 8.0f, 15, mainwheelvtx1, 20, 0, mainwheelvtx2, 5,
{ { 0, mainwheeldata, 0, 0, 0 } } };
static PlainVertex nacellevtx1[] = {
@ -230,13 +222,13 @@ static uint16 nacelledata[] = {
COMP_END,
PTYPE_END,
};
static Model nacellemodel = { 1.0f, 16, nacellevtx1, 20, 0, nacellevtx2,
0, 0, 0, 0, nacelledata, 2 };
Model nacellemodel = { 1.0f, 30.0f, 16, nacellevtx1, 20, 0, nacellevtx2, 2,
{ { 0, nacelledata, 0, 0, 0 } } };
// do wings as subobjects
static PlainVertex shipvtx1[] = {
static PlainVertex ship1vtx1[] = {
{ VTYPE_PLAIN, { 5.0f, 10.0f, 30.0f } }, // 6, top four body verts
{ VTYPE_PLAIN, { -5.0f, 10.0f, 30.0f } },
{ VTYPE_PLAIN, { 5.0f, 10.0f, -30.0f } },
@ -283,7 +275,7 @@ static PlainVertex shipvtx1[] = {
{ VTYPE_PLAIN, { 0.0f, -9.330127f, -13.0f } }, // 41, mainwheel
};
static CompoundVertex shipvtx2[] = {
static CompoundVertex ship1vtx2[] = {
{ VTYPE_ANIMLIN, { 25, 0, -1, -1, 0 } }, // 50, right wing yaxis
{ VTYPE_CROSS, { 50, 2, -1, -1, 0 } }, // right wing xaxis
@ -294,7 +286,7 @@ static CompoundVertex shipvtx2[] = {
{ VTYPE_NORM, { 12, 8, 6, -1, -1 } }, // 55, right text normal
};
static uint16 shipdata[] = {
static uint16 ship1data[] = {
PTYPE_MATFIXED, 100, 0, 100, 0, 0, 0, 100, 0, 0, 0,
PTYPE_QUADFLAT, 7, 6, 8, 9, // top
PTYPE_QUADFLAT, 13, 11, 15, 17, // bottom
@ -308,9 +300,9 @@ static uint16 shipdata[] = {
PTYPE_TRIFLAT | RFLAG_XREF, 6, 18, 10, // front side top
PTYPE_TRIFLAT | RFLAG_XREF, 10, 18, 11, // front side bottom
PTYPE_SUBOBJECT, 0x8000, SUB_WING, 20, 22, 2, 100,
PTYPE_SUBOBJECT, 0x8000, SUB_WING, 23, 50, 2, 100,
PTYPE_SUBOBJECT, 0x8000, SUB_WING, 26, 52, 2, 100,
PTYPE_SUBOBJECT, 0x8000, SUB_WING1, 20, 22, 2, 100,
PTYPE_SUBOBJECT, 0x8000, SUB_WING1, 23, 50, 2, 100,
PTYPE_SUBOBJECT, 0x8000, SUB_WING1, 26, 52, 2, 100,
PTYPE_MATFIXED, 20, 20, 20, 0, 0, 0, 100, 0, 0, 0,
PTYPE_ZBIAS, 54, 5,
@ -327,7 +319,7 @@ static uint16 shipdata[] = {
PTYPE_END,
};
static Thruster shipthruster[] = {
static Thruster ship1thruster[] = {
{ 29, 5 | THRUST_NOANG, 50.0f },
{ 30, 2 | THRUST_NOANG, 35.0f }, // retros
{ 31, 2 | THRUST_NOANG, 35.0f },
@ -336,11 +328,11 @@ static Thruster shipthruster[] = {
{ 36, 1, 25.0f }, { 37, 1, 25.0f }, // top
{ 38, 4, 25.0f }, { 39, 4, 25.0f }, // bottom
};
static Model shipmodel = { 1.0f, 42, shipvtx1, 50, 6, shipvtx2,
0, 0, 11, shipthruster, shipdata, 0 };
Model ship1model = { 1.0f, 40.0f, 42, ship1vtx1, 50, 6, ship1vtx2, 0,
{ { 0, ship1data, 0, 11, ship1thruster } } };
static PlainVertex wingvtx1[] = {
static PlainVertex wing1vtx1[] = {
{ VTYPE_PLAIN, { 0.0f, 0.0f, 1.0f } }, // 6, bottom front
{ VTYPE_PLAIN, { 0.0f, 0.0f, -1.0f } }, // bottom back
{ VTYPE_PLAIN, { 0.0f, 1.5f, 0.0f } }, // top front
@ -364,13 +356,13 @@ static PlainVertex wingvtx1[] = {
{ VTYPE_PLAIN, { -0.4f, 0.0f, 1.5f } }, // 22, tan 3->2 top, 0
{ VTYPE_PLAIN, { 0.4f, 0.0f, 1.5f } }, // tan 3->2 top, 1
};
static CompoundVertex wingvtx2[] = {
static CompoundVertex wing1vtx2[] = {
{ VTYPE_CROSS, { 19, 14, -1, -1, -1 } }, // 30, norm 0
{ VTYPE_CROSS, { 15, 16, -1, -1, -1 } }, // norm 1
{ VTYPE_CROSS, { 16, 17, -1, -1, -1 } }, // norm 3
{ VTYPE_CROSS, { 18, 19, -1, -1, -1 } }, // norm 2
};
static uint16 wingdata[] = {
static uint16 wing1data[] = {
PTYPE_MATFIXED, 100, 0, 100, 0, 0, 0, 100, 0, 0, 0,
PTYPE_COMPSMOOTH | RFLAG_XREF, 0, 5, 10, 12, 6, 30, // side
COMP_HERMITE, 7, 31, 14, 15,
@ -384,8 +376,8 @@ static uint16 wingdata[] = {
COMP_END,
PTYPE_END,
};
static Model wingmodel = { 25.0f, 24, wingvtx1, 30, 4, wingvtx2,
0, 0, 0, 0, wingdata, 2 };
Model wing1model = { 25.0f, 2.0f, 24, wing1vtx1, 30, 4, wing1vtx2, 2,
{ { 0, wing1data, 0, 0, 0 } } };
@ -614,8 +606,8 @@ static Thruster ship2thruster[] = {
{ 91, 0, 15.0f }, { 92, 3, 15.0f },
{ 93, 0, 15.0f }, { 94, 3, 15.0f },
};
static Model ship2model = { 1.0f, 98, ship2vtx1, 120, 1, ship2vtx2,
0, 0, 14, ship2thruster, ship2data, 10 };
Model ship2model = { 1.0f, 35.0f, 98, ship2vtx1, 120, 1, ship2vtx2, 10,
{ { 0, ship2data, 0, 14, ship2thruster } } };
@ -757,8 +749,8 @@ static uint16 station1data[] = {
PTYPE_END,
};
static Model station1model = { 1.0f, 36, station1vtx1, 100, 0, station1vtx2,
0, 0, 0, 0, station1data, 1 };
Model station1model = { 1.0f, 120.0f, 36, station1vtx1, 100, 0, station1vtx2, 1,
{ { 0, station1data, 0, 0, 0 } } };
static PlainVertex ship3vtx1[] = {
@ -891,8 +883,8 @@ static Thruster ship3thruster[] = {
{ 42, 1 | THRUST_XREF, 15.0f },
{ 43, 0 | THRUST_XREF, 15.0f },
};
static Model ship3model = { 1.0f, 44, ship3vtx1, 100, 2, ship3vtx2,
0, 0, 6, ship3thruster, ship3data, 6 };
Model ship3model = { 1.0f, 35.0f, 44, ship3vtx1, 100, 2, ship3vtx2, 6,
{ { 0, ship3data, 0, 6, ship3thruster } } };
@ -1007,8 +999,8 @@ static Thruster ship4thruster[] = {
// { 42, 1 | THRUST_XREF, 15.0f },
// { 43, 0 | THRUST_XREF, 15.0f },
};
static Model ship4model = { 1.0f, 41, ship4vtx1, 100, 1, ship4vtx2,
0, 0, 4, ship4thruster, ship4data, 10 };
Model ship4model = { 1.0f, 40.0f, 41, ship4vtx1, 100, 1, ship4vtx2, 10,
{ { 0, ship4data, 0, 4, ship4thruster } } };
static PlainVertex dishvtx1[] = {
@ -1055,8 +1047,8 @@ static uint16 dishdata[] = {
PTYPE_END,
};
static Model dishmodel = { 1.0f, 19, dishvtx1, 40, 0, dishvtx2,
0, 0, 0, 0, dishdata, 5 };
Model dishmodel = { 1.0f, 4.0f, 19, dishvtx1, 40, 0, dishvtx2, 5,
{ { 0, dishdata, 0, 0, 0 } } };
static PlainVertex ship5vtx1[] = {
@ -1154,15 +1146,15 @@ static uint16 ship5data[] = {
COMP_LINE, 9, 101,
COMP_END,
PTYPE_SUBOBJECT, 0x8000, SUB_WING2, 36, 40, 2, 70,
PTYPE_SUBOBJECT, 0x8000, SUB_WING2, 37, 41, 2, 70,
PTYPE_SUBOBJECT, 0x8000, SUB_WING2, 38, 42, 2, 70,
PTYPE_SUBOBJECT, 0x8000, SUB_WING2, 39, 43, 2, 70,
PTYPE_SUBOBJECT | SUBOBJ_THRUST, 0x8000, SUB_WING2, 36, 40, 2, 70,
PTYPE_SUBOBJECT | SUBOBJ_THRUST, 0x8000, SUB_WING2, 37, 41, 2, 70,
PTYPE_SUBOBJECT | SUBOBJ_THRUST, 0x8000, SUB_WING2, 38, 42, 2, 70,
PTYPE_SUBOBJECT | SUBOBJ_THRUST, 0x8000, SUB_WING2, 39, 43, 2, 70,
PTYPE_END,
};
static Model ship5model = { 1.0f, 44, ship5vtx1, 100, 2, ship5vtx2,
0, 0, 0, 0, ship5data, 5 };
Model ship5model = { 1.0f, 25.0f, 44, ship5vtx1, 100, 2, ship5vtx2, 5,
{ { 0, ship5data, 0, 0, 0 } } };
static PlainVertex wing2vtx1[] = {
@ -1210,59 +1202,9 @@ static Thruster wing2thruster[] = {
{ 20, 5, 25.0f },
{ 19, 2, 20.0f },
};
static Model wing2model = { 1.0f, 23, wing2vtx1, 30, 0, wing2vtx2,
0, 0, 2, wing2thruster, wing2data, 2 };
Model wing2model = { 1.0f, 25.0f, 23, wing2vtx1, 30, 0, wing2vtx2, 2,
{ { 0, wing2data, 0, 2, wing2thruster } } };
static PlainVertex tombstonevtx1[] = {
{ VTYPE_PLAIN, { 0.6f, 1.0f, -0.1f } }, // front quad
{ VTYPE_PLAIN, { 0.6f, -1.0f, -0.1f } },
{ VTYPE_PLAIN, { -0.6f, -1.0f, -0.1f } },
{ VTYPE_PLAIN, { -0.6f, 1.0f, -0.1f } },
{ VTYPE_PLAIN, { 0, 1, 0.1 } }, // cylinder
{ VTYPE_PLAIN, { 0, 1, -0.1 } },
{ VTYPE_PLAIN, { 0.6f, 1.0f, 0.1f } }, // rear quad
{ VTYPE_PLAIN, { 0.6f, -1.0f, 0.1f } },
{ VTYPE_PLAIN, { -0.6f, -1.0f, 0.1f } },
{ VTYPE_PLAIN, { -0.6f, 1.0f, 0.1f } },
{ VTYPE_PLAIN, { -0.5, 0.8, -0.1 } }, // text start
};
static uint16 tombstonedata[] = {
PTYPE_MATFIXED, 50, 50, 50, 0, 0, 0, 100, 0, 0, 0,
PTYPE_QUADFLAT, 6, 7, 8, 9,
PTYPE_QUADFLAT, 15, 14, 13, 12,
PTYPE_QUADFLAT, 6, 12, 13, 7,
PTYPE_QUADFLAT, 9, 8, 14, 15,
PTYPE_QUADFLAT, 8, 7, 13, 14,
PTYPE_CYLINDER, 0x8000, 16, 10, 11, 1, 60,
PTYPE_MATFIXED, 100, 0, 0, 0, 0, 0, 100, 0, 0, 0,
PTYPE_ZBIAS, 5, 5,
PTYPE_TEXT, 0, 0x8000, 16, 5, 0, 0, 0, 30,
PTYPE_END
};
static Model tombstonemodel = { 10.0f, 17, tombstonevtx1, 17, 0, 0,
0, 0, 0, 0, tombstonedata, 1 };
Model *ppModel[] = {
&ship5model,
&wing2model,
&dishmodel,
&nosewheelmodel,
&wingmodel,
&nacellemodel,
&nwunitmodel,
&mainwheelmodel,
&mwunitmodel,
&cylmodel,
&ship2model,
&shipmodel,
&station1model,
&ship3model,
&ship4model,
0,
// 0x10
&tombstonemodel,
0,
};

View File

@ -1,7 +1,6 @@
#include <SDL_opengl.h>
#include <malloc.h>
#include "sbre_int.h"
#include "sbre_anim.h"
#include "sbre.h" // for subobject
#include "../glfreetype.h"
@ -562,7 +561,7 @@ static int PrimFuncSubObject (uint16 *pData, Model *pMod, RState *pState)
glPushMatrix ();
// transform lin & ang thrust
if (ppModel[pData[2]]->numThrusters)
if (pData[0] & SUBOBJ_THRUST)
{
Vector compos;
MatTVecMult (&m, pState->pVtx+pData[3], &compos);

View File

@ -37,7 +37,7 @@ struct ObjParams
};
void sbreSetViewport (int w, int h, int d, float zn, float zf, float dn, float df);
void sbreSetViewport (int w, int h, float d, float zn, float zf, float dn, float df);
void sbreSetDirLight (float *pColor, float *pDir);
void sbreSetWireframe (int val);
void sbreRenderModel (Vector *pPos, Matrix *pOrient, int model, ObjParams *pParam,

View File

@ -37,20 +37,14 @@ struct Thruster
uint16 pos; // index into vertices
uint16 dir;
float power;
int detail; // 0 - min, 1 - mid, 2 - max
};
struct Light
{
uint8 animcolor;
uint8 animpower;
uint16 vtx;
float power;
float pColor[3];
};
struct Model
{
float scale;
float radius; // scale multiplies this too
int numPVtx;
PlainVertex *pPVtx;
@ -59,23 +53,60 @@ struct Model
int numCVtx;
CompoundVertex *pCVtx;
int numLights;
Light *pLight;
int numThrusters;
Thruster *pThruster;
uint16 *pData;
int numCache; // number of cached primitives
int *pNumVtx, *pNumIdx;
struct {
float pixrad; // size in screen pixels below which LOD applies
uint16 *pData1; // pixrad <= 0.0f is top LOD - kinda backward
uint16 *pData2;
int numThrusters;
Thruster *pThruster;
} pLOD[4];
int *pNumVtx, *pNumIdx; // caches
Vector **ppVCache;
uint16 **ppICache;
};
extern Model *ppModel[];
//*****************************************************************************
// AnimFuncs
enum animmod
{
AMOD_CLIP = 0, // just clip result to 0-1
AMOD_MOD1, // fmod(1), then clip
AMOD_REF, // fmod(2), reflect around 1, then clip
};
struct AnimFunc
{
int src;
int mod;
float order0;
float order1;
float order2;
float order3;
};
enum animfunc
{
AFUNC_GEAR = 0,
AFUNC_GFLAP,
AFUNC_THRUSTPULSE,
AFUNC_LIN4SEC,
};
const AnimFunc pAFunc[] =
{
{ ASRC_GEAR, AMOD_CLIP, -1.0f, 2.0f, 0.0f, 0.0f },
{ ASRC_GEAR, AMOD_CLIP, 0.0f, 2.0f, 0.0f, 0.0f },
{ ASRC_MINFRAC, AMOD_REF, 0.0f, 30.0f, 0.0f, 0.0f },
{ ASRC_MINFRAC, AMOD_MOD1, 0.0f, 15.0f, 0.0f, 0.0f },
};
//*****************************************************************************
// stuff from simtriang.cpp
#define TRIANG_MAXPOINTS 64
#define TRIANG_MAXSTEPS 5
@ -91,6 +122,7 @@ void Triangulate (Vector *pCPos, Vector *pCNorm, int steps,
Vector **ppVtx, int *pNV, uint16 **ppIndex, int *pNI);
//******************************************************************************
// Random rendering crap
struct RState
{
@ -103,6 +135,12 @@ struct RState
ObjParams *pObjParam; // dynamic object parameters
float dn, df; // near/far depth range
Vector compos; // object relative centre of mass
// Collision output stuff
int maxCVtx, maxCIdx;
int numCVtx, numCIdx;
Vector *pCollVtx;
int *pCollIdx;
};
enum primtype
@ -125,8 +163,10 @@ enum primtype
};
extern int (*pPrimFuncTable[])(uint16 *, Model *, RState *);
extern int (*pCollFuncTable[])(uint16 *, Model *, RState *);
static const int RFLAG_XREF = 0x8000;
static const int SUBOBJ_THRUST = 0x4000;
static const int THRUST_XREF = 0x8000;
static const int THRUST_NOANG = 0x4000;
@ -134,6 +174,7 @@ static const int THRUST_NOANG = 0x4000;
static const float SBRE_ZBIAS = 0.00002f;
static const float SBRE_AMB = 0.3f;
enum comptype
{
COMP_END = 0,
@ -150,7 +191,8 @@ const char pModelString[1][256] = {
"Bollocks",
};
void RenderTransparencies (RState *pState);
void RenderThrusters (RState *pState, int numThrusters, Thruster *pThrusters);
float ResolveAnim (ObjParams *pObjParam, uint16 type);
#endif /* __SBRE_INT_H__ */

64
src/sbre/sbre_models.h Normal file
View File

@ -0,0 +1,64 @@
#ifndef __SBRE_MODELS_H__
#define __SBRE_MODELS_H__
#include "sbre_int.h"
extern Model dishmodel, nosewheelmodel, nwunitmodel, mainwheelmodel, mwunitmodel;
extern Model wing1model, wing2model;
extern Model ship1model, ship2model, ship3model, ship4model, ship5model;
extern Model station1model;
// common subobject indices
const int SUB_NOSEWHEEL = 1;
const int SUB_NWUNIT = 2;
const int SUB_MAINWHEEL = 3;
const int SUB_MWUNIT = 4;
const int SUB_DISH = 5;
const int SUB_WING1 = 30;
const int SUB_WING2 = 31;
Model * const ppModel[] =
{
// 0, current test object
&ship5model,
// 1, common subobjects
&nosewheelmodel,
&nwunitmodel,
&mainwheelmodel,
&mwunitmodel,
&dishmodel,
0, 0, 0, 0,
// 10
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 20
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 30, single-use subobjects
&wing1model,
&wing2model,
0, 0, 0, 0, 0, 0, 0, 0,
// 40
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 50
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 60, JJ ships
&ship1model,
&ship2model,
&ship3model,
&ship4model,
&ship5model,
&station1model,
0, 0, 0, 0,
// 70
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 80
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
// 90, other people's ships
};
#endif // __SBRE_MODELS_H__

View File

@ -203,23 +203,19 @@ static void QuickSort (TransElem *pA, int end)
static int thrustgen = 0;
void RenderTransparencies (RState *pState)
void RenderThrusters (RState *pState, int numThrusters, Thruster *pThrusters)
{
Vector *pVtx = pState->pVtx;
Model *pModel = pState->pModel;
if (!thrustgen) GenerateThrusters ();
thrustgen = 1;
int maxElem = pModel->numThrusters*2;
if (!maxElem) return;
TransElem *pList = (TransElem *) alloca (maxElem*sizeof(TransElem));
TransElem *pList = (TransElem *) alloca (numThrusters*2*sizeof(TransElem));
Vector tv;
int i, numElem = 0;
for (i=0; i<pModel->numThrusters; i++)
for (i=0; i<numThrusters; i++)
{
Thruster *pThruster = pModel->pThruster+i;
Thruster *pThruster = pThrusters+i;
pList[numElem].pThruster = pThruster;
pList[numElem].pos = pVtx[pThruster->pos];
pList[numElem].dir = pVtx[pThruster->dir&0xff];