void Init_chipmunk(void) { id_parent = rb_intern("parent"); cpInitChipmunk(); rb_eval_string("Float::INFINITY = 1.0/0.0"); m_Chipmunk = rb_define_module("CP"); rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0); rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1); rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0); rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1); rb_define_module_function(m_Chipmunk, "moment_for_circle", rb_momentForCircle, 4); rb_define_module_function(m_Chipmunk, "moment_for_poly", rb_momentForPoly, 3); // TODO add seg moment function Init_cpVect(); Init_cpBB(); Init_cpBody(); Init_cpShape(); Init_cpConstraint(); Init_cpSpace(); }
int main(int argc, const char **argv) { cpInitChipmunk(); cp_collision_slop = 0.2f; #ifdef TIME_TRIAL sleep(1); for(int i=0; i<demoCount; i++){ if(i == 'l' - 'a') continue; time_trial(i, 1000); } // time_trial(0, 1000); exit(0); #endif mouseBody = cpBodyNew(INFINITY, INFINITY); glutStuff(argc, argv); runDemo(demos[firstDemoIndex]); glutMainLoop(); return 0; }
void Init_chipmunk(void) { id_parent = rb_intern("parent"); cpInitChipmunk(); m_Chipmunk = rb_define_module("CP"); rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0); rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1); rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0); rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1); rb_define_module_function(m_Chipmunk, "moment_for_circle", rb_momentForCircle, 4); rb_define_module_function(m_Chipmunk, "moment_for_poly", rb_momentForPoly, 3); rb_define_module_function(m_Chipmunk, "damped_spring", rb_dampedSpring, 8); Init_cpVect(); Init_cpBB(); Init_cpBody(); Init_cpShape(); Init_cpJoint(); Init_cpSpace(); }
static void physics_thread() { /* Now initialize the physics engine. */ cpInitChipmunk(); space = cpSpaceNew(); do { /* But here we do care about the elapsed time. */ synchronize(&oldtime /*,&server_elapsed*/); simple_lock(&physics_lock); physics(world, space); cpSpaceHashEach(space->activeShapes, &draw_player, NULL); //cpSpaceHashEach(space->staticShapes, &draw_static, NULL); simple_unlock(&physics_lock); if(to_remove_array.length > 0) lDestroy(&to_remove_array, remove_unused); } while(!physics_exit_time); lFree(&to_remove_array); cpSpaceFreeChildren(space); cpSpaceFree(space); }
int main(int argc, const char **argv) { ChipmunkDemo demo_list[] = { LogoSmash, PyramidStack, Plink, BouncyHexagons, Tumble, PyramidTopple, Planet, Springies, Pump, TheoJansen, Query, OneWay, Joints, Tank, Chains, Crane, ContactGraph, Buoyancy, Player, }; demos = demo_list; demoCount = sizeof(demo_list)/sizeof(ChipmunkDemo); int trial = 0; for(int i=0; i<argc; i++){ if(strcmp(argv[i], "-bench") == 0){ demos = bench_list; demoCount = bench_count; } else if(strcmp(argv[i], "-trial") == 0){ trial = 1; } } cpInitChipmunk(); if(trial){ // sleep(1); for(int i=0; i<demoCount; i++) time_trial(i, 1000); exit(0); } else { mouseBody = cpBodyNew(INFINITY, INFINITY); glutStuff(argc, argv); runDemo(demoIndex); glutMainLoop(); } return 0; }
int main(int argc, const char **argv) { cpInitChipmunk(); // for(int i=0; i<demoCount; i++) // time_trial(i, 1000); // time_trial('d' - 'a', 10000); // exit(0); mouseBody = cpBodyNew(INFINITY, INFINITY); glutStuff(argc, argv); runDemo(demos[firstDemoIndex]); glutMainLoop(); return 0; }
void ChipmunkTestLayer::init() { CCLayer::init(); CCLayer::setIsTouchEnabled(true); demoIndex = 0; cpInitChipmunk(); cp_collision_slop = 0.2f; mouseBody = cpBodyNew(INFINITY, INFINITY); runDemo(demos[firstDemoIndex]); label = CCLabelTTF::labelWithString(demos[firstDemoIndex]->name, "Arial", 32); label->setPosition( ccp(0, -300) ); label->setColor(ccBLACK); addChild(label); // [self schedule: @selector(step:)]; scheduleUpdate(); }
void eol_level_init() { cpInitChipmunk(); eol_logger_message( EOL_LOG_INFO, "eol_level:initializing\n"); _eol_level_manager = eol_resource_manager_init( "eol_level_manager", _eol_level_max, sizeof(eolLevel), eolTrue, eol_level_delete, eol_level_load_data_from_file ); eol_logger_message( EOL_LOG_INFO, "eol_level:initialized\n"); atexit(eol_level_close); _eol_level_initialized = eolTrue; }
void Init_chipmunk(void) { id_parent = rb_intern("parent"); cpInitChipmunk(); rb_eval_string("Float::INFINITY = 1.0/0.0"); m_Chipmunk = rb_define_module("CP"); rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0); rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1); rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0); rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1); rb_define_module_function(m_Chipmunk, "moment_for_circle", rb_momentForCircle, 4); rb_define_module_function(m_Chipmunk, "moment_for_poly", rb_momentForPoly, 3); rb_define_module_function(m_Chipmunk, "moment_for_segment", rb_momentForSegment, 3); rb_define_const(m_Chipmunk, "INFINITY", rb_float_new(INFINITY)); rb_define_const(m_Chipmunk, "VERSION" , rb_str_new2(cpVersionString)); Init_cpVect(); Init_cpArbiter(); Init_cpBB(); Init_cpBody(); Init_cpShape(); Init_cpConstraint(); Init_cpSpace(); }
//----------------------------------------------------------------// void moaicore::SystemInit () { _typeCheck (); srand (( u32 )time ( 0 )); zl_init (); #if USE_OPENSSL SSL_load_error_strings (); SSL_library_init (); #endif #if USE_ARES ares_set_default_dns_addr ( 0x08080808 ); #endif #if USE_CURL curl_global_init ( CURL_GLOBAL_WIN32 | CURL_GLOBAL_SSL ); #endif #if USE_CHIPMUNK cpInitChipmunk (); #endif }
void CDynamics2DEngine::Init(TConfigurationNode& t_tree) { try { /* Init parent */ CPhysicsEngine::Init(t_tree); /* Parse XML */ GetNodeAttributeOrDefault(t_tree, "static_cell_size", m_fStaticHashCellSize, m_fStaticHashCellSize); GetNodeAttributeOrDefault(t_tree, "active_cell_size", m_fActiveHashCellSize, m_fActiveHashCellSize); GetNodeAttributeOrDefault(t_tree, "static_cells", m_nStaticHashCells, m_nStaticHashCells); GetNodeAttributeOrDefault(t_tree, "active_cells", m_nActiveHashCells, m_nActiveHashCells); GetNodeAttributeOrDefault(t_tree, "elevation", m_fElevation, m_fElevation); if(NodeExists(t_tree, "boundaries")) { /* Parse the boundary definition */ TConfigurationNode& tBoundaries = GetNode(t_tree, "boundaries"); SBoundarySegment sBoundSegment; CVector2 cLastPoint, cCurPoint; std::string strConnectWith; TConfigurationNodeIterator tVertexIt("vertex"); /* Get the first vertex */ tVertexIt = tVertexIt.begin(&tBoundaries); if(tVertexIt == tVertexIt.end()) { THROW_ARGOSEXCEPTION("Physics engine of type \"dynamics2d\", id \"" << GetId() << "\": you didn't specify any <vertex>!"); } GetNodeAttribute(*tVertexIt, "point", cLastPoint); m_vecVertices.push_back(cLastPoint); /* Go through the other vertices */ ++tVertexIt; while(tVertexIt != tVertexIt.end()) { /* Read vertex data and fill in segment struct */ GetNodeAttribute(*tVertexIt, "point", cCurPoint); m_vecVertices.push_back(cCurPoint); sBoundSegment.Segment.SetStart(cLastPoint); sBoundSegment.Segment.SetEnd(cCurPoint); GetNodeAttribute(*tVertexIt, "connect_with", strConnectWith); if(strConnectWith == "gate") { /* Connect to previous vertex with a gate */ sBoundSegment.Type = SBoundarySegment::SEGMENT_TYPE_GATE; GetNodeAttribute(*tVertexIt, "to_engine", sBoundSegment.EngineId); } else if(strConnectWith == "wall") { /* Connect to previous vertex with a wall */ sBoundSegment.Type = SBoundarySegment::SEGMENT_TYPE_WALL; sBoundSegment.EngineId = ""; } else { /* Parse error */ THROW_ARGOSEXCEPTION("Physics engine of type \"dynamics2d\", id \"" << GetId() << "\": unknown vertex connection method \"" << strConnectWith << "\". Allowed methods are \"wall\" and \"gate\"."); } m_vecSegments.push_back(sBoundSegment); /* Next vertex */ cLastPoint = cCurPoint; ++tVertexIt; } /* Check that the boundary is a closed path */ if(m_vecVertices.front() != m_vecVertices.back()) { THROW_ARGOSEXCEPTION("Physics engine of type \"dynamics2d\", id \"" << GetId() << "\": the specified path is not closed. The first and last points of the boundaries MUST be the same."); } } /* Initialize physics */ cpInitChipmunk(); cpResetShapeIdCounter(); /* Used to attach static geometries so that they won't move and to simulate friction */ m_ptGroundBody = cpBodyNew(INFINITY, INFINITY); /* Create the space to contain the movable objects */ m_ptSpace = cpSpaceNew(); /* Subiterations to solve constraints. The more, the better for precision but the worse for speed */ m_ptSpace->iterations = GetIterations(); /* Resize the space hash. This has dramatic effects on performance. TODO: - find optimal parameters automatically (average entity size) cpSpaceReindexStaticHash(m_ptSpace, m_fStaticHashCellSize, m_nStaticHashCells); cpSpaceResizeActiveHash(m_ptSpace, m_fActiveHashCellSize, m_nActiveHashCells); */ /* Gripper-Gripped callback functions */ cpSpaceAddCollisionHandler( m_ptSpace, SHAPE_GRIPPER, SHAPE_GRIPPABLE, BeginCollisionBetweenGripperAndGrippable, ManageCollisionBetweenGripperAndGrippable, NULL, NULL, NULL); /* Add boundaries, if specified */ if(! m_vecSegments.empty()) { cpShape* ptSegment; for(size_t i = 0; i < m_vecSegments.size(); ++i) { if(m_vecSegments[i].Type == SBoundarySegment::SEGMENT_TYPE_WALL) { ptSegment = cpSpaceAddShape( m_ptSpace, cpSegmentShapeNew( m_ptGroundBody, cpv(m_vecSegments[i].Segment.GetStart().GetX(), m_vecSegments[i].Segment.GetStart().GetY()), cpv(m_vecSegments[i].Segment.GetEnd().GetX(), m_vecSegments[i].Segment.GetEnd().GetY()), 0.0f)); ptSegment->e = 0.0f; // no elasticity ptSegment->u = 1.0f; // max friction } else { /* There is at least a gate, transfer is activated */ m_bEntityTransferActive = true; } } } } catch(CARGoSException& ex) { THROW_ARGOSEXCEPTION_NESTED("Error initializing the dynamics 2D engine \"" << GetId() << "\"", ex); } }
void KRSimulator2D::initSimulatorSystem() { cpInitChipmunk(); }
void Init_chipmunk(void) { id_parent = rb_intern("parent"); cpInitChipmunk(); m_Chipmunk = rb_define_module("CP"); rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0); rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1); rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0); rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1); rb_define_module_function(m_Chipmunk, "contact_persistence", rb_get_cp_contact_persistence, 0); rb_define_module_function(m_Chipmunk, "contact_persistence=", rb_set_cp_contact_persistence, 1); rb_define_module_function(m_Chipmunk, "clamp", rb_cpfclamp, 3); rb_define_module_function(m_Chipmunk, "flerp", rb_cpflerp, 3); rb_define_module_function(m_Chipmunk, "flerpconst", rb_cpflerpconst, 3); rb_define_module_function(m_Chipmunk, "moment_for_circle", rb_cpMomentForCircle, 4); rb_define_module_function(m_Chipmunk, "moment_for_poly", rb_cpMomentForPoly, 3); rb_define_module_function(m_Chipmunk, "moment_for_segment", rb_cpMomentForSegment, 3); rb_define_module_function(m_Chipmunk, "moment_for_box", rb_cpMomentForBox, 3); rb_define_module_function(m_Chipmunk, "circle_moment", rb_cpMomentForCircle, 4); rb_define_module_function(m_Chipmunk, "poly_moment", rb_cpMomentForPoly, 3); rb_define_module_function(m_Chipmunk, "segment_moment", rb_cpMomentForSegment, 3); rb_define_module_function(m_Chipmunk, "box_moment", rb_cpMomentForBox, 3); rb_define_module_function(m_Chipmunk, "area_for_circle", rb_cpAreaForCircle, 2); rb_define_module_function(m_Chipmunk, "area_for_poly", rb_cpAreaForPoly, 1); rb_define_module_function(m_Chipmunk, "centroid_for_poly", rb_cpCentroidForPoly, 1); rb_define_module_function(m_Chipmunk, "recenter_poly", rb_cpRecenterPoly, 1); rb_define_module_function(m_Chipmunk, "area_for_segment", rb_cpAreaForSegment, 3); rb_define_module_function(m_Chipmunk, "area_for_box", rb_cpAreaForBox, 2); rb_define_module_function(m_Chipmunk, "circle_area", rb_cpAreaForCircle, 2); rb_define_module_function(m_Chipmunk, "poly_area", rb_cpAreaForPoly, 1); rb_define_module_function(m_Chipmunk, "segment_area", rb_cpAreaForSegment, 3); rb_define_module_function(m_Chipmunk, "box_area", rb_cpAreaForBox, 2); rb_define_const(m_Chipmunk, "ALL_LAYERS", UINT2NUM((unsigned int)CP_ALL_LAYERS)); rb_define_const(m_Chipmunk, "NO_GROUP", UINT2NUM(CP_NO_GROUP)); rb_eval_string("Float::INFINITY = 1.0/0.0 unless Float.const_defined? :INFINITY"); rb_eval_string("CP::INFINITY = 1.0/0.0 unless CP.const_defined? :INFINITY"); Init_cpVect(); Init_cpBB(); Init_cpBody(); Init_cpShape(); Init_cpConstraint(); Init_cpSpace(); Init_cpArbiter(); }
//----------------------------------------------------------------// void moaicore::InitGlobals ( USGlobals* globals ) { static bool sysInit = true; if ( sysInit ) { cpInitChipmunk (); sysInit = false; } uslsext::InitGlobals ( globals ); MOAIXmlParser::Affirm (); MOAIActionMgr::Affirm (); MOAIInputMgr::Affirm (); MOAILogMgr::Affirm (); MOAINodeMgr::Affirm (); MOAIVertexFormatMgr::Affirm (); MOAIShaderMgr::Affirm (); MOAIGfxDevice::Affirm (); MOAIDraw::Affirm (); MOAIDebugLines::Affirm (); MOAIPartitionResultMgr::Affirm (); MOAISim::Affirm (); MOAILogMessages::RegisterDefaultLogMessages (); // MOAI REGISTER_LUA_CLASS ( MOAIAction ) REGISTER_LUA_CLASS ( MOAIActionMgr ) REGISTER_LUA_CLASS ( MOAIAnim ) REGISTER_LUA_CLASS ( MOAIAnimCurve ) REGISTER_LUA_CLASS ( MOAIButtonSensor ) REGISTER_LUA_CLASS ( MOAICameraAnchor2D ) REGISTER_LUA_CLASS ( MOAICameraFitter2D ) REGISTER_LUA_CLASS ( MOAIColor ) REGISTER_LUA_CLASS ( MOAICompassSensor ) REGISTER_LUA_CLASS ( MOAIDataBuffer ) REGISTER_LUA_CLASS ( MOAIDataIOAction ) REGISTER_LUA_CLASS ( MOAIDebugLines ) REGISTER_LUA_CLASS ( MOAIDeckRemapper ) REGISTER_LUA_CLASS ( MOAIDraw ) REGISTER_LUA_CLASS ( MOAIEnvironment ) REGISTER_LUA_CLASS ( MOAIEaseDriver ) REGISTER_LUA_CLASS ( MOAIEaseType ) REGISTER_LUA_CLASS ( MOAIFileSystem ) REGISTER_LUA_CLASS ( MOAIFont ) REGISTER_LUA_CLASS ( MOAIGfxDevice ) REGISTER_LUA_CLASS ( MOAIGfxQuad2D ) REGISTER_LUA_CLASS ( MOAIGfxQuadDeck2D ) REGISTER_LUA_CLASS ( MOAIGfxQuadListDeck2D ) REGISTER_LUA_CLASS ( MOAIGrid ) REGISTER_LUA_CLASS ( MOAIHttpTask ) REGISTER_LUA_CLASS ( MOAIImage ) REGISTER_LUA_CLASS ( MOAIIndexBuffer ) REGISTER_LUA_CLASS ( MOAIInputDevice ) REGISTER_LUA_CLASS ( MOAIInputMgr ) REGISTER_LUA_CLASS ( MOAIJoystickSensor ) REGISTER_LUA_CLASS ( MOAIJsonParser ) REGISTER_LUA_CLASS ( MOAIKeyboardSensor ) REGISTER_LUA_CLASS ( MOAILayer2D ) REGISTER_LUA_CLASS ( MOAILayerBridge2D ) //REGISTER_LUA_CLASS ( MOAILayoutFrame ) REGISTER_LUA_CLASS ( MOAILocationSensor ) REGISTER_LUA_CLASS ( MOAILogMgr ) REGISTER_LUA_CLASS ( MOAIMesh ) REGISTER_LUA_CLASS ( MOAIMotionSensor ) REGISTER_LUA_CLASS ( MOAIParser ) REGISTER_LUA_CLASS ( MOAIParticleDistanceEmitter ) REGISTER_LUA_CLASS ( MOAIParticleForce ) REGISTER_LUA_CLASS ( MOAIParticleScript ) REGISTER_LUA_CLASS ( MOAIParticleState ) REGISTER_LUA_CLASS ( MOAIParticleSystem ) REGISTER_LUA_CLASS ( MOAIParticleTimedEmitter ) REGISTER_LUA_CLASS ( MOAIPartition ) REGISTER_LUA_CLASS ( MOAIPointerSensor ) REGISTER_LUA_CLASS ( MOAIProp ) REGISTER_LUA_CLASS ( MOAIProp2D ) REGISTER_LUA_CLASS ( MOAIScriptDeck ) REGISTER_LUA_CLASS ( MOAIScriptNode ) REGISTER_LUA_CLASS ( MOAISerializer ) REGISTER_LUA_CLASS ( MOAIShader ) REGISTER_LUA_CLASS ( MOAISim ) REGISTER_LUA_CLASS ( MOAIStretchPatch2D ) REGISTER_LUA_CLASS ( MOAISurfaceDeck2D ) REGISTER_LUA_CLASS ( MOAITextBox ) REGISTER_LUA_CLASS ( MOAITexture ) REGISTER_LUA_CLASS ( MOAIThread ) REGISTER_LUA_CLASS ( MOAITileDeck2D ) REGISTER_LUA_CLASS ( MOAITimer ) REGISTER_LUA_CLASS ( MOAITouchSensor ) REGISTER_LUA_CLASS ( MOAITraits ) REGISTER_LUA_CLASS ( MOAITransform ) REGISTER_LUA_CLASS ( MOAIVertexBuffer ) REGISTER_LUA_CLASS ( MOAIVertexFormat ) REGISTER_LUA_CLASS ( MOAIViewport ) REGISTER_LUA_CLASS ( MOAIXmlParser ) #if USE_BOX2D REGISTER_LUA_CLASS ( MOAIBox2DArbiter ) REGISTER_LUA_CLASS ( MOAIBox2DBody ) REGISTER_LUA_CLASS ( MOAIBox2DDistanceJoint ) REGISTER_LUA_CLASS ( MOAIBox2DFixture ) REGISTER_LUA_CLASS ( MOAIBox2DFrictionJoint ) REGISTER_LUA_CLASS ( MOAIBox2DGearJoint ) REGISTER_LUA_CLASS ( MOAIBox2DLineJoint ) REGISTER_LUA_CLASS ( MOAIBox2DMouseJoint ) REGISTER_LUA_CLASS ( MOAIBox2DPrismaticJoint ) REGISTER_LUA_CLASS ( MOAIBox2DPulleyJoint ) REGISTER_LUA_CLASS ( MOAIBox2DRevoluteJoint ) REGISTER_LUA_CLASS ( MOAIBox2DWeldJoint ) REGISTER_LUA_CLASS ( MOAIBox2DWorld ) #endif #if USE_CHIPMUNK MOAICp::Affirm (); REGISTER_LUA_CLASS ( MOAICp ) REGISTER_LUA_CLASS ( MOAICpArbiter ) REGISTER_LUA_CLASS ( MOAICpBody ) REGISTER_LUA_CLASS ( MOAICpConstraint ) REGISTER_LUA_CLASS ( MOAICpShape ) REGISTER_LUA_CLASS ( MOAICpSpace ) #endif globals->PushFinalizer < MOAIGlobalsFinalizer >(); }
static iBOOL WordInit(void) { // 屏幕信息数组 iU32 * LcdInfoArr; if( i51AdeMmiGetScreenScale ( &ScreenWidth , &ScreenHeight ) == 0 ) { return iFALSE; } LcdInfoArr = i51AdeMmiGetPanel(); if( iNULL == LcdInfoArr ) { return iFALSE; } ScreenBuffer = (iU16 *) LcdInfoArr[1] ; KeyQueue = i51KitKeyInputQueueCreat(); if( iNULL==KeyQueue ) return iFALSE; cpInitChipmunk(); cpResetShapeIdCounter(); /// init space. mmSABSpace = cpSpaceNew(); mmSABSpace->iterations = 1; mmSABSpace->elasticIterations = 10; mmSABSpace->gravity = cpv(0, 0); mmSABSpace->sleepTimeThreshold = 0.2f;//0.2f; cpBody *body, *staticBody = &(mmSABSpace->staticBody); cpShape *shape; cpFloat radius = 2.0f; for(int i=1; i<60; i++ ) { for( int j = 1; j < 40; j++ ) { WordFlag[i][j] = 1; } } for(int i=0; i<320; i++ ) { for( int j = 0; j < 240; j++ ) { BackgroundType[i][j] = 1; } } // Create segments around the edge of the screen. //i51AdeOsLog(0, "cpSpaceAddShape 1"); // shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(0,0), cpv(239,0), 0.0f)); //i51AdeOsLog(0, "cpShapeSetElasticity"); // shape->e = 1.0f; // shape->u = 1.0f; // shape->layers= 0X7FFFFFFF; // cpShapeSetElasticity(shape, 1.0f); //i51AdeOsLog(0, "cpShapeSetFriction"); // mmSABSpace->fr = 1.0f; // cpShapeSetFriction(shape, 1.0f); //i51AdeOsLog(0, "cpShapeSetLayers"); // mmSABSpace-> // cpShapeSetLayers(shape, NOT_GRABABLE_MASK); //i51AdeOsLog(0, "cpSpaceAddShape 2"); shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(0,0), cpv(0,319), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers= 0X7FFFFFFF; // cpShapeSetElasticity(shape, 1.0f); // cpShapeSetFriction(shape, 1.0f); // cpShapeSetLayers(shape, NOT_GRABABLE_MASK); //i51AdeOsLog(0, "cpSpaceAddShape 3"); shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(239,0), cpv(239,319), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers= 0X7FFFFFFF; shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(0,319), cpv(239,319), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers= 0X7FFFFFFF; shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(0,30), cpv(110,140), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers= 0X7FFFFFFF; shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(110,200), cpv(110,140), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers= 0X7FFFFFFF; shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(110,200), cpv(90,319), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers= 0X7FFFFFFF; shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(239,30), cpv(135,140), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers= 0X7FFFFFFF; shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(135,200), cpv(135,140), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers= 0X7FFFFFFF; shape = cpSpaceAddShape(mmSABSpace, cpSegmentShapeNew(staticBody, cpv(135,200), cpv(155,319), 0.0f)); shape->e = 1.0f; shape->u = 1.0f; shape->layers= 0X7FFFFFFF; cpFloat mass = 1; cpFloat width = 10; cpFloat height = 20; cpFloat spacing = width*0.3; // Add lots of boxes. for(int i=0; i<CHAIN_COUNT; i++){ cpBody *prev = NULL; for(int j=0; j<LINK_COUNT; j++){ //i51AdeOsLog(0, "i=%d,j=%d",i,j); // cpVect pos = cpv(rand()%228+5,rand()%350-400); cpVect pos = cpv((j)*4+5,(i)*4+5); //i51AdeOsLog(0, "cpSpaceAddBody"); // body = cpSpaceAddBody(mmSABSpace, cpBodyNew(mass, cpMomentForBox(mass, width, height))); // body = cpSpaceAddBody(mmSABSpace, cpBodyNew(10.0f, cpMomentForCircle(30.0f, 0.0f, radius, cpvzero))); body = cpSpaceAddBody(mmSABSpace, cpBodyNew(60.0f, cpMomentForCircle(60.0f, 0.0f, radius, cpvzero))); cpBodySetPos(body, pos); cpBodySetID(body,i*LINK_COUNT+j); cpArray ** TempArr = (cpArray **)(mmSABSpace->bodies->arr+(i*LINK_COUNT+j)); cpBody * TempPoint = (cpBody *)(*(mmSABSpace->bodies->arr+(i*LINK_COUNT+j))); //i51AdeOsLog(0, "cpSpaceAddShape"); // shape = cpSpaceAddShape(mmSABSpace, cpBoxShapeNew(body, width, height)); shape = cpSpaceAddShape(mmSABSpace, cpCircleShapeNew(body, radius, cpvzero)); shape->e = 0.2f; shape->u = 0.01f; cpPolyShape * PolyShape = (cpPolyShape *)shape; // cpShapeSetFriction(shape, 0.8f); cpFloat breakingForce = 80000; cpConstraint *constraint = NULL; //i51AdeOsLog(0, "cpSpaceAddConstraint"); if(prev == NULL){ // constraint = cpSpaceAddConstraint(mmSABSpace, cpSlideJointNew(body, staticBody, cpv(0, -height/2), cpv(pos.x, 0), 0, spacing)); } else { // constraint = cpSpaceAddConstraint(mmSABSpace, cpSlideJointNew(body, prev, cpv(0, -height/2), cpv(0, height/2), 0, spacing)); } // constraint->maxForce = breakingForce; // constraint-> // cpConstraintSetMaxForce(constraint, breakingForce); // cpConstraintSetPostSolveFunc(constraint, BreakableJointPostSolve); prev = body; //i51AdeOsLog(0, "prev = body;"); } } //i51AdeOsLog(0, "cpSpaceAddBody"); // body = cpSpaceAddBody(mmSABSpace, cpBodyNew(10.0f, cpMomentForCircle(30.0f, 0.0f, radius, cpvzero))); //i51AdeOsLog(0, "cpBodySetPos"); // cpBodySetPos(body, cpv(130-radius, 320 - radius*2)); // body->v = cpv(0,-2000); //cpBodySetPos(body, cpv(120-radius, 0)); //i51AdeOsLog(0, "cpBodySetVel"); // cpBodySetVel(body, cpv(0, -300)); //i51AdeOsLog(0, "cpSpaceAddShape"); // shape = cpSpaceAddShape(mmSABSpace, cpCircleShapeNew(body, radius, cpvzero)); //shape->e = 0.0f; //shape->u = 0.9f; //i51AdeOsLog(0, "cpShapeSetElasticity"); // cpShapeSetElasticity(shape, 0.0f); //i51AdeOsLog(0, "cpShapeSetFriction"); // cpShapeSetFriction(shape, 0.9f); //i51AdeOsLog(0, "return mmSABSpace"); /* cpSpaceHash * activeShapes = mmSABSpace->activeShapes; cpHashSetBin **table = activeShapes->handleSet->table; int size = activeShapes->handleSet->size; for(int i=0;i<size;i++) { shape = (cpShape*)table[i]; if(shape) { if(shape->klass->type==CP_POLY_SHAPE) { iS32 Point[4][2]; cpPolyShape * PolyShape = (cpPolyShape *)shape; i51KitG2CleanScreen(0, 0); Point[0][0] = (iS32)PolyShape->verts[0].x; Point[0][1] = (iS32)PolyShape->verts[0].y; Point[1][0] = (iS32)PolyShape->verts[1].x; Point[1][1] = (iS32)PolyShape->verts[1].y; Point[2][0] = (iS32)PolyShape->verts[2].x; Point[2][1] = (iS32)PolyShape->verts[2].y; Point[3][0] = (iS32)PolyShape->verts[3].x; Point[3][1] = (iS32)PolyShape->verts[3].y; i51KitG2DrawPolygon(4,Point,0XFF00); i51KitG2Update(); } } } */ }
int main(int argc, char **argv) { int i, fileMenuId; cpArray *constraints; domino_t *dom; projectile_t *pj; if (!Sys_CreateWindow("Atlas2D", 800, 600, false)) { Sys_KillWindow(); return 0; } atlInitAtlas(); #ifdef __APPLE__ /* fileMenuId = Sys_CreateMenu("File"); Sys_AppendMenuItem(fileMenuId, "Open...", openCB); Sys_AppendMenuSeparator(fileMenuId); Sys_AppendMenuItem(fileMenuId, "Save", saveCB); Sys_AppendMenuItem(fileMenuId, "Save As...", saveAsCB); */ #endif g_FontBase = Sys_LoadBmpFont("Helvetica"); cpInitChipmunk(); initSpace(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); while (!atlEscapePressed) { update(); glClear(GL_COLOR_BUFFER_BIT); if (editorBody) { drawEditorPalette(); } render_cannon(g_Cannon); atlDrawPhysicsObject(platforms[0]->shape, g_Space); /* cpSpaceHashEach(g_Space->staticShapes, (cpSpaceHashIterator)atlDrawPhysicsObject, g_Space); cpSpaceHashEach(g_Space->activeShapes, (cpSpaceHashIterator)atlDrawPhysicsObject, g_Space); */ for (i = 0; i < MAX_DOMINOES; ++i) { dom = g_Dominoes[i]; if (!dom) continue; render_domino(dom); } for (i = 0; i < g_Cannon->ai; ++i) { pj = g_Cannon->ammo[i]; if (!pj) continue; render_projectile(pj); } constraints = g_Space->constraints; for (i = 0; i < constraints->num; ++i) { atlDrawConstraint((cpConstraint *)constraints->arr[i]); } Sys_SwapBuffers(); Sys_EventLoop(); } /* has to be called before the cpSpaceFree* functions because it removes * bodies and shapes itself */ FreeDominoes(); cpSpaceFreeChildren(g_Space); cpSpaceFree(g_Space); for (i = 0; i < MAX_PLATFORMS; ++i) { if (platforms[i]) free(platforms[i]); } if (g_Cannon) free(g_Cannon); atlFreeImages(); atlFreeBmpFont(g_FontBase); Sys_KillWindow(); return 0; }
PhysicsManager::PhysicsManager() : mStepTime(30.0f), mBufferedTime(0.0f) { cpInitChipmunk(); }
wyChipmunk::wyChipmunk() : m_space(cpSpaceNew()) { // set option // non-zero means use debug drawing logic m_options.debugDraw = 0; m_options.drawHash = 0; m_options.drawBBs = 0; m_options.drawShapes = 1; m_options.collisionPointSize = 0.f; m_options.bodyPointSize = 0.f; m_options.lineThickness = 1.0f; // init chipmunk cpInitChipmunk(); #if ANDROID // if first, we need init chipmunk and find field if(sFirstChipmunk) { // set flag sFirstChipmunk = false; // get env JNIEnv* env = getEnv(); // no jar flag bool noJava = false; // find field ids jclass clazz = env->FindClass(CLASS_SPACE); if(env->ExceptionOccurred() != NULL) { env->ExceptionClear(); noJava = true; } else { g_fid_Space_mPointer = env->GetFieldID(clazz, "mPointer", "I"); env->DeleteLocalRef(clazz); } if(!noJava) { clazz = env->FindClass(CLASS_BODY); g_fid_Body_mPointer = env->GetFieldID(clazz, "mPointer", "I");(clazz, "mPointer"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_SHAPE); g_fid_Shape_mPointer = env->GetFieldID(clazz, "mPointer", "I");(clazz, "mPointer"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_CONSTRAINT); g_fid_Constraint_mPointer = env->GetFieldID(clazz, "mPointer", "I");(clazz, "mPointer"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_ARBITER); g_fid_Arbiter_mPointer = env->GetFieldID(clazz, "mPointer", "I");(clazz, "mPointer"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_ITORQUEUPDATER); g_mid_ITorqueUpdater_updateTorque = env->GetMethodID(clazz, "updateTorque", "(IF)F"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_IFORCEUPDATER); g_mid_IForceUpdater_updateForce = env->GetMethodID(clazz, "updateForce", "(IF)F"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_IVELOCITYUPDATER); g_mid_IVelocityUpdater_updateVelocity = env->GetMethodID(clazz, "updateVelocity", "(IFFFF)V"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_IPOSITIONUPDATER); g_mid_IPositionUpdater_updatePosition = env->GetMethodID(clazz, "updatePosition", "(IF)V"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_IBODYVISITOR); g_mid_IBodyVisitor_visit = env->GetMethodID(clazz, "visit", "(ILjava/lang/Object;)V"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_IPOSTSTEPCALLBACK); g_mid_IPostStepCallback_postStep = env->GetMethodID(clazz, "postStep", "(Ljava/lang/Object;Ljava/lang/Object;)V"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_IPOINTQUERYCALLBACK); g_mid_IPointQueryCallback_onMatch = env->GetMethodID(clazz, "onMatch", "(ILjava/lang/Object;)V"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_ISEGMENTQUERYCALLBACK); g_mid_ISegmentQueryCallback_onMatch = env->GetMethodID(clazz, "onMatch", "(IFFFLjava/lang/Object;)V"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_SEGMENTQUERYINFO); g_fid_SegmentQueryInfo_shapePointer = env->GetFieldID(clazz, "shapePointer", "I"); g_fid_SegmentQueryInfo_distance = env->GetFieldID(clazz, "distance", "F"); g_fid_SegmentQueryInfo_normalX = env->GetFieldID(clazz, "normalX", "F"); g_fid_SegmentQueryInfo_normalY = env->GetFieldID(clazz, "normalY", "F"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_ICOLLISIONHANDLER); g_mid_ICollisionHandler_begin = env->GetMethodID(clazz, "begin", "(IILjava/lang/Object;)I"); g_mid_ICollisionHandler_preSolve = env->GetMethodID(clazz, "preSolve", "(IILjava/lang/Object;)I"); g_mid_ICollisionHandler_postSolve = env->GetMethodID(clazz, "postSolve", "(IILjava/lang/Object;)V"); g_mid_ICollisionHandler_separate = env->GetMethodID(clazz, "separate", "(IILjava/lang/Object;)V"); env->DeleteLocalRef(clazz); clazz = env->FindClass(CLASS_SHAPEANIMATION_CALLBACK); g_mid_ShapeAnimationCallback_onAnimationEnd = env->GetMethodID(clazz, "onAnimationEnd", "(I)V"); g_mid_ShapeAnimationCallback_onAnimationAborted = env->GetMethodID(clazz, "onAnimationAborted", "(I)V"); env->DeleteLocalRef(clazz); } } #endif // #if ANDROID }