Thread: 3D Vectors

  1. #16
    Registered User PotitKing's Avatar
    Join Date
    Dec 2001
    Posts
    28
    I suggest you learn some vector math before doing this, It's always helpful
    % gcc -v
    Configured with: FreeBSD/i386 system compiler
    Thread model: posix
    gcc version 3.3.3 [FreeBSD] 20031106

  2. #17
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    just to sum up what everyone said, first find the *speed* that you want to move this frame, then you find the direction you want to move in. The direction you want to move in has a length of one, therefore when you add the direction multiplied by speed you move speed units in the direction of your unit vector

    float speed = 5;

    Vector3 Direction = Vector3(1, 0, 0)
    Direction's length is obviously one, when you multiply Direction by 5 you get
    Vector3(5, 0, 0) therefore you move 5 units along the x axis

    Here's one that's not so obvious
    Vector3 Direction = Vector3(.707, 0, .707)

    Direction has a length of 1
    sqrt(.707^2+.707^2) = 1


    Position = Position + (Direction * speed)


    but the same idea works

  3. #18
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Originally posted by Azmeos
    Ok, so

    magnitude = sqrt(x^2+y^2+z^2);

    where x, y and z are really x1-x2, y1-y2, and z1-z2 ?
    Not quite... You got it backwards (granted, for finding the magnitude this doesn't matter, but for the direction vector it does).

    It should be 'destination - current_location' (x2 - x1, etc...).

    *edit*

    I'd take PotitKing's advice. If you can't find sufficient resources online, then Dover publishes some good and inexpensive books on the subject.
    Last edited by Zach L.; 08-16-2003 at 10:35 PM.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  2. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  3. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 10:35 AM
  4. 3D starfield
    By VirtualAce in forum Game Programming
    Replies: 6
    Last Post: 06-26-2003, 12:40 PM
  5. 3d engines
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 12-17-2001, 11:19 AM