Sign in to follow this  
Belnazaar

Rotation problem (adjusting position)

Recommended Posts

Belnazaar    122
The engine i am using forced me to have arms of player character separated from the body. So arm has some relative position from the origin point(0 0 0, i wouldn't be asking this if I could somehow change it) as you can see in this picture: http://img210.imageshack.us/my.php?image=36986427.jpg So i rotate the arm by 90 degrees on Y axis (rotation is done by Quaternions), and i get my arm in this position: http://img220.imageshack.us/my.php?image=16362906.jpg Then i adjust its position so it would be on its previous: http://img218.imageshack.us/my.php?image=40872131.jpg Then i set the Y rotation to 270 degrees and i set the X position offset to be negative: http://img151.imageshack.us/my.php?image=27940479.jpg I'm bad at this kind of math so could someone help me how to write formula for adjusting position according to the object rotation? Please i'm in really need of this.

Share this post


Link to post
Share on other sites
mattyhalewood    122
I have a couple of functions below that I think will serve your purpose.

They work out the relative X and Z positions at a given angle and distance to a 3D co-ordinate with respect to the Y-axis.

You just add the result to the current position of your character.


Functions:

float In_Game_Objects::circleObjectX(int distance, float angle)
{
return distance * sin(angleY + angle); //angleY is planes
//(characters)current y angle
}

float In_Game_Objects::circleObjectZ(int distance, float angle)
{
return distance * cos(angleY + angle);
}



How I use them:

camera1.posX = plane1.posX + plane1.circleObjectX(20, 0.0f);
camera1.posZ = plane1.posZ + plane1.circleObjectZ(20, 0.0f);

How you may use them:

rightArmX = character.posX + character.circleObjectX(5, 90.0f);
rightArmZ = character.posZ + character.circleObjectZ(5, 90.0f);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this