ArticulatedPhysicsEntity::~ArticulatedPhysicsEntity() { SimplePhysicsEntity* entity; unsigned entityId; unsigned rigidBodyIndex, entityIndex; std::map<unsigned, unsigned>::iterator it; Physics* physics = (Physics*)SystemCore::getModuleByName("Physics"); if (physics && articulatedBody->isAddedToSimulation()) physics->removePhysicsObject(this); // Clear rigidBody-Pointer in SimplePhysicsEntity for (it = rigidBodyMapping.begin(); it != rigidBodyMapping.end(); ++it) { rigidBodyIndex = (*it).first; entityIndex = (*it).second; entityId = this->environmentBasedId + entityIndex; entity = (SimplePhysicsEntity*)WorldDatabase::getEntityWithEnvironmentId(entityId); if (entity) entity->rigidBody = NULL; } // for delete articulatedBody; } // ~ArticulatedPhysicsEntity
void SoftBody::createPhysShape() { Physics* physics = Physics::getPhysics(isServerObject()); if (physics) { createUniqVertexList(); PhysSoftInfo physDescr; physDescr.shapeType = PhysInfo::ST_SOFTMESH; physDescr.physPolyList = mPhysPolyList; physDescr.owner = this; physDescr.mass = mDataBlock->mass; physDescr.poseMatchKoef = mDataBlock->poseMatchKoef; for(U8 i=0;i<mDataBlock->attachedPointsNum;i++) { physDescr.attachPoints.push_back(mDataBlock->attachedPoints[i]); } mPhysShape = physics->createPhysShapeSoft(physDescr); mPhysShape->setTransform(mObjToWorld); } }
void update(long double dt){ _fireTimer -= (float)dt; if (_fireTimer < 0.f) _fireTimer = 0.f; int mouseRX, mouseRY; SDL_GetRelativeMouseState(&mouseRX, &mouseRY); // Rotate camera FPS style _physics->rotationForce(Vector3f((float)(mouseRY * _sensitivity * dt), (float)(mouseRX * _sensitivity * dt), 0.f)); const Uint8* keyDown = SDL_GetKeyboardState(0); // W = forward if (keyDown[SDL_SCANCODE_W]) _physics->pushForce((float)(_pushSpeed * dt)); if (keyDown[SDL_SCANCODE_S]) _physics->pushForce((float)((-_pushSpeed / 100) * dt)); // Left Mouse = Fire bullet if (SDL_GetMouseState(0, 0) & SDL_BUTTON(SDL_BUTTON_LEFT) && !_fired && !_fireTimer){ Entity* bullet = EntityManager::createEntity<Bullet>("bullet", ID()); bullet->invoke(&Component::load); _fireTimer = 0.5f; _fired = true; } else if (!SDL_GetMouseState(0, 0) & SDL_BUTTON(SDL_BUTTON_LEFT) && _fired){ _fired = false; } }
int main() { Physics p; Achievements a; p.update(); a.update(); return 0; }
int main() { Physics phys; int x = 0; while (true) { phys.run(); } return 0; }
void LinkedPhysicsEntity::setEnvironment(Environment* env) { Entity::setEnvironment(env); if (!addedToSimulation) { initializeJoints(); Physics* physicsModule = (Physics*)SystemCore::getModuleByName("Physics"); assert(physicsModule); physicsModule->addPhysicsObject(this); addedToSimulation = true; } // if } // setEnvironment
CursorSpringConnector::~CursorSpringConnector() { Physics* physicsModule; physicsModule = (Physics*)SystemCore::getModuleByName("Physics"); if (physicsModule) { physicsModule->removePhysicsObject(this); physicsModule->removeSimulationStepListener(this); physicsModule->removeSystemThreadListener(this); } // if } // ~CursorSpringConnector
void ArticulatedPhysicsEntity::setEnvironment(Environment* env) { Entity::setEnvironment(env); if (articulatedBody && !addedToSimulation) { Physics* physicsModule = (Physics*)SystemCore::getModuleByName("Physics"); assert(physicsModule); physicsModule->addPhysicsObject(this); addedToSimulation = true; } // if } // setEnvironment
void PinballHost::init(const char *gameName) { std::cout << "starting " << gameName << std::endl; PinballBridgeInterface *bi = new PinballBridgeInterface(); bi->setGameName(gameName); Playfield *f = new Playfield(); f->setBridgeInterface(bi); f->init(); Physics *p = new Physics(); p->setBridgeInterface(bi); p->setPlayfield(f); p->init(); Camera *c = new Camera(); c->setBridgeInterface(bi); c->setPlayfield(f); c->init(); Editor *t = new Editor(); t->setBridgeInterface(bi); t->setPlayfield(f); t->setCamera(c); t->setPhysics(p); t->init(); GlutEngine *e = new GlutEngine(); e->init(); Renderer *r = new Renderer(); r->setBridgeInterface(bi); r->setPlayfield(f); r->setPhysics(p); r->setCamera(c); r->setEditor(t); r->init(); Game *g = new Game(); g->setBridgeInterface(bi); g->setPhysics(p); g->setRenderer(r); g->init(); // TODO: find factoring error/s e->setPhysics(p); e->setRenderer(r); e->setGame(g); e->setEditor(t); _engine = e; }
void Enemy::canGoY(float dt, const Physics &phys) { pos.y += vel.y * dt; for (float changeY = phys.testY(*this); changeY!=0; changeY = phys.testY(*this)) { pos.y += phys.testY(*this); if (phys.gravAngle%180 == 0) vel.setY(0, phys.gravAngle); else hitWall = true; } if (phys.testBoundsY(*this) != 0) { // when fallen into the pit anger(phys); dead = true; // indicate death to reset } }
int main(int argc, char** argv) { Physics physics; if (argc != 3 && argc != 2) { cerr << "usage: " << argv[0] << " <scene.sce> [output_suffix]" << endl; return 1; } physics.parse(argv[1]); physics.write(argv[2] ? argv[2] : "scene"); return 0; }
void Player::canGoY(float dt, const Physics &phys) { pos.y += vel.y * dt; for (float changeY = phys.testY(*this); changeY!=0; changeY = phys.testY(*this)) { pos.y += changeY; vel.y = 0; if ( // if there was a collision with the ground ( (changeY < 0 && phys.gravAngle==0*90) || (changeY>0 && phys.gravAngle==2*90) ) && abs(changeY)<=abs(phys.testX(*this)) ) inAir = false; } if (phys.testBoundsY(*this) != 0) dead = true; // player fell into a pit. }
// === private functions: === void Player::canGoX(float dt, const Physics &phys) { pos.x += vel.x * dt; for (float changeX = phys.testX(*this); changeX!=0; changeX = phys.testX(*this)) { // as long as there are collisions, keep checking pos.x += changeX; vel.x = 0; if ( // if there was a collision with the ground ( (changeX < 0 && phys.gravAngle==1*90) || (changeX>0 && phys.gravAngle==3*90) ) && abs(changeX)<=abs(phys.testY(*this)) ) inAir = false; } if (phys.testBoundsX(*this) != 0) dead = true; // player fell into a pit. }
GameLevel* Game::CreateGameLevel( const int modeID, const int levelID ) { Physics* physics = Physics::GetInstance(); physics->Init(); GameLevel* gameLevel = new GameLevel( modeID, levelID ); gameLevel->Init(); physics->FreeInstance(); return gameLevel; }
void PinballHost::init() { PinballBridgeInterface *bi = new PinballBridgeInterface(); bi->setGameName("Flipperfall"); bi->init(); Playfield *f = new Playfield(); f->setBridgeInterface(bi); f->init(); Physics *p = new Physics(); p->setBridgeInterface(bi); p->setPlayfield(f); p->init(); Camera *c = new Camera(); c->setBridgeInterface(bi); c->setPlayfield(f); c->init(); Editor *t = new Editor(); t->setBridgeInterface(bi); t->setPlayfield(f); t->setCamera(c); t->setPhysics(p); t->init(); GlutEngine *e = new GlutEngine(); e->init(); Renderer *r = new Renderer(); r->setBridgeInterface(bi); r->setPlayfield(f); r->setPhysics(p); r->setCamera(c); r->setEditor(t); r->init(); Game *g = new Game(); g->setBridgeInterface(bi); g->setPhysics(p); g->setRenderer(r); g->init(); // TODO: find factoring error/s e->setPhysics(p); e->setRenderer(r); e->setGame(g); e->setEditor(t); _glutEngine = e; }
void ballSetStart() { if(sphereMesh.whichHole.last) { cout << "YOU WON!!!!!" << endl; NUMBER_OF_WINS ++; buildMaze( abs(boardMesh.initial_bound.second.z - boardMesh.initial_bound.first.z) - 1, abs(boardMesh.initial_bound.second.x - boardMesh.initial_bound.first.x) - 1); } else { cout << "AWWWWW!! TOO BAD!!!!!!" << endl; } cout << "NUMBER OF WINS: " << NUMBER_OF_WINS << endl; MOUSE_X = 0; MOUSE_Y = 0; DELTA_X_CHANGE = 0.0; DELTA_Y_CHANGE = 0.0; //for mouse movement stuff X_CHANGE = 0.05; Y_CHANGE = 0.05; boardMesh.initialize("board"); boardMesh.initial_bound = meshManager.getBounds("board"); boardMesh.current_position = boardMesh.initial_bound; sphereMesh.initialize("sphere"); sphereMesh.initial_bound = meshManager.getBounds("sphere"); sphereMesh.current_position = sphereMesh.initial_bound; //set the location of the ball on top of the start hole sphereMesh.offset.x = mazeHoles[0].offset.x; sphereMesh.offset.z = mazeHoles[0].offset.z; sphereMesh.offset.y = 3.0f; //translate to the start position and update the current positions sphereMesh.model=glm::translate(glm::mat4(1.0f), glm::vec3( sphereMesh.offset.x, sphereMesh.offset.y, sphereMesh.offset.z)); sphereMesh.current_position.first = sphereMesh.initial_bound.first + sphereMesh.offset; sphereMesh.current_position.second = sphereMesh.initial_bound.second + sphereMesh.offset; //set up the board and ball in the simulated physics world if(initPhysics == true) { myPhysics.makeBoard(boardMesh); myPhysics.makeBall(sphereMesh); myPhysics.makeWalls(myMaze); initPhysics = false; } else { myPhysics.resetMaze(sphereMesh, myMaze); } }
void GravitationalForce::apply_fun(float d_t){ for (unsigned int i = 0; i < mInfluencedPhysics.size()-1; i++){ Physics* lhs = mInfluencedPhysics[i]; for (unsigned int j = i+1 ; j < mInfluencedPhysics.size(); j++){ Physics* rhs = mInfluencedPhysics[j]; Vector3 distanceVector = rhs->getPosition()-lhs->getPosition(); float distance = distanceVector.length(); //Distanz in Ordnung if (distance < getMaxDistance() && distance >= 1.0){ if(distance < 1){ distance = 1; } distanceVector.normalize(); //Anziehungskraft berechnen float force = mScale * (rhs->getMass()*lhs->getMass() / (distance*distance)); //Anziehungskraft in Ordnung if (force > getMinForce()){ Vector3 Rhs_forceVector = distanceVector; Rhs_forceVector *= force; //Anziehungskraft um d_t skaliert anwenden lhs->applyForce(Rhs_forceVector*d_t); Vector3 Lhs_forceVector = (-1.0) * distanceVector; Lhs_forceVector *= force; //Anziehungskraft um d_t skaliert anwenden rhs->applyForce(Lhs_forceVector*d_t); } } } } }
// helper functions for update() void Enemy::canGoX(float dt, const Physics &phys) { pos.x += vel.x * dt; float changeX = phys.testX(*this); while (changeX!=0) { // as long as there are collisions with the level, keep checking pos.x += changeX; if (phys.gravAngle%180 == 0) hitWall = true; else vel.setY(0, phys.gravAngle); changeX = phys.testX(*this); } changeX = phys.testBoundsX(*this); if (changeX != 0) { anger(phys); dead = true; // indicate death to reset } }
int debug(int argc,char** argv){ test(); const int temp[] = {0, 7306, 77, 9859, 8996, 0, 7615, 0, 0, 1641, 8007, 0, 1666, 1098, 3253, 0, 5908, 6549, 7241, 8392, 2533, 8392, 7810, 150, 0, 8248, 1100, 0, 0, 0, 300, 350, 300 , 2324, 4627, 1393, 457, 4736, 0, 819, 0, 289, 0, 0, 2872, 5034, 1, 539, 2160, 3399, 9902, 1094, 6143, 100, 0, 4660, 5670, 400, 1214, 0, 5202, 0, 6629, 5316, 0, 8392, 7810, 1519, 4743, 0, 513, 3589, 1790, 25, 1433, 5552, 0, 8695, 3, 9352, 1413, 9324, 1, 25, 3278, 0, 0, 0, 6020, 0, 1071, 2400, 3678, 1641, 8007, 0, 4650, 1098, 1801, 1211, 2465, 6549, 6435, 1471, 3032, 2598, 100, 3005, 9326, 150, 1,25, 3278, 0, 4710, 9276, 3266, 4386, 0, 0, 7340, 0, 0, 3559, 9407, 0, 4710, 6038 , 3187, 9961, 7280, 1460, 7224, 7744, 200, 5723, 2289, 0, 3948, 9274, 0, 573, 0, 8815, 3264, 0, 3809, 0, 0, 0}; int size = sizeof( temp ) / sizeof ( *temp ); std::vector<int> ancestor (temp, temp+size); Physics* WWDPhysics = new Physics(); //init creature readDNA(&ancestor,WWDPhysics); //WWDPhysics->testPhysics(); //default glut doesn't return from mainloop WWDPhysics->solveGroundConflicts(); return glutmain(argc, argv,1024,600,"Walking with dinosaurs",WWDPhysics); }
static SmartPtr<TaskBasic> Physics_schedule_task(Physics& ph, TaskBasic* task, py::object time) { btScalar cpp_time = -1; if(time.ptr() != Py_None) { cpp_time = py::extract<btScalar>(time); } ph.scheduleTask(task, cpp_time); return task; }
void FlockingParticlesApp::draw() { ci::gl::clear(Color(0, 0, 0)); glColor3f(1,1,1); glPointSize(3); // draw all particles at once using vbo drawArrays(vboParticles, 0, physics->getNumParticles()); }
int main() { Physics app; // DIYmain app; if (app.startup() == false) { return -1; } while (app.update() == true) { app.draw(); } app.shutdown(); return 0; }
int main(int argc, const char * argv[]) { Hero hero; Achievements achievements; Physics physics; // init physics.addObserver(&achievements); achievements.showUnlocked(); // do physics.updateEntity(hero); achievements.showUnlocked(); // clean up physics.removeObserver(&achievements); return 0; }
void CursorSpringConnector::step(float dt, unsigned simulationTime) { TransformationData localCursorTrans, rigidBodyTrans; #if OSG_MAJOR_VERSION >= 2 cursorTransformationLock->acquire(); #else cursorTransformationLock->aquire(); #endif localCursorTrans = cursorTransformation; cursorTransformationLock->release(); Physics* physics = (Physics*)SystemCore::getModuleByName("Physics"); if (!physics) return; Simulation* simulation = physics->getSimulation(); if (!simulation) return; rigidBody = simulation->getRigidBodyByID(rigidBodyId); if (!rigidBody) { printd(WARNING, "CursorSpringConnector::executeJointMode(): RigidBody for manipulation not found in Simulation!\n"); return; } // if rigidBodyTrans = rigidBody->getTransformation(); if (connectionMode == VELOCITY_MODE) executeVelocityMode(dt, localCursorTrans, rigidBodyTrans); else if (connectionMode == SPRING_MODE) executeSpringMode(dt, localCursorTrans, rigidBodyTrans); else if (connectionMode == FORCETORQUE_MODE) executeForceTorqueMode(dt, localCursorTrans, rigidBodyTrans); else if (connectionMode == JOINT_MODE) executeJointMode(dt, localCursorTrans, rigidBodyTrans); else printd(ERROR, "CursorSpringConnector::step(): unknown connection mode!\n"); oldCursorTransformation = localCursorTrans; } // step
//---------------------------------------------------------------------------- void RigidBody::createPhysShape() { //Physics* physics = isServerObject() ? gServerPhysics : gClientPhysics; Physics* physics = Physics::getPhysics(isServerObject()); if (physics) { PhysInfo physDescr; //transform into radian VectorF angleRadians = mDataBlock->mRotation/180.f*float(M_PI); physDescr.transform.set(angleRadians, mDataBlock->mPos); physDescr.owner = this; physDescr.shapeType = (PhysInfo::ShapeType)mDataBlock->mShapeType; physDescr.mass = mDataBlock->mass; if (physDescr.shapeType==PhysInfo::ST_SPHERE) { Box3F scaledObjBox = mObjBox; scaledObjBox.minExtents.convolve(mObjScale); scaledObjBox.maxExtents.convolve(mObjScale); F32 radius = (scaledObjBox.maxExtents - scaledObjBox.getCenter()).len(); physDescr.params = VectorF(radius,0.f,0.f); } else //if (physDescr.shapeType==PhysInfo::ST_BOX) { Box3F rotBox = mObjBox; physDescr.transform.mul(rotBox); VectorF length = VectorF(rotBox.len_x(),rotBox.len_y(),rotBox.len_z()); length.convolve(mObjScale); physDescr.params = length; } //physDescr.params = VectorF(1.f,1.f,1.f); //physDescr.shapeType = PhysInfo::ST_SPHERE; //physDescr.mass = 5.f; //physDescr.params = VectorF(0.5f,0.f,0.f); mPhysShape = physics->createPhysShape(physDescr); mPhysShape->setTransform(mObjToWorld); mPhysShape->setForce(mForce); mPhysShape->setTorque(mTorque); mPhysShape->setLinVelocity(mLinVelocity); mPhysShape->setAngVelocity(mAngVelocity); } }
//Start the ball moving using direction and power from GLUI input void launchBall(int i){ ballMoving = true; launchAngleRadians = (float) launchAngle * (PI/180); launchVector = normalize(vec3(sin(launchAngleRadians), 0.0, cos(launchAngleRadians))); Level *currentLevel = levelController->getCurrentLevel(); Ball *ball = currentLevel->getBall(); Physics *physics = ball->getPhysics(); puttSFX(physics->getSpeed(), sound); float prevY = physics->getDirection().y; physics->setDirection(glm::vec3(launchVector.x, prevY, launchVector.z)); // If new tile is flat make sure no y-component if(levelController->getCurrentLevel()->getTile(ball->getCurrentTileID())->getShapes().at(0)->normals()[0] == glm::vec3(0.0,1.0,0.0)){ physics->setDirection( glm::vec3(physics->getDirection().x, 0.0, physics->getDirection().z)); } // If new tile is not flat add y-component else{ glm::vec3 oldDirection = physics->getDirection(); glm::vec3 upVector = glm::vec3(0.0,1.0,0.0); // Get current tile normal glm::vec3 tileNormal = levelController->getCurrentLevel()->getTile(ball->getCurrentTileID())->getShapes().at(0)->normals()[0]; glm::vec3 xVector = glm::cross(oldDirection, upVector); glm::vec3 newDirection = glm::normalize(glm::cross(tileNormal, xVector)); physics->setDirection(newDirection); } physics->setSpeed(launchPower/100.1f); // Increment current hole score and update glui currentHoleScore++; numStrokes->set_int_val(currentHoleScore); angleSpinner->disable(); powerSpinner->disable(); fireButton->disable(); }
std::list<std::reference_wrapper<DynamicRigidBody>> AABBBroadphase::DetectDynamicCollisions(const DynamicRigidBody &rigidBodyA, Physics &physics) { std::list<std::reference_wrapper<DynamicRigidBody>> retList; for (DynamicRigidBody &rigidBodyB : physics.GetAllDynamic()) { if (&rigidBodyA != &rigidBodyB) { if (rigidBodyA.Collider->BroadphaseAABB.Intersects(rigidBodyB.Collider->BroadphaseAABB)) { retList.push_back(rigidBodyB); } } } return retList; }
void Physics::AllCollisions(void* ptr, void* data) { assert(data != NULL && ptr != NULL); cpArbiter *arb = reinterpret_cast<cpArbiter*> (ptr); Physics* p = reinterpret_cast<Physics*> (data); PhysicsObject* obj1 = p->FindObject(arb->a->body, arb->a); PhysicsObject* obj2 = p->FindObject(arb->b->body, arb->b); assert(obj1 != NULL); assert(obj2 != NULL); assert(sizeof (CollisionPoint) == sizeof (cpContact)); CollisionObject col(obj1, obj2, reinterpret_cast<CollisionPoint*> (arb->contacts), arb->numContacts); p->listener->HandleCollision(&col); }
int main(int argc, char* args[]) { SDL_Init(SDL_INIT_EVERYTHING); Renderer scene; Interface input; Physics logic; Resource *init_obj; init_obj = new Resource; scene.objects = init_obj; input.objects = init_obj; logic.objects = init_obj; while(init_obj->game_on){ scene.update(); input.update(); logic.update(); } delete init_obj; SDL_Quit(); return 0; }
void FlockingParticlesApp::testParticleCreation() { printf("running testParticleCreation\n"); timer->stop(); timer->start(); BasicSpace* space = new BasicSpace(Vec3f::zero(), Vec3f(getWindowWidth(), getWindowHeight(), 0)); Physics* physics = new Physics(space); Emitter* emitter = new Emitter(physics); physics->emitter = emitter; emitter->setPosition(space->getCenter()); emitter->setInterval(0.0001); emitter->setRate(50000); emitter->setMax(50 * 1000); int numIterations = 10; for(int i=0; i<numIterations; i++) { physics->update(0.016f); //physics->createParticle(); } timer->stop(); printf("%f s \n", timer->getSeconds()); }