🔒 Locked
algorithm for camera movement
Advertisement
Original Post
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.
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:
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]
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]
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...
[grhodes_at_work made link active]
[edited by - grhodes_at_work on January 13, 2004 6:03:01 PM]
http://astronomy.swin.edu.au/~pbourke/curves/bezier/cubicbezier.html
but in your case i don't think its probably necessary...
[grhodes_at_work made link active]
[edited by - grhodes_at_work on January 13, 2004 6:03:01 PM]
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]
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]
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.
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).
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement