Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ehmdjii

algorithm for camera movement

This topic is 5332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi i am programming a short demo and i need to do a lot of smooth movement with the camera and some objects as well. its some kind of spaceship flying through a canyon. now is there somewhere outthere an algorithm or library where i can just fill in values like positioncoordinates and timevalues and the movement is done automatically or will i have to do everything myself? i use openGL btw. thanks.

Share this post


Link to post
Share on other sites
Advertisement
You can use bezier curves which does pretty much what you want...

http://astronomy.swin.edu.au/~pbourke/curves/bezier/

there is one thing missing in the source code that your gonna need... its this:


struct XYZ
{
double x;
double y;
double z;
}


give it a lost of coordinates in 3D space and it will plot out a smooth curve that follows the path (more or less ).



As for the angle of the camera do you just want it pointing straight ahead or do you want it to move around looking at different things while you fly past?

[grhodes_at_work made link active]

[edited by - grhodes_at_work on January 13, 2004 6:03:25 PM]

Share this post


Link to post
Share on other sites
as i said this is really cool!

what i need now is to align the spaceship to the path.
i can get a vector by subtracting two close points on the path, but how do i use that vector to rotate my spaceship?

thanks!

Share this post


Link to post
Share on other sites
One way to do it is, for example the default forward vector of the model is [1, 0, 0].

using the forward vector and the vector from the path you can generate a normal.

by using a dot product you can find the angle between the two vectors, now all you need to do is perform a rotation about the normal by that angle.

angle = acos( v1.dot(v2) / (v1.length() * v2.length())

I dont know what maths your usuing for rotations, i use quaternions, its very easy to generate a rotation about an arbitrary vector.

[edited by - aleks_1661 on January 13, 2004 7:12:47 PM]

Share this post


Link to post
Share on other sites
thanks

theres something im doing wrong, its rotated strangely:


shipangle=angle(shipvector,shipdefault);
shipnormal=cross(shipvector,shipdefault);
glRotatef(shipangle,shipnormal[0],shipnormal[1],shipnormal[2]);

Share this post


Link to post
Share on other sites
quote:
Original post by ehmdjii
thanks

theres something im doing wrong, its rotated strangely:


shipangle=angle(shipvector,shipdefault);
shipnormal=cross(shipvector,shipdefault);
glRotatef(shipangle,shipnormal[0],shipnormal[1],shipnormal[2]);



I think this will work in that the front of your space ship will always be alligned with the path BUT the roof of your space ship will not necessarily be pointing upwards.

Assuming your X and Y coordinates are in the horizontal plane and your Z axis is the up direction and that the space ship is originally pointing in the (1, 0, 0) direction. You would need to first perform a rotation around the Y axis (i.e. pitch the space ship up and down) then perform a rotation around the Z axis (i.e. yaw). This should make it so the roof of your space ship always points upwards.

Share this post


Link to post
Share on other sites
hmmm something still doesnt work.

i think the problem is with the cross product not calculating correctly.

btw: the spaceship''s roof shouldnt always point upwards. example the ship is flying upwards or downwards.

Share this post


Link to post
Share on other sites
quote:
Original post by ehmdjii
hmmm something still doesnt work.

i think the problem is with the cross product not calculating correctly.

btw: the spaceship''s roof shouldnt always point upwards. example the ship is flying upwards or downwards.


What i mean is that you don''t want your spaceship tilted to one side, you want the up direction of your space ship to be in the plane that contains the direction vector of your space ship and the vector (0,0,1).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!