
Junior Member
Regular Contributor
Vector from Vertex to Viewer
My objects and the viewer are moving and rotating around in an OpenGLScene. In that scene I want to draw particles as textures on a square (blended). To avoid distortions the squares have always to face the viewer. I know how to undo these rotations but that needs a lot of matrix multiplications. I think it would be much easier to set up the squares with the correct coordinates. So I need a vector from a point in 3Dspace to the actual viewer or at least perpendicular to the viewing plane (distance is also intereting). Can anyone help?

Senior Member
OpenGL Guru
Re: Vector from Vertex to Viewer
Hello Marc
Creating a vector from one point to another is not to complicated. Let's say Px, Py and Pz is the point in 3d space you want a vector to, and Cx, Cy, Cz is the camera position.
Vx = Px  Cx
Vy = Py  Cy
Vz = Pz  Cz
...where Vx, Vy, Vz is the vector FROM camera TO a point.
If you want the square to always face the camera, you can use this vector as the squares normal.
You said the distance was important. You can get the distance with sqrt(Vx*Vx + Vy*Vy + Vz*Vz)...
Now, please don't ask me about how to setup the square to actually face the camera, cause i don't know that :P
Bob

Re: Vector from Vertex to Viewer
I would use the matrix stuff... All the squares are facing in the same direction, so you can use a single inverse rotation matrix to rotate all of them. I mean, no need to calculate the same matrix for each particle.
[This message has been edited by Hude (edited 03012000).]

Junior Member
Regular Contributor
Re: Vector from Vertex to Viewer
Bob, getting a vector out of two points is not the Problem, but to get the coordinates of these two points is the problem (at least for me). How can I bring OpenGL to tell me, where a given point is locatet after several transformations? I don't want to do the matrix stuff by myself, because I think the OGLdrivers can do a better job by using MMX/ISSE/3DNow!

Junior Member
Regular Contributor
Re: Vector from Vertex to Viewer
Hude, is there something like glStoreMatrix? I saw only LoadMatrix and MultMatrix. At the moment I compile a displaylist with the rotations in it, but I'm not sure if that helps (no performance improvement).

Re: Vector from Vertex to Viewer
No, there is no such thing as glStoreMatrix or equivalent. And you can't get OpenGL tell where any transformed point is located in view space. So, this leaves you with two alternatives: 1) use OpenGL rotations, 2) make your own rotations.

Junior Member
Regular Contributor
Re: Vector from Vertex to Viewer
I think, that I have to use OpenGL rotations, too. But yesterday I found something like glStoreMatrix:
glGetDoublev(GL_MODELVIEW_MATRIX, PointerToArrayWith16GLdouble)
and
glGetDoublev(GL_PROJECTION_MATRIX, PointerToArrayWith16GLdouble)
there is a floatversion, too (just for information, to whom it may concern ).
Thank you for your time.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules