void PhantomAABB::Move(hkVector4& delta) { aabb.m_min = hkVector4(aabb.m_min(0) + delta(0), aabb.m_min(1) + delta(1), aabb.m_min(2) + delta(2)); aabb.m_max = hkVector4(aabb.m_max(0) + delta(0), aabb.m_max(1) + delta(1), aabb.m_max(2) + delta(2)); if (phantom) phantom->setAabb(aabb); }
const int PairCollisionFilter::runIrr() { device->run(); driver->beginScene(); scene_manager->drawAll(); gui_env->drawAll(); hkVector4 new_pos = movingBox->getPosition(); scene::IMeshSceneNode* g_box = (scene::IMeshSceneNode*) scene_manager->getSceneNodeFromId(1); g_box->setPosition(core::vector3df(new_pos(0), new_pos(1), new_pos(2))); //reset moving box position if(receiver.IsKeyDown(EKEY_CODE::KEY_KEY_R)) { movingBox->setPosition(hkVector4(0.f, 7.f, 0.f)); } //press space to make flying moving box if(receiver.IsKeyDown(EKEY_CODE::KEY_SPACE)) { movingBox->setLinearVelocity(hkVector4(0.f, 3.f, 0.f)); } driver->endScene(); return 0; }
void DebugDrawManager::add_cycle( const hkVector4& pos, const hkVector4& d, float r, uint32_t color, bool bDepth) { #ifdef HAVOK_COMPILE hkQuaternion orientation; hkVector4 normal = d; const int steps=64; normal.normalize3(); hkQuaternionUtil::_computeShortestRotation(hkVector4(0,0,1,0),normal, orientation); hkVector4 p; p.setRotatedDir(orientation,hkVector4(r,0,0,0)); p.add4(pos); for(int i=1;i<=steps;++i) { const hkReal angle=i/(hkReal)steps*HK_REAL_PI*2; hkVector4 v(0,0,0,0); v(0) = r*hkMath::cos(angle); v(1) = r*hkMath::sin(angle); hkVector4 c; c.setRotatedDir(orientation,v); c.add4(pos); add_line(p, c, color, bDepth); p=c; } p.setAddMul4(pos, normal, r/4.0f); add_line(pos, p, color, bDepth); #endif }
ComponentColliderBox::ComponentColliderBox(hkVector4& _size) : ComponentCollider() { size = hkVector4(_size); size.div4(hkVector4(2, 2, 2, 2)); sizeUnscaled = size; collider = null; }
void Racer::applyFriction(float seconds) { float xFrictionForce = 3.0f * 20 * -chassisMass / 4.0f; float zFrictionForce = 1.5f * 20 * -chassisMass / 4.0f; hkVector4 point; D3DXMATRIX transMat; (body->getTransform()).get4x4ColumnMajor(transMat); hkVector4 xVector = hkVector4(transMat._11, transMat._12, transMat._13); hkVector4 zVector = hkVector4(transMat._31, transMat._32, transMat._33); if (wheelFL->touchingGround) { applyFrictionToTire(&attachFL, wheelFL->body, &xVector, &zVector, xFrictionForce, zFrictionForce, seconds); } if (wheelFR->touchingGround) { applyFrictionToTire(&attachFR, wheelFR->body, &xVector, &zVector, xFrictionForce, zFrictionForce, seconds); } if (wheelRL->touchingGround) { applyFrictionToTire(&attachRL, wheelRL->body, &xVector, &zVector, xFrictionForce, zFrictionForce, seconds); } if (wheelRR->touchingGround) { applyFrictionToTire(&attachRR, wheelRR->body, &xVector, &zVector, xFrictionForce, zFrictionForce, seconds); } }
hkpRigidBody* PhysicsWrapper::SetupSphericalRigidBody(float radius, float mass, D3DXVECTOR3 position, D3DXVECTOR3 velocity, bool isStatic, ProjectStructs::PROJECTILE *projectile){ hkVector4 relPos( 0.0f,radius, 0.0f); hkpRigidBodyCinfo info; hkpMassProperties massProperties; hkpInertiaTensorComputer::computeSphereVolumeMassProperties(radius, mass, massProperties); info.m_mass = massProperties.m_mass; info.m_centerOfMass = massProperties.m_centerOfMass; info.m_friction = 0.75f; info.m_inertiaTensor = massProperties.m_inertiaTensor; info.m_shape = new hkpSphereShape( radius ); relPos.add4(hkVector4(position.x, position.y, position.z)); info.m_position = relPos; info.m_linearVelocity = hkVector4(velocity.x, velocity.y, velocity.z); if(isStatic) { info.m_motionType = hkpMotion::MOTION_FIXED; info.m_qualityType = HK_COLLIDABLE_QUALITY_FIXED; } else{ info.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA; info.m_qualityType = HK_COLLIDABLE_QUALITY_MOVING; } hkpRigidBody* rb = new hkpRigidBody( info ); rb->addProperty(HK_OBJECT_IS_PROJECTILE, hkpPropertyValue(projectile)); physicsWorld->addEntity( rb ); rb->removeReference(); info.m_shape->removeReference(); return rb; }
void VehicleApiDemo::buildLandscape() { // // Create the landscape to drive on. Just a flat box bounded by 4 walls (also boxes). // { const hkReal sideLength = 100.0f; const hkReal depth = 1.0f; const hkReal width = 3.0f; const hkReal height = 5.0f; // Size of the boxes. hkVector4 halfExtentsGround = hkVector4(sideLength, depth, sideLength); hkVector4 halfExtents1 = hkVector4(width, height, sideLength); hkVector4 halfExtents2 = hkVector4(sideLength, height, width); hkpRigidBodyCinfo groundInfo; groundInfo.m_position.set(5.0f, -2.0f, 5.0f); groundInfo.m_motionType = hkpMotion::MOTION_FIXED; groundInfo.m_friction = 0.5f; // ground { groundInfo.m_shape = new hkpBoxShape(halfExtentsGround, 0 ); groundInfo.m_position.set( 0, -2, 0 ); m_world->addEntity( new hkpRigidBody(groundInfo) )->removeReference(); groundInfo.m_shape->removeReference(); } // wall12 { groundInfo.m_shape = new hkpBoxShape(halfExtents1, 0 ); groundInfo.m_position.set( sideLength+width, height - 2.0f, 0.0f); m_world->addEntity( new hkpRigidBody(groundInfo) )->removeReference(); groundInfo.m_position.set( -sideLength-width, height - 2.0f, 0.0f); m_world->addEntity( new hkpRigidBody(groundInfo) )->removeReference(); groundInfo.m_shape->removeReference(); } // wall34 { groundInfo.m_shape = new hkpBoxShape(halfExtents2, 0 ); groundInfo.m_position.set( 0.0f, height - 2.0f, -(sideLength+width) ); m_world->addEntity( new hkpRigidBody(groundInfo) )->removeReference(); groundInfo.m_position.set( 0.0f, height - 2.0f, +(sideLength+width) ); m_world->addEntity( new hkpRigidBody(groundInfo) )->removeReference(); groundInfo.m_shape->removeReference(); } } }
BoxHavok::BoxHavok() { this->halfExtent = hkVector4(0.0f, 0.0f, 0.0f); this->startingPosition = hkVector4(0.0f, 0.0f, 0.0f); this->mass = 0.0f; this->friction = 0.1f; this->restitution = 0.0f; this->moveable = true; }
VehicleCloning::VehicleCloning(hkDemoEnvironment* env, hkBool createWorld) : hkDefaultPhysicsDemo(env) { m_bootstrapIterations = 200; m_track = HK_NULL; m_numWheels = 4; m_landscapeContainer = HK_NULL; setUpWorld(); if (!createWorld) { return; } m_world->lock(); const VehicleCloningVariant& variant = g_variants[m_variantId]; m_vehicles.setSize( variant.m_numVehicles ); // Create a vehicle to use as a template for cloning other vehicles hkpPhysicsSystem* vehicleSystem = createVehicle(); // Clone the vehicle and add the clones to the world hkArray<hkAabb> spawnVolumes; spawnVolumes.pushBack(hkAabb(hkVector4(-95, 2, -95), hkVector4(95, 8, 95))); AabbSpawnUtil spawnUtil( spawnVolumes ); for ( int i = 0; i < variant.m_numVehicles; ++i ) { hkpPhysicsSystem* newVehicleSystem = vehicleSystem->clone(); hkVector4 objectSize( 4, 4, 4 ); hkVector4 position; spawnUtil.getNewSpawnPosition( objectSize, position ); newVehicleSystem->getRigidBodies()[0]->setPosition(position); m_vehicles[i] = static_cast<hkpVehicleInstance*>(newVehicleSystem->getActions()[0]); m_vehicles[i]->addReference(); m_world->addPhysicsSystem( newVehicleSystem ); newVehicleSystem->removeReference(); } createWheels(variant.m_numVehicles); vehicleSystem->removeReference(); m_world->unlock(); }
Extrusion::Extrusion(Vector3 pos, Vector3 size, Vector3 axis, float extrusionTravel, hkpWorld * world, SceneManager * sceneMgr): mWorld(world), mSceneMgr(sceneMgr) { hkVector4 halfSize(size.x * 0.5f, size.y * 0.5, size.z * 0.5); hkpBoxShape * shape = new hkpBoxShape(halfSize, 0); hkpRigidBodyCinfo info; info.m_shape = shape; info.m_mass = 800.0f; hkpInertiaTensorComputer::setShapeVolumeMassProperties(shape, info.m_mass, info); info.m_motionType = hkpMotion::MOTION_BOX_INERTIA; info.m_position.set(pos.x, pos.y, pos.z); mBody = new hkpRigidBody(info); mWorld->addEntity(mBody); shape->removeReference(); hkpRigidBodyCinfo anchorInfo; anchorInfo.m_motionType = hkpMotion::MOTION_FIXED; anchorInfo.m_position = hkVector4(pos.x + (20.0f * axis.x), pos.y, pos.z + (20.0f * axis.z)); anchorInfo.m_shape = new hkpSphereShape(0.1f); hkpRigidBody * anchor = new hkpRigidBody(anchorInfo); mWorld->addEntity(anchor); // Setup prismatic constraint hkVector4 a(axis.x, axis.y, axis.z); hkpPrismaticConstraintData * prismatic = new hkpPrismaticConstraintData(); prismatic->setMaxLinearLimit(extrusionTravel); prismatic->setMinLinearLimit(0.0f); prismatic->setInWorldSpace(mBody->getTransform(), anchor->getTransform(), hkVector4(pos.x, pos.y, pos.z), a); hkpConstraintInstance * prismaticConstraint = new hkpConstraintInstance(mBody, anchor, prismatic); mWorld->addConstraint(prismaticConstraint); prismaticConstraint->removeReference(); prismatic->removeReference(); // Ogre char entityName[] = "000ExtrusionEntity"; entityName[0] += numExtrusions; mMesh = mSceneMgr->createEntity(entityName, "cube.mesh"); AxisAlignedBox aab = mMesh->getBoundingBox(); mMesh->setMaterialName("Examples/CubeDefault"); Vector3 meshSize = aab.getSize(); Vector3 scaling = size / meshSize; char nodeName[] = "000ExtrusionNode"; nodeName[0] += numExtrusions; mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(nodeName); mNode->setPosition(pos.x, pos.y, pos.z); mNode->setScale(scaling); mNode->attachObject(mMesh); numExtrusions++; }
void CrashTestDummiesDemo::createGroundBox() { hkpShape* shape = new hkpBoxShape(hkVector4(20,20,0.1f), 0.01f); hkpRigidBodyCinfo info; info.m_shape = shape; info.m_motionType = hkpMotion::MOTION_FIXED; info.m_position = hkVector4(2.0f, 1.0f, -0.1f); info.m_friction = 1.0f; hkpRigidBody* body = new hkpRigidBody(info); m_world->addEntity(body); body->removeReference(); shape->removeReference(); }
void RearWheel::setPosAndRot(float posX, float posY, float posZ, float rotX, float rotY, float rotZ) // In Radians { drawable->setPosAndRot(posX, posY, posZ, rotX, rotY, rotZ); hkQuaternion quat; quat.setAxisAngle(hkVector4(1.0f, 0.0f, 0.0f), rotX); quat.mul(hkQuaternion(hkVector4(0.0f, 1.0f, 0.0f), rotY)); quat.mul(hkQuaternion(hkVector4(0.0f, 0.0f, 1.0f), rotZ)); hkVector4 pos = hkVector4(posX, posY, posZ); body->setPositionAndRotation(hkVector4(posX, posY, posZ), quat); }
void DebugDrawManager::add_axis( const hkQsTransform& t, float size , bool bDepth) { #ifdef HAVOK_COMPILE const hkVector4& start_pos = t.m_translation; hkVector4 x_end; x_end.setTransformedPos(t, hkVector4(size,0,0)); hkVector4 y_end; y_end.setTransformedPos(t, hkVector4(0,size,0)); hkVector4 z_end; z_end.setTransformedPos(t, hkVector4(0,0,size)); add_line(start_pos, x_end, RGBA(255,0,0,255), bDepth); add_line(start_pos, y_end, RGBA(0,255,0,255), bDepth); add_line(start_pos, z_end, RGBA(0,0,255,255), bDepth); #endif }
// This is called every simulation time step. We need to // - Step the simulation. // - Sync each vehicle's display wheels. // - Draw skid marks for the first vehicle if it is skidding. hkDemo::Result VehicleCloning::stepDemo() { // // Step the world. // { hkDefaultPhysicsDemo::stepDemo(); } // // Synch the display wheels. // for (int vehicleId = 0; vehicleId < m_vehicles.getSize(); vehicleId++ ) { if (m_vehicles[vehicleId]->getChassis()->getPosition()(1) < -20 ) { m_vehicles[vehicleId]->getChassis()->setPosition(hkVector4(0,4,0)); } VehicleApiUtils::syncDisplayWheels(m_env, *m_vehicles[vehicleId], m_displayWheelId[vehicleId], m_tag); } // Update the tyre marks for the first vehicle. VehicleDisplayUtils::updateTyremarks( m_timestep, m_vehicles[0] ); return DEMO_OK; }
void CrashTestDummiesDemo::createFastObject() { hkpShape* shape = new hkpSphereShape(0.3f); hkpRigidBodyCinfo info; info.m_shape = shape; info.m_motionType = hkpMotion::MOTION_DYNAMIC; info.m_qualityType = HK_COLLIDABLE_QUALITY_BULLET; info.m_position(2) -= 0.1f; info.m_mass = 10.100f; info.m_position = hkVector4(30.0f, 1.0f, 1.3f); info.m_linearVelocity = hkVector4(-200.0f, 0.0f, 0.0f); hkpRigidBody* body = new hkpRigidBody(info); m_world->addEntity(body); body->removeReference(); shape->removeReference(); }
hkpShape* HK_CALL VehicleApiUtils::createDisc(hkReal radius, hkReal thickness, int numSides) { hkArray<hkVector4> vertices; // // Create the vertices array. // for(int i = 0; i < numSides; i++) { hkTransform t; t.setIdentity(); hkVector4 trans = hkVector4(0.0f, radius, 0.0f); hkReal angle = HK_REAL_PI * 2 * i / (hkReal) numSides; hkVector4 axis(0.0f, 0.0f, 1.0f, 0.0f); hkQuaternion q(axis, angle); trans.setRotatedDir(q, trans); hkVector4 v = trans; v(2) = -(thickness / 2.0f); vertices.pushBack(v); v(2) = (thickness / 2.0f); vertices.pushBack(v); } return new hkpConvexVerticesShape(vertices); }
RearWheel::RearWheel(IDirect3DDevice9* device, int filter) { touchingGround = false; drawable = new Drawable(REARWHEEL, "textures/tire.dds", device); hkVector4 startAxis; startAxis.set(-0.15f, 0, 0); hkVector4 endAxis; endAxis.set(0.15f, 0, 0); hkReal radius = 0.4f; hkpRigidBodyCinfo info; info.m_gravityFactor = 0.0f; info.m_shape = new hkpCylinderShape(startAxis, endAxis, radius); info.m_qualityType = HK_COLLIDABLE_QUALITY_CRITICAL; info.m_restitution = 0.0f; info.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(hkpGroupFilterSetup::LAYER_DYNAMIC, filter); body = new hkpRigidBody(info); //Create rigid body body->setLinearVelocity(hkVector4(0, 0, 0)); info.m_shape->removeReference(); lastPos.set(0,0,0); rotation = 0.0; }
hkDemo::Result OutOfWorldRaycastDemo::stepDemo() { m_world->lock(); //if( m_env->m_gamePad->wasButtonPressed(HKG_PAD_BUTTON_1) ) { for (int i=0; i<2; i++) { hkVector4 p( m_rand.getRandReal01(), m_rand.getRandReal01(), m_rand.getRandReal01() ); p.sub4( hkVector4(0.5f,0.5f,0.5f) ); p.mul4( 19.0f ); // change to larger value to put one or both outside m_boxes[i]->setPosition(p); } } if (m_variantId == 0) { doRaycast(m_boxes[0], m_boxes[1]); doRaycast(m_boxes[1], m_boxes[0]); } else { doLinearCast(m_boxes[0], m_boxes[1]); doLinearCast(m_boxes[1], m_boxes[0]); } m_world->unlock(); return hkDefaultPhysicsDemo::stepDemo(); }
void Racer::buildConstraint(hkVector4* attachmentPt, hkpGenericConstraintData* constraint, WheelType type) { hkpConstraintConstructionKit* kit = new hkpConstraintConstructionKit(); kit->begin(constraint); kit->setLinearDofA(xAxis, xID); kit->setLinearDofB(xAxis, xID); kit->setLinearDofA(yAxis, yID); kit->setLinearDofB(yAxis, yID); kit->setLinearDofA(zAxis, zID); kit->setLinearDofB(zAxis, zID); kit->setPivotA(hkVector4(0,0,0)); kit->setPivotB(*attachmentPt); kit->setAngularBasisABodyFrame(); kit->setAngularBasisBBodyFrame(); kit->constrainLinearDof(xID); kit->constrainLinearDof(zID); //kit->constrainToAngularDof(xID); kit->constrainAllAngularDof(); if (type == FRONT) { kit->setLinearLimit(yID, -0.15f, 0.35f); } else { kit->setLinearLimit(yID, -0.15f, 0.42f); } kit->end(); constraint->setSolvingMethod(hkpConstraintAtom::METHOD_STABILIZED); }
static LandscapeContainer* createFlatLand( const int landscapeSize, const hkVector4& scaling ) { FlatlandLandscapeContainer* landscapeContainer = new FlatlandLandscapeContainer(); landscapeContainer->m_flatland = new FlatLand(landscapeSize); landscapeContainer->m_flatland->setScaling(scaling); landscapeContainer->m_shape = landscapeContainer->m_flatland->createMoppShapeForSpu(); hkAabb aabb(hkVector4(-95, 2, -95), hkVector4(95, 8, 95)); landscapeContainer->m_spawnVolumes.pushBack(aabb); landscapeContainer->m_cameraFrom.set(138, 60, -136); landscapeContainer->m_cameraTo.set(0,0,0); return landscapeContainer; }
void Box::init(hkpWorld *world) { float calcMass = density * sx * sy * sz; //mass = density*vol hkpBoxShape* sBox = new hkpBoxShape(hkVector4(sx, sy, sz)); sBox->setRadius(0.001f); // adjust the convex radius as req’d setRigidBodyInfo(world, sBox, calcMass); }
void Object_Player::characterInputOutput(D3DXVECTOR3 lookAt) { hkpCharacterInput input; hkpCharacterOutput output; input.m_inputLR = velLR; input.m_inputUD = velUD; input.m_wantJump = wantJump; input.m_atLadder = false; input.m_up = hkVector4(0, 1, 0); input.m_forward.set(0.0f, 0.0f, D3DXToRadian(rotation.x)); input.m_forward.setRotatedDir(hk_rotation, input.m_forward); hkStepInfo stepInfo; stepInfo.m_deltaTime = 1.0f / 60.0f; stepInfo.m_invDeltaTime = 1.0f / (1.0f / 60.0f); input.m_stepInfo = stepInfo; input.m_characterGravity.set(0, -16, 0); input.m_velocity = objectBody->getRigidBody()->getLinearVelocity(); input.m_position = objectBody->getRigidBody()->getPosition(); objectBody->checkSupport(stepInfo, input.m_surfaceInfo); context->update(input, output); objectBody->setLinearVelocity(output.m_velocity, 1.0f / 60.0f); }
void DemoKeeper::resetAll( void ) { Keyframe_demoRunning = false; binaryaction_demoRunning = false; mWorld->markForWrite(); mWorld->setGravity(hkVector4(0.f,-9.81f,0.f)); mWorld->unmarkForWrite(); }
void Box::setVel(float x, float y, float z) { vel.x = x; vel.y = y; vel.z = z; this->getRigidBody()->setLinearVelocity(hkVector4(x, y, z)); }
Landmine::Landmine(IDirect3DDevice9* device) { drawable = new Drawable(LANDMINEMESH, "textures/landmine.dds", device); hkVector4 startAxis; startAxis.set(0, -0.05f, 0); hkVector4 endAxis; endAxis.set(0, 0.05f, 0); hkReal radius = 0.6f; hkpRigidBodyCinfo info; info.m_shape = new hkpCylinderShape(startAxis, endAxis, radius); info.m_qualityType = HK_COLLIDABLE_QUALITY_MOVING; info.m_angularDamping = 1.0f; hkpMassProperties massProperties; hkpInertiaTensorComputer::computeCylinderVolumeMassProperties(startAxis, endAxis, radius, 20.0, massProperties); info.setMassProperties(massProperties); body = new hkpRigidBody(info); //Create rigid body body->setLinearVelocity(hkVector4(0, 0, 0)); body->setAngularVelocity(hkVector4(0, 0, 0)); info.m_shape->removeReference(); hkpPropertyValue val; val.setPtr(this); body->setProperty(1, val); listener = new LandmineListener(this); body->addContactListener(listener); Physics::physics->addRigidBody(body); destroyed = false; triggered = false; emitter = Sound::sound->getEmitter(); owner = NULL; triggeredTime = 0.1f; activationTime = 1.0f; activated = false; }
hkpShape* ObjectPool::calculateCollisionMesh(irr::scene::IAnimatedMesh* objectMesh, ObjectType objectType, bool /*box*/) { hkpShape* hkShape = 0; if (objectType == Tree || objectType == MyTree) { hk::lock(); hkShape = new hkpBoxShape(hkVector4(1.0f, 20.0f, 1.0f), 0); hk::unlock(); return hkShape; } if (objectMesh == 0) return hkShape; int sizeOfBuffers = 0; for (unsigned int i = 0; i < objectMesh->getMeshBufferCount(); i++) { if (objectMesh->getMeshBuffer(i)->getVertexType() != irr::video::EVT_STANDARD) { printf("object %u type mismatch %u\n", i, objectMesh->getMeshBuffer(i)->getVertexType()); assert(0); return hkShape; } sizeOfBuffers += objectMesh->getMeshBuffer(i)->getVertexCount(); } float* my_vertices = new float[sizeOfBuffers*3]; int cursor = 0; for (unsigned int i = 0; i < objectMesh->getMeshBufferCount();i++) { irr::scene::IMeshBuffer* mb = objectMesh->getMeshBuffer(i); irr::video::S3DVertex* mb_vertices = (irr::video::S3DVertex*)mb->getVertices(); for (unsigned int j = 0, tmpCounter = cursor*3; j < mb->getVertexCount(); j++, tmpCounter+=3) { my_vertices[tmpCounter] = mb_vertices[j].Pos.X /* scale.X */; my_vertices[tmpCounter+1] = mb_vertices[j].Pos.Y /* scale.Y */; my_vertices[tmpCounter+2] = mb_vertices[j].Pos.Z /* scale.Z */; //my_vertices[(cursor+j)*4+3] = 0.0f; } cursor += mb->getVertexCount(); } hk::lock(); hkStridedVertices stridedVerts; stridedVerts.m_numVertices = sizeOfBuffers; stridedVerts.m_striding = 3*sizeof(float); stridedVerts.m_vertices = my_vertices; hkShape = new hkpConvexVerticesShape(stridedVerts); hk::unlock(); delete [] my_vertices; return hkShape; }
RearWheel::RearWheel(IDirect3DDevice9* device, int filter) { touchingGround = false; drawable = new Drawable(REARWHEEL, "tire.dds", device); hkVector4 startAxis = hkVector4(-0.2f, 0, 0); hkVector4 endAxis = hkVector4(0.2f, 0, 0); hkReal radius = 0.42f; hkpRigidBodyCinfo info; info.m_shape = new hkpCylinderShape(startAxis, endAxis, radius); info.m_qualityType = HK_COLLIDABLE_QUALITY_MOVING; info.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(hkpGroupFilterSetup::LAYER_DYNAMIC, filter); body = new hkpRigidBody(info); //Create rigid body body->setLinearVelocity(hkVector4(0, 0, 0)); info.m_shape->removeReference(); }
gep::CollisionMesh* gep::CollisionMeshFileLoader::loadResource(CollisionMesh* pInPlace) { CollisionMesh* result = nullptr; bool isInPlace = true; if (pInPlace == nullptr) { result = new CollisionMesh(); isInPlace = false; } auto* havokLoader = g_resourceManager.getHavokResourceLoader(); auto* container = havokLoader->load(m_path.c_str()); GEP_ASSERT(container != nullptr, "Could not load asset! %s", m_path.c_str()); if (container) { auto* physicsData = reinterpret_cast<hkpPhysicsData*>(container->findObjectByType(hkpPhysicsDataClass.getName())); GEP_ASSERT(physicsData != nullptr, "Unable to load physics data!"); if (physicsData) { const auto& physicsSystems = physicsData->getPhysicsSystems(); GEP_ASSERT(physicsSystems.getSize() == 1, "Wrong number of physics systems!"); auto body = physicsSystems[0]->getRigidBodies()[0]; auto hkShape = body->getCollidable()->getShape(); auto shape = conversion::hk::from(const_cast<hkpShape*>(hkShape)); auto type = shape->getShapeType(); if ( type == hkcdShapeType::BV_COMPRESSED_MESH || type == hkcdShapeType::CONVEX_VERTICES ) { hkTransform transform = body->getTransform(); transform.getRotation().setAxisAngle(hkVector4(0.0f, 0.0f, 1.0f), GetPi<float>::value()); auto hkTransformShape = new hkpTransformShape(hkShape, transform); hkTransformShape->addReference(); shape = GEP_NEW(m_pAllocator, HavokShape_Transform)(hkTransformShape); //auto meshShape = static_cast<HavokMeshShape*>(shape); //Transform* tempTrans = new Transform(); //conversion::hk::from(transform, *tempTrans); // //// Since havok content tools are buggy (?) and no custom transformation can be applied, //// we have to convert into our engine's space by hand. //// TODO: Ensure, that this transformation is correct in every case //tempTrans->setRotation(tempTrans->getRotation() * Quaternion(vec3(1,0,0),180)); //meshShape->setTransform(tempTrans); } result->setShape(shape); } } return result; }
void Racer::reset() { hkVector4 reset = hkVector4(0.0f, 0.0f, 0.0f); setPosAndRot(0.0f, 10.0f, 0.0f, 0, 0, 0); body->setLinearVelocity(reset); wheelFL->body->setLinearVelocity(reset); wheelFR->body->setLinearVelocity(reset); wheelRL->body->setLinearVelocity(reset); wheelRR->body->setLinearVelocity(reset); }
AddRemoveBodiesDemo::AddRemoveBodiesDemo(hkDemoEnvironment* env) : hkDefaultPhysicsDemo(env), m_frameCount(0), m_currentBody(0) { for( int i = 0; i < NUM_BODIES; i++ ) { m_bodies[i] = HK_NULL; } // // Setup the camera // { hkVector4 from(0.0f, 30.0f, 50.0f); hkVector4 to (0.0f, 0.0f, 0.0f); hkVector4 up (0.0f, 1.0f, 0.0f); setupDefaultCameras(env, from, to, up); float lightDir[] = { -1, -0.5f , -0.25f}; float lightAabbMin[] = { -15, -15, -15}; float lightAabbMax[] = { 15, 15, 15}; setLightAndFixedShadow(lightDir, lightAabbMin, lightAabbMax ); } // // Setup and create the hkpWorld // { hkpWorldCinfo info; info.m_gravity = hkVector4(0.0f, -9.8f, 0.0f); info.setBroadPhaseWorldSize(1000.0f); info.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_8ITERS_MEDIUM); info.m_collisionTolerance = 0.01f; m_world = new hkpWorld( info ); m_world->lock(); setupGraphics(); } // Register the single agent required (a hkpBoxBoxAgent) { hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher()); } // Create the rigid bodies createBodies(); // Create the ground createGround(); m_world->unlock(); }