Skip to main content
GameDev.net gamedev.net
🔒 Locked

Those directional arrows...

Started by Hybrid May 8, 2003 at 2:13 PM 0 replies 400+ views
Original Post
Hybrid
Hybrid
You know those 3D directional arrows you see in racing games, that are like part of the HUD, and point to the next checkpoint? See the green arrow at the bottom middle of this pic: http://www.gamesdomain.com/gdreview/zones/reviews/pc/nov00/insne04.jpg How do you go about implementing that? How do you make it always point to the same place based on where the user is looking (so that it rotates, when the camera moves), so that it always points to the correct position in the game world? Would you also have to render it specially in OpenGL? I''m guessing it would involve getting the current view matrix from OpenGL, similar to billboarding, but in 3D. Just I don''t have a clue what maths are involved. Thanks in advance.
quasar3d
quasar3d
make a vector from the camera pos to the point you want the arrow to point at. mkae another vector that points straight up. Take the crossproduct of these two vectors. Again take a crossproduct of the first vector and the vector you got from the previous cross product.
Now you have 4 vectors. You don't need the up vector. If you normalize the 3 other vectors, you have the rotated unit vetors, and so you can just fill a matrix with them:


    
VECTOR3D xunit,yunit,zunit,up

zunit = Target - CameraPos;
up.Set(0,1,0);
xunit = CrossProduct(zunit,up);
yunit = CrossProduct(zunit,xunit);
xunit.Normalize();
yunit.Normalize();
zunt.Normalize();

D3DMATRIX mat;
mat._11 = xunit.x;
mat._21 = xunit.y;
mat._31 = xunit.z;
mat._41 = 0;

mat._12 = yunit.x;
mat._22 = yunit.y;
mat._32 = yunit.z;
mat._42 = 0;

mat._13 = zunit.x;
mat._23 = zunit.y;
mat._33 = zunit.z;
mat._43 = 0;



My Site

[edited by - Quasar3D on May 11, 2003 7:48:21 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.