Skip to main content
gamedev.net
🔒 Locked

direction vector

Started by AGD011 Sep 4, 2003 at 1:31 PM 3 replies 600+ views
Original Post
AGD011
AGD011
ok, I''ve read a number of articles regarding this question yet for some reason I''m still missing something. I am trying to get a basic direction vector....this should be easy because I''m on a flat surface (not looking up or down, and no tilting left/right). according to the axis I''m working with (X,Y,Z)..the X axis rotate''s the view angle left/right. I have two points: position[3] and direction[3]. from what I''ve read, this should be as easy as saying rotation[0]=(direction[0]-position[0]). ([0]=x, [1]=y etc.) why is this not working...what am I missing? thankyou in advance for all help. I know this topic has been talked about before, but the previous articles are not turning on any lightbulbs...
Nypyren
Nypyren
Uhm... whoa.

Direction vectors are usually not thought of as positions.


If you have two points in space, A and B, you can find the offset vector from A to B by saying D = A-B (which expands to D.x = B.x-A.x, D.y=B.y-A.y) and then if you want the direction, it's as simple as adjusting the offset vector to a length of 1. (You can force a vector to length 1 by dividing both X and Y by the vector's original length)

However, I must ask this: WHAT are you trying to do again?

I shall rewrite your original example code:

offset = look_at - direction;
direction = offset / offset.GetLength();
distance = offset.GetLength();


Assuming that those variables are instances of a class that overloads the - and / operators and defines a GetLength function.

[edited by - Nypyren on September 4, 2003 4:28:15 PM]
AGD011
AGD011
thank you for your response...sorry if I was unclear in the first post.

ok, imagine that you are in a paint program and you draw a line. the first time you click your mouse is where the line begins (point1), the place where you release the mouse is where the line ends (point2). I am trying to make point1 the position. (the camera will appear here ), I want to make point2 the direction the camera is looking.

does that make more sense? am I going about this the wrong way?

MV
MV
Use gluLookAt( p1.x, p1.y, p1.z, p2.x - p1.x, p2.y - p1.y, p2.z - p1.z, 1.0f, 0.0f, 0.0f ) Maybe you should invert last 3 values. Nothing else to do !
uber_n00b
uber_n00b
I agree. look up more on gluLookAt (I was going to post that last night but gamedev decided to not load my response =\)
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.

Topic Locked

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

Sign in to reply to this topic.