Jacopo Terrinoni
Jacopo Terrinoni

Reputation: 173

How to rotate an object along a circular path?

I'm trying to realize a bicycle that moves along a circular path, using webGL programming language. My problem is related to the rotation of the bicycle itself that does not rotate on itself during its circular movement, but it remains with its initial angle, although the object is correctly translated in a circular fashion along the track.

In order to provide circular movements to the bicycle, I'm using the cosine and sine functions and each time varying the angle. The axes that I have to take into consideration are the x-axis and z-axis while the y-axis is fixed.

Any suggestions?

Upvotes: 0

Views: 325

Answers (1)

WacławJasper
WacławJasper

Reputation: 3364

If I understood you correctly, what you want is essentially to orient the bicycle so that it faces its direction of motion?

That is usually done by calculating the model (bicycle)'s modelToWorld matrix. Your matrix lib probably have a .lookAt function and you should use that to calculate the modelToWorld matrix.

You should be able to calculate the bike's forward direction. If its moving around in a circle then it is normalize(cross(normalize(bikePos-circleCenter), UP_VECTOR)).

Upvotes: 1

Related Questions