Trying to get constant speed

This is a discussion on Trying to get constant speed within the Game Programming forums, part of the General Programming Boards category; I am having some trouble figuring this out. Basically i have set up a bunch of predetermined positions on the ...

  1. #1
    Registered User gpr1me's Avatar
    Join Date
    Mar 2006
    Posts
    14

    Trying to get constant speed

    I am having some trouble figuring this out. Basically i have set up a bunch of predetermined positions on the map which i visit in some predinfined order. The camera follows the path specified. It will go to one position which i set by the center of the gluLookAt() function. The center is the direction my camera is moving. My move function is this:

    Code:
    void Camera::MoveForward( void )
    {
    	eye.x += (center.x - eye.x) / step;
    	//eye.y += (center.y - eye.y) / step;
    	eye.z += (center.z - eye.z) / step;
    
    	center.x += (center.x  - eye.x) / step;
    	//center.y += (center.y - eye.y) / step;
    	center.z += (center.z - eye.z) / step;
    }
    I have commented out the y positions because i do not want it to change. A am also increasing the center position so the camera will not slow down when it gets near the position it's going to. Once it gets to that position i update the center to the next position and it continues.

    Now my problem is if i have say 3 positions (p1, p2, p3) i want to camera to go to. It will start at p1->p2->p3. And say the distance between p1 and p2 is 10 and the distance between p2 and p3 is 20. This means that the camera will move from p2 to p3 faster than it moved from p1 to p2.

    How should i fix this problem? I am thinking i should have the center position always a constant distance away from my eye position and in the direction of the next position on the map to visit. How would i do this?

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Just keep some sort of constant velocity value and increase your position by that value instead of the differences between the points.

  3. #3
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    You can normalized the velocity, then set the speed and add the velocity to the position. In this case, the speed will be 10.

    Velocity.normalize();
    Velocity *= speed;
    Position += Velocity;
    Hello, testing testing. Everthing is running perfectly...for now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. Speed of light isn't constant...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 08-16-2001, 04:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21