void Config::SaveConfigRule() { std::string file = Utils::getConfigFile(RULES_CONFIG); std::string tmp = file + "_tmp"; cInfo() << "Saving " << file << "..."; TiXmlDocument document; TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "UTF-8", ""); TiXmlElement *rulesnode = new TiXmlElement("calaos:rules"); rulesnode->SetAttribute("xmlns:calaos", "http://www.calaos.fr"); document.LinkEndChild(decl); document.LinkEndChild(rulesnode); for (int i = 0;i < ListeRule::Instance().size();i++) { Rule *rule = ListeRule::Instance().get_rule(i); rule->SaveToXml(rulesnode); } if (document.SaveFile(tmp)) { ecore_file_unlink(file.c_str()); ecore_file_mv(tmp.c_str(), file.c_str()); } cInfo() << "Done."; }
btRigidBody* BulletWorldControllerInst::AddLocalRigidBody(ork::ent::Entity* pent , btScalar mass, const btTransform& startTransform , btCollisionShape* shape) { OrkAssert(pent); // rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0, 0, 0); if(isDynamic && shape) shape->calculateLocalInertia(mass,localInertia); btMotionState *motionstate = new EntMotionState(startTransform, pent); btRigidBody::btRigidBodyConstructionInfo cInfo(mass, motionstate, shape, localInertia); btRigidBody *body = new btRigidBody(cInfo); body->setUserPointer(pent); body->setRestitution(1.0f); body->setFriction(1.0f); //body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); body->setUserPointer(pent); mDynamicsWorld->addRigidBody(body); if( mBWCBD.GetGravity().MagSquared() == 0.0f ) { body->setGravity(btVector3(0.0f, 0.0f, 0.0f)); } return body; }
GameObject::GameObject(btCollisionShape* pShape, float mass, const btVector3 &initialPosition, const btQuaternion &initialRotation) { isSprite = false; m_pShape = pShape; //m_color = color; btTransform transform; m_tempvector = initialPosition; m_temptransform = transform; transform.setIdentity(); transform.setOrigin(initialPosition); transform.setRotation(initialRotation); m_pMotionState = new DMotionState(transform); btVector3 localInertia(0,0,0); if (mass != 0.0f) pShape->calculateLocalInertia(mass, localInertia); btRigidBody::btRigidBodyConstructionInfo cInfo(mass, m_pMotionState, pShape, localInertia); m_pBody = new btRigidBody(cInfo); m_entity = NULL; m_mesh = NULL; m_sprite = NULL; }
btRigidBody* localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape) { bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) shape->calculateLocalInertia(mass,localInertia); btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia); box_body.push_back(new btRigidBody(cInfo)); box_body[box_body.size()-1]->setContactProcessingThreshold(m_defaultContactProcessingThreshold); m_dynamicsWorld->addRigidBody(box_body[box_body.size()-1]); return box_body[box_body.size()-1]; /* btRigidBody* body = new btRigidBody(cInfo); body->setContactProcessingThreshold(m_defaultContactProcessingThreshold); m_dynamicsWorld->addRigidBody(body); return body; */ }
void Config::saveStateCache() { Eet_File *ef; std::string file = Utils::getCacheFile("iostates.cache"); std::string tmp = file + "_tmp"; ConfigStateCache *cache; cache = new ConfigStateCache; cache->version = CONFIG_STATES_CACHE_VERSION; cache->states = cache_states; ef = eet_open(tmp.c_str(), EET_FILE_MODE_WRITE); if (!ef) { cWarning() << "Could not open iostates.cache for write !"; delete cache; return; } Eina_Bool ret = eet_data_write(ef, edd_cache, "calaos/states/cache", cache, EINA_TRUE); eet_close(ef); delete cache; if (ret) { ecore_file_unlink(file.c_str()); ecore_file_mv(tmp.c_str(), file.c_str()); } cInfo() << "State cache file written successfully (" << file << ")"; }
btRigidBody* AWPhysics::PhysicsManager::createRigidBody(float mass, const btTransform& startTransform, btCollisionShape* shape) { btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE)); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0, 0, 0); if (isDynamic) shape->calculateLocalInertia(mass, localInertia); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects #define USE_MOTIONSTATE 1 #ifdef USE_MOTIONSTATE btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btRigidBody::btRigidBodyConstructionInfo cInfo(mass, myMotionState, shape, localInertia); btRigidBody* body = new btRigidBody(cInfo); //body->setContactProcessingThreshold(m_defaultContactProcessingThreshold); #else btRigidBody* body = new btRigidBody(mass, 0, shape, localInertia); body->setWorldTransform(startTransform); #endif// body->setUserIndex(-1); m_dynamicsWorld->addRigidBody(body); return body; }
void DynamicCharacterController::setup (btScalar height, btScalar width, btScalar stepHeight) { btVector3 spherePositions[2]; btScalar sphereRadii[2]; sphereRadii[0] = width; sphereRadii[1] = width; spherePositions[0] = btVector3 (0.0, (height/btScalar(2.0) - width), 0.0); spherePositions[1] = btVector3 (0.0, (-height/btScalar(2.0) + width), 0.0); m_halfHeight = height/btScalar(2.0); m_shape = new btMultiSphereShape (&spherePositions[0], &sphereRadii[0], 2); btTransform startTransform; startTransform.setIdentity (); startTransform.setOrigin (btVector3(0.0, 2.0, 0.0)); btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btRigidBody::btRigidBodyConstructionInfo cInfo(1.0, myMotionState, m_shape); m_rigidBody = new btRigidBody(cInfo); // kinematic vs. static doesn't work //m_rigidBody->setCollisionFlags( m_rigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); m_rigidBody->setSleepingThresholds (0.0, 0.0); m_rigidBody->setAngularFactor (0.0); }
void Utils::initConfigOptions(char *configdir, char *cachedir, bool quiet) { if (configdir) _configBase = configdir; if (cachedir) _cacheBase = cachedir; std::string file = getConfigFile(LOCAL_CONFIG); if (!quiet) { cInfo() << "Using config path: " << getConfigFile(""); cInfo() << "Using cache path: " << getCacheFile(""); } if (!ecore_file_can_write(getConfigFile("").c_str())) throw (std::runtime_error("config path is not writable")); if (!ecore_file_can_write(getCacheFile("").c_str())) throw (std::runtime_error("cache path is not writable")); if (!fileExists(file)) { //create a defaut config std::ofstream conf(file.c_str(), std::ofstream::out); conf << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << std::endl; conf << "<calaos:config xmlns:calaos=\"http://www.calaos.fr\">" << std::endl; conf << "<calaos:option name=\"fw_version\" value=\"0\" />" << std::endl; conf << "</calaos:config>" << std::endl; conf.close(); set_config_option("fw_target", "calaos_tss"); set_config_option("fw_version", "0"); set_config_option("show_cursor", "true"); set_config_option("use_ntp", "true"); set_config_option("device_type", "calaos_server"); set_config_option("dpms_enable", "false"); set_config_option("smtp_server", ""); set_config_option("cn_user", "user"); set_config_option("cn_pass", "pass"); set_config_option("longitude", "2.322235"); set_config_option("latitude", "48.864715"); if (!quiet) std::cout << "WARNING: no local_config.xml found, generating default config with username: \"user\" and password: \"pass\"" << std::endl; } }
RobotPhysics* Physics::addRobot(Color clr, btVector3 pos, btVector3 rotation,float sizeRobot, float mass,Color colorPlayer,Color colorTeam){ btBoxShape* modelShape = new btBoxShape(btVector3(sizeRobot/2,sizeRobot/2,sizeRobot/2)); btCompoundShape* compound = new btCompoundShape(); btTransform localTrans; localTrans.setIdentity(); localTrans.setOrigin(btVector3(0.0,4.0,0)); compound->addChildShape(localTrans,modelShape); btTransform transRobot; transRobot.setIdentity(); transRobot.setOrigin(btVector3(pos.getX(),pos.getY(),pos.getZ())); if(rotation.length() != 0){ rotation *= PI/180; float rad = rotation.length(); btVector3 axis = rotation.normalize(); btQuaternion quat(axis,rad); transRobot.setRotation(quat); } btVector3 localInertia(0,0,0); compound->calculateLocalInertia(mass,localInertia); btMotionState* robotMotState = new btDefaultMotionState(transRobot); btRigidBody::btRigidBodyConstructionInfo cInfo(mass,robotMotState,compound,localInertia); btRigidBody* bdRobot = new btRigidBody(cInfo); bdRobot->setCollisionFlags(bdRobot->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); bdRobot -> setLinearVelocity(btVector3(0,0,0)); bdRobot -> setAngularVelocity(btVector3(0,0,0)); world->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs( bdRobot-> getBroadphaseHandle(), world -> getDispatcher() ); bdRobot->setIdDebug(1); bodies.push_back(new BulletObject(bdRobot,"robot",clr)); bodies[bodies.size()-1]->halfExt = modelShape->getHalfExtentsWithMargin(); bdRobot->setUserPointer(bodies[bodies.size()-1]); world->addRigidBody (bdRobot); RobotPhysics* localRobot = new RobotPhysics(pos,0.2,bdRobot,colorPlayer,colorTeam); localRobot->buildRobot(world); world-> addVehicle(localRobot-> getRaycast()); genRobots.push_back(localRobot); return localRobot; }
void Config::LoadConfigRule() { std::string file = Utils::getConfigFile(RULES_CONFIG); if (!Utils::fileExists(file)) { std::ofstream conf(file.c_str(), std::ofstream::out); conf << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << std::endl; conf << "<calaos:rules xmlns:calaos=\"http://www.calaos.fr\">" << std::endl; conf << "</calaos:rules>" << std::endl; conf.close(); } TiXmlDocument document(file); if (!document.LoadFile()) { cError() << "There was a parse error in " << file; cError() << document.ErrorDesc(); cError() << "In file " << file << " At line " << document.ErrorRow(); exit(-1); } TiXmlHandle docHandle(&document); TiXmlElement *rule_node = docHandle.FirstChildElement("calaos:rules").FirstChildElement().ToElement(); if (!rule_node) { cError() << "Error, <calaos:rules> node not found in file " << file; } for(; rule_node; rule_node = rule_node->NextSiblingElement()) { if (rule_node->ValueStr() == "calaos:rule" && rule_node->Attribute("name") && rule_node->Attribute("type")) { std::string name, type; name = rule_node->Attribute("name"); type = rule_node->Attribute("type"); Rule *rule = new Rule(type, name); rule->LoadFromXml(rule_node); ListeRule::Instance().Add(rule); } } cInfo() << "Done. " << ListeRule::Instance().size() << " rules loaded."; }
void VehicleObject::init_vehicle_physics(const Vector3f& box_size, const PhysObjInfo& info, const VehicleProperties& properties) { m_iright_index = 0; m_iup_index = 1; m_iforward_index = 2; set_vehicle_properties(properties); m_box_size = btVector3((btScalar)box_size.x, (btScalar)box_size.y, (btScalar)box_size.z); //Physics stuff btCollisionShape* pChassisShape = new btBoxShape(m_box_size); m_pListOfCollisionShapes.push_back(pChassisShape); btCompoundShape* pCompoundShape = new btCompoundShape(); m_pListOfCollisionShapes.push_back(pCompoundShape); btTransform localTrans; localTrans.setIdentity(); localTrans.setOrigin(btVector3(0, 1, 0)); pCompoundShape->addChildShape(localTrans, pChassisShape); //Setup chassis btTransform chassisTrans; chassisTrans.setIdentity(); chassisTrans.setOrigin(btVector3(0, 0, 0)); btVector3 localInertia(0, 0, 0); pCompoundShape->calculateLocalInertia(info.mass, localInertia); btDefaultMotionState* vehicleMotionState = new btDefaultMotionState(chassisTrans); btRigidBody::btRigidBodyConstructionInfo cInfo(info.mass, vehicleMotionState, pCompoundShape, localInertia); if(m_rbody) { delete m_rbody; m_rbody = 0; } m_rbody = new btRigidBody(cInfo); m_rbody->setContactProcessingThreshold(1e18f); m_rbody->setUserPointer(&m_entity_id); //initialise other parts of the vehicle init_engine(); init_vehicle(); init_wheels(); }
void Config::LoadConfigIO() { std::string file = Utils::getConfigFile(IO_CONFIG); if (!Utils::fileExists(file)) { std::ofstream conf(file.c_str(), std::ofstream::out); conf << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << std::endl; conf << "<calaos:ioconfig xmlns:calaos=\"http://www.calaos.fr\">" << std::endl; conf << "<calaos:home></calaos:home>" << std::endl; conf << "</calaos:ioconfig>" << std::endl; conf.close(); } TiXmlDocument document(file); if (!document.LoadFile()) { cError() << "There was a parse error"; cError() << document.ErrorDesc(); cError() << "In file " << file << " At line " << document.ErrorRow(); exit(-1); } TiXmlHandle docHandle(&document); TiXmlElement *room_node = docHandle.FirstChildElement("calaos:ioconfig").FirstChildElement("calaos:home").FirstChildElement().ToElement(); for(; room_node; room_node = room_node->NextSiblingElement()) { if (room_node->ValueStr() == "calaos:room" && room_node->Attribute("name") && room_node->Attribute("type")) { std::string name, type; int hits = 0; name = room_node->Attribute("name"); type = room_node->Attribute("type"); if (room_node->Attribute("hits")) room_node->Attribute("hits", &hits); Room *room = new Room(name, type, hits); ListeRoom::Instance().Add(room); room->LoadFromXml(room_node); } } cInfo() << "Done. "; }
void ChunkBase::initPhysicsBody() { if (mPhysicsAttached) deactivatePhysicsBody(); if (mIsModified) generateVertices(); if (isEmpty) return; btCollisionShape* newShape; btTriangleIndexVertexArray* newIvArray = new btTriangleIndexVertexArray(); btIndexedMesh mesh; mesh.m_numTriangles = mNumIndices / 3; mesh.m_triangleIndexBase = (const unsigned char *) mIndices; mesh.m_triangleIndexStride = 3 * sizeof(uint16_t); mesh.m_numVertices = mNumVertices; mesh.m_vertexBase = (const unsigned char *) mVertices; mesh.m_vertexStride = VertexSize * sizeof(float); newIvArray->addIndexedMesh(mesh, PHY_SHORT); newShape = new btBvhTriangleMeshShape(newIvArray, true); newShape->setMargin(0.1f); if (mPhysicsBody == 0) { btTransform trans; trans.setIdentity(); trans.setOrigin(btVector3((btScalar) (btScalar) (mX * ChunkSizeX), (btScalar) (mY * ChunkSizeY), (btScalar) (mZ * ChunkSizeZ))); btMotionState* mState = new btDefaultMotionState(trans); btRigidBody::btRigidBodyConstructionInfo cInfo(0.0f, mState, newShape); mPhysicsBody = new btRigidBody(cInfo); mPhysicsBody->setCollisionFlags(mPhysicsBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT); } else { mPhysicsBody->setCollisionShape(newShape); } if (mPhysicsIvArray != 0) { delete mPhysicsIvArray; } mPhysicsIvArray = newIvArray; if (mPhysicsShape != 0) { delete mPhysicsShape; } mPhysicsShape = newShape; }
void NTPClock::updateClock() { if (exe) return; if (Utils::get_config_option("use_ntp") == "true") { handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _NTPHandle1, this); cInfo() << "NTPClock::updateClock() Updating clock..."; std::string cmd = "/usr/sbin/ntpdate calaos.fr"; exe = ecore_exe_run(cmd.c_str(), NULL); } }
btRigidBody* StaticObject::createRigidBody(const btTransform& _startTransform, btCollisionShape* _shape, MyMotionState* _myMotionState, float _mass, const btVector3& _overrideInertia /* = btVector3(0.f, 0.f, 0.f) */) { btAssert(!_shape || _shape->getShapeType() != INVALID_SHAPE_PROXYTYPE); btAssert(_myMotionState); btVector3 localInertia = _overrideInertia; if (_mass != 0.f && localInertia.isZero()) _shape->calculateLocalInertia(_mass, localInertia); btRigidBody::btRigidBodyConstructionInfo cInfo(_mass, _myMotionState, _shape, localInertia); btRigidBody* body = new btRigidBody(cInfo); body->setContactProcessingThreshold(BT_LARGE_FLOAT); return body; }
//RigidBody void PhysicsObject::createRigidBody(float mass, float friction, float restitution) { bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) this->collisionShape->calculateLocalInertia(mass,localInertia); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(btTransform::getIdentity()); btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,this->collisionShape,localInertia); this->rigidBody = new btRigidBody(cInfo); this->rigidBody->setContactProcessingThreshold(BT_LARGE_FLOAT); this->rigidBody->setFriction(friction); this->rigidBody->setRestitution(restitution); this->rigidBody->setCcdMotionThreshold(.1f); this->rigidBody->setCcdSweptSphereRadius(.1f); }
void ActionMail::sendMail() { std::string tmpFile; int cpt = 0; //Get a temporary filename do { tmpFile = "/tmp/calaos_mail_body_"; tmpFile += Utils::to_string(cpt); cpt++; } while (ecore_file_exists(tmpFile.c_str())); //Write body message to a temp file std::ofstream ofs; ofs.open(tmpFile.c_str(), std::ofstream::trunc); ofs << mail_message; ofs.close(); std::stringstream cmd; cmd << Prefix::Instance().binDirectoryGet(); cmd << "/calaos_mail"; if (ecore_file_exists(cmd.str().c_str())) { cmd << " "; cmd << "--delete "; //force temp file deletion after mail is sent if (Utils::get_config_option("smtp_debug") == "true") cmd << "--verbose "; cmd << "--from \"" << mail_sender << "\" "; cmd << "--to \"" << mail_recipients << "\" "; cmd << "--subject \"" << mail_subject << "\" "; cmd << "--body " << tmpFile << " "; if (!mail_attachment_tfile.empty()) cmd << "--attach " << mail_attachment_tfile; cInfo() << "Executing command : " << cmd.str(); ecore_exe_run(cmd.str().c_str(), NULL); } else { cError() << "Command " << cmd.str() << " not found"; } }
void RigidBody::init( const Format &format ) { mType = getPhyObjType( format.mCollShape->getName() ); mCollGroup = format.mCollisionGroup; mCollMask = format.mCollisionMask; mCollisionShape = format.mCollShape; mCollisionShape->setLocalScaling( toBullet(format.mInitialScale) ); recalculateBoundingSphere(); btVector3 localInertia(0,0,0); if( format.mMass != 0.0f && ! format.mSetKinematic ) { mCollisionShape->calculateLocalInertia( format.mMass, localInertia ); } mMotionState = format.mMotionState; btRigidBody::btRigidBodyConstructionInfo cInfo( format.mMass, mMotionState.get(), mCollisionShape.get(), localInertia ); cInfo.m_friction = format.mFriction; cInfo.m_restitution = format.mRestitution; mRigidBody.reset( new btRigidBody(cInfo) ); if( format.mSetKinematic ) { mRigidBody->setCollisionFlags( mRigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT ); setActivationState( DISABLE_DEACTIVATION ); } if( format.mAddToWorld ) { Context()->addRigidBody( mRigidBody.get(), mCollGroup, mCollMask ); mAddedToWorld = true; } if( ! mMotionState ) { btTransform trans; trans.setOrigin( toBullet( format.mInitialPosition ) ); trans.setRotation( toBullet( format.mInitialRotation ) ); mRigidBody->setWorldTransform( trans ); } mRigidBody->setUserPointer( format.mRigidBodyUserPtr ? format.mRigidBodyUserPtr : this ); }
void NTPClock::applyCalendarFromServer(std::string source, std::string s, void *listener_data, void* sender_data) { if (networkCmdCalendarApply[2] == "ntp_on") { cInfo() << "Enabling NTP"; enable(true); int timeZone; std::istringstream iss(networkCmdCalendarApply[3]); iss >> timeZone; cApply.timeZone.current = timeZone; cApply.applyTimezone(); updateClock(); }
btRigidBody * btSimpleDynamicsWorld::localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape) { // Create a rigid body for a body part and add it to the physics world btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE)); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); // Test if dynamic object btVector3 localInertia(0,0,0); // Create inertia matrix if (isDynamic) shape->calculateLocalInertia(mass,localInertia); // Calculate inertia matrix from primitive shape and mass //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); // Create default motion state btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia); // Create rigid body info structure btRigidBody* body = new btRigidBody(cInfo); // Create new rigid body //body->setContactProcessingThreshold(m_defaultContactProcessingThreshold); // Default Contact Threshold addRigidBody(body); // Add body to the physics world return body;// Return the body pointer }
void Config::loadStateCache() { ConfigStateCache *cache; std::string file = Utils::getCacheFile("iostates.cache"); Eet_File *ef = eet_open(file.c_str(), EET_FILE_MODE_READ); if (!ef) { cWarning() << "Could not open iostates.cache for read !"; return; } cache = (ConfigStateCache *)eet_data_read(ef, edd_cache, "calaos/states/cache"); if (!cache) { eet_close(ef); cWarning() << "Could not read iostates.cache, corrupted file?"; return; } if (cache->version < CONFIG_STATES_CACHE_VERSION) { cWarning() << "File version too old, upgrading to new format"; cache->version = CONFIG_STATES_CACHE_VERSION; } //read all states and put it in cache_states Eina_Iterator *it = eina_hash_iterator_tuple_new(cache->states); void *data; while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = (Eina_Hash_Tuple *)data; ConfigStateValue *state = (ConfigStateValue *)t->data; std::string skey = state->id; std::string svalue = state->value; SaveValueIO(skey, svalue, false); } eina_iterator_free(it); eina_hash_free(cache->states); free(cache); eet_close(ef); cInfo() << "States cache read successfully."; }
btRigidBody* World::CreateRigidBody(float mass, const btTransform &startTransform, btCollisionShape *shape) { btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE)); //rigidbody is dynamic if and only if mass is non zero, otherwise static bool isDynamic = (mass != 0.f); btVector3 localInertia(0,0,0); if (isDynamic) shape->calculateLocalInertia(mass, localInertia); //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform); btRigidBody::btRigidBodyConstructionInfo cInfo(mass, myMotionState, shape, localInertia); btRigidBody* body = new btRigidBody(cInfo); return body; }
RigidBodyBullet::RigidBodyBullet() : RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_RIGID_BODY), kinematic_utilities(NULL), locked_axis(0), gravity_scale(1), mass(1), linearDamp(0), angularDamp(0), can_sleep(true), omit_forces_integration(false), restitution_combine_mode(PhysicsServer::COMBINE_MODE_INHERIT), friction_combine_mode(PhysicsServer::COMBINE_MODE_INHERIT), force_integration_callback(NULL), isTransformChanged(false), previousActiveState(true), maxCollisionsDetection(0), collisionsCount(0), maxAreasWhereIam(10), areaWhereIamCount(0), countGravityPointSpaces(0), isScratchedSpaceOverrideModificator(false) { godotMotionState = bulletnew(GodotMotionState(this)); // Initial properties const btVector3 localInertia(0, 0, 0); btRigidBody::btRigidBodyConstructionInfo cInfo(mass, godotMotionState, compoundShape, localInertia); btBody = bulletnew(btRigidBody(cInfo)); setupBulletCollisionObject(btBody); set_mode(PhysicsServer::BODY_MODE_RIGID); reload_axis_lock(); areasWhereIam.resize(maxAreasWhereIam); for (int i = areasWhereIam.size() - 1; 0 <= i; --i) { areasWhereIam.write[i] = NULL; } btBody->setSleepingThresholds(0.2, 0.2); }
GameObject::GameObject(btCollisionShape* pShape, float mass, const btVector3 &color, const btVector3 &initialPosition, const btQuaternion &initialRotation) { // store the shape for later usage m_pShape = pShape; // store the color m_color = color; // create the initial transform btTransform transform; transform.setIdentity(); transform.setOrigin(initialPosition); transform.setRotation(initialRotation); // create the motion state from the // initial transform m_pMotionState = new OpenGLMotionState(transform); // calculate the local inertia btVector3 localInertia(0, 0, 0); // objects of infinite mass can't // move or rotate if (mass != 0.0f) pShape->calculateLocalInertia(mass, localInertia); // create the rigid body construction // info using the mass, motion state // and shape btRigidBody::btRigidBodyConstructionInfo cInfo(mass, m_pMotionState, pShape, localInertia); // create the rigid body m_pBody = new btRigidBody(cInfo); }
/* ----------------------------------------------------------------------- | build bullet height field shape and generate ogre mesh from grayscale image | | @param in : | @param out: raw data of height field terrain | ToDo: adjest grid scale, grid height, local scale, max/min height ----------------------------------------------------------------------- */ bool buildHeightFieldTerrainFromImage(const Ogre::String& filename, btDynamicsWorld* dynamicsWorld, btAlignedObjectArray<btCollisionShape*>& collisionShapes, void* &data) { Ogre::Image img; try { img.load(filename, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); } catch(Ogre::Exception err) { LOG(err.what()); return false; } size_t grid_w = 65, grid_h = 65; // must be (2^N) + 1 size_t grid_max_w = 129, grid_max_h = 129; // must be (2^N) + 1 size_t img_w = img.getWidth(); size_t img_h = img.getHeight(); // validate image size is (2^N) + 1 if ((img_w-1) & (img_w-2)) img_w = grid_w; if ((img_h-1) & (img_h-2)) img_h = grid_h; //if (img_w > grid_max_w) img_w = grid_max_w; //if (img_h > grid_max_h) img_h = grid_max_h; LOG("LoadImage name=%s, width=%d, height=%d, width^2+1=%d, height^2+1=%d", filename.c_str(), img.getWidth(), img.getHeight(), img_w, img_h); img.resize(img_w, img_h); size_t pixelSize = Ogre::PixelUtil::getNumElemBytes(img.getFormat()); size_t bufSize = img.getSize() / pixelSize; data = new Ogre::Real[ bufSize ]; Ogre::Real* dest = static_cast<Ogre::Real*>(data); memset(dest, 0, bufSize); /* | @ Notice the alignment problem | - uchar to float alignment | - pixel format in bytes as rawdata type, also affects alignment */ Ogre::uchar* src = img.getData(); for (size_t i=0;i<bufSize;++i) { dest[i] = ((Ogre::Real)src[i * pixelSize] - 127.0f)/16.0f; } // parameter int upAxis = 1; btScalar gridSpacing = 5.0f; btScalar gridHeightScale = 0.2f; btScalar minHeight = -10.0f; btScalar maxHeight = 10.0f; btScalar defaultContactProcessingThreshold = BT_LARGE_FLOAT; btHeightfieldTerrainShape *heightfieldShape = new btHeightfieldTerrainShape(img_w, img_h, dest, gridHeightScale, minHeight, maxHeight, upAxis, PHY_FLOAT, false); btAssert(heightfieldShape && "null heightfield"); // shape btVector3 localScaling(1.0f, 1.0f, 1.0f); heightfieldShape->setLocalScaling(localScaling); collisionShapes.push_back(heightfieldShape); // rigidBody btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0))); btRigidBody::btRigidBodyConstructionInfo cInfo(0, motionState, heightfieldShape, btVector3(0,0,0)); btRigidBody* rigidBody = new btRigidBody(cInfo); rigidBody->setContactProcessingThreshold(defaultContactProcessingThreshold); int flags = rigidBody->getCollisionFlags(); rigidBody->setCollisionFlags(flags | btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT); dynamicsWorld->addRigidBody(rigidBody); // add ogre height field mesh Ogre::SceneManager* sceneMgr = Ogre::Root::getSingletonPtr()->getSceneManager("DefaultSceneManager"); btAssert(sceneMgr); Ogre::ManualObject* obj = sceneMgr->createManualObject("btHeightFieldEntity"); btVector3 aabbMin, aabbMax; heightfieldShape->getAabb(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)), aabbMin, aabbMax); btHeightFieldProcessor callback(obj, "DefaultPlane"); heightfieldShape->processAllTriangles(&callback, aabbMin, aabbMax); sceneMgr->getRootSceneNode()->attachObject(obj); return true; }
void TimeRange::computeSunSetRise(int year, int month, int day, int &rise_hour, int &rise_min, int &set_hour, int &set_min) { if (year == cyear && month == cmonth && day == cday && (sunrise_hour_cache != 0 || sunrise_min_cache != 0 || sunset_hour_cache != 0 || sunset_min_cache != 0)) { rise_hour = sunrise_hour_cache; rise_min = sunrise_min_cache; set_hour = sunset_hour_cache; set_min = sunset_min_cache; return; } double longitude; double latitude; Params opt; get_config_options(opt); if (!opt.Exists("longitude") || !opt.Exists("latitude")) { longitude = 2.548828; latitude = 46.422713; cError() << "Horaire: To use sunset/sunrise, you have to set your longitude/latitude in configuration!"; cError() << "Horaire: Please go to the webpage of the server to set these parameters."; } else { from_string(get_config_option("longitude"), longitude); from_string(get_config_option("latitude"), latitude); } double rise, set; int res; cInfo() << "Horaire: Computing sunrise/sunset for date " << day << "/" << month << "/" << year; res = sun_rise_set(year, month, day, longitude, latitude, &rise, &set); if (res != 0) { rise_hour = 0; rise_min = 0; set_hour = 0; set_min = 0; cError() << "Horaire: Error in sunset/sunrise calculation!"; return; } long tzOffset = getTimezoneOffset(); rise_min = minutes(rise + minutes((double)tzOffset / 3600.0)); rise_hour = hours(rise + (double)tzOffset / 3600.0); set_min = minutes(set + minutes((double)tzOffset / 3600.0)); set_hour = hours(set + (double)tzOffset / 3600.0); std::stringstream streamrise, streamset; streamrise << std::setfill('0') << std::setw(2) << rise_hour << ":" << rise_min; streamset << std::setfill('0') << std::setw(2) << set_hour << ":" << set_min; cInfo() << "Horaire: sunrise is at " << streamrise.str() << " and sunset is at " << streamset.str(); sunrise_hour_cache = rise_hour; sunrise_min_cache = rise_min; sunset_hour_cache = set_hour; sunset_min_cache = set_min; cyear = year; cmonth = month; cday = day; }
ApplicationMain::ApplicationMain(int argc, char **argv) { cInfo() << "Calaos Home, starting..."; if (system("killall -9 eskiss 2> /dev/null") == -1) cCritical() << "Error forking !"; //init random generator srand(time(NULL)); //Init SSL and CURL SSL_load_error_strings(); SSL_library_init(); curl_global_init(CURL_GLOBAL_ALL); char *themefile = argvOptionParam(argv, argv + argc, "--theme"); if (themefile) { ApplicationMain::theme = themefile; cInfo() << "Using specified theme file: " << ApplicationMain::getTheme(); } else { ApplicationMain::theme = Prefix::Instance().dataDirectoryGet() + "/default.edj"; if (ecore_file_exists(ApplicationMain::theme.c_str())) cInfo() << "Using theme file " << theme; else cError() << theme << " Not found!"; } //Init efl core if (!eina_init()) throw (runtime_error("Unable to init Eina")); if (!ecore_init()) throw (runtime_error("Unable to init Ecore")); if (!ecore_con_init()) throw (runtime_error("Unable to init Ecore-Con")); if (!ecore_con_url_init()) throw (runtime_error("Unable to init Ecore-Con-Url")); if (!evas_init()) throw (runtime_error("Unable to init Evas")); if (!ecore_evas_init()) throw (runtime_error("Unable to init Ecore-Evas")); if (!edje_init()) throw (runtime_error("Unable to init Edje")); edje_frametime_set(1.0 / 60.0); edje_scale_set(1.0); if (!elm_init(argc, argv)) throw (runtime_error("Unable to init Elementary")); //Load Calaos specific ELM extensions elm_theme_extension_add(NULL, ApplicationMain::getTheme()); //Create the main window window = elm_win_add(NULL, "calaos-home", ELM_WIN_BASIC); elm_win_title_set(window, "Calaos Home"); elm_win_borderless_set(window, true); bool bFullscreen = argvOptionCheck(argv, argv + argc, "--fullscreen"); elm_win_fullscreen_set(window, bFullscreen); //Automatically quit main loop when the window is closed elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); elm_win_autodel_set(window, true); if (argvOptionCheck(argv, argv + argc, "--set-elm-config")) { //force setting the correct elementary options for touchscreen elm_config_finger_size_set(10); elm_config_scroll_bounce_enabled_set(true); elm_config_scroll_thumbscroll_enabled_set(true); elm_config_scroll_thumbscroll_threshold_set(24); elm_config_scroll_thumbscroll_momentum_threshold_set(100.0); elm_config_scroll_bounce_friction_set(0.5); elm_config_scroll_page_scroll_friction_set(0.5); elm_config_scroll_bring_in_scroll_friction_set(0.5); elm_config_scroll_zoom_friction_set(0.5); elm_config_scroll_thumbscroll_friction_set(1.0); elm_config_scroll_thumbscroll_border_friction_set(0.5); elm_config_scroll_thumbscroll_sensitivity_friction_set(0.25); } evas_object_event_callback_add(window, EVAS_CALLBACK_RESIZE, _window_resize_cb, this); evas = evas_object_evas_get(window); Evas_Object *bg = elm_bg_add(window); evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(window, bg); evas_object_show(bg); evas_object_size_hint_min_set(bg, 200, 200); elm_bg_color_set(bg, 0, 0, 0); layout = elm_layout_add(window); if (!elm_layout_file_set(layout, ApplicationMain::getTheme(), EDJE_GROUP_MAIN_LAYOUT)) { string e = "Unable to find group \""; e += EDJE_GROUP_MAIN_LAYOUT; e += "\" in theme \""; e += ApplicationMain::getTheme(); e += "\""; throw (runtime_error(e)); } //create the screen suspend object and put it on the canvas ScreenSuspendView *screen_suspend = new ScreenSuspendView(evas, window); screen_suspend->Show(); screen_suspend->setAutoDelete(true); evas_object_size_hint_weight_set(layout, 1.0, 1.0); evas_object_show(layout); evas_object_resize(window, 1024, 768); evas_object_show(window); ecore_evas_focus_set(ecore_evas_ecore_evas_get(evas_object_evas_get(window)), true); Resize(); try { controller = new ApplicationController(evas, layout); } catch(exception const& e) { cCritical() << "Can't create ApplicationController"; throw; } }