I'm creating a q3radiant map maker in VB and OpenGL. I'm finishing it off now, but my texture coordinate generation system is giving me some hassle...
I'm using the method behind glTexGen[idf] with GL_OBJECT_SPACE, which is basically this (assuming X, Y and Z are the position in 3D space of the vertex we're generating texcoords for):
TexCoord = (X * Vector[0]) + (Y * Vector[1]) + (Z * Vector[2])
This is, I believe, the way that q3radiant and Valve's Hammer editor generate textures, as the textures in a certain plane always match up.
Now, for the s texture direction, the vector must be the triangle's normal rotated 90 degrees around it's (not the world's) z axis, so if the vector was something like (0.707, 0.707, 0), then the s vector would be (0.707, -0.707, 0). For the t texture direction, the vector must be the triangle's normal rotated -90 degrees around it's (not the world's) x axis. So (0.707, 0.707, 0) becomes (0, 0, -1).
I tried this theory in my map maker, but rotated the normals provided about the world's x and z axes. It worked perfectly for triangles in the xz plane, but not for any others.
So, can anyone explain to me how I can derive the two vectors I need from the triangle's normal? Rotating the normal around the world's x and z axes only works for triangles in the xz plane, and I don't know how to rotate the normal around
it's x and z axes. If I did, this problem would be solved...
btw, if anyone knows a different, better and completely robust method for texcoord generation (like the one 3D Studio Max, q3radiant and Hammer editor use), feel free to add it, but I think this is the only method
Movie Quote of the Week:
"The greatest trick the Devil ever pulled was convincing the
world he didn't exist."
- Roger "Verbal" Kint, The Usual Suspects.
Try http://uk.geocities.com/mentalmantle - DarkVertex Coming Soon!
[edited by - iNsAn1tY on August 27, 2002 3:19:37 PM]
[edited by - iNsAn1tY on August 27, 2002 3:40:34 PM]