本文整理汇总了C++中CC_DEGREES_TO_RADIANS函数的典型用法代码示例。如果您正苦于以下问题:C++ CC_DEGREES_TO_RADIANS函数的具体用法?C++ CC_DEGREES_TO_RADIANS怎么用?C++ CC_DEGREES_TO_RADIANS使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CC_DEGREES_TO_RADIANS函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cpBodySetAngle
void CCPhysicsSprite::setRotation(float fRotation)
{
if (m_bIgnoreBodyRotation)
{
CCSprite::setRotation(fRotation);
}
else
{
cpBodySetAngle(m_pCPBody, -CC_DEGREES_TO_RADIANS(fRotation));
}
}
示例2: cc_to_b2Vec
void GearButton::createBody()
{
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position = cc_to_b2Vec(getParent()->convertToWorldSpace(getPosition()).x, getParent()->convertToWorldSpace(getPosition()).y);
bodyDef.angle = -CC_DEGREES_TO_RADIANS(getRotation());
bodyDef.userData = this;
_body = GameManager::getInstance()->getBox2dWorld()->CreateBody(&bodyDef);
((LayerItem*)getParent()->getUserObject())->_fixturesCache->addFixturesToBody(_body, "GearButton");
}
示例3: getRotation
void BlockHouse::fireBullet()
{
float rotation = getRotation();
float angleInRad = -CC_DEGREES_TO_RADIANS(rotation);
Vec2 realFirePoint = firePoint.rotateByAngle(Vec2::ZERO, angleInRad);
Vec2 dir = target - realFirePoint;
Bullet *bullet = Bullet::createWithDirection(dir);
bullet->setPosition(realFirePoint);
static_cast<GamePlayScene *>(getParent())->addBullet(bullet);
}
示例4: ccp
//label 描边
void LabelUtils::createStroke(CCLabelTTF *label, float size, ccColor3B color)
{
CCSize originalSize = label->getTexture()->getContentSize();
float wid = originalSize.width + size * 2;
float hei = originalSize.height + size * 2;
CCPoint originalPos = label->getPosition();
CCPoint originalAnchor = label->getAnchorPoint();
ccColor3B originalColor = label->getColor();
ccBlendFunc originalBlend = label->getBlendFunc();
CCNode* node = label->getChildByTag(TAG_STROKE);
CCRenderTexture* rt = NULL;
if(node) {
rt = dynamic_cast<CCRenderTexture*>(node);
if(rt) {
// rt->clear(0, 0, 0, 0); //这里有问题,会有一个黑色块
// CCLOG("use pre-existing CCrenderTexture!");
rt->removeFromParentAndCleanup(true);
rt = NULL;
}
}
if(!rt) {
rt = CCRenderTexture::create(wid, hei);
}
label->setColor(color);
label->setBlendFunc((ccBlendFunc) {
GL_SRC_ALPHA, GL_ONE
});
// rt->setAnchorPoint(originalAnchor); //没用
CCPoint center = ccp(wid * originalAnchor.x, hei * originalAnchor.y);
rt->beginWithClear(0, 0, 0, 0);
for(int i=0; i<360; i+= 15) {
float radians = CC_DEGREES_TO_RADIANS(i);
label->cocos2d::CCNode::setPosition(center.x + sin(radians)*size, center.y + cos(radians)*size);
label->visit();
}
rt->end();
label->setPosition(originalPos);
label->setColor(originalColor);
label->setBlendFunc(originalBlend);
float rtX = originalSize.width / 2 + size;
float rtY = originalSize.height / 2 - size;
rt->setPosition(rtX, rtY);
if(rt->getParent() == NULL) label->addChild(rt, -100, TAG_STROKE);
//测试
// CCLayerColor* layer = CCLayerColor::create(ccc4(0, 0, 0, 128), wid, hei);
// layer->setPosition(rt->getPosition());
// label->addChild(layer);
}
示例5: sin
void TransformHelp::nodeToMatrix(const BaseData &node, Mat4 &matrix)
{
matrix = Mat4::IDENTITY;
/// TODO: fix, translate macros, node.skewX stored as degrees?
/// check whether 3.10 store node.skewX as radians
if (node.skewX == -node.skewY)
{
double sine = sin(CC_DEGREES_TO_RADIANS(node.skewX));
double cosine = cos(CC_DEGREES_TO_RADIANS(node.skewX));
matrix.m[0] = node.scaleX * cosine;
matrix.m[1] = node.scaleX * -sine;
matrix.m[4] = node.scaleY * sine;
matrix.m[5] = node.scaleY * cosine;
}
else
{
matrix.m[0] = node.scaleX * cos(CC_DEGREES_TO_RADIANS(node.skewY));
matrix.m[1] = node.scaleX * sin(CC_DEGREES_TO_RADIANS(node.skewY));
matrix.m[4] = node.scaleY * sin(CC_DEGREES_TO_RADIANS(node.skewX));
matrix.m[5] = node.scaleY * cos(CC_DEGREES_TO_RADIANS(node.skewX));
}
matrix.m[12] = node.x;
matrix.m[13] = node.y;
}
示例6: Vec3
void HelloWorld::myupdate(float dt){
camera->setPosition3D(car_cabine->getPosition3D() + Vec3(100.0f * sinf(_angle), 30.0f, 100.0f * cosf(_angle)));
camera->lookAt(car_cabine->getPosition3D(), Vec3(0.0f, 1.0f, 0.0f));
if (_hud->movingleft == true){
constraint5->setLimit(CC_DEGREES_TO_RADIANS(-20), CC_DEGREES_TO_RADIANS(0));
physics_rbd_wheel_bar->setAngularVelocity(Vec3(0.0, 1.0, 0.0));
//physics_rbd_wheel_bar->setAngularFactor(Vec3(0.0, 0.0, 0.0));
}
if (_hud->movingright == true){
constraint5->setLimit(CC_DEGREES_TO_RADIANS(0), CC_DEGREES_TO_RADIANS(20));
physics_rbd_wheel_bar->setAngularVelocity(Vec3(0.0, -1.0, 0.0));
//physics_rbd_wheel_bar->setAngularFactor(Vec3(0.0, 0.0, 0.0));
}
if (_hud->movingup == true){
constraint5->setLimit(CC_DEGREES_TO_RADIANS(-0.5), CC_DEGREES_TO_RADIANS(0.5));
Vec3 mynearP((int)wheel1->getPosition3D().x, 0.0, (int)wheel1->getPosition3D().z), myfarP((int)wheel3->getPosition3D().x, 0.0, (int)wheel3->getPosition3D().z);
Vec3 mynearP2((int)wheel2->getPosition3D().x, 0.0, (int)wheel2->getPosition3D().z), myfarP2((int)wheel4->getPosition3D().x, 0.0, (int)wheel4->getPosition3D().z);
Vec3 mydir(myfarP - mynearP);
Vec3 mydir2(myfarP2 - mynearP2);
Vec3 mylinearVel = (mydir+mydir2)/2;
mylinearVel.normalize();
mylinearVel *= 50.0f;
mylinearVel.y = 0;
physics_rbd_wheel3->setLinearVelocity(mylinearVel);
physics_rbd_wheel4->setLinearVelocity(mylinearVel);
}
}
示例7: CCASSERT
nav::Triangle DelaunayAlgorithm::calculateTriangleByCircle(const nav::Circle&circle)
{
CCASSERT(circle.getR() > 0, "create traingle that circle's r must > 0");
float length = circle.getR() * 2.0f;
float d = 90.0f;
float r = CC_DEGREES_TO_RADIANS(d);
cocos2d::Point a(length, 0);
a.rotate(cocos2d::Point(0, 0), r);
a = a + circle.getCenter();
d = 90.0f + 120.0f;
r = CC_DEGREES_TO_RADIANS(d);
cocos2d::Point b(length, 0);
b.rotate(cocos2d::Point(0, 0), r);
b = b + circle.getCenter();
d = 90.0f + 240.f;
r = CC_DEGREES_TO_RADIANS(d);
cocos2d::Point c(length, 0);
c.rotate(cocos2d::Point(0, 0), r);
c = c + circle.getCenter();
nav::Triangle triangle(a, c, b);
return triangle;
}
示例8: CC_DEGREES_TO_RADIANS
void B2Sprite::setRotation(float fRotation)
{
if (m_bIgnoreBodyRotation)
{
CCSprite::setRotation(fRotation);
}
else
{
b2Vec2 p = m_pB2Body->GetPosition();
float radians = CC_DEGREES_TO_RADIANS(fRotation);
m_pB2Body->SetTransform(p, radians);
}
}
示例9: CC_DEGREES_TO_RADIANS
void Sprite3DLesson5::update(float delta)
{
static float accAngle = 0.f;
accAngle += delta * CC_DEGREES_TO_RADIANS(60);
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
float radius = 50.f;
Vec3 center(visibleSize.width / 2.f + origin.x, visibleSize.height / 4.f + origin.y, 0);
float x = cosf(accAngle) * radius + center.x, z = sinf(accAngle) * radius + center.z;
_sprite->setPosition3D(Vec3(x, center.y, z));
}
示例10: CC_DEGREES_TO_RADIANS
void CSSceneSkyBoxTest::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event *event)
{
if (touches.size())
{
auto touch = touches[0];
auto delta = touch->getDelta();
static float _angle = 0.f;
_angle -= CC_DEGREES_TO_RADIANS(delta.x);
_camera->setPosition3D(Vec3(50.0f * sinf(_angle), 0.0f, 50.0f * cosf(_angle)));
_camera->lookAt(Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 1.0f, 0.0f));
}
}
示例11: abs
void CFmBall::StickMove(int aX)
{
int t;
int tx = -sin(CC_DEGREES_TO_RADIANS(m_nAngle))*m_nSpeed;
if (tx == 0)
return;
if (m_pPos->GetX() > aX)
{
if (m_pPos->GetX() + tx > aX)
return;
}
else
{
if (m_pPos->GetX() + tx < aX)
return;
}
t = abs(((aX-m_pPos->GetX())/100) / tx);
*m_pPos = *m_pPos + FmP3D(-sin(CC_DEGREES_TO_RADIANS(m_nAngle))*m_nSpeed*t, cos(CC_DEGREES_TO_RADIANS(m_nAngle))*m_nSpeed*t, m_nSpeedZ*t)/100;
}
示例12: CC_DEGREES_TO_RADIANS
void Platform::initPlatform(int width, float angle, CCPoint position) {
//Define shape
b2PolygonShape box;
box.SetAsBox(width * 0.5f /PTM_RATIO, PLATFORM_HEIGHT * 0.5f / PTM_RATIO);
//Define fixture
b2FixtureDef fixtureDef;
fixtureDef.shape = &box;
fixtureDef.density = 1;
fixtureDef.restitution = 0;
//reutilize body from the pool: so destroy any existent fixture
if (_body->GetFixtureList()) {
_body->DestroyFixture(_body->GetFixtureList());
}
_body->CreateFixture(&fixtureDef);
_body->SetTransform(b2Vec2(position.x / PTM_RATIO, position.y / PTM_RATIO), CC_DEGREES_TO_RADIANS(-angle));
_body->SetActive(true);
CCSprite * block;
float startX = -width * 0.5f + TILE * 0.5f;
//set unused tiles in the platform invisible
for (int i = 0; i < TILES_PER_PLATFORM; i++) {
block = (CCSprite *) _tiles->objectAtIndex(i);
if (i >= width/TILE) {
block->setVisible(false);
} else {
block->setVisible(true);
block->setPosition(ccp(startX + i * TILE,
0));
block->setFlipY(false);
block->setFlipX(false);
if (angle == 0.0) {
if (position.y >= TILE * 13) block->setFlipY(true);
}
if (angle == 90.0) {
if (position.x > TILE * 5) block->setFlipY(true);
}
}
}
switchTexture();
this->setRotation(angle);
this->setPosition(position);
setVisible(true);
}
示例13: getShootParams
Tank::ExecResult Tank::executeAim(Vec2 p)
{
if (surfaceId) {
if (Planet* planet = _game->objs()->getByIdAs<Planet>(surfaceId)) {
Vec2 fromPoint;
Vec2 sourceDir;
getShootParams(fromPoint, sourceDir);
Vec2 targetDir = (p - getShootCenter()).getNormalized();
if (targetDir.isSmall() || sourceDir.isSmall()) {
gunRotationSpeed(0.0f);
return ExecResult::Done; // We do not know where to aim, so we are done
}
float aDist = angleDistance(sourceDir.getAngle(), targetDir.getAngle());
if (fabsf(aDist) < CC_DEGREES_TO_RADIANS(5)) {
if (fabsf(aDist) < CC_DEGREES_TO_RADIANS(0.2)) {
gunRotationSpeed(0.0f);
return ExecResult::Done;
} else if (aDist < 0) {
gunRotationSpeed(-0.1f);
return ExecResult::InProgress;
} else {
gunRotationSpeed(0.1f);
return ExecResult::InProgress;
}
} else if (aDist < 0) {
gunRotationSpeed(-1.0f);
return ExecResult::InProgress;
} else {
gunRotationSpeed(1.0f);
return ExecResult::InProgress;
}
} else {
return ExecResult::Failed;
}
} else {
return ExecResult::Delayed;
}
}
示例14: clear
void Star::drawStar(float radiusOut, float radiusIn)
{
clear();
ensureCapacity(50);
float tempAngle = 360/6;
int vIndex = 0;
for (float angle = 0; angle < 360; angle += tempAngle) {
Vec3 p0 = Vec3(0.0f,0.0f,0.0f);
Vec3 p1;
p1.x = radiusOut * cosf(CC_DEGREES_TO_RADIANS(angle));
p1.y = radiusOut * sinf(CC_DEGREES_TO_RADIANS(angle));
p1.z = 0.0f;
Vec3 p2;
p2.x = radiusIn * cosf(CC_DEGREES_TO_RADIANS(angle+tempAngle/2));
p2.y = radiusIn * sinf(CC_DEGREES_TO_RADIANS(angle+tempAngle/2));
p2.z = 0.0f;
Vec3 p3 = Vec3(0.0f,0.0f,0.0f);
Vec3 p4;
p4.x = radiusIn * cosf(CC_DEGREES_TO_RADIANS(angle+tempAngle/2));
p4.y = radiusIn * sinf(CC_DEGREES_TO_RADIANS(angle+tempAngle/2));
p4.z = 0.0f;
Vec3 p5;
p5.x = radiusOut * cosf(CC_DEGREES_TO_RADIANS(angle+tempAngle));
p5.y = radiusOut * sinf(CC_DEGREES_TO_RADIANS(angle+tempAngle));
p5.z = 0.0f;
_buffer[vIndex*6+0] = {p0, Color4B(255, 255, 255, 255)};
_buffer[vIndex*6+1] = {p1, Color4B(255, 0, 0, 255)};
_buffer[vIndex*6+2] = {p2, Color4B(0, 255, 0, 255)};
_buffer[vIndex*6+3] = {p3, Color4B(255, 255, 255, 255)};
_buffer[vIndex*6+4] = {p4, Color4B(0, 255, 0, 255)};
_buffer[vIndex*6+5] = {p5, Color4B(255, 0, 0, 255)};
vIndex++;
}
_bufferCount += vIndex*6;
_dirty = true;
}
示例15: CCRANDOM_MINUS1_1
void TestParticleSystem::paint()
{
if (!printed) {
printed = true;
}
for (int i = particles.size() -1; i >= 0; i--) {
TestParticle* particle = particles.at(i);
particle->rotation += CCRANDOM_MINUS1_1();
// Transform
float c = cosf(CC_DEGREES_TO_RADIANS(particle->rotation));
float s = sinf(CC_DEGREES_TO_RADIANS(particle->rotation));
// Create transformation matrix for scale, position and rotation
Mat4 matrix = Mat4(c * particle->size, s * particle->size, 0.0, 0.0,
-s * particle->size, c * particle->size, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
particle->pos.x, particle->pos.y, 0.0, 1.0);
particle->transform.multiply(matrix);
}
}