本文整理汇总了C++中CC_RADIANS_TO_DEGREES函数的典型用法代码示例。如果您正苦于以下问题:C++ CC_RADIANS_TO_DEGREES函数的具体用法?C++ CC_RADIANS_TO_DEGREES怎么用?C++ CC_RADIANS_TO_DEGREES使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CC_RADIANS_TO_DEGREES函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CC_RADIANS_TO_DEGREES
cocos2d::Vec2 Tower::convertFromTowerSceneToTowerLayer(Vec2 mLoc)
{
Vec2 lLoc = _towerLayer->getPosition();
float angle = CC_RADIANS_TO_DEGREES(lLoc.getAngle());
if(angle >= 0 && angle <= 90)
{
return (mLoc - lLoc);
}
else if(angle > 90 && angle <= 180)
{
return (mLoc+Vec2(abs(lLoc.x), -lLoc.y));
}
else if(angle >= -180 && angle <= -270)
{
return (mLoc + lLoc);
}
else if (angle > -270 && angle < 0)
{
return (mLoc - lLoc);
}
return Vec2::ZERO;
}
示例2: scheduleUpdate
bool Bullet::init(Vec2 velocity)
{
Node::init();
scheduleUpdate();
mVelocity = velocity;
auto bullet = Sprite::create("Bullet.png");
bullet->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
bullet->setName("Bullet");
float radian = atan2f(mVelocity.x, mVelocity.y);
// ラジアンから度へ変換
float angle = CC_RADIANS_TO_DEGREES(radian);
// 0 ~ 360度に限定
angle += 360;
while (angle >= 360) {
angle -= 360;
}
setRotation(angle);
addChild(bullet);
return true;
}
示例3: CC_RADIANS_TO_DEGREES
bool Radar::init()
{
if ( !Node::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
auto bg = Sprite::create("radar_1.png");
this->addChild(bg);
auto zeye = Director::getInstance()->getZEye();
auto eyeDegrees = CC_RADIANS_TO_DEGREES(atan2f(visibleSize.width*0.5, zeye)*2);
log("eyeAngle = %f", eyeDegrees);
auto eyeBg = ProgressTimer::create(Sprite::create("radar_2.png"));
this->addChild(eyeBg);
eyeBg->setType(ProgressTimer::Type::RADIAL);
eyeBg->setMidpoint(Vec2(0.5f, 0.5f));
eyeBg->setPercentage(eyeDegrees/3.6);
eyeBg->setRotation(-eyeDegrees*0.5);
auto scanSp = Sprite::create("radar_3.png");
this->addChild(scanSp);
scanSp->runAction(RepeatForever::create(RotateBy::create(2.0, 360)));
pDrawNode = DrawNode::create();
this->addChild(pDrawNode);
// dNode->drawSolidCircle(Vec2(0, 0), 100, CC_DEGREES_TO_RADIANS(90), 8, Color4F(1, 0, 0, 1));
return true;
}
示例4: CC_RADIANS_TO_DEGREES
void OptionLayer::onTouchesBegan(const std::vector<Touch*>& touches, Event *event)
{
Size winSize = Director::getInstance()->getWinSize();
for (auto touch : touches){
Point position = touch->getLocation();
this->activeJoystick(this->getLocation());
auto distance = position.getDistance(this->getLocation());
auto deltaAngle = this->getLocation() - position;
auto angle = CC_RADIANS_TO_DEGREES(deltaAngle.getAngle());
if (distance <= this->getRadius()) {
if ((angle > -180 && angle < -135) || (angle > 135 && angle <= 180)) {
this->delegator->onWalk(Direction::DIRECTION_RIGHT);
}else if(angle >= -135 && angle <= -45) {
this->delegator->onWalk(Direction::DIRECTION_UP);
}else if(angle > -45 && angle <= 45) {
this->delegator->onWalk(Direction::DIRECTION_LEFT);
}else if(angle > 45 && angle <= 135) {
this->delegator->onWalk(Direction::DIRECTION_DOWN);
}
} else {
// right
}
}
}
示例5: CC_RADIANS_TO_DEGREES
void Unit::shootWeapon(float attackRatio)
{
if(this->target != nullptr){
Sprite* weapon = Sprite::create(this->weaponName);
Point unitPosition = this->getPosition();
Point destination = this->target->getPosition();
Point diff = destination-unitPosition;
float angle = CC_RADIANS_TO_DEGREES(-1*diff.getAngle());
weapon->setRotation(angle);
weapon->setPosition(this->getPosition());
this->gameLayer->map->addChild(weapon,100);
float time = unitPosition.getDistance(destination)/this->attackSpeed;
auto moveAction = MoveTo::create(time,destination);
auto damageAction = CallFunc::create(CC_CALLBACK_0(Unit::damageEnermy, this));
auto removeAction = CallFuncN::create(CC_CALLBACK_1(Unit::removeWeapon, this));
auto actionSequence = Sequence::create(damageAction, moveAction,removeAction, NULL);
weapon->runAction(actionSequence);
}
}
示例6: startWithTarget
void OrbitCamera::startWithTarget(Node *target)
{
ActionCamera::startWithTarget(target);
float r, zenith, azimuth;
this->sphericalRadius(&r, &zenith, &azimuth);
if( isnan(_radius) )
_radius = r;
if( isnan(_angleZ) )
_angleZ = (float)CC_RADIANS_TO_DEGREES(zenith);
if( isnan(_angleX) )
_angleX = (float)CC_RADIANS_TO_DEGREES(azimuth);
_radZ = (float)CC_DEGREES_TO_RADIANS(_angleZ);
_radX = (float)CC_DEGREES_TO_RADIANS(_angleX);
}
示例7: checkNearestMonster
void BaseMageTower::shoot(float dt)
{
auto instance = GameManager::getInstance();
checkNearestMonster();
if(nearestMonster!=NULL && nearestMonster->getCurrHp() > 0)
{
auto currBullet = MageTowerBullet();
SoundManager::playMageTowerShot();
Point shootVector = nearestMonster->baseSprite->getPosition() - this->getParent()->getPosition();
auto position=currBullet->getPosition()-shootVector;
auto rotation=atan2(position.y,position.x);
float angleDegrees = CC_RADIANS_TO_DEGREES(rotation);
currBullet->setRotation(180.0f-angleDegrees);
towerBase->runAction(Animate::create(AnimationCache::getInstance()->getAnimation(String::createWithFormat("level%d_mage_shine",level)->getCString())));
if(shootVector.y>0){
shooter->runAction(Animate::create(AnimationCache::getInstance()->getAnimation("mage_shoot_up")));
}else{
shooter->runAction(Animate::create(AnimationCache::getInstance()->getAnimation("mage_shoot_down")));
}
auto actionMove=MoveTo::create(0.25f,shootVector);
auto action=Spawn::create(actionMove,NULL);
currBullet->setBulletAction(action);
currBullet->shoot();
currBullet = NULL;
}
}
示例8: limitVelocity
void Bird::update( float dt )
{
const float limited = 3.0f;
this->setPosition(_body->GetPosition().x * PTM_RATIO, _body->GetPosition().y * PTM_RATIO);
b2Vec2 vel = _body->GetLinearVelocity();
if (_awake && vel.x < limited)
_body->SetLinearVelocity(b2Vec2(limited + 1, 0));
limitVelocity();
CCLOG("Position: %f", this->getPositionX());
//CCLOG("Angle: %f | %f", vel.x, vel.y);
b2Vec2 weightedVel = vel;
const int NUM_PREV_VELS = 5;
queue<b2Vec2> quue;
for(int i = 0; i < _prevVels.size(); ++i) {
weightedVel += _prevVels[i];
}
weightedVel = b2Vec2(weightedVel.x/NUM_PREV_VELS, weightedVel.y/NUM_PREV_VELS);
_prevVels.push_back(vel);
if (_prevVels.size() >= NUM_PREV_VELS)
_prevVels.clear();
vel = weightedVel;
if (vel.x < 0) {
vel.x = - vel.x;
vel.y = - vel.y;
}
float angle = -1 * CC_RADIANS_TO_DEGREES(ccpToAngle(ccp(vel.x, vel.y)));
angle = MIN(90, angle);
angle = MAX(-90, angle);
if (_awake)
this->setRotation(angle);
}
示例9: getChildByTag
void MainLayer::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
CCSetIterator it = pTouches->begin();
CCTouch* touch = (CCTouch*)(*it);
CCPoint location = touch->locationInView( touch->view() );
CCPoint convertedLocation = CCDirector::sharedDirector()->convertToGL(location);
CCNode* s = getChildByTag(kTagSprite);
s->stopAllActions();
s->runAction( CCMoveTo::actionWithDuration(1, CCPointMake(convertedLocation.x, convertedLocation.y) ) );
float o = convertedLocation.x - s->getPosition().x;
float a = convertedLocation.y - s->getPosition().y;
float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) );
if( a < 0 )
{
if( o < 0 )
at = 180 + fabs(at);
else
at = 180 - fabs(at);
}
s->runAction( CCRotateTo::actionWithDuration(1, at) );
}
示例10: b2c
void PhySprite::update(float delta) {
if (b2PhyBody) {
this->setPosition(ccp(b2c(b2PhyBody->GetPosition().x),
b2c(b2PhyBody->GetPosition().y)));
this->setRotation(-1 * CC_RADIANS_TO_DEGREES(b2PhyBody->GetAngle()));
}
}
示例11: update
void LightTest::update( float delta )
{
static float angleDelta = 0.0;
if (_directionalLight)
{
_directionalLight->setRotation3D(Vec3(-45.0, -CC_RADIANS_TO_DEGREES(angleDelta), 0.0f));
}
if (_pointLight)
{
_pointLight->setPositionX(100.0f * cosf(angleDelta + 2.0 * delta));
_pointLight->setPositionY(100.0f);
_pointLight->setPositionZ(100.0f * sinf(angleDelta + 2.0 * delta));
}
if (_spotLight)
{
_spotLight->setPositionX(100.0f * cosf(angleDelta + 4.0 * delta));
_spotLight->setPositionY(100.0f);
_spotLight->setPositionZ(100.0f * sinf(angleDelta + 4.0 * delta));
_spotLight->setDirection(-Vec3(cosf(angleDelta + 4.0 * delta), 1.0, sinf(angleDelta + 4.0 * delta)));
}
angleDelta += delta;
TestCase::update(delta);
}
示例12: switch
bool Flame::init(Item& item)
{
bool result;
if (ItemModel::init(item)) {
switch (_type) {
case Flame_Blue:
setTexture(IMAGE_FLAME_BLUE);
break;
case Flame_Orange:
setTexture(IMAGE_FLAME_ORANGE);
break;
case Flame_Violet:
setTexture(IMAGE_FLAME_VIOLET);
break;
case Flame_White:
setTexture(IMAGE_FLAME_WHITE);
break;
default:
return false;
}
setRotation(CC_RADIANS_TO_DEGREES(item.angle));
setScale(item.scale);
result = true;
}else{
result = false;
}
return result;
}
示例13: Point
float PhotoLayer::getRotateAngle(Point startPos1, Point startPos2, Point endPos1, Point endPos2){
float angle = 0.0f;
//两个向量
Point *sp = new Point(startPos2.x - startPos1.x, startPos2.y - startPos1.y);
Point *ep = new Point(endPos2.x - endPos1.x, endPos2.y - endPos1.y);
// cos(A) = (x1 * x2 + y1 * y2) / (sqrt(x1 * x1 + y1 * y1) * sqrt(x2 * x2 + y2 * y2))
double n = sp->x * ep->x + sp->y * ep->y;
double m = sqrt(sp->x * sp->x + sp->y * sp->y) * sqrt(ep->x * ep->x + ep->y * ep->y);
double cosmn = n / m;
if (m!=0 && (cosmn>=1.000001 || cosmn <= 0.999999)) {
angle = CC_RADIANS_TO_DEGREES(acos(cosmn));
//log("n=%f,m=%f,n/m=%f,cos=%f,angle=%f",n,m,n/m,acos(cosmn),angle);
}
//sin(A) = (x1 * y2 - y1 * x2 ) / (sqrt(x1 * x1 + y1 * y1) * sqrt(x2 * x2 + y2 * y2))
//sin(A) 小于0 则顺时针, 大于0则逆时针
double n1 = sp->x * ep->y - sp->y * ep->x;
if (m !=0 && n1/m > 0) {
angle = -1 * angle;
}
//log("return angle=%f",angle);
return angle;
}
示例14: CC_RADIANS_TO_DEGREES
float MathUtils::angleFromVector(cocos2d::Point p0, cocos2d::Point p1)
{
cocos2d::Point direction = p1 - p0;
float rad = CC_RADIANS_TO_DEGREES(-direction.getAngle());
return fmod(rad, 360.0f); // keep angle in the 360 range
}
示例15: log
bool Stage01::onTouchBegan(Touch* touch, Event *event)
{
log("onTouchBegan-----------------------------");
auto location = touch->getLocation();
auto s = getChildByTag(1);
mFootPrint = Sprite::create("footprint.png");
float spritex = (location.x + s->getPosition().x) / 2;
float spritey = (location.y + s->getPosition().y) / 2;
mFootPrint->setPosition(spritex, spritey);
float dis = sqrt((s->getPositionX() - location.x)*(s->getPositionX() - location.x) + (s->getPositionY() - location.y)*(s->getPositionY() - location.y));
mFootPrint->setScale(dis / 50, 1.0);
mFootPrint->setOpacity(100);
//mFootPrint->setPosition(s->getPosition());
float o = location.x - s->getPosition().x;
float a = location.y - s->getPosition().y;
float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) );
if( a < 0 )
{
if( o < 0 )
at = 180 + fabs(at);
else
at = 180 - fabs(at);
}
//mFootPrint->runAction( RotateTo::create(0.0001, at + 90) );
mFootPrint->setRotation(at + 90);
this->addChild(mFootPrint);
return true;
}