juddo

Member

12

132 Neutral

• Rank
Member

2. calculating normals for triangle strip model, not terrain

thank you Lauris Kaplinski for the great reply! i did as you mentioned and have a better result, just not the right one. i tried changing odd to even and (k & 1) is the only one that gives near results. i've taken a screenshot to show what i see... && i can see through the mesh which i hope is a result of incorrect normals, or else something in my rendering section is broken! [source lang="cpp"] float vu[3]; float vv[3]; float cp[3]; float result; for (int k = 0; k < nvertices - 2; 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 + 2][0] - vertices[k][0]; vv[1] = vertices[k + 2][1] - vertices[k][1]; vv[2] = vertices[k + 2][2] - vertices[k][2]; cp[0] = (vu[1] * vv[2]) - (vu[2] * vv[1]); cp[1] = (vu[2] * vv[0]) - (vu[0] * vv[2]); cp[2] = (vu[0] * vv[1]) - (vu[1] * vv[0]); 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; if (k &amp;amp; 1) { normals[k][0] = -normals[k][0]; normals[k][1] = -normals[k][1]; normals[k][2] = -normals[k][2]; } } [/source] above i changed the cross product from what i had originally. a few articles i read on calculating normals seem to use the same cross product. i hope its not incorrect. changing it gives me a completely dark shaded model. *scratches head*

4. calculating normals for triangle strip model, not terrain

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; && 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[0], model_.normals[1], model_.normals[2]); glVertex3f(model_.vertices[0], model_.vertices[1], model_.vertices[2]); } glEnd(); glPopMatrix(); [/source] thanks for your time, best regards, justin
5. reading a games binary file vertex floating points

thanks for that fantastic reply hodgman. i really couldnt ask for more help! [source lang="plain"]With your code, you're only reading a single byte into byte0/byte1, but they're uninitialized, so their upper 3 bytes contain random values -- you should initialize those ints to 0 before using fread.[/source] as soon as i read this, the penny dropped. yesterday i spent almost all day on this and recalled getting completely random results every time i ran the program with a particular line of code i was using. i went back to how i was trying to convert the integers and set byte0 and byte1 to 0 and wouldnt you know it! it worked! thank you so much for all the help. best regards, justin
6. reading a games binary file vertex floating points

i hope this answers your question. documentation on this file type says "models have vertexes in two byte signed integer format. to convert to float you convert the integer into a float, but you need to divide it by the radix point (some multiple of two - forgot which?)" in my hex editor, i found the starting point of the vertex data which i have pasted below. x, y, z, w (always 0?) A9F3 1101 0EFD 0000 thanks for your time.
7. reading a games binary file vertex floating points

thanks for the reply ultramailman. i am only trying to read the binary data, not store it. i am trying to port a game reading original game content (ps2 game files.) i was reading the two bytes seperately because i believe they need to be the other way around for pc. a script i have that converts the data into a 3ds file, looks like this; [source lang="plain"] <loop one - read the data (x,y,z,w)> Get type1 Short 0 ; Get type2 Short 0 ; Get type3 Short 0 ; Get type4 Short 0 ; Put type1 Short MEMORY_FILE1 ; Put type2 Short MEMORY_FILE1 ; Put type3 Short MEMORY_FILE1 ; <loop two - convert data to floats> Get first Byte MEMORY_FILE1 ; Get second Byte MEMORY_FILE1 ; If second > 127 ; Math second -= 256 ; Endif ; Math nb = second ; Math nb *= 256 ; Math nb += first ; Put nb float MEMORY_FILE2 ; [/source]
8. reading a games binary file vertex floating points

hodgman, the data is stored as two byte signed integers. thanks for the clarification. i have included some code i've been toying with all day. it's giving me normal looking floats, but im almost certain it's not correct (very similar numbers.) [source lang="cpp"] signed int byte0; signed int byte1; float temp; fread(&byte0, 1, 1, f); fread(&byte1, 1, 1, f); temp = ((byte0 & 0xFF) / 256.f) + byte1; [/source] i've got a script (quickbms script, but i want to do this in c++) that deals with this issue (converting two byte signed int to float) and by looking at it, suggests i am doing this wrong. this is the scripts pseudo code. [source lang="plain"] byte0 byte1 float temp if byte1 > 127 byte1 -= 256 temp = byte1 temp *= 256 temp += byte0 [/source] i tried the above in a small console program i wrote just for this and get weird results.
9. reading a games binary file vertex floating points

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
10. vertex unsharing - triangle list question

hey there... just following up on this; i did as you said karwosts and grabbed a mesh with a texture and kept at it. im glad to say i finally got it to work :) just to clarify, milkshape does appear to store unique uv data... as i had suspected? thankyou 0xffffffff and karwosts for all your help! what a great community ;) regards, justin