Move an object in the direction of a bezier curve?

Posted by Sent1nel on Stack Overflow See other posts from Stack Overflow or by Sent1nel
Published on 2011-01-15T22:10:18Z Indexed on 2011/01/15 23:53 UTC
Read the original article Hit count: 146

Filed under:
|
|

I have an object with which I would like to make follow a bezier curve and am a little lost right now as to how to make it do that based on time rather than the points that make up the curve.

.::Current System::. Each object in my scene graph is made from position, rotation and scale vectors. These vectors are used to form their corresponding matrices: scale, rotation and translation. Which are then multiplied in that order to form the local transform matrix. A world transform (Usually the identity matrix) is then multiplied against the local matrix transform.

class CObject
{
public:
 // Local transform functions
 Matrix4f GetLocalTransform() const;
 void SetPosition(const Vector3f& pos);
 void SetRotation(const Vector3f& rot);
 void SetScale(const Vector3f& scale);

    // Local transform
    Matrix4f m_local; 
    Vector3f m_localPostion;
    Vector3f m_localRotation; // rotation in degrees (xrot, yrot, zrot)
    Vector3f m_localScale;
}

Matrix4f CObject::GetLocalTransform()
{
    Matrix4f out(Matrix4f::IDENTITY);

    Matrix4f scale(), rotation(), translation();

    scale.SetScale(m_localScale);
    rotation.SetRotationDegrees(m_localRotation);
    translation.SetTranslation(m_localTranslation);

    out = scale * rotation * translation;
}

The big question I have are

1) How do I orientate my object to face the tangent of the Bezier curve?

2) How do I move that object along the curve without just setting objects position to that of a point on the bezier cuve?

Heres an overview of the function thus far

void CNodeControllerPieceWise::AnimateNode(CObject* pSpatial, double deltaTime)
{
    // Get object latest pos.
    Vector3f posDelta = pSpatial->GetWorldTransform().GetTranslation();

    // Get postion on curve
    Vector3f pos = curve.GetPosition(m_t);

    // Get tangent of curve
    Vector3f tangent = curve.GetFirstDerivative(m_t);

}

Edit: sorry its not very clear. I've been working on this for ages and its making my brain turn to mush.

I want the object to be attached to the curve and face the direction of the curve.

As for movement, I want to object to follow the curve based on the time this way it creates smooth movement throughout the curve.

© Stack Overflow or respective owner

Related posts about c++

Related posts about math