View Full Version : Splitting up a Block

Hello,

I've made a 3D-Engine and the Maps consists of Blocks. The Position and Size of each Block is defined in a *.lvl-File:

GLfloat Pos.X

GLfloat Pos.Y

GLfloat Pos.Z

GLfloat Size.X

GLfloat Size.Y

GLfloat Size.Z

The Code to render a Block is:

glTranslatef(Pos.X,Pos.Y,Pos.Z);

glScale3f(Size.X,Size.Y.Size.Z);

glCallList(box);

A Map looks like this for exmple: http://www.cone-grafix.de/krypton/kshot2.jpg

Now, I want to implement some Effects. But for this, I have to split all the Blocks up into Triangles. Now my Question: How can I do that?

I forgot: Please don't say that I should change my Format because I made an Editor for it...

coredump

07-23-2001, 01:23 PM

IMHO the best way would be to parse your "box" into polygons. all you need are the vertices. i have some classes to help me with it:

class Vector

{

public:

float x;

float y;

float z;

Vector() {}

...

};

class polygon

{

public:

unsigned short numberOfVertices;

Vector *vertices;

unsigned short numberOfIndices;

unsigned short *indices;

Vector normal;

polygon() {}

};

the indices allow me to use triangle strips and fans. ex:

...

polygon p;

p.numberOfVertices = 4;

p.vertices = new Vector[p.numberOfVertices];

p.vertices[0] = v1;

p.vertices[1] = v2;

p.vertices[2] = v3;

p.vertices[3] = v4;

p.numberOfIndices = (p.numberOfVertices - 2) * 3;

p.indices = new unsigned short[p.numberOfIndices];

p.indices[0] = 0;

p.indices[1] = 1;

p.indices[2] = 2;

p.indices[3] = 0;

p.indices[4] = 2;

p.indices[5] = 3;

...

then, to draw the polygon:

void polygon::draw()

{

...

glBegin(GL_TRIANGLES); // also works w/GL_TRIANGLE_FAN

for (int i = 0; i < numberOfIndices / 3; i += 3)

{

glVertex3f(vertices[indices[i]].x, vertices[indices[i]].y, vertices[indices[i]].z);

glVertex3f(vertices[indices[i + 1]].x, vertices[indices[i + 1]].y, vertices[indices[i + 1]].z);

glVertex3f(vertices[indices[i + 2]].x, vertices[indices[i + 2]].y, vertices[indices[i + 2]].z);

}

glEnd();

...

}

each polygon makes (numberOfVertices - 2) triangles. hope this helps. e-mail me if you need more help/code. good luck.

b

Thanx, but that's not my problem. I even don't get the Vertices... I just have a compiled List as Block and I want to get the Vertices to split it up into Polygones. Well, I tried to get the upper left Vertex like this:

Vertex1.X=BlockPos.X-BlockSize.X;

Vertex1.Y=BlockPos.Y+BlockSize.Y;

Vertex1.Z=BlockPos.Z+BlockSize.Z;

Well, then after I had three Vertices I tried to draw a Polygone. But the Size was too big and the Position wasn't correct.

But what's wrong? I think this Code above should work...

Stormie

07-24-2001, 03:58 AM

Originally posted by MarcoB:

I just have a compiled List as Block and I want to get the Vertices to split it up into Polygones.

Well, what is in this compiled list?? Is it 6 quads? If so you must already have the vertices, so it should be straightforward to convert it into triangles.

If the code to generate the display list is something you found (rather than wrote yourself), and you don't 100% understand it, post it here and surely someone will explain.

I found the solution. Thanx.

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.