Search code examples
cocos2d-iphoneaccelerometer

Is M_PI*2 (in Cocos2d) equal to 1 second? How?


what tells us that this is in "second" ? (is M_PI*2 equal to 1 second? how?)

float32 maxRevsPerSecond = 7.0;
float32 accelerationFraction = acceleration.y*6;
float32 motorSpeed = (M_PI*2) * maxRevsPerSecond * accelerationFraction;

Thanks


Solution

  • M_PI is the system's definiton for the value of π (3.14159...) Thefefore, motorSpeed is an angular (rotational) value in radians per second.


    The above initial answer was only based on the variable names in the example code. Doing some net searching, I see this code is part of an example in the book Learning Cocos2D. In the section Making the Cart Move with the Accelerometer the book says:

    Since you set up revolute joints for the cart wheels, rotating the wheels is easy. Revolute joints have a built-in “motor” that defines how quickly the wheels rotate in radians per second.

    ...

    Think of a motor as an automatic mechanism that turns the wheels based on the motorSpeed. motorSpeed is in radians per second,...