View Full Version : Vector from Vertex to Viewer
My objects and the viewer are moving and rotating around in an OpenGL-Scene. 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 3D-space to the actual viewer or at least perpendicular to the viewing plane (distance is also intereting). Can anyone help?
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
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 03-01-2000).]
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 OGL-drivers can do a better job by using MMX/ISSE/3DNow!
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).
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.
I think, that I have to use OpenGL rotations, too. But yesterday I found something like glStoreMatrix:
there is a float-version, too (just for information, to whom it may concern http://www.opengl.org/discussion_boards/ubb/smile.gif).
Thank you for your time.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.