#include "HavokUtilities.hpp" // Keycode #include // Classlists #define INCLUDE_HAVOK_PHYSICS_CLASSES #define HK_CLASSES_FILE #include // Generate a custom list to trim memory requirements #define HK_COMPAT_FILE #include void addFixedSurface(hkpWorld* world, const hkVector4& position, const hkVector4& dimensions); /* Havok Physics Tutorial 1 console application. Author: Piotr Pluta http://piotrpluta.opol.pl June 2009 */ int main(int argc, const char** argv) { HavokUtilities* havokUtilities = new HavokUtilities(); havokUtilities->registerVisualDebugger(); addFixedSurface(havokUtilities->getWorld(), hkVector4(0,0,0), hkVector4(50.0f,1.0f,50.0f)); //create watch object - we will simulate for 30 seconds of real time hkStopwatch stopWatch; stopWatch.start(); hkReal lastTime = stopWatch.getElapsedSeconds(); //initialize fixed time step - one step every 1/60 of a second hkReal timestep = 1.f / 60.f; //calculate number of steps for entire loop //(30 seconds divided by single time step) int numSteps = int(30.f / timestep); //application loop, breaks after 15 real time seconds for ( int i = 0; i < numSteps; ++i ) { //step the simulation and VDB havokUtilities->stepSimulation(timestep); havokUtilities->stepVisualDebugger(timestep); //pause until the actual time has passed while (stopWatch.getElapsedSeconds() < lastTime + timestep); { lastTime += timestep; } } delete havokUtilities; } void addFixedSurface(hkpWorld* world, const hkVector4& position, const hkVector4& dimensions) { //addFixedSurface function //creates fixed surface with specified position and dimensions //create box shape using given dimensions hkpConvexShape* shape = new hkpBoxShape(dimensions,0); //create rigid body information structure hkpRigidBodyCinfo rigidBodyInfo; //MOTION_FIXED means static element in game scene rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED; rigidBodyInfo.m_shape = shape; rigidBodyInfo.m_position = position; //create new rigid body with supplied info hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); //add rigid body to physics world world->lock(); world->addEntity(rigidBody); //decerase reference counter for rigid body and shape rigidBody->removeReference(); shape->removeReference(); world->unlock(); }