Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Mesh Always Facing Cursor

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

I have a mesh .X file "floor" as a level. It is just a plane primitive stretching 100' by 50'. I also have a player mesh that runs about on the floor using the WSAD keys. At the moment I am not rotating the player mesh. It's Y world coordinate does not change - just the X and Z ones. How do I get it so that this player mesh is always facing the mouse cursor? The player mesh essentially needs to rotate on the Y axis. So how would I designate part of the player mesh as being the "front" (attach a normal vector??) and then how would I continually rotate it to always look at the mouse. I am assuming the XY mouse coordinates would need to be transformed to 3D world coordinates. I have looked at the Pick SDK example but couldn't gleam anything practical out of it ... How do I figure out what I should rotate the mesh to? Thanks for any info .. R [edited by - RayWilson on April 1, 2003 8:36:47 AM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
are you having trouble with the picking part, or the overall concept?

overall, here''s the steps i''d think you''d need to do:

o "unproject" the mouse point into the 3D world to get a line
o find the intersection of that line with the floor mesh
o subtract the hero''s x/z coord (using the intersecting point''s y) from the intersecting point to get a vector from the hero to the pick point
o dot product that vector with the hero model''s initial directional vector (usually +x for my models but depends upon which direction the "face" is initially pointing) to get the cosine of the angle that the hero needs to be rotated to
o get the angle from the cosine and set the hero''s y-rotation angle to that
o re-build the hero''s world matrix by concatenating the y-rotation matrix (built from the y-rotation angle) with the hero''s translation matrix and any other matrices you may be using - use this as the world matrix for rendering purposes

of course this will "instantly" re-orient the hero to face the pick point. animating the rotation would depend on if you have an animation sequence for your mesh or not. either way you''d probably want to use a quaternion to smooth things out.

Share this post

Link to post
Share on other sites
Thanks so much guys - this is informational gold! I think I have finally transformed the mouse coords in to world coords! That''s a great start!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!