#### Archived

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

# algorithm for camera movement

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

## 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 on other sites
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?

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

##### Share on other sites
If its imperitive that your flight path goes exactly through control point you choose... then you can use this:

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

but in your case i don't think its probably necessary...

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

##### Share on other sites
this algorithm is really cool! thank you!

##### 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 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 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 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 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 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).

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011467
• ### Who's Online (See full list)

There are no registered users currently online

×