Jump to content

  • Log In with Google      Sign In   
  • Create Account


juddo

Member Since 30 Aug 2010
Offline Last Active Dec 05 2012 07:14 AM

Topics I've Started

calculating normals for triangle strip model, not terrain

07 November 2012 - 08:44 PM

hello all,

i am reading vertex data from a game file that stores a character model in triangle strips (ps2 game, hence why triangle strips are used). i did concider converting the triangle strips into vertex indexing to help ease the pain of calculating my normals at runtime, but still would like some help calculating normals for triangle strips.

i recently read on here that triangle strips flip cw/ccw culling every triangle if backface culling is on. below is my code for calculating normals at the moment;

[source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices; k++) { vu[0] = vertices[k + 1][0] - vertices[k][0]; vu[1] = vertices[k + 1][1] - vertices[k][1]; vu[2] = vertices[k + 1][2] - vertices[k][2]; vv[0] = vertices[k + 1][0] - vertices[k + 2][0]; vv[1] = vertices[k + 1][1] - vertices[k + 2][1]; vv[2] = vertices[k + 1][2] - vertices[k + 2][2]; cp[0] = (vu[2] * vv[1]) - (vu[1] * vv[2]); cp[1] = (vu[0] * vv[2]) - (vu[2] * vv[0]); cp[2] = (vu[1] * vv[0]) - (vu[0] * vv[1]); result = (float)sqrt((cp[0]*cp[0]) + (cp[1]*cp[1]) + (cp[2]*cp[2])); if (result == 0.0f) result = 1.0f; normals[k][0] = cp[0] / result; normals[k][1] = cp[1] / result; normals[k][2] = cp[2] / result; }[/source]

when i run my program with the above code, i see the following;

Posted Image

&&

Posted Image

you can see on this side shot that i can see through the model (less than desireable.) at the moment i am iterating through every vertex, do i need an offset in my loop to calculate the next triangle or next vertex? it looks like the normals are facing away from each other...

and this is the drawing code...

[source lang="cpp"]glPushMatrix(); glTranslatef(posx_, posy_, posz_); glRotatef(90.0f, 0, 0, 1); glRotatef(turnrate_, 1, 0, 0); glBegin(GL_TRIANGLE_STRIP); for (int i = 0; i < model_.nvertices; i++) { glNormal3f(model_.normals[i][0], model_.normals[i][1], model_.normals[i][2]); glVertex3f(model_.vertices[i][0], model_.vertices[i][1], model_.vertices[i][2]); } glEnd();glPopMatrix();[/source]


thanks for your time,


best regards,

justin

reading a games binary file vertex floating points

29 October 2012 - 10:36 PM

hello,

i have spent an hour or so googleing how to do the following but didnt find anything that covered this specifically. (may have been how i phrased my words, not sure?)

i want to read (c++ - fread()) a binary file from a game that contains floating point vertex data stored in two byte signed integer format (x,y,z,w - w is always 0). then i want to convert that into floats that i can use with opengl to draw the vertex data. apparently i also need to divide this by the radix point (which is some multiple of two?)?


i would appreciate any help as i've hit a wall here...

thanks for your time,

best regards,


justin

vertex unsharing - triangle list question

30 August 2010 - 10:26 PM

hello!

i've stopped myself several times from posting a thread here regarding my unclear and miss understanding of model vertex sharing, hoping i'd find the answer i was after sooner or later... but i simply can't find a clear answer for what im having trouble understanding anywhere.

the thick of it is;

i'm trying to draw my model (exported from milkshape - that has many shared vertices) with the gldrawelements function. i understand milkshape is short changing me on vertex, normal and uv data (because of shared vertices). i also understand i need to make an array for gldrawelements made up of;

verx very verz
norx nory norz (this vertex normal)
u v (this vertex uv)

this is where i get a little frazzled. i know gldrawelements uses _one_ index (the triangles list) to draw the three vertex, normal and uv data arrays. what i cant wrap my head around is, when i unshare a vertex, where does this new vertex go in the new vertex array? after the vertex in question? at the end? what im super unclear on is what happens with the ordering of the triangles? do i make a new triangle? or do i just update the triangle? does the number of triangles stay the same? im so confused! :(

i wrote a few test programs to duplicate data on what i though was the right way and ended up with some silly high numbers of vertices? i've even tried writing a plugin with the milkshape sdk. the entire program seems to run on this shared vertices idea. i cant find a way to get the real vertex count (always the shared vertex count).

anyway, i figure the following with the exported ascii format;

if the vertex exists > check for same uv coords
if same uv coords > disregard?
if not the same uv coords > add vertex, normal, uv and bone data to the end of their new arrays

now what would i do? i surely need todo something with the triangle data? i'd have all these extra vertices and the triangle list wouldnt point to any of them?

the maximum number of vertices would be (number of vertices * 3) right? what about the triangles? does the number of triangles ever increase?

so unsure...

thanks alot for your time!

regards,


justin

PARTNERS