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

Dir vector from two 3D points.

Started by md2ge Mar 22, 2000 at 4:18 AM 4 replies 550+ views
Original Post
md2ge
md2ge
Is there a way to get a dir vector from two known (xyz) points in 3D? Thank, Rick
Ingenu
Ingenu
This is the basic of vectors...
with two point you can define two vectors.
If you know the first and second points (beginning and ending points) you can only have one vector.

(I wonder if I''ve well understood)

A(xa,ya,za)
B(xb,yb,zb)

Dir(xb-xa,yb-ya,zb-za)

IF everything defined in a 3d orthonormed system.

-* Sounds, music and story makes the difference between good and great games *-
-* So many things to do, so little time to spend. *-
md2ge
md2ge
Maybe I should describe what Im trying to do, to make sure we are on the same page =)

I''m using OpenGL, I want to place my camera at P1 and I want to use gluLookAt so that I can get camera to follow P2 as it moves around while keeping camera centered on it.

The 3 parameters I''m not sure about are dir.x dir.y dir.z

Rick
Ingenu
Ingenu
I think the equation is right IF you''re usign world coordinates for both objects.
IF the dir is defined in the Camera cooridnates then it''s a little bit harder.
But I don''t think it''s that, my first answer should be ok.

(I''ll check it this evening @ home)


-* Sounds, music and story makes the difference between good and great games *-
-* So many things to do, so little time to spend. *-
Cygon
Cygon
What you''re searching for is a LookAt() function.
One of the samples in the DX SDK contains a good function doing this, it orientates a camera (or any other matrix) to point onto a given vector. I know you''re using OpenGL, but since this is with full source and doesn''t use MS-specific things, it should be no problem to convert it
(I think OpenGL vectors should also contain x, y and z like the microsoft ones *g*)

\samples\multimedia\d3dim\src\d3dframe\d3dutil.cpp
search for ''lookat'' in the file.
If you do not have the DX SDK I can mail you the file

-Markus-
Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
md2ge
md2ge
I have the 6.1 sdk but it''s only the libs/h files if you could e-mail that to md2ge@hotmail.com I''d be gratefull.

Problem is I don''t plan to use this only for camera movement, I''m working on a landscape 3d engine and I want to implement a line-of-sight function.

Thanks

Topic Locked

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

Sign in to reply to this topic.