Creating a rotation vector for cpvrotate

Official forum for the Chipmunk2D Physics Library.
Post Reply
lucas
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am
Contact:

Creating a rotation vector for cpvrotate

Post by lucas »

Hi,
I'm trying to use the cpvrotate function to rotate an object I'm drawing. It's easy when I have a corresponding object, but this time I'm trying to do it with a radian value. Having a look at the rotation of some cpBodies, I got this:

Code: Select all

//rad is between -M_PI (-3.14...) and M_PI (3.14)
cpVect rot = cpv(1.0f, rad/M_PI);
This partially works, but it only rotates a quarter of the amount you'd expect and becomes smaller unless rot = cpv(1.0f, 1.0f).
How can I change the code to fix this?

Thanks!
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Re: Creating a rotation vector for cpvrotate

Post by supertommy »

How about:

Code: Select all

cpVect rot = cpv(cosf(rad), sinf(rad));
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Creating a rotation vector for cpvrotate

Post by slembcke »

supertommy wrote:How about:

Code: Select all

cpVect rot = cpv(cosf(rad), sinf(rad));
Correct. The cpvrotate() function uses complex multiplication, so you just need a normalized vector. Also there is the function cpvforangle() that takes a radian value and gives you a normalized vector.

I am a bit confused why you are using cpvrotate() in order to rotate an object. What kind of object are we referring to exactly?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
lucas
Posts: 54
Joined: Wed Sep 26, 2007 2:34 am
Contact:

Re: Creating a rotation vector for cpvrotate

Post by lucas »

A polygon, but I haven't created it yet. When I use cpvrotate, it is being drawn using SDL when the mouse is held down.

Anyway, sinf and cosf work fine, thanks!

By the way, I dugg Chipmunk: http://digg.com/programming/Chipmunk_Ga ... ics_Engine
Tangame - a tangram puzzle game with physics.
http://code.google.com/p/tangame/
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests