本文整理汇总了C++中PhysicsSprite::getRotation方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsSprite::getRotation方法的具体用法?C++ PhysicsSprite::getRotation怎么用?C++ PhysicsSprite::getRotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsSprite
的用法示例。
在下文中一共展示了PhysicsSprite::getRotation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void HelloWorld::update(float dt)
{
CCPoint velocity = joyStick->getVelocity(); // range 0-1
if (velocity.x != 0 || velocity.y != 0) {
if (speed < MAX_SPEED)
speed += 50;
// +y轴为起始轴 顺时针转 atan2范围是PI - 负PI atan是 PI/2 - 负PI/2
float c = atan2(velocity.x, velocity.y);
c = c * 180/M_PI;
// 度数为0 - 360.忘记了可以nslog下
if (c <= 0)
c += 360;
float d = CC_RADIANS_TO_DEGREES(playerBody->GetAngle()),b;
if (d <= 0) {
d = -d;
b =(int)d % 360;
}else
b =360 - abs((int)d) % 360;
//CCLog("stickangle:%f,playerangle:%f %f",c,b,CC_RADIANS_TO_DEGREES(playerBody->GetAngle()));
float omega = 100.0f;
if (abs(b - c) > 1.0f)
{
if (b > c) {
if (b - c < 180)
omega = omega;
else
omega = -omega;
}else
{
if (c - b < 180)
omega = -omega;
else
omega = omega;
}
playerBody->SetAngularVelocity(CC_DEGREES_TO_RADIANS(omega));
}else
playerBody->SetAngularVelocity(CC_DEGREES_TO_RADIANS(0.0f));
}else
{
playerBody->SetAngularVelocity(CC_DEGREES_TO_RADIANS(0.0f));
}
if (speed > 0)
speed -= 10;
if (speed < 0) {
speed = 0;
}
PhysicsSprite *player = (PhysicsSprite *)playerBody->GetUserData();
float playerAngle = player->getRotation();
b2Vec2 v2Linear;
v2Linear.Set(sin(CC_DEGREES_TO_RADIANS(playerAngle)) * speed / PTM_RATIO,cos(CC_DEGREES_TO_RADIANS(playerAngle) )* speed / PTM_RATIO);
playerBody->SetLinearVelocity(v2Linear);
}