It is currently Thu Jul 20, 2017 7:42 pm




 Page 1 of 1 [ 3 posts ] 
Author Message
 Post subject: Rotate obiect from mouse cursor in 3d
PostPosted: Tue May 04, 2010 5:29 am 

Joined: Sat Apr 19, 2008 6:26 am
Posts: 62
Welcome

I would like to do a rotation in the direction of the cursor mouse like Shadowgrounds. In 2d no problem. I do not know how to correctly calculate the 3D game.


Offline
 Profile  
 
 Post subject:
PostPosted: Fri May 21, 2010 9:19 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1102
Location: Ontario Canada
In 3d it is a little trickier than 2D. Here is the general idea.

First you need to find out where the cursor is in 3D space. You can do this by projecting a line from the camera to the cursor's position. Where this line intersects the "ground" is where the cursor is pointing.

Once you have this co-ordinate, you can then figure out how much to rotate your character to point in that direction. Create a vector from your character to the 3D Point. Using the dot product between this vector and the vector pointing in the direction that the character is currently facing, you can get the angle that the character will need to turn. To know the rotation axis, you can take the cross product between the two vectors. Make sense?


Offline
 Profile  
 
 Post subject:
PostPosted: Sat May 22, 2010 9:25 am 

Joined: Sat Apr 19, 2008 6:26 am
Posts: 62
Thanks for answer.

Quote:
Once you have this co-ordinate, you can then figure out how much to rotate your character to point in that direction. Create a vector from your character to the 3D Point. Using the dot product between this vector and the vector pointing in the direction that the character is currently facing, you can get the angle that the character will need to turn. To know the rotation axis, you can take the cross product between the two vectors. Make sense?



I know (this step i use in my 2d game like "alien breed").

Quote:
First you need to find out where the cursor is in 3D space. You can do this by projecting a line from the camera to the cursor's position. Where this line intersects the "ground" is where the cursor is pointing.


Intersection - forgot - thanks. I try. [/quote]


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 3 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron