bool ParticleFlower::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { // duration _duration = DURATION_INFINITY; // Gravity Mode setEmitterMode(Mode::GRAVITY); // Gravity Mode: gravity setGravity(Vec2(0,0)); // Gravity Mode: speed of particles setSpeed(80); setSpeedVar(10); // Gravity Mode: radial setRadialAccel(-60); setRadialAccelVar(0); // Gravity Mode: tangential setTangentialAccel(15); setTangentialAccelVar(0); // angle _angle = 90; _angleVar = 360; // emitter position Size winSize = Director::getInstance()->getWinSize(); this->setPosition(winSize.width/2, winSize.height/2); setPosVar(Vec2::ZERO); // life of particles _life = 4; _lifeVar = 1; // size, in pixels _startSize = 30.0f; _startSizeVar = 10.0f; _endSize = START_SIZE_EQUAL_TO_END_SIZE; // emits per second _emissionRate = _totalParticles/_life; // color of particles _startColor.r = 0.50f; _startColor.g = 0.50f; _startColor.b = 0.50f; _startColor.a = 1.0f; _startColorVar.r = 0.5f; _startColorVar.g = 0.5f; _startColorVar.b = 0.5f; _startColorVar.a = 0.5f; _endColor.r = 0.0f; _endColor.g = 0.0f; _endColor.b = 0.0f; _endColor.a = 1.0f; _endColorVar.r = 0.0f; _endColorVar.g = 0.0f; _endColorVar.b = 0.0f; _endColorVar.a = 0.0f; Texture2D* texture = getDefaultTexture(); if (texture != nullptr) { setTexture(texture); } // additive this->setBlendAdditive(true); return true; } return false; }
bool ParticleSmoke::initWithTotalParticles(int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { // duration _duration = DURATION_INFINITY; // Emitter mode: Gravity Mode setEmitterMode(Mode::GRAVITY); // Gravity Mode: gravity setGravity(Vector2(0,0)); // Gravity Mode: radial acceleration setRadialAccel(0); setRadialAccelVar(0); // Gravity Mode: speed of particles setSpeed(25); setSpeedVar(10); // angle _angle = 90; _angleVar = 5; // emitter position Size winSize = Director::getInstance()->getWinSize(); this->setPosition(Vector2(winSize.width/2, 0)); setPosVar(Vector2(20, 0)); // life of particles _life = 4; _lifeVar = 1; // size, in pixels _startSize = 60.0f; _startSizeVar = 10.0f; _endSize = START_SIZE_EQUAL_TO_END_SIZE; // emits per frame _emissionRate = _totalParticles/_life; // color of particles _startColor.r = 0.8f; _startColor.g = 0.8f; _startColor.b = 0.8f; _startColor.a = 1.0f; _startColorVar.r = 0.02f; _startColorVar.g = 0.02f; _startColorVar.b = 0.02f; _startColorVar.a = 0.0f; _endColor.r = 0.0f; _endColor.g = 0.0f; _endColor.b = 0.0f; _endColor.a = 1.0f; _endColorVar.r = 0.0f; _endColorVar.g = 0.0f; _endColorVar.b = 0.0f; _endColorVar.a = 0.0f; Texture2D* texture = getDefaultTexture(); if (texture != nullptr) { setTexture(texture); } // additive this->setBlendAdditive(false); return true; } return false; }
void Simulation::setGravity(float dx, float dy, float dz) { setGravity(Cloth::Vector3(dx, dy, dz)); }
Node::NodeSP SceneLoader::__loadPhysics(const QDomElement& og_component, Node::NodeSP dt_node) { Node::NodeSP node = dt_node; if ( !og_component.isNull() ) { QString name = og_component.attribute(SL_NAME); if ( node == nullptr ) { node = mScene->addChildNode(new Node(name + "_node")); QDomElement pos = og_component.firstChildElement(SL_POS); node->setPosition(pos.attribute(SL_X).toFloat(), pos.attribute(SL_Y).toFloat(), pos.attribute(SL_Z).toFloat()); } //get necessary attributes before initialize physics component QString shape = og_component.attribute(SL_PHYSICS_SHAPE); auto type = PhysicsBodyComponent::CONVEX; if ( shape == SL_PHYSICS_SHAPE_BOX ) { type = PhysicsBodyComponent::BOX; } else if ( shape == SL_PHYSICS_SHAPE_CYLINDER ) { type = PhysicsBodyComponent::CYLINDER; } else if ( shape == SL_PHYSICS_SHAPE_SPHERE ) { type = PhysicsBodyComponent::SPHERE; } else if ( shape == SL_PHYSICS_SHAPE_TRIMESH ) { type = PhysicsBodyComponent::TRIMESH; } //add physics component auto physics = node->addComponent<PhysicsBodyComponent>( new PhysicsBodyComponent(og_component.attribute(SL_PHYSICS_MESH_COM_NAME), name, type) ); //set physics attributes QDomElement res_move = og_component.firstChildElement(SL_PHYSICS_RESMOVE); QDomElement res_rotate = og_component.firstChildElement(SL_PHYSICS_RESROTATE); QDomElement gravity = og_component.firstChildElement(SL_PHYSICS_GRAVITY); physics->setRestrictMovement(res_move.attribute(SL_X).toFloat(), res_move.attribute(SL_Y).toFloat(), res_move.attribute(SL_Z).toFloat()); physics->setRestrictRotation(res_rotate.attribute(SL_X).toFloat(), res_move.attribute(SL_Y).toFloat(), res_move.attribute(SL_Z).toFloat()); physics->setMass(og_component.attribute(SL_PHYSICS_MASS).toFloat()); physics->setGravity(gravity.attribute(SL_X).toFloat(), gravity.attribute(SL_Y).toFloat(), gravity.attribute(SL_Z).toFloat()); QString enable = og_component.attribute(SL_COMPONENT_ENABLED); if ( enable == SL_TRUE ) { physics->enable(); } else if ( enable == SL_FALSE ) { physics->disable(); } } return node; }
bool OptionScene::init() { if (!Scene::init()) return false; Size visibleSize = Director::getInstance()->getVisibleSize(); //--·µ»Ø°´Å¥--// auto exitScene = [](Ref* pSender) { Director::getInstance()->replaceScene(TransitionFlipX::create(0.5f, MainScene::create(), TransitionScene::Orientation::LEFT_OVER)); }; auto backItem = MenuItemImage::create("UI/BackNormal.png", "UI/BackSelected.png", exitScene); backItem->setPosition(Vec2(backItem->getContentSize().width / 2 + 10, visibleSize.height - backItem->getContentSize().height / 2 - 10)); auto backMenu = Menu::create(backItem, NULL); backMenu->setPosition(Vec2::ZERO); this->addChild(backMenu); //--¸ù²Ëµ¥--// auto rootLayout = createLayout(Lang::get("optionTitle"), this->getContentSize()); this->addChild(rootLayout); auto list = ListView::create(); list->setDirection(ScrollView::Direction::VERTICAL); list->setGravity(ListView::Gravity::CENTER_HORIZONTAL); list->setBounceEnabled(true); list->setItemsMargin(10); list->setContentSize(Size(700, 480)); list->setAnchorPoint(Vec2(0.5f, 0.5f)); list->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2 - 20)); rootLayout->addChild(list); //--ÓïÑÔ°´Å¥--// auto langButton = createButton(Lang::get("selectLang"), Size(600, 60), [=](Ref* pSender) { auto button = (Button*)pSender; auto langLayout = createLayout(Lang::get("selectLang"), Size(600, 600)); auto langList = ListView::create(); langList->setDirection(ScrollView::Direction::VERTICAL); langList->setItemsMargin(10); langList->setGravity(ListView::Gravity::CENTER_HORIZONTAL); langList->setBounceEnabled(true); langList->setContentSize(Size(600, 480)); langList->setAnchorPoint(Vec2(0.5f, 0.5f)); langList->setPosition(Vec2(langLayout->getContentSize().width / 2, langLayout->getContentSize().height / 2 - 20)); langLayout->addChild(langList); auto langs = Lang::getAllLangs(); auto autoLangButton = createButton(Lang::get("autoLang"), Size(500, 60), [this](Ref* pSender) { auto button = static_cast<Button*> (pSender); highlightingButton->loadTextureNormal("UI/ButtonNormal.png"); highlightingButton->setContentSize(Size(500, 60)); highlightingButton = button; button->loadTextureNormal("UI/ButtonActive.png"); button->setContentSize(Size(500, 60)); Lang::setAutoLang(true); Lang::loadAutoLang(); }); if (Lang::isAutoLang()) { autoLangButton->loadTextureNormal("UI/ButtonActive.png"); autoLangButton->setContentSize(Size(500, 60)); highlightingButton = autoLangButton; } langList->addChild(autoLangButton); for (auto i : langs) { auto langButton = createButton(i.first, Size(500, 60), [i, this](Ref* pSender) { auto button = static_cast<Button*> (pSender); highlightingButton->loadTextureNormal("UI/ButtonNormal.png"); highlightingButton->setContentSize(Size(500, 60)); highlightingButton = button; button->loadTextureNormal("UI/ButtonActive.png"); button->setContentSize(Size(500, 60)); Lang::setAutoLang(false); Lang::loadLang(i.second); }); if (!Lang::isAutoLang() && i.second == Lang::getCurrentLang()) { langButton->loadTextureNormal("UI/ButtonActive.png"); langButton->setContentSize(Size(500, 60)); highlightingButton = langButton; } langList->addChild(langButton); } goInto(rootLayout, button, langLayout); backItem->setCallback([=](Ref* pSender) { goOut(rootLayout, button, langLayout); backItem->setCallback(exitScene); }); }); list->addChild(langButton); return true; }
bool ParticleExplosion::initWithTotalParticles(unsigned int numberOfParticles) { if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) ) { // duration _duration = 0.1f; setEmitterMode(Mode::GRAVITY); // Gravity Mode: gravity setGravity(Point(0,0)); // Gravity Mode: speed of particles setSpeed(70); setSpeedVar(40); // Gravity Mode: radial setRadialAccel(0); setRadialAccelVar(0); // Gravity Mode: tangential setTangentialAccel(0); setTangentialAccelVar(0); // angle _angle = 90; _angleVar = 360; // emitter position Size winSize = Director::getInstance()->getWinSize(); this->setPosition(Point(winSize.width/2, winSize.height/2)); setPosVar(Point::ZERO); // life of particles _life = 5.0f; _lifeVar = 2; // size, in pixels _startSize = 15.0f; _startSizeVar = 10.0f; _endSize = START_SIZE_EQUAL_TO_END_SIZE; // emits per second _emissionRate = _totalParticles/_duration; // color of particles _startColor.r = 0.7f; _startColor.g = 0.1f; _startColor.b = 0.2f; _startColor.a = 1.0f; _startColorVar.r = 0.5f; _startColorVar.g = 0.5f; _startColorVar.b = 0.5f; _startColorVar.a = 0.0f; _endColor.r = 0.5f; _endColor.g = 0.5f; _endColor.b = 0.5f; _endColor.a = 0.0f; _endColorVar.r = 0.5f; _endColorVar.g = 0.5f; _endColorVar.b = 0.5f; _endColorVar.a = 0.0f; Texture2D* texture = getDefaultTexture(); if (texture != NULL) { setTexture(texture); } // additive this->setBlendAdditive(false); return true; } return false; }
void TableSelect::initTable(Size visibleSize,Vec2 origin){ //layout left auto backgroundLeft = M9Path::create("tab_one.9.png",Size(visibleSize.width*0.2f,visibleSize.height*0.75f)); backgroundLeft->setPosition(origin.x,origin.y+ visibleSize.height/2-backgroundLeft->getContentSize().height/2); this->addChild(backgroundLeft); auto hoatdong = MLabel::create("Hoạt động",32); hoatdong->setPosition(Vec2(origin.x+backgroundLeft->getContentSize().width/2-hoatdong->getContentSize().width/2, backgroundLeft->getPosition().y+backgroundLeft->getContentSize().height -1.8f*hoatdong->getContentSize().height)); this->addChild(hoatdong); Layout* layoutLeft = Layout::create(); layoutLeft->setContentSize(Size(backgroundLeft->getWidth()-30,backgroundLeft->getHeight()*5/6)); layoutLeft->setPosition(Vec2(origin.x+15,origin.y+visibleSize.height*0.125f)); this->addChild(layoutLeft); auto lv1 = ListView::create(); //auto testxxx = MText::create("This is a notification xxxxxx!",15); //lv1->setItemModel(testxxx); for(int i=0;i<20;i++){ auto testxxx = MText::create("This is a notification xxxxxx!,nothing.don't look at me!please!",15); testxxx->ignoreContentAdaptWithSize(false); testxxx->setContentSize(Size(layoutLeft->getContentSize().width,testxxx->getHeight()*2)); lv1->pushBackCustomItem(testxxx); } lv1->setItemsMargin(10); //lv1->setBounceEnabled(true); lv1->setGravity(ListView::Gravity::LEFT); lv1->setContentSize(layoutLeft->getContentSize()); //lv1->setPosition(layoutLeft->getPosition()); lv1->setScrollBarEnabled(false); layoutLeft->addChild(lv1); //==========================Layout Right auto backgroundRight = M9Path::create("tab_two.9.png",Size(visibleSize.width*0.8f,visibleSize.height*0.75f)); backgroundRight->setPosition(origin.x+visibleSize.width*0.2f, origin.y+visibleSize.height/2-backgroundRight->getHeight()/2); this->addChild(backgroundRight); auto ban_so = MLabel::create("Bàn số ▿",32); ban_so->setPosition(Vec2(origin.x-ban_so->getWidth()/2 + visibleSize.width*0.32f, hoatdong->getPosition().y)); this->addChild(ban_so); auto tien_cuoc = MLabel::create("Tiền cược ▿",32); tien_cuoc->setPosition(Vec2(origin.x-tien_cuoc->getWidth()/2 + visibleSize.width*0.55f, hoatdong->getPosition().y)); this->addChild(tien_cuoc); auto trang_thai = MLabel::create("Trạng thái ▿",32); trang_thai->setPosition(Vec2(origin.x-trang_thai->getWidth()/2 + visibleSize.width*0.76f, hoatdong->getPosition().y)); this->addChild(trang_thai); auto khoa = MLabel::create("Khóa ▿",32); khoa->setPosition(Vec2(origin.x-khoa->getWidth()/2 + visibleSize.width*0.945f, hoatdong->getPosition().y)); this->addChild(khoa); Layout* layoutRight = Layout::create(); layoutRight->setContentSize(Size(backgroundRight->getWidth()-30,backgroundRight->getHeight()*5/6)); layoutRight->setPosition(Vec2(origin.x+15+backgroundLeft->getWidth(),origin.y+visibleSize.height*0.125f)); this->addChild(layoutRight); auto lvRight = ListView::create(); //auto model = Button::create(); //lvRight->setItemModel(model); for (int i=0; i<20; i++) { auto bkg_item = Sprite::create("bgr_list_item.png"); auto number_table = MLabel::create("6",30); auto money = MLabel::create("1000 xu",30); auto status = MLabel::create("xxx",30); auto lock = Sprite::create("ic_lock.png"); auto custom_item = Layout::create(); custom_item->setContentSize(Size(layoutRight->getContentSize().width,lock->getContentSize().height*2)); bkg_item->setScale(layoutRight->getContentSize().width/bkg_item->getContentSize().width, lock->getContentSize().height*2/bkg_item->getContentSize().height); bkg_item->setPosition(layoutRight->getContentSize().width/2,custom_item->getContentSize().height/2); number_table->setPosition(Vec2(number_table->getContentSize().width/2+backgroundRight->getContentSize().width/8, custom_item->getContentSize().height / 2.0f-number_table->getContentSize().height/2)); money->setPosition(Vec2(money->getContentSize().width/2+backgroundRight->getContentSize().width*2.5f/8, custom_item->getContentSize().height / 2.0f-money->getContentSize().height/2)); status->setPosition(Vec2(status->getContentSize().width/2+backgroundRight->getContentSize().width*5/8, custom_item->getContentSize().height / 2.0f-status->getContentSize().height/2)); lock->setPosition(Vec2(lock->getContentSize().width/2+backgroundRight->getContentSize().width*7/8, custom_item->getContentSize().height / 2.0f)); custom_item->addChild(bkg_item); custom_item->addChild(number_table); custom_item->addChild(money); custom_item->addChild(status); custom_item->addChild(lock); lvRight->pushBackCustomItem(custom_item); } lvRight->setItemsMargin(15); lvRight->setBounceEnabled(true); lvRight->setGravity(ListView::Gravity::LEFT); lvRight->setContentSize(layoutRight->getContentSize()); layoutRight->addChild(lvRight); //====== }
void setupInitialConditions() { auto species = speciesHandler.copyAndAddObject(LinearViscoelasticFrictionSpecies()); species->setDensity(constants::pi / 6.0); double stiffness = 1e5; setParticleDimensions(2); species->setDensity(2500); species->setStiffness(stiffness); species->setSlidingStiffness(2.0 / 7.0 * stiffness); species->setSlidingFrictionCoefficient(0.5); species->setRollingStiffness(2.0 / 5.0 * stiffness); species->setRollingFrictionCoefficient(0.5); species->setTorsionStiffness(2.0 / 5.0 * stiffness); species->setTorsionFrictionCoefficient(0.5); setGravity(Vec3D(0.0, 0.0, 0.0)); setTimeMax(8e-2); setTimeStep(2.0e-4); setFileType(FileType::NO_FILE); setXMin(0.0); setYMin(0.0); setXMax(1.0); setYMax(1.0); PeriodicBoundary b0; b0.set(Vec3D(1, 0, 0), getXMin(), getXMax()); boundaryHandler.copyAndAddObject(b0); b0.set(Vec3D(0, 1, 0), getYMin(), getYMax()); boundaryHandler.copyAndAddObject(b0); BaseParticle P0, P1, P2, P3, P4, P5, P6, P7; //Particle to be removed P0.setPosition(Vec3D(0.1, 0.1, 0.0)); P1.setPosition(Vec3D(0.3, 0.3, 0.0)); //Contacts starts normal becomes periodic P2.setPosition(Vec3D(0.6, 0.041, 0.0)); P2.setAngularVelocity(Vec3D(0.3, 0.6, 0.9)); P3.setPosition(Vec3D(0.4, 0.001, 0.0)); //Normal case P4.setPosition(Vec3D(0.6, 0.82, 0.0)); P4.setAngularVelocity(Vec3D(0.3, 0.6, 0.9)); P5.setPosition(Vec3D(0.4, 0.78, 0.0)); //Contact starts periodic becomes normal and periodic again P6.setPosition(Vec3D(0.02, 0.42, 0.0)); P6.setAngularVelocity(Vec3D(0.3, 0.6, 0.9)); P7.setPosition(Vec3D(0.82, 0.38, 0.0)); P0.setVelocity(Vec3D(0.0, 0.0, 0.0)); P1.setVelocity(Vec3D(0.0, 0.0, 0.0)); P2.setVelocity(Vec3D(-1.0, 0.0, 0.0)); P3.setVelocity(Vec3D(1.0, 0.0, 0.0)); P4.setVelocity(Vec3D(-1.0, 0.0, 0.0)); P5.setVelocity(Vec3D(1.0, 0.0, 0.0)); P6.setVelocity(Vec3D(-1.0, 0.0, 0.0)); P7.setVelocity(Vec3D(1.0, 0.0, 0.0)); P0.setRadius(0.1); P1.setRadius(0.1); P2.setRadius(0.1); P3.setRadius(0.1); P4.setRadius(0.1); P5.setRadius(0.1); P6.setRadius(0.1); P7.setRadius(0.1); particleHandler.copyAndAddObject(P0); particleHandler.copyAndAddObject(P1); particleHandler.copyAndAddObject(P2); particleHandler.copyAndAddObject(P3); particleHandler.copyAndAddObject(P4); particleHandler.copyAndAddObject(P5); particleHandler.copyAndAddObject(P6); particleHandler.copyAndAddObject(P7); }
void Simulation::configure(const config::Configuration& config) { // Resize world { auto size = config.get<SizeVector>("world-size"); if (size.getWidth() == Zero || size.getHeight() == Zero) throw config::Exception("Width or height is zero!"); setWorldSize(size); } // Time step setTimeStep(config.get<units::Time>("dt")); if (config.has("length-coefficient")) { m_converter.setLengthCoefficient(config.get<RealType>("length-coefficient")); } // Set gravity setGravity(config.get("gravity", getGravity())); // Number of iterations setIterations(config.get("iterations", getIterations())); // Background color setBackgroundColor(config.get("background", getBackgroundColor())); #if CONFIG_RENDER_TEXT_ENABLE setFontColor(config.get("text-color", getBackgroundColor().inverted())); #endif #if CONFIG_RENDER_TEXT_ENABLE setFontSize(config.get("text-size", getFontSize())); #endif #if CONFIG_RENDER_TEXT_ENABLE setSimulationTimeRender(config.get("show-simulation-time", isSimulationTimeRender())); #endif #ifdef CECE_ENABLE_RENDER setVisualized(config.get("visualized", isVisualized())); #endif // Parse plugins for (auto&& pluginConfig : config.getConfigurations("plugin")) { // Returns valid pointer or throws an exception requirePlugin(pluginConfig.get("name"))->configure(*this, pluginConfig); } // Parse parameters for (auto&& parameterConfig : config.getConfigurations("parameter")) { setParameter(parameterConfig.get("name"), units::parse(parameterConfig.get("value"))); } // Register user types for (auto&& typeConfig : config.getConfigurations("type")) { addObjectType({ typeConfig.get("name"), typeConfig.get("base"), typeConfig.toMemory() }); } // Parse init for (auto&& initConfig : config.getConfigurations("init")) { const String typeName = initConfig.has("language") ? initConfig.get("language") : initConfig.get("type"); auto initializer = getPluginContext().createInitializer(typeName); if (initializer) { // Configure initializer initializer->loadConfig(*this, initConfig); // Register initializer addInitializer(std::move(initializer)); } } // Parse modules for (auto&& moduleConfig : config.getConfigurations("module")) { // Get name auto name = moduleConfig.get("name"); if (hasModule(name)) continue; const String typeName = moduleConfig.has("language") ? moduleConfig.get("language") : moduleConfig.has("type") ? moduleConfig.get("type") : name ; auto module = getPluginContext().createModule(typeName, *this); if (module) { module->loadConfig(*this, moduleConfig); addModule(std::move(name), std::move(module)); } } // Parse programs for (auto&& programConfig : config.getConfigurations("program")) { const String typeName = programConfig.has("language") ? programConfig.get("language") : programConfig.get("type"); auto program = getPluginContext().createProgram(typeName); if (program) { // Configure program program->loadConfig(*this, programConfig); // Register program addProgram(programConfig.get("name"), std::move(program)); } } // Parse objects for (auto&& objectConfig : config.getConfigurations("object")) { // Create object auto object = buildObject( objectConfig.get("class"), objectConfig.get("type", object::Object::Type::Dynamic) ); if (object) object->configure(objectConfig, *this); } if (config.has("data-out-objects-filename")) { m_dataOutObjects = makeUnique<OutFileStream>(config.get("data-out-objects-filename")); *m_dataOutObjects << "iteration;totalTime;id;typeName;posX;posY;velX;velY\n"; } }
// ------------------------------------------------------ set gravity void ofxBox2d::setGravity(ofPoint pt) { setGravity(pt.x, pt.y); }
bool ColladaConverter::convert() { unsigned i; //succesfully loaded file, now convert data if (m_dom->getAsset() && m_dom->getAsset()->getUnit()) { domAsset::domUnitRef unit = m_dom->getAsset()->getUnit(); domFloat meter = unit->getMeter(); printf("asset unit meter=%f\n",meter); // m_unitMeterScaling = meter; } if ( m_dom->getAsset() && m_dom->getAsset()->getUp_axis() ) { domAsset::domUp_axis * up = m_dom->getAsset()->getUp_axis(); switch( up->getValue() ) { case UPAXISTYPE_X_UP: printf(" X is Up Data and Hiearchies must be converted!\n" ); printf(" Conversion to X axis Up isn't currently supported!\n" ); printf(" COLLADA_RT defaulting to Y Up \n" ); setGravity(CrtVec3f(-10,0,0)); setCameraInfo(btVector3(1,0,0),1); break; case UPAXISTYPE_Y_UP: printf(" Y Axis is Up for this file \n" ); printf(" COLLADA_RT set to Y Up \n" ); setGravity(CrtVec3f(0,-10,0)); setCameraInfo(btVector3(0,1,0),0); break; case UPAXISTYPE_Z_UP: printf(" Z Axis is Up for this file \n" ); printf(" All Geometry and Hiearchies must be converted!\n" ); setGravity(CrtVec3f(0,0,-10)); break; default: break; } } //we don't handle visual objects, physics objects are rered as such for (unsigned int s=0;s<m_dom->getLibrary_visual_scenes_array().getCount();s++) { domLibrary_visual_scenesRef scenesRef = m_dom->getLibrary_visual_scenes_array()[s]; for (unsigned int i=0;i<scenesRef->getVisual_scene_array().getCount();i++) { domVisual_sceneRef sceneRef = scenesRef->getVisual_scene_array()[i]; for (unsigned int n=0;n<sceneRef->getNode_array().getCount();n++) { domNodeRef nodeRef = sceneRef->getNode_array()[n]; nodeRef->getRotate_array(); nodeRef->getTranslate_array(); nodeRef->getScale_array(); } } } // Load all the geometry libraries for ( i = 0; i < m_dom->getLibrary_geometries_array().getCount(); i++) { domLibrary_geometriesRef libgeom = m_dom->getLibrary_geometries_array()[i]; printf(" CrtScene::Reading Geometry Library \n" ); for ( unsigned int i = 0; i < libgeom->getGeometry_array().getCount(); i++) { //ReadGeometry( ); domGeometryRef lib = libgeom->getGeometry_array()[i]; domMesh *meshElement = lib->getMesh(); if (meshElement) { // Find out how many groups we need to allocate space for int numTriangleGroups = (int)meshElement->getTriangles_array().getCount(); int numPolygonGroups = (int)meshElement->getPolygons_array().getCount(); int totalGroups = numTriangleGroups + numPolygonGroups; if (totalGroups == 0) { printf("No Triangles or Polygons found int Geometry %s \n", lib->getId() ); } else { //printf("Found mesh geometry (%s): numTriangleGroups:%i numPolygonGroups:%i\n",lib->getId(),numTriangleGroups,numPolygonGroups); } } domConvex_mesh *convexMeshElement = lib->getConvex_mesh(); if (convexMeshElement) { printf("found convexmesh element\n"); // Find out how many groups we need to allocate space for int numTriangleGroups = (int)convexMeshElement->getTriangles_array().getCount(); int numPolygonGroups = (int)convexMeshElement->getPolygons_array().getCount(); int totalGroups = numTriangleGroups + numPolygonGroups; if (totalGroups == 0) { printf("No Triangles or Polygons found in ConvexMesh Geometry %s \n", lib->getId() ); }else { printf("Found convexmesh geometry: numTriangleGroups:%i numPolygonGroups:%i\n",numTriangleGroups,numPolygonGroups); } }//fi }//for each geometry }//for all geometry libraries //m_dom->getLibrary_physics_models_array() for ( i = 0; i < m_dom->getLibrary_physics_scenes_array().getCount(); i++) { domLibrary_physics_scenesRef physicsScenesRef = m_dom->getLibrary_physics_scenes_array()[i]; for (unsigned int s=0;s<physicsScenesRef->getPhysics_scene_array().getCount();s++) { domPhysics_sceneRef physicsSceneRef = physicsScenesRef->getPhysics_scene_array()[s]; if (physicsSceneRef->getTechnique_common()) { if (physicsSceneRef->getTechnique_common()->getGravity()) { const domFloat3 grav = physicsSceneRef->getTechnique_common()->getGravity()->getValue(); printf("gravity set to %f,%f,%f\n",grav.get(0),grav.get(1),grav.get(2)); setGravity(CrtVec3f((float)grav.get(0),(float)grav.get(1),(float)grav.get(2))); } } for (unsigned int ps=0;ps<physicsSceneRef->getInstance_physics_model_array().getCount();ps++) { domInstance_physics_modelRef instance_physicsModelRef = physicsSceneRef->getInstance_physics_model_array()[ps]; daeElementRef ref = instance_physicsModelRef->getUrl().getElement(); domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; unsigned int p,r; for ( p=0;p<model->getInstance_physics_model_array().getCount();p++) { domInstance_physics_modelRef instancePhysicsModelRef = model->getInstance_physics_model_array()[p]; daeElementRef ref = instancePhysicsModelRef->getUrl().getElement(); domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; //todo: group some shared functionality in following 2 'blocks'. for (r=0;r<instancePhysicsModelRef->getInstance_rigid_body_array().getCount();r++) { domInstance_rigid_bodyRef instRigidbodyRef = instancePhysicsModelRef->getInstance_rigid_body_array()[r]; btScalar mass = 1.f; bool isDynamics = true; btCollisionShape* colShape = 0; btCompoundShape* compoundShape = 0; xsNCName bodyName = instRigidbodyRef->getBody(); domInstance_rigid_body::domTechnique_commonRef techniqueRef = instRigidbodyRef->getTechnique_common(); if (techniqueRef) { if (techniqueRef->getMass()) { mass = (btScalar)techniqueRef->getMass()->getValue(); } if (techniqueRef->getDynamic()) { isDynamics = techniqueRef->getDynamic()->getValue(); } } if (bodyName && model) { //try to find the rigid body for (unsigned int r=0;r<model->getRigid_body_array().getCount();r++) { domRigid_bodyRef rigidBodyRef = model->getRigid_body_array()[r]; if (rigidBodyRef->getSid() && !strcmp(rigidBodyRef->getSid(),bodyName)) { btRigidBodyOutput output; output.m_colShape = colShape; output.m_compoundShape = compoundShape; output.m_mass = 1.f; output.m_isDynamics = true; btRigidBodyInput rbInput; rbInput.m_rigidBodyRef2 = rigidBodyRef; rbInput.m_instanceRigidBodyRef = instRigidbodyRef; ConvertRigidBodyRef( rbInput , output ); mass = output.m_mass; isDynamics = output.m_isDynamics; colShape = output.m_colShape; compoundShape = output.m_compoundShape; } } ////////////////////// } if (compoundShape) colShape = compoundShape; if (colShape) { btRigidBodyInput input; input.m_instanceRigidBodyRef = instRigidbodyRef; input.m_rigidBodyRef2 = 0; input.m_bodyName = (char*)bodyName; PreparePhysicsObject(input, isDynamics,mass,colShape); } } } for (r=0;r<instance_physicsModelRef->getInstance_rigid_body_array().getCount();r++) { domInstance_rigid_bodyRef instRigidbodyRef = instance_physicsModelRef->getInstance_rigid_body_array()[r]; btScalar mass = 1.f; bool isDynamics = true; btCollisionShape* colShape = 0; btCompoundShape* compoundShape = 0; xsNCName bodyName = instRigidbodyRef->getBody(); domInstance_rigid_body::domTechnique_commonRef techniqueRef = instRigidbodyRef->getTechnique_common(); if (techniqueRef) { if (techniqueRef->getMass()) { mass = (btScalar)techniqueRef->getMass()->getValue(); } if (techniqueRef->getDynamic()) { isDynamics = techniqueRef->getDynamic()->getValue(); } } if (bodyName && model) { //try to find the rigid body for (unsigned int r=0;r<model->getRigid_body_array().getCount();r++) { domRigid_bodyRef rigidBodyRef = model->getRigid_body_array()[r]; if (rigidBodyRef->getSid() && !strcmp(rigidBodyRef->getSid(),bodyName)) { btRigidBodyOutput output; output.m_colShape = colShape; output.m_compoundShape = compoundShape; output.m_mass = 1.f; output.m_isDynamics = true; btRigidBodyInput rbInput; rbInput.m_rigidBodyRef2 = rigidBodyRef; rbInput.m_instanceRigidBodyRef = instRigidbodyRef; ConvertRigidBodyRef( rbInput , output ); mass = output.m_mass; isDynamics = output.m_isDynamics; colShape = output.m_colShape; compoundShape = output.m_compoundShape; } } ////////////////////// } if (compoundShape) colShape = compoundShape; if (colShape) { btRigidBodyInput input; input.m_instanceRigidBodyRef = instRigidbodyRef; input.m_rigidBodyRef2 = 0; input.m_bodyName = (char*)bodyName; PreparePhysicsObject(input, isDynamics,mass,colShape); } } //for each instance_rigid_body } //for each physics model //handle constraints for (unsigned int ma=0;ma<physicsSceneRef->getInstance_physics_model_array().getCount();ma++) { domInstance_physics_modelRef instance_physicsModelRef = physicsSceneRef->getInstance_physics_model_array()[ma]; daeElementRef ref = instance_physicsModelRef->getUrl().getElement(); domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; { ConstraintInput cInput; cInput.m_instance_physicsModelRef = instance_physicsModelRef; cInput.m_model = model; prepareConstraints(cInput); } //also don't forget the model's 'instance_physics_models! for ( unsigned int p=0;p<model->getInstance_physics_model_array().getCount();p++) { domInstance_physics_modelRef instancePhysicsModelRef = model->getInstance_physics_model_array()[p]; daeElementRef ref = instancePhysicsModelRef->getUrl().getElement(); domPhysics_modelRef model = *(domPhysics_modelRef*)&ref; ConstraintInput cInput; cInput.m_instance_physicsModelRef = instancePhysicsModelRef; cInput.m_model = model; prepareConstraints(cInput); } } //2nd time, for each physics model } } return true; }
void BulletInstance::setDefaultGravity() { setGravity(BulletConfig::gravity * METERS); }
ofxMSAPhysics* ofxMSAPhysics::setGravity(float gy) { setGravity(0, gy, 0); return this; }
void CIrrOdeWorld::initPhysics() { if (m_bPhysicsInitialized) return; m_iNodesInitialized=0; CIrrOdeSceneNode::initPhysics(); m_iWorldId=m_pOdeDevice->worldCreate(); m_iJointGroupId=m_pOdeDevice->jointGroupCreate(0); if (!m_pWorldSpace) m_pWorldSpace=new CIrrOdeSpace(this,m_pSceneManager); if (m_pWorldSpace!=NULL) m_pWorldSpace->initPhysics(); setLinearDamping (m_fDampingLinear ); setAngularDamping (m_fDampingAngular ); setLinearDampingThreshold (m_fDampingLinearThreshold ); setAngularDampingThreshold(m_fDampingAngularThreshold); setAutoDisableFlag (m_iAutoDisableFlag ); setAutoDisableLinearThreshold (m_fAutoDisableLinearThreshold ); setAutoDisableAngularThreshold(m_fAutoDisableAngularThreshold); setAutoDisableSteps (m_iAutoDisableSteps ); setAutoDisableTime (m_fAutoDisableTime ); setGravity(m_cGravity); if (m_fMaxAngularSpeed!=_DEFAULT_MAX_ANGULAR_SPEED) setMaxAngularSpeed(m_fMaxAngularSpeed); #ifdef _TRACE_INIT_PHYSICS printf("world created .. id=%i\n",(int)m_iWorldId); #endif irr::core::list<CIrrOdeSpace *>::Iterator s; for (s=m_pSpaces.begin(); s!=m_pSpaces.end(); s++) { #ifdef _TRACE_INIT_PHYSICS printf("CIrrOdeWorld::initPhysics: init space\n"); #endif CIrrOdeSpace *pSpace=(*s); pSpace->initPhysics(); } irr::core::list<CIrrOdeGeom *>::Iterator i; for (i=m_pGeoms.begin(); i!=m_pGeoms.end(); i++) { #ifdef _TRACE_INIT_PHYSICS printf("CIrrOdeWorld::initPhysics: init geom\n"); #endif CIrrOdeGeom *pGeom=(*i); pGeom->initPhysics(); } irr::core::list<CIrrOdeBody *>::Iterator b,ib2; for (b=m_pBodies.begin(); b!=m_pBodies.end(); b++) { #ifdef _TRACE_INIT_PHYSICS printf("CIrrOdeWorld::initPhysics: init body\n"); #endif CIrrOdeBody *b1=*b; b1->initPhysics(); } irr::core::list<irr::ode::IIrrOdeStepMotor *>::Iterator it; for (it=m_lStepMotors.begin(); it!=m_lStepMotors.end(); it++) (*it)->initPhysics(); m_bPhysicsInitialized = true; }