# getting/saving direction

how can I save direction in ogl, if I have say, a rotating model, and I want to backface-cull it myself using my own viewDirection-vector? - do I have to write my own counter-rotate function, or is there a simpler way?

jonn

Hi!
Why don´t you do your backface removal before all transformations?

Greets, XBTC!

[This message has been edited by XBCT (edited 02-02-2001).]

how could I know what’s visible before transformations?.. furthermore, there’s many other thing I need the direction saved for besides culling…

jonn

Performance-wise better let OpenGL do that for you! Unless you have some totally messed up model with incoherent triangle winding.

You need the inverse modelview-projection matrix (which sometimes does not exists, but that’s exceptions) then transform your viewing direction with that and cull the polygons depending on the sign of the dot product of face normal (cross product of triangle edges) and the transformed culling vector.
This could result in problems with edge-on or small polygons especially in perspective projected view. Actually there you need to transform the viewing position and build the difference vector to the object coordinates and …

Well, my recommendation is: Don’t.

…I believe ogl culls polygons by winding, calculating unnecessary transform to screen-coords for ‘to-be-culled’ polygons, and including perspective -isn’t that heavier than culling by facenormal(dot)viewDir? -the normals being already calculated and all…

for the matrix-inversion, isn’t that exactly what I suggested in the first post? the ‘counter-rot -func’…and of course, the inversion in this case exist allways - if you can rotate in some direction, you can allways rotate back

I know how the math and culling algos, but I guess what I really am after is some elegant way to code it in ‘ogl’

jonn

[This message has been edited by jonn (edited 02-03-2001).]

Hi!
I think the fastest way is to cull those backfaces out before all transformations.
You do it this way:

P = Viewpoint
V = Vertex of the face you won´t to test
DV = Vector from P to V
N = Normal of the face
d = Dotproduct

DV = V - P;
d = DV*N

If d > 0 it´s a backface.
If d < 0 it´s a frontface.

HTH, XBTC!

[This message has been edited by XBCT (edited 02-03-2001).]

Thanks, but I know how to cull, It’s NOT the point I’m after

what I’m after is something like, well, -if I had my Own rotatation-functions, and if I rotated a polygon, then my original viewDir-vector would remain the same, and culling with the dotproduct of viewDir*faceNormal would produce the correct culling. but in ogl the vertices of the polygon get passed in glVertex3f(x1,y1,z1) making them INVISIBLE to original coordinate-sys (where the x1,y1,z1 are!)

it just seems stupid to transform the viewDir back and forth, when it actually does NOT change!

if there was some kind of a ‘glVector(x,y,z)’-object that would make a vector ‘visible’ to ogl, that’d do the trick…

there’s probably a ‘too easy to be found’ -solution to this which I just can’t think of

jonn

[This message has been edited by jonn (edited 02-03-2001).]

Hi!
I really don´t understand what you want to do and I doubt that you understand what I described…
The culling I described works perfectly with OpenGl(there´s no single line of code missing in my example, you can use it as it is without doing any other transformations) and I don´t understand what you mean with “invisible”…

Greets, XBTC!

[This message has been edited by XBCT (edited 02-03-2001).]

oh, sorry, I didn’t notice you we’re answering my first reply to your first post, my mistake… -I just used culling as an example, the actual culling-method was not what I’m after, so I didn’t read your reply carefully enough I guess…

jonn

Hi!