Jump to content
  • Advertisement
Sign in to follow this  
Drumstick

Rotating the avatar based on where you are pointing him... (OpenGL)

This topic is 4527 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

Okay, so if someone could help me out, it would be great. I'm modeling objects in my world with both a position vector and a unit vector that points in the direction that object is facing. I'm having trouble drawing the object with OpenGL so that it actually faces in the direction that the unit vector says it does. I assume you translate it to the position, and then somehow use a matrix to rotate it into the right direction. If you have a function (like the glRotate functions) that takes the a vector for the axis of rotation and then a magnitude, what do you input into the function so that it will rotate the object to face the direction unit vector? The way I have it set up now works (sort of), but I'm clearly faking it, and I don't think the asin fuction is very fast. Anyone know how to do this properly? my work so far looks like this:
	if(active->getEntity()->GetDirX() > 0.0f)
		glRotatef(asin(active->getEntity()->GetDirY())*180/pi, 0.0f, 0.0f, 1.0f);
	else
		glRotatef(180-asin(active->getEntity()->GetDirY())*180/pi, 0.0f, 0.0f, 1.0f);
	active->getEntity()->Animate(10.0/FPS);

Share this post


Link to post
Share on other sites
Advertisement
How about storing the actual rotation in radians ? Like, having 1 float for rotation around the world-up axis. With that you can easily create a rotation matrix. 1 vector kind of has more information, but it is lacking the information of the 2 other orientations. Also, if you need this orientation vector you can easily calculate it from the rotation angle.

You can express the code

glRotatef(asin(active->getEntity()->GetDirY())*180/pi, 0.0f, 0.0f, 1.0f);

as

glRotatef(active->entity()->GetUpRotation(), 0.0f, 0.0f, 1.0f);

assuming that 0.0,0.0,1.0 is the up direction of your world.

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!