CoD2 D3DBSP
Tech: LuaJIT + FFI for C-structs
Toujane example
Movement:
WASD for Position
Arrow Keys for Camera
Q/E for Camera Down/Up (like in CoD2)
PHP Code:
typedef struct
{
float position[3];
float normal[3];
int bla[11];
} aDrawVert;
typedef struct
{
int length;
int offset;
} aLump;
typedef struct
{
char ident[4];
int version;
aLump lumps[100];
} aHeader;
typedef struct
{
short index[3];
} aTriangle; // depricated
typedef struct
{
unsigned short offset;
//unsigned short b;
//unsigned short c;
} aDrawIndex;
/*typedef struct
{
unsigned short a;
unsigned short b;
unsigned short c;
} aDrawIndex;*/
// is empty in mp_analyse1
typedef struct
{
float position[3];
} aCollisionVert;
typedef struct
{
int planeIndex;
int children[2];
int mins[3];
int maxs[3];
} aNode;
typedef struct
{
//int cluster; // ???
//int area; // ???
//int mins[3]; // ???
//int maxs[3]; // ???
//int faceFirst;
//int faceCount;
//int brushFirst;
//int brushCount;
int someA[4];
int firstLeafBrush; // lookup in leafbrushes
int numLeafBrushes;
int someB[3];
} aLeaf;
typedef struct
{
unsigned short bla;
unsigned short foo;
unsigned int vertexFirst;
unsigned short nVertex;
unsigned short nTriangles;
unsigned int triangleFirst;
} aTriangleSoup;
Draw all triangle faces:
PHP Code:
function bspdraw()
colors = {
{0, 0, 0},
{0, 0, 1},
{0, 1, 0},
{0, 1, 1},
{1, 0, 0},
{1, 0, 1},
{1, 1, 0},
{1, 1, 1}
}
for i = 0,nTriangleSoups-1 do
soup = triangleSoups + i
gl.glBegin(gl.GL_TRIANGLES)
for nTriangles = 0, soup.nTriangles-1 do
drawIndex = drawIndexes + (soup.triangleFirst + nTriangles)
co = colors[(nTriangles%8) + 1]
gl.glColor3f(co[1], co[2], co[3])
a = vertices + (drawIndex.offset + soup.vertexFirst)
gl.glVertex3fv(a.position)
end
gl.glEnd()
end
end
Serthy, could you post your full solution of how to use your structs? That would help alot