View Full Version : ARB_VP. Pos from tex coord

02-21-2004, 07:33 AM
Hi guys,

I've only been using vertex programs for about 12 hours now... So bare with me.

My current goal is to start with a vertex of coordinate (0,0,1).
The vertex program will accept only a pair of texture coordinates. From this I want to use the XTestureCoord to rotate the vertex around the X-axis and same with the Y.

In other words:
1. Defined initial position of vertex (0,0,1).
2.Supplied texture coordinates.
3.rescale texcoord range from 0->1 to -0.5->0.5.
4.Rotate X axis by XTex*90degrees. (ie: somewhere along the 90degree arc - +/-45degrees.
5.Rotate Y axis by YTex*90degrees.
6.Output result as both the new position and the new normal. (Will be unit lenth I presume)

I conceptually understand everything I need EXCEPT steps 4/5. How would I do this? I'm not even sure where to start.

Thanks in advance.

02-21-2004, 01:51 PM
3.rescale texcoord range from 0->1 to -0.5->0.5.
4.Rotate X axis by XTex*90degrees.
5.Rotate Y axis by YTex*90degrees.

Rotation about the x-axis involves changing the y and z coordinates by sines and cosines of the angle. It will be this, or something like this depending on how your coordinate system is set-up.

Rotate X-axis cos/sin are of x angle
new_y = cos * old_y - sin * old_z;
new_z = sin * old_y + cos * old_z;

Rotate Y-axis cos/sin are of y angle
new_x = cos * old_x - sin * old_z;
new_z = sin * old_x + cos * old_z;

Be sure to propagate the z-coords from the first rotation to the second. (first rotation's new_z becomes old_z in the second).

There's a big catch here, you may not have access to a sin cos function in your vertex program. In which case you will need to approximate them.

02-21-2004, 02:50 PM

I used to do this kind of thing (using sin/cos values to rotate about a point) in my software engine(s) back in the day.(tm)

But I figured it was such a common operation in GL, that there would be a straight-forward way to do it in a ARB_VP.

I know the high-level theory. But the implementation eludes me. Would it be possible to upload a "rotate by 90 degree" matrix which is then multiplied by the re-scaled TexCoord to achieve +/-45 degress?

Perhaps I am showing how rusty my GL coding has become... But this would *seem* more elegant.

Perhaps I need to spend more time analysing the spec. I'll repost when I find more info.
If anyone has any more suggestions I'd love to hear them! http://www.opengl.org/discussion_boards/ubb/smile.gif