Dragonfly::Dragonfly(void) { speed = 0; maxSpeed = 1; scale = 0.5; slowingDown = false; resolution = 24; quadric = gluNewQuadric(); targetSpeed = maxSpeed; tailRotation = 0; frontWing = Wing(); backWing = Wing(); setFriction(0.3); tex = dragonflyTextures(); /*modelFile = "Resources/Crystal_8_Sides.obj"; // Load model model = glmReadOBJ(modelFile); scale = glmUnitize(model); glmFacetNormals(model); smoothAngle = 90.0; glmVertexNormals(model, smoothAngle);*/ }
Boat::Boat(string m, string t, string s, glm::vec3 position, glm::vec3 direction, glm::vec3 up, string path) : PropObject(m, t, s, position, direction, up, path) { oceanHeightModObjects->push_back(this); turnRate = 0.0f; setMass(10000.0f); setFriction(2.0f); body->setDamping(0.9f, 0.9f); //setGravity(0,-19.62f*2,0); //body->setAngularFactor(1.0f); collisionType = "vehicle"; buoyancyPoints.push_back(BuoyancyPoint(0.0f, -1.0f, 26.85f)); buoyancyPoints.push_back(BuoyancyPoint(0.0f, -1.0f, -26.85f)); buoyancyPoints.push_back(BuoyancyPoint(9.0f, -1.0f, 0.0f)); buoyancyPoints.push_back(BuoyancyPoint(-9.0f, -1.0f, 0.0f)); buoyancyPoints.push_back(BuoyancyPoint(9.0f, -1.0f, 14.0f)); buoyancyPoints.push_back(BuoyancyPoint(-9.0f, -1.0f, 14.0f)); buoyancyPoints.push_back(BuoyancyPoint(9.0f, -1.0f, -14.0f)); buoyancyPoints.push_back(BuoyancyPoint(-9.0f, -1.0f, -14.0f)); for (list<BuoyancyPoint>::iterator it = buoyancyPoints.begin(); it != buoyancyPoints.end(); it++) (it)->update(&body->getWorldTransform()); }
void CSubStructure::onInit(IGameObject& object, IGameWorld& world) { // init all components foreachComponent([](IComponent& component, IGameObject& object){component.init(object);}, std::ref(object)); // need to write the component subobject loop ourselves here, because we need the shared_ptr // build the physic body for(auto& cell : mCells) { auto fixture = physics::Fixture::create(object.getBody(), cell->shape(), 10.f); fixture.setRestitution(0.1); fixture.setFriction(0.5); for(std::size_t i = 0; i < cell->component_count(); ++i) { addChild(cell->getComponent(i)); fixture.addMass(cell->getComponent(i)->weight()); } } // add the armour segments to the object definition for(unsigned i = 0; i < mArmour.size(); ++i) { auto pob = std::make_shared<property::CPropertyObject>("armour" + to_string(i)); addChild(pob); pob->addChild(mArmour[i].armour->getSharedPropertyObject()); pob->addProperty( property::CProperty::create("p1", pob.get(), mArmour[i].p1) ); pob->addProperty( property::CProperty::create("p2", pob.get(), mArmour[i].p2) ); } }
PhysicsRigidBody* PhysicsMgr::createRigidBodyMesh(Mesh* mesh, Matrix44* transform) { auto rig = new PhysicsRigidBody(); btScalar mass(0.0f); btTransform startTransform; btTriangleMesh * meshInterface = new btTriangleMesh(); auto idxSize = mesh->getIndicesSize(); for(auto i =0; i < idxSize; i+=3) { auto v1 = mesh->getVertex(i); auto v2 = mesh->getVertex(i + 1); auto v3 = mesh->getVertex(i + 2); meshInterface->addTriangle(btVector3(v1.m_pos.x, v1.m_pos.y, v1.m_pos.z), btVector3(v2.m_pos.x, v2.m_pos.y, v2.m_pos.z), btVector3(v3.m_pos.x, v3.m_pos.y, v3.m_pos.z)); } auto tetraShape = new btBvhTriangleMeshShape(meshInterface, true, true); startTransform.setIdentity(); if (transform) { startTransform.setFromOpenGLMatrix(transform->data()); } auto btRig = shared()->createRigidBodyInternal(mass, startTransform, tetraShape, btVector4(1, 0, 0, 1)); btRig->setContactProcessingThreshold(BT_LARGE_FLOAT); btRig->setFriction (btScalar(0.9)); btRig->setCcdMotionThreshold(.1); btRig->setCcdSweptSphereRadius(0); rig->setRigidBody(btRig); rig->genUserIndex(); btRig->setUserIndex(rig->userIndex()); btRig->setUserPointer(rig); return rig; }
void PlaneCollision::create(Vector3 origin, float length, float width, float elast, float friction, bool is_container, Vector3 orientation) { setElast(elast); setFriction(friction); setIsContainer(is_container); Quadrilateral::create(origin,length,width,orientation); }
Integrator::Integrator( double temperature, double frictionCoeff, double stepSize, const Parameters ¶ms ) : maxEigenvalue( 4.34e5 ), stepsSinceDiagonalize( 0 ), mParameters( params ), mAnalysis( new Analysis ) { setTemperature( temperature ); setFriction( frictionCoeff ); setStepSize( stepSize ); setConstraintTolerance( 1e-4 ); setMinimumLimit( mParameters.minLimit ); setRandomNumberSeed( ( int ) time( 0 ) ); }
World::World() { // Create the terrain. mTerrain = gTerrainManager->getTerrain("data/heightmap17_257.raw"); // Create the skybox. mSky = new Sky("data/imgs/grassenvmap1024.dds", 10000.0f); setGravity(-1.3f); setFriction(-0.18f); }
/** Initializes a new power-up object with the supplied position and index. */ bool Powerup::init(const Vec2& pos, const PowerupType& t, int i) { if (CapsuleObstacle::init(pos)) { _type = t; _index = i; setDensity(0.0f); setFriction(0.0f); setFixedRotation(true); return true; } return false; };
void PhysicsObject::Init(Vec2 Pos,double e,double mu,double mass){ this->Pos=Pos; Vel.SetValue(0,0); angle=0; angleSpeed=0; setRestitution(e); setFriction(mu); setMass(mass); ID = runningNr; runningNr += 1; }
bool Physics3DCollider::init(Physics3DColliderDes *info) { _physics3DShape = info->shape; _physics3DShape->retain(); _btGhostObject = new btCollider(this); _btGhostObject->setCollisionShape(_physics3DShape->getbtShape()); setTrigger(info->isTrigger); setFriction(info->friction); setRollingFriction(info->rollingFriction); setRestitution(info->restitution); setHitFraction(info->hitFraction); setCcdSweptSphereRadius(info->ccdSweptSphereRadius); setCcdMotionThreshold(info->ccdMotionThreshold); _type = Physics3DObject::PhysicsObjType::COLLIDER; return true; }
Game::Game() : m_circleId(0), start(0), bPeriodEnd(false), m_totalObjects(0), m_elasticity(0.2f), m_friction(0.02f), m_airjetForce(0.0f), massId(0), mAppliedAirJet(true), mAirjetMagnitude(0.0f), mPause(false) { bRope = false; setElasticity(0.8f); setFriction(0.02f); Primitive::setGame(this); // init rope int ropePoints = 8; m_rope.init(10.0f, ropePoints, Vector(-4,12), Vector(4,12), true, true); // Initial values for components' frequencies m_physicsFreq = 200; m_networkFreq = 50; m_graphicsFreq = 60; createLines(); m_circles.reserve(50); m_manifold = new ContactManifold(); }
Player::Player(Item* parent) : QBody(parent), m_currentPathPoint(), m_going(false), m_punchSound(std::make_shared<QSound>(":/resources/punch_sound.wav")), m_object(this), m_score() { setBodyType(QBody::BodyType::Dynamic); auto circle = std::make_unique<Box2DCircle>(); circle->setRadius(2.5); circle->setFriction(0.0); circle->setDensity(1.0); circle->setPosition(QPointF(-2.5, -2.5)); circle->setCategories(QFixture::Category2); circle->setCollidesWith(QFixture::Category1); circle->setRestitution(0.2); addFixture(std::move(circle)); setPosition(QPointF(70, 950)); setLinearDamping(5); setAngularDamping(5); }
void PhysicsShape::setMaterial(const PhysicsMaterial& material) { setDensity(material.density); setRestitution(material.restitution); setFriction(material.friction); }
int PhysicObject::methodsBridge(lua_State* luaVM) { if (isCurrentMethod("applyImpulse")) { applyImpulse(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3)), CVector(lua_tonumber(luaVM, 4), lua_tonumber(luaVM, 5), lua_tonumber(luaVM, 6))); return 0; } if (isCurrentMethod("applyForce")) { applyForce(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3)), CVector(lua_tonumber(luaVM, 4), lua_tonumber(luaVM, 5), lua_tonumber(luaVM, 6))); return 0; } if (isCurrentMethod("setLinearVelocity")) { setLinearVelocity(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3))); return 0; } if (isCurrentMethod("getLinearVelocity")) { luaPushVector(luaVM, getLinearVelocity().x, getLinearVelocity().y, getLinearVelocity().z); return 1; } if (isCurrentMethod("setMass")) { setMass(lua_tonumber(luaVM, 1)); return 0; } if (isCurrentMethod("getMass")) { lua_pushnumber(luaVM, getMass()); return 1; } if (isCurrentMethod("setCollisionShapeType")) { setCollisionShapeType((CollisionShapeType)lua_tointeger(luaVM, 1)); return 0; } if (isCurrentMethod("getCollisionShapeType")) { lua_pushinteger(luaVM, getCollisionShapeType()); return 1; } if (isCurrentMethod("enablePhysics")) { enablePhysics(lua_toboolean(luaVM, 1)); return 0; } if (isCurrentMethod("isEnabledPhysics")) { lua_pushboolean(luaVM, isEnabledPhysics()); return 1; } if (isCurrentMethod("setAngularFactor")) { setAngularFactor(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3))); return 0; } if (isCurrentMethod("getAngularFactor")) { luaPushVector(luaVM, getAngularFactor().x, getAngularFactor().y, getAngularFactor().z); return 1; } if (isCurrentMethod("setLinearFactor")) { setLinearFactor(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3))); return 0; } if (isCurrentMethod("getLinearFactor")) { luaPushVector(luaVM, getLinearFactor().x, getLinearFactor().y, getLinearFactor().z); return 1; } if (isCurrentMethod("setTrigger")) { setTrigger(lua_toboolean(luaVM, 1)); return 0; } if (isCurrentMethod("isTrigger")) { lua_pushboolean(luaVM, isTrigger()); return 1; } if (isCurrentMethod("getCollisionShape")) { if (getCollisionShape() == NULL) { lua_pushnil(luaVM); } else { lua_getglobal(luaVM, getCollisionShape()->getGOID().c_str()); } return 1; } if (isCurrentMethod("setCollisionShape")) { if (lua_isnil(luaVM, 1)) { setCollisionShape(NULL); return 0; } lua_pushstring(luaVM, "cpointer"); lua_gettable(luaVM, -2); GOCollisionShape* o = (GOCollisionShape*)lua_tointeger(luaVM, -1); setCollisionShape(o); lua_pop(luaVM, -1); return 0; } if (isCurrentMethod("setEnableDeactivation")) { setEnableDeactivation(lua_toboolean(luaVM, 1)); return 0; } if (isCurrentMethod("isEnableDeactivation")) { lua_pushboolean(luaVM, isEnableDeactivation()); return 1; } if (isCurrentMethod("setFriction")) { setFriction(lua_tonumber(luaVM, 1)); return 0; } if (isCurrentMethod("getFriction")) { lua_pushnumber(luaVM, getFriction()); return 1; } if (isCurrentMethod("setRestitution")) { setRestitution(lua_tonumber(luaVM, 1)); return 0; } if (isCurrentMethod("getRestitution")) { lua_pushnumber(luaVM, getRestitution()); return 1; } if (isCurrentMethod("setLinearDumping")) { setLinearDumping(lua_tonumber(luaVM, 1)); return 0; } if (isCurrentMethod("getLinearDumping")) { lua_pushnumber(luaVM, getLinearDumping()); return 1; } if (isCurrentMethod("setAngularDumping")) { setAngularDumping(lua_tonumber(luaVM, 1)); return 0; } if (isCurrentMethod("getAngularDumping")) { lua_pushnumber(luaVM, getAngularDumping()); return 1; } if (isCurrentMethod("setAngularVelocity")) { setAngularVelocity(CVector(lua_tonumber(luaVM, 1), lua_tonumber(luaVM, 2), lua_tonumber(luaVM, 3))); return 0; } if (isCurrentMethod("getAngularVelocity")) { CVector av = getAngularVelocity(); luaPushVector(luaVM, av.x, av.y, av.z); return 1; } if (isCurrentMethod("addConstraint")) { if (lua_isnil(luaVM, 1)) { return 0; } lua_pushstring(luaVM, "cpointer"); lua_gettable(luaVM, -2); GOConstraint* o = (GOConstraint*)lua_tointeger(luaVM, -1); addConstraint(o); lua_pop(luaVM, -1); return 0; } if (isCurrentMethod("getConstraints")) { lua_newtable(luaVM); int tableIndex = lua_gettop(luaVM); vector<GOConstraint*> objs; for (unsigned int i = 0; i < constraints.size(); ++i) { if (constraints.at(i)->id == "undefined" || constraints.at(i)->id == "") continue; objs.push_back(constraints.at(i)); } for (unsigned int i = 0; i < objs.size(); ++i) { lua_pushinteger(luaVM, i+1); lua_getglobal(luaVM, objs.at(i)->id.c_str()); lua_settable (luaVM, tableIndex); } return 1; } if (isCurrentMethod("removeConstraint")) { if (lua_isnil(luaVM, 1)) { return 0; } lua_pushstring(luaVM, "cpointer"); lua_gettable(luaVM, -2); GOConstraint* o = (GOConstraint*)lua_tointeger(luaVM, -1); removeConstraint(o); lua_pop(luaVM, -1); return 0; } if (isCurrentMethod("removeAllConstrains")) { removeAllConstraints(); return 0; } if (isCurrentMethod("secondObjectForConstraint")) { if (lua_isnil(luaVM, 1)) { return 0; } lua_pushstring(luaVM, "cpointer"); lua_gettable(luaVM, -2); GOConstraint* o = (GOConstraint*)lua_tointeger(luaVM, -1); secondObjectForConstraint(o); lua_pop(luaVM, -1); return 0; } if (isCurrentMethod("isSecondObjectForConstraints")) { lua_newtable(luaVM); int tableIndex = lua_gettop(luaVM); vector<GOConstraint*> objs; for (unsigned int i = 0; i < secondObjectForConstraints.size(); ++i) { if (secondObjectForConstraints.at(i)->id == "undefined" || secondObjectForConstraints.at(i)->id == "") continue; objs.push_back(secondObjectForConstraints.at(i)); } for (unsigned int i = 0; i < objs.size(); ++i) { lua_pushinteger(luaVM, i+1); lua_getglobal(luaVM, objs.at(i)->id.c_str()); lua_settable (luaVM, tableIndex); } return 1; } if (isCurrentMethod("notUseAsSecondObjectForConstraint")) { if (lua_isnil(luaVM, 1)) { return 0; } lua_pushstring(luaVM, "cpointer"); lua_gettable(luaVM, -2); GOConstraint* o = (GOConstraint*)lua_tointeger(luaVM, -1); notUseAsSecondObjectForConstraint(o); lua_pop(luaVM, -1); return 0; } return LuaBridge::methodsBridge(luaVM); }
void PhysicObject::loadPhysProperties(FILE* f) { enablePhysics(readChar(f)); if (!isEnabledPhysics()) return; setMass(readFloat(f)); setAngularFactor(readVector(f)); setLinearFactor(readVector(f)); //writeVector(getLinearVelocity(), f); setTrigger(readChar(f)); setCollisionShapeType((CollisionShapeType)readChar(f)); setEnableDeactivation(readChar(f)); setFriction(readFloat(f)); setRestitution(readFloat(f)); setLinearDumping(readFloat(f)); setAngularDumping(readFloat(f)); // load custom collision shape if (getCollisionShapeType() == CST_CUSTOM) { switch ((GOCollisionShapeType)readChar(f)) { case GOCST_COMPOUND_SHAPE: setCollisionShape(new GOCompoundCollisionShape(f)); break; case GOCST_BOX: setCollisionShape(new GOBoxCollisionShape(f)); break; case GOCST_SPHERE: setCollisionShape(new GOSphereCollisionShape(f)); break; case GOCST_CYLINDER: setCollisionShape(new GOCylinderCollisionShape(f)); break; case GOCST_UNDEFINED: setCollisionShape(new GOUndefinedCollisionShape(f)); break; case GOCST_CAPSULE: setCollisionShape(new GOCapsuleCollisionShape(f)); break; case GOCST_CONE: setCollisionShape(new GOConeCollisionShape(f)); break; case GOCST_MESH: setCollisionShape(new GOMeshCollisionShape(f)); break; default: Log::error("PhysicObject::loadPhysProperties(FILE* f): Undefined custom shape type."); } } // load constraints int c_count = readChar(f); for (int i = 0; i < c_count; i++) { GOConstraint* cs; unsigned char type = readChar(f); switch (type) { case GO_P2P_CONSTRAINT: cs = new GOP2PConstraint(f); break; case GO_HINGE_CONSTRAINT: cs = new GOHingeConstraint(f); break; case GO_SLIDER_CONSTRAINT: cs = new GOSliderConstraint(f); break; default: Log::error("PhysicObject::loadPhysProperties(FILE* f): Undefined constraint type."); } addConstraint(cs); } }
//-------------------------------------------------------------- void ofxBulletBaseShape::setProperties(float a_restitution, float a_friction) { setRestitution(a_restitution); setFriction(a_friction); }
// on "init" you need to initialize your instance bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Vec2 visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); timeSinceLastMouseUp = 9999; timeSinceLastNotifierUpdate = 0; timeSinceLastObjectCull = 0; // add "HelloWorld" splash screen" auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.x/2 + origin.x, visibleSize.y/2 + origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); overlaySprite = Sprite::create(); overlaySprite->setPosition(visibleSize/2); this->addChild(overlaySprite, UI_DEPTH); auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24); // position the label on the center of the screen label->setPosition(Vec2(0,label->getContentSize().height/2)); // add the label as a child to this layer overlaySprite->addChild(label, 1); cursorSprite = Sprite::create("cursors/arrow.png"); addChild(cursorSprite, CURSOR_DEPTH); cursorSprite->setScale(0.7); protractor = (Sprite*) new Protractor("protractor", PROTRACTOR_SIZE); addChild(protractor, 1); commorose = (Sprite*) new Commorose("commorose"); addChild(commorose, CURSOR_DEPTH - 1); commorose->setVisible(false); TorpedoData::init("torpedos.jld"); playerSub = (Sprite*) new Submarine("player-sub.png"); auto s = (Submarine*)playerSub; s->setName(PLAYER_SUB_NAME); s->setPhysicsModel(PhysicsModel::Newtonian); s->setMass(300); s->setFriction(5); s->setMaxForce(20 * 1000); s->setPropulsionType(PropulsionType::Diesel); s->setNoisiness(40); addChild(playerSub, UI_DEPTH); playerDeltaForcePerSecond = 2000; playerTurning = false; ((Submarine*)playerSub)->addTorpedoPrototype(new TorpedoData("testpedo", "testpedo")); notifier = (Sprite*) new Notifier("notifier", visibleSize); ((Notifier*)notifier)->setThrustBar(0); ((Notifier*)notifier)->setNoiseBar(0); addChild(notifier, UI_DEPTH); moveScreenBy(Director::getInstance()->getVisibleSize()/-2); lookAt(Vec2::ZERO); this->scheduleUpdate(); return true; }