Jump to content
  • Advertisement
Sign in to follow this  

how to calculate rotation of car along a path

This topic is 3632 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 gurus of gamedev :) I am coding a 3d city tour simulation with car going on fixed paths. I interpolate the car model using the Catmull-Rom algorithm but I have problems in calculating the rotation to add to the model in order to orient it to the direction of motion. here is what I currently do:
std::vector<C3dModel::TransformVector> CTrack::SetPosition(void)
	vector<C3dModel::TransformVector> tv;
	transientPoint = this->Interpolate(currentPoint,percentage);
		//currentPoint = (currentPoint==lastPoint) ? loopPoint : currentPoint+1;
		nextPoint = (nextPoint==lastPoint) ? loopPoint+1 : ++currentPoint+1;
		if(currentPoint==lastPoint)  currentPoint = loopPoint ;
		percentage = 0.f;
	C3dModel::TransformVector v = {C3dModel::TRANSLATE, 0,transientPoint.x,transientPoint.y,transientPoint.z};
	//printf("from:%d to %d: car position:(%3.3f,%3.3f,%3.3f)\n",currentPoint,currentPoint+1,transientPoint.x,transientPoint.y,transientPoint.z);
	float rotation = atan2f((wayPoints[nextPoint].z - transientPoint.z) , (wayPoints[nextPoint].x - transientPoint.x))*180.f/PI ;
	C3dModel::TransformVector r = {C3dModel::ROTATE, rotation, 0.f, 1.0f, 0.f};
	printf("from:%d to %d: rotate car:(%3.3f)\n",currentPoint,nextPoint,rotation);
	return tv;

Any Answer will be greatly appreciated!

Share this post

Link to post
Share on other sites
the direction of of a point on the path is the first derivative of the catmull rom equation. That should give you the orientation of the car, or what it should be to stick to the path.

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!