# compare normals with view vectors

Hi…

How could I compare normals with the view vectors in order to determine surface visiblity?..

Thanks

Nico

You calculate the dotproduct of the two vectors.

v=viewvector
n=normal
dp = v.xn.x + v.yn.y + v.z*n.z
If dp<0 the face is facing towards you

None of the vectors needs o be normalized.

If you use the dotproduct a problem arise, what viewvector is to be used?
You can use the line-of-sight, but then some polygons on the edge to visibility might be removed even though it’s visible.
You can use a vector from viewpoint to one vertex, but then, choosing different vertices will give different result if polygon is on the visibilityendge. You also have to recalculate the viewvecotr each time.

Another way to determine visibility is to calculare the area of the projected polygon. This works only if you do your own projection. This is also the kind if visibilitytest OpenGL is doing.

Thanks a lot but I do I compute the view vector?

p0=Camera position
p=Point you’re looking at
v=viewvector

v.x=p.x-p0.x
v.y=p.y-p0.y
v.z=p.z-p0.z

What do you need this for? You could use the built in culling.

How do I get the camera position?

What I’d like to do is to draw edges which are located on the silhouette. They are therefore shared between front-facing and back-facing triangles…

Many thanks

Well… and the point I’m looking at?

Thanks

Well Nico, what calls are you using to set up your view ? Do you call gluLookAt or do you do anything special with glMultMatrix, glTranslate or anything else ?
We need to know that to tell you the camera position and your target point…

Eric

Here is what I use for my camera…

glMatrixMode (GL_PROJECTION);
glFrustum (-0.1333, 0.1333, -0.1, 0.1, 0.2, 150.0);
glMatrixMode(GL_MODELVIEW);
gluLookAt(0, 1.5, 2, 0, 1.5, 0, 0, 1, 0);

Thanks

If you are using gluLookAt, you call the functions like this.

gluLookAt(c.x, c.y, c.z, t.x, t.y, t.z, u.x, u.y, u.z)

You now have your viewpoint and targetpoint right here. c is viewpoint, and t is targetpoint.

What about the view vector if I rotate… with glrotatef,gltranslate…?

By the way… to be honest I don’t realy know how to use gluLookAt…

Thanks for helping me

Ok, then I explain it for you.

gluLookAt takes nine arguments. First three arguments is the point where you want to place the viewpoint. Argument 4 to 6 is the point you want to look at. All coords in worldcoordinates.

The last three is a pain. It’s called “the upvector”. It’s a vector specifying where up (relative camera) is. If you place the camera on the ground, pointing stright forward, the upvector is <0,1,0>, it’s pointing upwards (positive y-axis is up). If you move the target so the camera is pointing 45 degree upwards, you get an upvector of <0,0.707,-0.707> (up for the camera is now upwards and backwards).
The angle between the viewvector and the upvector should be 90 degree.

Can’t say much more, it’s a quite hard thing to explain.

I understand what this call is but how can I use it to view anything… every time I tried nothing showed up…

• Which function should I put it in?
• What other calls should I use?

Will it be updated as I’ll move my camera?

Thanks

What if I use glRotatef… the normal would not change, the view vector either… so how could I do some hidden line removal?

Thanks

I remember reading in Computer Graphics Principles and practice that after you do all of the transforms for perspective projection, all the polygons that aren’t facing you are the one’s who’s normals have -z values. In opengl is there no way to read the values for normal vectors after the transfoms? This is just a shot in the dark, so if this sounds totally stupid just tell me to shut up and I will do so

argh !!!

Do not do that !
Cause you’ll spend time to TRANSFORM what you DON’T NEED !

Never ,ever do something you can do early late cause you’ll lost many, many CPU cycles !

Do backface culling before any T and L !

Remove things as early as you can!

What about glRotatef then… how to hide faces that are not facing the camera… as if the glRotatef value changes, both normals and view vectors remain the same…

Thanks