Sign in to follow this  

Rotation angle from position/vector (2D)

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

Anyone know how to get a rotation value out of a vector? say i have a person whos origin is 0,0 (can change tho) and they are holding a gun at any given direction (which is found by taking X/Y pos of the mouse and going gunpos = bodypos + (mousepos/maxmousepos * maxlength).... all i need to know is how to find what orientation the gun should be (so it is facing away from origin) and rotate it with D3DXMatrixRotationZ any help is appreciated

Share this post


Link to post
Share on other sites
well, you are not very explicit, but i'll give a try. when you have a 2d vector and you want to find what the rotation is, you must use trigonometric fucntions. so let's say oX axis goes right and oY goes up. we will say that a rotation of 0 degrees is your gun is heading to the right (along oX). let's call this angle Alpha. let's say your coordinates are (X, Y). now
tan(Alpha) = Y/X; what you want to know is Alpha so
Alpha = arctan(Y/X); something like this.

Share this post


Link to post
Share on other sites
sorry, heres a game http://www.madnesscombat.com/madness.zip

the way he handles the gun is what i want, ive got the hand moving down and what not, just having trouble with the rotation, ill give that tan fxn a shot (i suck at trig...and math in general )

Share this post


Link to post
Share on other sites
well, if you dont know math, then just leave the graphics programming away. the 2d is VERY VERY simple, but when you'll move to 3d, there the pain comes, with 3d vectors and quaternions(4d vectors). if you don't manage to understand some simple 2d transformations, then 3d will overwhelm you. get a math book first, and then move on to graphics. trigonometry, geometry and analithical geometry are very simple, because all the forumulas are generated using figures. so they are very simple to understand.

Share this post


Link to post
Share on other sites
nah, ive already done 3d games before, and can deal with all the transformations normally, its just this time i dont know the rotation because of how the game actually plays, which is new to me

(if i have the 3 rotations i can just plug them into a quaternion and be away because DX does it all for me :) )

Share this post


Link to post
Share on other sites
yeah, you're right. the dx does it for you. but if you want to program in opengl(like i do, i like it more), there is no quaternion support. or, let's say, you want to build the most realistic physics engine. personally, i think this is the most hard thing to do, where physics(mechanics) and math are used intesively, from integration schemes (see Runge-Kutta) to a lot of matrices and vectors. so, finally, you do have to know the math thing too. but, for the beginning, it's ok you know dx. everything must start somewhere, and i think that learning a graphics API is the place to start.

Share this post


Link to post
Share on other sites

This topic is 4764 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.

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