static cpSpace * init(void) { cpSpace *space = cpSpaceNew(); cpSpaceSetIterations(space, 30); cpSpaceSetGravity(space, cpv(0, -100)); cpSpaceSetSleepTimeThreshold(space, 0.5f); cpSpaceSetCollisionSlop(space, 0.5f); cpBody *body, *staticBody = cpSpaceGetStaticBody(space); cpShape *shape; // Create segments around the edge of the screen. shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f)); cpShapeSetElasticity(shape, 1.0f); cpShapeSetFriction(shape, 1.0f); cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER); shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f)); cpShapeSetElasticity(shape, 1.0f); cpShapeSetFriction(shape, 1.0f); cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER); shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f)); cpShapeSetElasticity(shape, 1.0f); cpShapeSetFriction(shape, 1.0f); cpShapeSetFilter(shape, NOT_GRABBABLE_FILTER); // Add lots of boxes. for(int i=0; i<14; i++){ for(int j=0; j<=i; j++){ body = cpSpaceAddBody(space, cpBodyNew(1.0f, cpMomentForBox(1.0f, 30.0f, 30.0f))); cpBodySetPosition(body, cpv(j*32 - i*16, 300 - i*32)); shape = cpSpaceAddShape(space, cpBoxShapeNew(body, 30.0f, 30.0f, 0.5f)); cpShapeSetElasticity(shape, 0.0f); cpShapeSetFriction(shape, 0.8f); } } // Add a ball to make things more interesting cpFloat radius = 15.0f; body = cpSpaceAddBody(space, cpBodyNew(10.0f, cpMomentForCircle(10.0f, 0.0f, radius, cpvzero))); cpBodySetPosition(body, cpv(0, -240 + radius+5)); shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero)); cpShapeSetElasticity(shape, 0.0f); cpShapeSetFriction(shape, 0.9f); return space; }
PhysicsWorld::PhysicsWorld() { mySpace = cpSpaceNew(); // Set default gravity cpVect gravity = cpv(0, -10); cpSpaceSetGravity(mySpace, gravity); }
void DynamicObjectStabilizator::fixatePoints() { // vector<IDynamicObject *>::iterator begin = m_DynamicObjects.begin(); // vector<IDynamicObject *>::iterator end = m_DynamicObjects.end(); // vector<IDynamicObject *>::iterator iter = begin + 1; // for( ; iter != end ; iter++ ) size_t count = m_DynamicObjects.size(); for( size_t object_i = 0 ; object_i < 2 ; object_i++ ) { const IGeometryObject & geometryObjext = m_DynamicObjects[object_i]->getGeometryObject(); if( geometryObjext.getType() != GEOMETRYOBJECT_POINT ) { // assert( false ); continue; } cpBody * kineticBody = cpBodyNewKinematic(); cpSpaceAddBody( m_Space, kineticBody ); m_KineticBodies.push_back( kineticBody ); const GeometryPoint & geometryPoint = dynamic_cast<const GeometryPoint &>( geometryObjext ); int x = geometryPoint.getX(); int y = geometryPoint.getY(); cpVect mousePoint = cpv( x, y ); cpShape * shape = cpSpacePointQueryNearest( m_Space, mousePoint, 100.0, GRAB_FILTER, 0 ); if( 0 == shape ) { return; } cpVect new_mouse_position = cpv( x, y ); cpBodySetPosition( kineticBody, new_mouse_position ); cpBody * trackingBody = cpShapeGetBody( shape ); cpConstraint * joint = cpPivotJointNew2( kineticBody, trackingBody, cpvzero, cpvzero ); cpSpaceAddConstraint( m_Space, joint ); m_Joints.push_back( joint ); break; //one pointb } }
void PhysicsShape::componentComplete() { if(m_shapeType == PhysicsTypes::Box) { cpVect niz[] = { cpv(-(this->width()/2.0f), -(this->height()/2.0f)), cpv(-(this->width()/2.0f), (this->height()/2.0f)), cpv( (this->width()/2.0f), (this->height()/2.0f)), cpv( (this->width()/2.0f), -(this->height()/2.0f)) }; m_shape = cpPolyShapeNew(NULL, 4, niz, cpv(m_offsetX, -m_offsetY)); } else if(m_shapeType == PhysicsTypes::Circle) { m_shape = cpCircleShapeNew(NULL, m_diameter/2, cpvzero); } else { //TODO error qDebug() << "Error circle"; } m_shape->data = this; cpShapeSetFriction(m_shape, m_friction); cpShapeSetElasticity(m_shape, m_elasticity); if(m_sensor) { cpShapeSetSensor(m_shape, true); } cpShapeSetLayers(m_shape, m_layer); m_isPhysicsCreated = true; m_world->addPhysicsInterface(this); if(m_debugDraw) { this->setFlag(QQuickItem::ItemHasContents, true); } if(m_debugPrint) { qDebug() << "PhysicsShape - componentComplete()"; qDebug() << " Is sensor:" << m_sensor; qDebug() << " Shape type:" << m_shapeType; qDebug() << " Name:" << m_name; qDebug() << " Width:" << this->width(); qDebug() << " Height:" << this->height(); qDebug() << " QQuickitem pos:" << this->x() << this->y(); qDebug() << " Offset pos:" << this->m_offsetX << this->m_offsetY; } QQuickItem::componentComplete(); }
void Ring::init(float backBoardLength, float groundLength, float ringSize, float e, float u) { /* cpBody* backBoardBody; cpShape* backBoardShape; cpShape* groundShape; cpShape* ring1Shape; cpShape* ring2Shape;*/ int easy = -3; // 난이도 하락시키는 직선높이 차이 this->ringSize = ringSize; backBoardBody = cpBodyNew(INFINITY, INFINITY); setPosition(cpv(57, 250)); //backBoardBody->p = cpv(60, 250); // 50 //backBoardBody->p = cpv(60, 100); backBoardShape = cpSegmentShapeNew(backBoardBody, cpv(0,0), cpv(0, backBoardLength), 1.f); // CCLog("backboard shape %x", backBoardShape); backBoardShape->e = BACKBOARD_E; backBoardShape->u = u; groundShape = cpSegmentShapeNew(backBoardBody, cpv(0,0), cpv(groundLength - 2.f, easy), 1.f); // CCLog("ground shape %x", groundShape); groundShape->e = e / 3.f; groundShape->u = u; subObject = cpSegmentShapeNew(backBoardBody, cpv(groundLength -2.f, easy), cpv(groundLength - 2.f, -10.f), 1.f); // 길다란 보조 장치, 자연스러운 공경로를 위해 // CCLog("subobject shape %x", subObject); subObject->e = e; subObject->u = u; ring1Shape = cpCircleShapeNew(backBoardBody, 1.f, cpv(groundLength, easy )); // CCLog("ring1 shape %x", ring1Shape); ring1Shape->e = e / 3.f; ring1Shape->u = u; ring2Shape = cpCircleShapeNew(backBoardBody, 1.f, cpv(groundLength + ringSize, 0.f)); // CCLog("ring2 shape %x", ring2Shape); ring2Shape->e = e; ring2Shape->u = u; ring3Shape = cpCircleShapeNew(backBoardBody, 1.f, cpv((2*groundLength + ringSize) / 2.f, 0.f)); // CCLog("ring3 shape %x", ring2Shape); ring3Shape->e = e; ring3Shape->u = u; }
static void loadEditorPalette(void) { double rx, ry; float xp; rx = atlWindowWidth() / 2.0; ry = atlWindowHeight() / 2.0; xp = -rx+editorBody->p.x+25; paletteObjects[0] = createPaletteObject(cpv(xp, ry-45), "data/textures/wood0.png", 100, 1.0f); paletteObjects[1] = createPaletteObject(cpv(xp, ry-(45*2)), "data/textures/marble0.png", 400, 2.0f); paletteObjects[2] = createPaletteObject(cpv(xp, ry-(45*3)), NULL, 400, 2.0f); }
// Iterate over all of the bodies and reset the ones that have fallen offscreen. static void eachBody(cpBody *body, void *unused) { cpVect pos = cpBodyGetPos(body); if(pos.y < -260 || cpfabs(pos.x) > 340){ cpFloat x = rand()/(cpFloat)RAND_MAX*640 - 320; cpBodySetPos(body, cpv(x, 260)); } }
ConvexObject::ConvexObject(std::vector<cpVect> points, float mass) : PhysicalObject(points, mass) { cpRecenterPoly(points.size(), points.data()); shape = cpPolyShapeNew(body, points.size(), points.data(), cpv(0, 0)); shape->data = static_cast<PhysicalObject *>(this); shapes.push_back(shape); }
cpFloat cpMomentForBox2(cpFloat m, cpBB box) { cpFloat width = box.r - box.l; cpFloat height = box.t - box.b; cpVect offset = cpvmult(cpv(box.l + box.r, box.b + box.t), 0.5f); return cpMomentForBox(m, width, height) + m*cpvlengthsq(offset); }
CEmbodiedEntity* CDynamics2DEngine::CheckIntersectionWithRay(Real& f_t_on_ray, const CRay3& c_ray) const { /* Query all hits along the ray */ SDynamics2DSegmentHitData sHitData(c_ray); cpSpaceSegmentQuery( m_ptSpace, cpv(c_ray.GetStart().GetX(), c_ray.GetStart().GetY()), cpv(c_ray.GetEnd().GetX() , c_ray.GetEnd().GetY() ), CP_ALL_LAYERS, CP_NO_GROUP, Dynamics2DSegmentQueryFunc, &sHitData); /* Check whether we have a hit */ if(sHitData.Body != NULL) { f_t_on_ray = sHitData.T; } return sHitData.Body; }
cpBody* drawing_new(cpFloat x, cpFloat y, long color_rgb) { cpBody *drawing = cpBodyNew(INITIAL, INITIAL); cpBodySetPos(drawing, cpv(x, y)); Point_array *pa = point_array_new(x, y, color_rgb); cpBodySetUserData(drawing, pa); return drawing; }
static cpSpace * init(void) { cpResetShapeIdCounter(); space = cpSpaceNew(); space->iterations = 30; cpSpaceResizeStaticHash(space, 40.0f, 1000); cpSpaceResizeActiveHash(space, 40.0f, 1000); space->gravity = cpv(0, -100); space->sleepTimeThreshold = 0.5f; cpBody *body, *staticBody = &space->staticBody; cpShape *shape; // Create segments around the edge of the screen. shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers = NOT_GRABABLE_MASK; shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers = NOT_GRABABLE_MASK; shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers = NOT_GRABABLE_MASK; // Add lots of boxes. for(int i=0; i<14; i++){ for(int j=0; j<=i; j++){ body = cpSpaceAddBody(space, cpBodyNew(1.0f, cpMomentForBox(1.0f, 30.0f, 30.0f))); body->p = cpv(j*32 - i*16, 300 - i*32); shape = cpSpaceAddShape(space, cpBoxShapeNew(body, 30.0f, 30.0f)); shape->e = 0.0f; shape->u = 0.8f; } } // Add a ball to make things more interesting cpFloat radius = 15.0f; body = cpSpaceAddBody(space, cpBodyNew(10.0f, cpMomentForCircle(10.0f, 0.0f, radius, cpvzero))); body->p = cpv(0, -240 + radius+5); shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero)); shape->e = 0.0f; shape->u = 0.9f; return space; }
int main (int argc, char **argv) { cpSpace *space = cpSpaceNew(); cpSpaceSetGravity(space, cpv(0, GRAVITY)); cpEnableSegmentToSegmentCollisions(); cpShape *ground = cpSpaceAddShape(space, cpSegmentShapeNew(space->staticBody, cpv(0, 5), cpv(10, -5), 0)); cpShapeSetFriction(ground, 0.3); cpBody *drawing = drawing_new(2, 7, 0); drawing = drawing_update(space, drawing, 3, 8); drawing = drawing_update(space, drawing, 3, 9); drawing = drawing_update(space, drawing, 2, 9); //cpBody *drawing = drawing_new(0, 0, 0); //drawing = drawing_update(space, drawing, 2, 0); //drawing = drawing_update(space, drawing, 2, 2); //drawing = drawing_update(space, drawing, 0, 2); print_positions(drawing); //drawing_activate(drawing); //print_positions(drawing); cpVect vel, pos; int i = 0; for(cpFloat time = 0; time < 2; time += TIMESTEP){ pos = cpBodyGetPos(drawing); vel = cpBodyGetVel(drawing); printf( "Time = %2.2f Position = (%2.2f, %2.2f) Velocity = (%2.2f, %2.2f)\n", time, pos.x, pos.y, vel.x, vel.y); cpSpaceStep(space, TIMESTEP); i++; if (i == 20) { drawing_activate(space, drawing); print_positions(drawing); } } print_positions(drawing); free_body_full(drawing); cpShapeFree(ground); cpSpaceFree(space); return EXIT_SUCCESS; }
void HelloWorld::addPhysicSprite() { #if CC_ENABLE_CHIPMUNK_INTEGRATION // Use batch node. Faster CCSpriteBatchNode *parent = CCSpriteBatchNode::create(s_SpinPea, 100); m_pSpriteTexture = parent->getTexture(); addChild(parent, 100, kTagParentNode); CCPoint pos = ccp(200,200); int posx, posy; CCNode *parent = getChildByTag(kTagParentNode); posx = CCRANDOM_0_1() * 200.0f; posy = CCRANDOM_0_1() * 200.0f; posx = (posx % 4) * 85; posy = (posy % 3) * 121; int num = 4; cpVect verts[] = { cpv(-24,-54), cpv(-24, 54), cpv( 24, 54), cpv( 24,-54), }; cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero)); body->p = cpv(pos.x, pos.y); cpSpaceAddBody(m_pSpace, body); cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero); shape->e = 0.5f; shape->u = 0.5f; cpSpaceAddShape(m_pSpace, shape); CCPhysicsSprite *sprite = CCPhysicsSprite::createWithTexture(m_pSpriteTexture, CCRectMake(posx, posy, 85, 121)); parent->addChild(sprite,50); sprite->setCPBody(body); sprite->setPosition(pos); #endif }
cpBody* PhysicsWorld::AddRectBody(cpFloat width, cpFloat height, cpFloat xPosition, cpFloat yPosition, cpFloat mass) { // Create and add the body cpBody *boxBody = cpSpaceAddBody(mySpace, cpBodyNew(mass, cpMomentForBox(mass, width, height))); // Set it's position in the world cpBodySetPos(boxBody, cpv(xPosition, yPosition)); return boxBody; }
cpFloat cpMomentForBox2(cpFloat m, cpBB box) { cpFloat width = box.r - box.l; cpFloat height = box.t - box.b; cpVect offset = cpvmult(cpv(box.l + box.r, box.b + box.t), 0.5f); // TODO NaN when offset is 0 and m is INFINITY return cpMomentForBox(m, width, height) + m*cpvlengthsq(offset); }
static cpBody *MakeBody(const float x, const float y, const float w) { cpBody *body = cpSpaceAddBody(space.Space, cpBodyNewStatic()); cpBodySetPosition(body, cpv(x + w / 2, y - GAP_HEIGHT / 2)); cpShape *shape = cpSpaceAddShape( space.Space, cpBoxShapeNew(body, w, GAP_HEIGHT, 0.0)); cpShapeSetElasticity(shape, BLOCK_ELASTICITY); cpShapeSetFriction(shape, 1.0f); return body; }
static void add_user_point (float x, float y, gui_world *world) { cpVect point = cpv(x,y); if ((world->physics->drawing_box) && (x < world->graphics->x1 || y < world->graphics->y1 || x > world->graphics->x2 || y > world->graphics->y2)) { world->draw_success = false; } world->graphics->user_points = g_array_append_vals(world->graphics->user_points, &point, 1); }
static cpVect rand_pos(cpFloat radius) { cpVect v; do { v = cpv(frand()*(640 - 2*radius) - (320 - radius), frand()*(480 - 2*radius) - (240 - radius)); } while(cpvlength(v) < 85.0f); return v; }
static cpBody *utils_update_drawing(cpBody *drawing) { cpFloat mass = cpBodyGetMass(drawing); cpFloat moment = cpBodyGetMoment(drawing); Point_array *pa = cpBodyGetUserData(drawing); cpFloat x = g_array_index(pa->x_values, cpFloat, 0); cpFloat y = g_array_index(pa->y_values, cpFloat, 0); cpVect pos_a, pos_b; cpVect origin = cpBodyGetPos(drawing); cpFloat mi, micx = 0, micy = 0; int length = pa->x_values->len; for (int index = 1; index < length; index++) { pos_a = cpv(g_array_index(pa->x_values, cpFloat, index - 1), g_array_index(pa->y_values, cpFloat, index - 1)); pos_b = cpv(g_array_index(pa->x_values, cpFloat, index), g_array_index(pa->y_values, cpFloat, index)); cpvadd(pos_a, origin); cpvadd(pos_b, origin); x += pos_b.x; y += pos_b.y; mi = (CRAYON_MASS * cpAreaForSegment( pos_a, pos_b, CRAYON_RADIUS )); micx += mi * ((pos_a.x + pos_b.x) / 2); micy += mi * ((pos_a.y + pos_b.y) / 2); mass += mi; moment += cpMomentForSegment(mass, pos_a, pos_b); // not actually sum } cpBodySetMass(drawing, mass); cpBodySetMoment(drawing, moment); // center of mass is the average of all vertices NOT //cpVect new_origin = cpv(x / length, y / length); cpVect new_origin = cpv(micx / mass, micy / mass); cpBodySetPos( drawing, new_origin ); //cpBodySetPos(drawing, cpv(pos.x + (second.x / length), pos.y + (second.y / length))); pa = shift_origin(pa, origin, new_origin); cpBodySetUserData(drawing, pa); return drawing; }
// adds a fresstyle shape with impulse to the cpSpace void core_add_freestyle_shape_with_impulse ( cpSpace * space, cpVect* verts , const int num_verts, Color *color, const double friction, const double elasticity, const double density, const int index, cpVect impulse, cpVect offset ) { cpBody * body = core_add_freestyle_shape ( space, verts , num_verts, color, friction, elasticity, density, index ); if ( body == NULL ) return; // apply impulse impulse = cpv ( impulse.x*IMPULSE_MULTIPLIER, impulse.y*IMPULSE_MULTIPLIER ); cpBodyApplyImpulse ( body, impulse, offset ); }
void RigidBody2D::SetPosition(const Vector2f& position) { cpBodySetPosition(m_handle, cpv(position.x, position.y)); if (m_isStatic) { m_world->RegisterPostStep(this, [](Nz::RigidBody2D* body) { cpSpaceReindexShapesForBody(body->GetWorld()->GetHandle(), body->GetHandle()); }); } }
void ChipmunkTestLayer::initPhysics() { #if CC_ENABLE_CHIPMUNK_INTEGRATION // init chipmunk //cpInitChipmunk(); _space = cpSpaceNew(); //_space->gravity = cpv(0, -100); _space->gravity = cpv(0, 0); // // rogue shapes // We have to free them manually // // bottom _walls[0] = cpSegmentShapeNew( _space->staticBody, cpv(VisibleRect::leftBottom().x,VisibleRect::leftBottom().y), cpv(VisibleRect::rightBottom().x, VisibleRect::rightBottom().y), 0.0f); // top _walls[1] = cpSegmentShapeNew( _space->staticBody, cpv(VisibleRect::leftTop().x, VisibleRect::leftTop().y), cpv(VisibleRect::rightTop().x, VisibleRect::rightTop().y), 0.0f); // left _walls[2] = cpSegmentShapeNew( _space->staticBody, cpv(VisibleRect::leftBottom().x,VisibleRect::leftBottom().y), cpv(VisibleRect::leftTop().x,VisibleRect::leftTop().y), 0.0f); // right _walls[3] = cpSegmentShapeNew( _space->staticBody, cpv(VisibleRect::rightBottom().x, VisibleRect::rightBottom().y), cpv(VisibleRect::rightTop().x, VisibleRect::rightTop().y), 0.0f); for( int i=0;i<4;i++) { _walls[i]->e = 1.0f; _walls[i]->u = 1.0f; cpSpaceAddStaticShape(_space, _walls[i] ); } // Physics debug layer _debugLayer = PhysicsDebugNode::create(_space); this->addChild(_debugLayer, Z_PHYSICS_DEBUG); #endif }
static cpSpace * init(void) { QUERY_START = cpvzero; space = cpSpaceNew(); cpSpaceSetIterations(space, 5); { // add a fat segment cpFloat mass = 1.0f; cpFloat length = 100.0f; cpVect a = cpv(-length/2.0f, 0.0f), b = cpv(length/2.0f, 0.0f); cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForSegment(mass, a, b))); cpBodySetPos(body, cpv(0.0f, 100.0f)); cpSpaceAddShape(space, cpSegmentShapeNew(body, a, b, 20.0f)); } { // add a static segment cpSpaceAddShape(space, cpSegmentShapeNew(cpSpaceGetStaticBody(space), cpv(0, 300), cpv(300, 0), 0.0f)); } { // add a pentagon cpFloat mass = 1.0f; const int NUM_VERTS = 5; cpVect verts[NUM_VERTS]; for(int i=0; i<NUM_VERTS; i++){ cpFloat angle = -2*M_PI*i/((cpFloat) NUM_VERTS); verts[i] = cpv(30*cos(angle), 30*sin(angle)); } cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForPoly(mass, NUM_VERTS, verts, cpvzero))); cpBodySetPos(body, cpv(50.0f, 50.0f)); cpSpaceAddShape(space, cpPolyShapeNew(body, NUM_VERTS, verts, cpvzero)); } { // add a circle cpFloat mass = 1.0f; cpFloat r = 20.0f; cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForCircle(mass, 0.0f, r, cpvzero))); cpBodySetPos(body, cpv(100.0f, 100.0f)); cpSpaceAddShape(space, cpCircleShapeNew(body, r, cpvzero)); } return space; }
cpBody* drawing_new(cpFloat x, cpFloat y, long color_rgb) { cpBody *drawing = cpBodyNew(INITIAL, INITIAL); cpVect clickpoint = cpv(x, y); cpBodySetPos(drawing, clickpoint); cpVect position = cpBodyGetPos(drawing); fprintf(stdout, "INITIAL POSITION AT: (%5.2f, %5.2f)\n\n", position.x, position.y); Body_data *pa = point_array_new(0, 0, color_rgb); cpBodySetUserData(drawing, pa); return drawing; }
void ParticleEmitter::draw() { for (size_t i = 0; i < particles.size(); ++i) { sf::Vector2f pos = game_map->cp2sfml(cpv(particles[i].x, particles[i].y)); sprite.SetPosition(pos.x - game_map->cam_x, pos.y - game_map->cam_y); sprite.SetRotation(particles[i].angle); float a = std::min(1.0f-particles[i].age/particles[i].maxAge, particles[i].age/particles[i].maxAge*5.f); sprite.SetColor(sf::Color(255, 255, 255, std::min(255, std::max(0, (int)(a*255))))); App->Draw(sprite); } }
void GameScene::touchHandler(const string& type, const vector<cocos2d::Touch*>& touches, cocos2d::Event* event) { if (type == "began") { auto& winSize = cocos2d::Director::getInstance()->getWinSize(); CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Intro.mp3"); static_cast<cpBody*>(ball->getUserData())->v = cpv( touches[0]->getLocation().x < winSize.width * 0.5f ? -ballSpeed : ballSpeed, ballSpeed ); } }
static void set_arrowDirection() { int x = 0, y = 0; if(key_up) y += 1; if(key_down) y -= 1; if(key_right) x += 1; if(key_left) x -= 1; arrowDirection = cpv(x, y); }
static void set_arrowDirection() { int x = 0, y = 0; if(key_up) y += 1; if(key_down) y -= 1; if(key_right) x += 1; if(key_left) x -= 1; ChipmunkDemoKeyboard = cpv(x, y); }
void CDynamics2DSingleBodyObjectModel::MoveTo(const CVector3& c_position, const CQuaternion& c_orientation) { /* Move the body to the desired position */ m_ptBody->p = cpv(c_position.GetX(), c_position.GetY()); CRadians cXAngle, cYAngle, cZAngle; c_orientation.ToEulerAngles(cZAngle, cYAngle, cXAngle); cpBodySetAngle(m_ptBody, cZAngle.GetValue()); /* Update shape index */ cpSpaceReindexShapesForBody(GetDynamics2DEngine().GetPhysicsSpace(), m_ptBody); /* Update ARGoS entity state */ UpdateEntityStatus(); }