Jump to content
  • Advertisement
Sign in to follow this  
Houlala

Camera Path - Movements along a spline

This topic is 3883 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 everyone, I have troubles since few days. Here is my problem : I have a curve (Catmull-Rom spline) and I have a camera (with position, lookat, up and x vector). The goal is to move the camera along the spline and point to a specific target (which can change during the animation). So, at the init sequence, I set up an arbitrary vector (0, 0, 1) (because my z is my elevation) for the up vector and afterthat, I use cross products to find other axes. The problem is that the camera is spinning during the animation and don't know why :( Here is my method to get the vectors :
// my vectors
m_direction = m_target - m_position;
m_direction.normalize();

// ^ --> cross products
m_x = up_compute ^ m_direction;
m_x.normalize();

m_up = m_direction ^ m_x;
m_up.normalize();

// Here, I have a Frenet Frame, as in this paper
// http://www.cs.cmu.edu/~fp/courses/graphics/asst5/cameraMovement.pdf

// * --> dot products
// Gram Schmidt orthonormalization
d0 = m_direction * m_up;
m_up -= m_direction * d0;
m_up.normalize();

d0 = m_direction * m_x;
d1 = m_up * m_x;
m_x -= m_direction * d0 + m_up * d1;
m_x.normalize();

// just building opengl matrix but it doesn't matter
m_matrix[ 0] = m_direction.x;
m_matrix[ 1] = m_direction.y;
m_matrix[ 2] = m_direction.z;
m_matrix[ 3] = 0.0;
m_matrix[ 4] = m_x.x;
m_matrix[ 5] = m_x.y;
m_matrix[ 6] = m_x.z;
m_matrix[ 7] = 0.0;
m_matrix[ 8] = m_up.x;
m_matrix[ 9] = m_up.y;
m_matrix[10] = m_up.z;
m_matrix[11] = 0.0;
m_matrix[12] = m_position.x;
m_matrix[13] = m_position.y;
m_matrix[14] = m_position.z;
m_matrix[15] = 1.0;


So, when I do this with and fixed up (like (0, 0, 1)), it works but I can't do loopings (yeehaa) with my curve, there is an upside-down effect :(. I can't find solution for my problem so I ask you if you have some solutions :P. Shall I have to use the quaternions to fix my problem ? Is there something that I forgot ? Thank you all (and sorry for my bad bad english :/)

Share this post


Link to post
Share on other sites
Advertisement
A few comments/questions:

The comments in your code mention a Frenet frame, but I don't see you performing any such computations anywhere. Is a Frenet frame actually being used?

Also, your matrix, as is, is not inverted. Are you inverting it elsewhere in the code before submitting it to OpenGL? (This is assuming that you intend for the object to function as a camera, as your post suggests.)

Your 'aim at' code looks correct as far as I can tell, so it seems your camera should be behaving correctly (the only time this algorithm will fail is when the target is directly above or below the camera position).

The orthonormalization in your code is unnecessary, by the way; since you've just computed the basis vectors from scratch, they should be (near) orthonormal already.

Also:

<rant>
// * --> dot products
// Gram Schmidt orthonormalization
d0 = m_direction * m_up;
m_up -= m_direction * d0;
This is why I hate operator overloading for vector products. The fact that you have to put a comment in your code explaining what the heck is actually going on should tell you something :-) The code should read clearly without comments, and without comments, the above is confusing (you have to stop and think for a second to figure out what the different *'s represent).

This:
d0 = dot(m_direction, m_up);
m_up -= m_direction * d0;
Is much clearer. And no comments necessary!

</rant>

Anyway, back to your problem. From looking at what you posted I can't quite tell why your camera isn't behaving as you expect it to, so you might need to provide some more information clarifying things a bit (unless I'm missing something obvious, that is, which is entirely possible).

Share this post


Link to post
Share on other sites
Hi,
Thank you jyk for your fast reply :P

First of all, for the Frenet frame, I just use the method which is in the PDF. (The computation of the next basis with the current basis). That's all :P

For the GL Matrix, I use row matrix just like that :
[0] ... [3]
...
[11] ... [15]

So, it's cool, no problem with it. (I think ;)).

For the orthonormalization, I did it because I use my GL matrix to display a camera mesh in my scene which was a little bit distorded and not with the orthonorm.

To finish, at the beginning I thought that the problem became from the initialization of the up vector...
What do you think about that ?


PS : Thanks for the tip in C++ but I love too much overloading :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!