View Full Version : VP rotations
02-24-2004, 06:17 PM
I posted this Q on in the math/algo forum, but didn't get anywhere, so I'm reposting here.
In a Vertex Program (ARB), I want to rotate each vertex around the X-axis by it's X-texture coordinate. (*whew*)
How would I do that? It's a piece of cake if I do it myself pre-render. But I want to
a) learn more about VPs and
b) Think the hardware would be able to do this more efficiently.
Can anybody help a poor coder understand?
02-25-2004, 08:12 AM
You just need to make an appropriate transformation matrix and multiply the vertex position by it. In the back of the red book there's a discussion of what matrix glRotate generates. Googling for rotation matrix will probably be helpful too.
02-25-2004, 02:12 PM
I've looked some more into this. Please feel free to comment on my math (granted it's quite poor).
OK, to quote the Red Book:
glRotatef(a,0,1,0) results in :
| cos a, 0, sin a, 0 |
| 0, 1, 0, 0 |
|-sin a, 0, cos a, 0 |
| 0, 0, 0, 1 |
Therefore glRotatef(90,0,1,0) results in :
| 0, 0, 1, 0 |
| 0, 1, 0, 0 |
|-1, 0, 0, 0 |
| 0, 0, 0, 1 |
(This is the matrix I would initialling be sending to my vertex_program.)
Then the vertex_program uses texcoord.x (S) [0->1] and subtracts 0.5 there-by giving a range of [-0.5->0.5].
We take this new S and, in theory, rotate our matrix by it to obtain a vertex specific rotation of [-45deg->45deg].
Problem: This doesn't look like it'll work.
I say this because if the final S = 0, then the resulting matrix is NOT an identity matrix as I would have expected... Since a rotation of 0deg is essentially no rotation at all.
Am I barking up the wrong tree? Am I even in the right yard?
02-25-2004, 04:59 PM
I'm not sure why you'd send the glRotatef(90,0,1,0) matrix to the program. You'll need to compute the matrix, complete with sines and cosines, for each vertex. Then when you give it 0 it will give you the identity matrix.
02-25-2004, 05:13 PM
You need to generate the matrix in real time, by calling sin and cos on the angles for all four elements.
If your flavor of vertex processing doesn't have sin and cos (or sincos) then you can approximate them using polynomial series. A polynomial approximation of degree 3 can easily be done by stuffing 1,x,x**2,x**3 into a vector and doing a dp4 with a constant contaning coefficients.
Hope this helps.
02-25-2004, 07:12 PM
Thanks for the replies to date.
I'm using ARB_vertex_program.
The document I was working off (I was under the impression it was the official spec) never mentioned SIN/COS functions. I too thought this was strange since they're such usefull/important commands.
I've since found (ie: googled) other documents. Some of which mention SIN (but no COS) and one which mentions both. What gives?
Who's truth is the right one?
Which document if the *official* one which mentions both as well as their syntax?
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.