//-------------------------------------------------------------------------------------------------- /// Create a 3D solid box at the specified position and with the given total extents /// /// \param centerPos Position of center of box /// \param extentX Total extent of box along x-axis /// \param extentY Total extent of box along y-axis /// \param extentZ Total extent of box along z-axis /// \param builder Geometry builder to use when creating geometry //-------------------------------------------------------------------------------------------------- void GeometryUtils::createBox(const Vec3f& centerPos, float extentX, float extentY, float extentZ, GeometryBuilder* builder) { Vec3f halfExtent(extentX/2, extentY/2, extentZ/2); Vec3f min(centerPos - halfExtent); Vec3f max(centerPos + halfExtent); createBox(min, max, builder); }
bool BoxColliderComponent::VInit() { if( !m_pPhysicsShape ) { hkVector4 halfExtent( m_halfSize.x, m_halfSize.y, m_halfSize.z ); m_pPhysicsShape = new hkpBoxShape( halfExtent, 0.0f ); } return true; }
Racer::Racer(IDirect3DDevice9* device, RacerType racerType) { engineVoice = NULL; gunMountDraw = new Drawable(GUNMOUNTMESH, "textures/gun.dds", device); Renderer::renderer->addDrawable(gunMountDraw); gunDraw = new Drawable(GUNMESH, "textures/gun.dds", device); Renderer::renderer->addDrawable(gunDraw); engineVoice = Sound::sound->reserveSFXVoice(); health = 100; kills = 0; suicides = 0; deaths = 0; givenDamage = 0; takenDamage = 0; laserReady = true; laserTime = 0.0f; respawnTimer = 0.0f; respawned = true; index = -1; currentSteering = 0.0f; currentAcceleration = 0.0f; lookDir.set(0, 0, 1); lookHeight = 0; switch (racerType) { case RACER1: drawable = new Drawable(RACER, "textures/racerred.dds", device); break; case RACER2: drawable = new Drawable(RACER, "textures/racerblue.dds", device); break; case RACER3: drawable = new Drawable(RACER, "textures/racerorange.dds", device); break; case RACER4: drawable = new Drawable(RACER, "textures/racergreen.dds", device); break; case RACER5: drawable = new Drawable(RACER, "textures/racerteal.dds", device); break; case RACER6: drawable = new Drawable(RACER, "textures/raceryellow.dds", device); break; case RACER7: drawable = new Drawable(RACER, "textures/racerpurple.dds", device); break; case RACER8: drawable = new Drawable(RACER, "textures/racerpink.dds", device); break; default: drawable = new Drawable(RACER, "textures/racerred.dds", device); } // Set up filter group (so the car doesn't collide with the wheels) int collisionGroupFilter = Physics::physics->getFilter(); hkpRigidBodyCinfo info; hkVector4 halfExtent(0.9f, 0.6f, 2.3f); //Half extent for racer rigid body box info.m_shape = new hkpBoxShape(halfExtent); info.m_qualityType = HK_COLLIDABLE_QUALITY_CRITICAL; info.m_centerOfMass.set(0.0f, 0.0f, 0.0f); info.m_restitution = 0.0f; info.m_maxAngularVelocity = 10.0f; info.m_maxLinearVelocity = 170.0f; info.m_angularDamping = 0.4f; hkpMassProperties massProperties; hkpInertiaTensorComputer::computeBoxVolumeMassProperties(halfExtent, chassisMass, massProperties); info.setMassProperties(massProperties); info.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(hkpGroupFilterSetup::LAYER_AI, collisionGroupFilter); body = new hkpRigidBody(info); //Create rigid body body->setLinearVelocity(hkVector4(0, 0, 0)); info.m_shape->removeReference(); hkpPropertyValue val; val.setPtr(this); body->setProperty(0, val); index = Renderer::renderer->addDrawable(drawable); Physics::physics->addRigidBody(body); // Create tires wheelFL = new FrontWheel(device, collisionGroupFilter); Renderer::renderer->addDrawable(wheelFL->drawable); Physics::physics->addRigidBody(wheelFL->body); wheelFR = new FrontWheel(device, collisionGroupFilter); Renderer::renderer->addDrawable(wheelFR->drawable); Physics::physics->addRigidBody(wheelFR->body); wheelRL = new RearWheel(device, collisionGroupFilter); Renderer::renderer->addDrawable(wheelRL->drawable); Physics::physics->addRigidBody(wheelRL->body); wheelRR = new RearWheel(device, collisionGroupFilter); Renderer::renderer->addDrawable(wheelRR->drawable); Physics::physics->addRigidBody(wheelRR->body); // Now constrain the tires hkpGenericConstraintData* constraint; hkpConstraintInstance* constraintInst; constraint = new hkpGenericConstraintData(); buildConstraint(&attachFL, constraint, FRONT); constraintInst = new hkpConstraintInstance(wheelFL->body, body, constraint); Physics::world->addConstraint(constraintInst); constraint->removeReference(); constraint = new hkpGenericConstraintData(); buildConstraint(&attachFR, constraint, FRONT); constraintInst = new hkpConstraintInstance(wheelFR->body, body, constraint); Physics::world->addConstraint(constraintInst); constraint->removeReference(); constraint = new hkpGenericConstraintData(); buildConstraint(&attachRL, constraint, REAR); constraintInst = new hkpConstraintInstance(wheelRL->body, body, constraint); Physics::world->addConstraint(constraintInst); constraint->removeReference(); constraint = new hkpGenericConstraintData(); buildConstraint(&attachRR, constraint, REAR); constraintInst = new hkpConstraintInstance(wheelRR->body, body, constraint); Physics::world->addConstraint(constraintInst); constraint->removeReference(); hkpConstraintStabilizationUtil::stabilizeRigidBodyInertia(body); reset(&(hkVector4(0, 0, 0, 0)), 0); emitter = Sound::sound->getEmitter(); braking = false; }
Racer::Racer(IDirect3DDevice9* device, Renderer* r, Physics* p, RacerType racerType) { index = -1; currentSteering = 0.0f; switch (racerType) { case PLAYER: drawable = new Drawable(RACER, "racer1.dds", device); break; case AI1: drawable = new Drawable(RACER, "racer2.dds", device); break; default: drawable = new Drawable(RACER, "racer2.dds", device); } // Set up filter group (so the car doesn't collide with the wheels) int collisionGroupFilter = p->getFilter(); hkpRigidBodyCinfo info; hkVector4 halfExtent(0.9f, 0.7f, 2.3f); //Half extent for racer rigid body box info.m_shape = new hkpBoxShape(halfExtent); info.m_qualityType = HK_COLLIDABLE_QUALITY_CRITICAL; info.m_centerOfMass = hkVector4(0.0f, -0.4f, -1.2f); // move CM a bit info.m_restitution = 0.1f; hkpMassProperties massProperties; hkpInertiaTensorComputer::computeBoxVolumeMassProperties(halfExtent, chassisMass, massProperties); info.setMassProperties(massProperties); info.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(hkpGroupFilterSetup::LAYER_AI, collisionGroupFilter); body = new hkpRigidBody(info); //Create rigid body body->setLinearVelocity(hkVector4(0, 0, 0)); info.m_shape->removeReference(); index = r->addDrawable(drawable); p->addRigidBody(body); // Create tires wheelFL = new FrontWheel(device, collisionGroupFilter); r->addDrawable(wheelFL->drawable); p->addRigidBody(wheelFL->body); WheelListener* listenFL = new WheelListener(&(wheelFL->touchingGround)); wheelFL->body->addContactListener(listenFL); wheelFR = new FrontWheel(device, collisionGroupFilter); r->addDrawable(wheelFR->drawable); p->addRigidBody(wheelFR->body); WheelListener* listenFR = new WheelListener(&(wheelFR->touchingGround)); wheelFL->body->addContactListener(listenFR); wheelRL = new RearWheel(device, collisionGroupFilter); r->addDrawable(wheelRL->drawable); p->addRigidBody(wheelRL->body); WheelListener* listenRL = new WheelListener(&(wheelRL->touchingGround)); wheelFL->body->addContactListener(listenRL); wheelRR = new RearWheel(device, collisionGroupFilter); r->addDrawable(wheelRR->drawable); p->addRigidBody(wheelRR->body); WheelListener* listenRR = new WheelListener(&(wheelRR->touchingGround)); wheelFL->body->addContactListener(listenRR); // Now constrain the tires hkpGenericConstraintData* constraint; hkpConstraintInstance* constraintInst; constraint = new hkpGenericConstraintData(); buildConstraint(&attachFL, constraint, FRONT); constraintInst = new hkpConstraintInstance(wheelFL->body, body, constraint); p->world->addConstraint(constraintInst); constraint->removeReference(); constraint = new hkpGenericConstraintData(); buildConstraint(&attachFR, constraint, FRONT); constraintInst = new hkpConstraintInstance(wheelFR->body, body, constraint); p->world->addConstraint(constraintInst); constraint->removeReference(); constraint = new hkpGenericConstraintData(); buildConstraint(&attachRL, constraint, REAR); constraintInst = new hkpConstraintInstance(wheelRL->body, body, constraint); p->world->addConstraint(constraintInst); constraint->removeReference(); constraint = new hkpGenericConstraintData(); buildConstraint(&attachRR, constraint, REAR); constraintInst = new hkpConstraintInstance(wheelRR->body, body, constraint); p->world->addConstraint(constraintInst); constraint->removeReference(); hkpConstraintStabilizationUtil::stabilizeRigidBodyInertia(body); reset(); }