View Full Version : getting the proper normal
Hi, I have the following problem:
For further calculations I need the normals of some planes to point in the correct direction, namely they are supposed to point to the viewer and not away from him.
So is there a way to get the viewers point as a vector that is also specified in the same coordinate system like the plane vectors, so I can compare the vectors?
07-05-2004, 01:29 PM
For further calculations I need the normals of some planes to point in the correct direction, namely they are supposed to point to the viewer and not away from him.Perhaps you could restate your problem, as my thick skull is thicker than ever today.
I'll hazard a guess. You could think of a plane as having 2 sides: the front side (positive) and back side (negative). You could have the viewer on either side. To pick the side the viewer is on, simply get the viewer's distance to the plane. If the distance is positive, then the normal already faces the viewer; if the distance is negative, then flip the plane (negate the normal and distance).
Thanks, that doesn't sound bad... But how do I get get the viewer's distance to the plane? Sorry but I'm just a poor beginner :(
07-06-2004, 06:42 AM
Let P be a plane such that Pxyz is the normal and the distance Pd = dot( any point on the plane, Pxyz ).
Now, for a viewer position Vxyz, the signed distance D to the plane is
D = Px*Vx + Py*Vy + Pz*Vz - Pd
07-06-2004, 06:50 AM
Another solution would be be to assume the view is down a positive z-axis in a left handed coordinate system (OpenGL eye coordinates), transform the normal into the same coordinate system by multiplying it with the inverse transpose modelview matrix, then do a scalar multiplication of the transformed plane normal with the vector to the viewer (0,0,-1) and if it's positive the normal points to the viewer, if it's negative you must flip it.
But the distance approach looks simpler, because you don't need an inverse transpose matrix.
OK, I think I got it so far, but the thing I'm still missing now is how to get the viewer's position...? Thanks for your help!
07-06-2004, 08:30 AM
You know, the camera position in world-space.
I don't want to appear stupid, but this was not the answer to my question, was it? I wanted to know HOW to get the position, that means what function do I have to call to get it - not what this position can also be called.
07-06-2004, 08:57 AM
Easy buddy, I wasn't making fun of you. Just goofin off.
As for your question, there is no function to get this position, per se. You, the programmer, control the camera position yourself as part of the scene mangement.
You could transform the point (0,0,0,1) with the inverse modelview matrix (with only the view matrix at the top of the stack), but you should have this camera position handy anyway. How are you setting up the modelview matrix in the first place?
If all this sounds alien, check this out:
I hope this helps.
I thought about that too, but when I multiply the point(0,0,0,1) by the modelview matrix, the result is always again(0,0,0,1), or maybe simply multiplying is not correct?
Oh sorry I didn't notice it had to be the INVERSE matrix! So there is no way to avoid to calculate the inverse..?
07-06-2004, 10:01 AM
I thought about that too, but when I multiply the point(0,0,0,1) by the modelview matrix, the result is always again(0,0,0,1), or maybe simply multiplying is not correct?That's likely because your modelview is an identity matrix. Note that you need the inverse modelview matrix.
You see, in order to setup the GL for rendering your scene, you need to provide it with the camera information (position and rotation). You can do this with the glTranslatef() and glRotatef() functions, repectively.
This entire process is described in chapter 3 of the Red Book
07-06-2004, 10:08 AM
So there is no way to avoid to calculate the inverse..?The exception would be when you know the modelview to be a rotation matrix only, then a simple transpose would suffice.
OK, thanks a lot for your patience! I will think about it and then try my luck... :rolleyes:
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.