Archived

This topic is now archived and is closed to further replies.

Texture Coord Problem...

This topic is 5590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Following is my interpretation of what you said: you require two orthogonal vectors on the plane containing triangle with given normal.

Now my interpretation is correct, here''s the solution:

take a vector not equal to the normal call it v.

let u= v x n
(now u is perpendicular to the normal and hence in its plane)
let w= n x u
(and w is perpendicular to both n and u, so its in the plane and orthogonal to u)

so your two vectors are u and w.

unless you want very specific kind of orthogonal vectors...

Share this post


Link to post
Share on other sites
quote:
Original post by iNsAn1tY
and I don''t know how to rotate the normal around it''s x and z axes.


Do you mean that you want to create a set of axes for x'',y'' and z'' where the plane x''y'' coincides with the plane of the triangle... and the triangle''s normal vector lies in the direction of z''???

Timkin

Share this post


Link to post
Share on other sites
Timkin, that's what I wanted to do, but I just thought up a different method:

I simply took the normal, whatever it might be, resolved it back into the x and z angles which describe it by rotating it back until it was at (0, 1, 0), then took the sCoord and tCoord, which at (0, 1, 0) are (1, 0, 0) and (0, 0, -1) respectively, and put them through a rotation matrix built out of the x and z angles which describe the original normal. This manoeuvres the sCoord and tCoord into the same plane as the triangle.

There might be better ways of doing this, but this method works perfectly, and now all the polygons which lie in a plane have uniform texture coordinates, and where two walls meet, the texture is perfectly aligned, just like in HalfLife and Quake III...


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 28, 2002 10:19:56 AM]

Share this post


Link to post
Share on other sites