Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "precompiled.h"
- #include "PhysicsManager.h"
- #include "Player.h"
- #include "Scenery.h"
- namespace PhysicsManager{
- Player *ref_player;
- std::vector<Scenery> scenery;
- hkpWorld *world;
- void HK_CALL errorReport(const char* msg, void* userContext)
- {
- printf("%s", msg);
- }
- void HK_CALL PhysicsManager::Init_Havok(){
- hkMallocAllocator baseMalloc;
- // Need to have memory allocated for the solver. Allocate 1mb for it.
- hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault( &baseMalloc, hkMemorySystem::FrameInfo(1024 * 1024) );
- hkBaseSystem::init( memoryRouter, errorReport );
- }
- void HK_CALL PhysicsManager::Cleanup_Havok(){
- hkBaseSystem::quit();
- hkMemoryInitUtil::quit();
- }
- void HK_CALL PhysicsManager::createWorld(){
- // Set world properties.
- hkpWorldCinfo info;
- world = new hkpWorld( hkpWorldCinfo() );
- // Register all collision agents
- // It's important to register collision agents before adding any entities to the world.
- hkpAgentRegisterUtil::registerAllAgents( world->getCollisionDispatcher() );
- }
- void HK_CALL PhysicsManager::cleanupWorld(){
- // Release the reference on the world
- world->removeReference();
- }
- void HK_CALL PhysicsManager::add_RigidBody_Player( Player &p ){
- hkpRigidBody* rigidBody;
- {
- // Create the box.
- hkVector4 halfExtents;
- //halfExtents.set(0.5f, 1.0f, 1.5f);
- glm::vec3 ex = p.Get_Extents();
- halfExtents.set( ex.x, ex.y, ex.z );
- hkpBoxShape* boxShape = new hkpBoxShape(halfExtents);
- hkpRigidBodyCinfo bodyCinfo;
- bodyCinfo.m_shape = boxShape;
- // Calculate the mass properties for the shape
- const hkReal boxMass = 10.0f;
- hkpMassProperties massProperties;
- hkpInertiaTensorComputer::computeShapeVolumeMassProperties(boxShape, boxMass, massProperties);
- bodyCinfo.setMassProperties(massProperties);
- // Elasticity (value between 0 and 1.99, default = 0.4)
- bodyCinfo.m_restitution = (hkReal) 0.4;
- // Set our start position.
- glm::vec3 pos = p.GetPosition();
- bodyCinfo.m_position = hkVector4( pos.x, pos.y, pos.z, 1 );
- // Create the rigid body
- rigidBody = new hkpRigidBody(bodyCinfo);
- rigidBody->setName( "player" );
- // No longer need the reference on the boxShape, as the rigidBody now owns it
- boxShape->removeReference();
- }
- // Add the rigidBody to the world
- world->addEntity(rigidBody);
- // No longer need the ref of rigidBody - as the world now owns it
- rigidBody->removeReference();
- }
- void HK_CALL PhysicsManager::add_RigidBody_Scenery( Scenery &s ){
- hkpRigidBody* rigidBody;
- {
- glm::vec3 ex = s.Get_Extents();
- glm::vec4 pos = s.GetPosition();
- // Create the box.
- hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(ex.x, ex.y, ex.z));
- // Create info.
- hkpRigidBodyCinfo bodyCinfo;
- bodyCinfo.m_shape = boxShape;
- // Calculate the mass properties for the shape
- const hkReal boxMass = 10.0f;
- hkpMassProperties massProperties;
- hkpInertiaTensorComputer::computeShapeVolumeMassProperties(boxShape, boxMass, massProperties);
- bodyCinfo.setMassProperties(massProperties);
- // Elasticity (value between 0 and 1.99, default = 0.4)
- bodyCinfo.m_restitution = (hkReal) 1.9;
- // Set our start position.
- bodyCinfo.m_position = hkVector4( pos.x, pos.y, pos.z, pos.w );
- // Create the rigid body
- rigidBody = new hkpRigidBody(bodyCinfo);
- rigidBody->setName( s.GetName().c_str() );
- // No longer need the reference on the boxShape, as the rigidBody now owns it
- boxShape->removeReference();
- }
- // Add the rigidBody to the world
- world->addEntity(rigidBody);
- // No longer need the ref of rigidBody - as the world now owns it
- rigidBody->removeReference();
- }
- void HK_CALL PhysicsManager::add_Body(){
- }
- void HK_CALL PhysicsManager::Update( GLdouble time ){}
- void HK_CALL PhysicsManager::Update_Transforms( vector<Scenery*> &sv ){
- for( int c = 0; c < sv.size(); c++ ){
- }
- }
- }
- // [id=keycode]
- #include <Common/Base/keycode.cxx>
- // [id=productfeatures]
- // We're using only physics - we undef products even if the keycode is present so
- // that we don't get the usual initialization for these products.
- #undef HK_FEATURE_PRODUCT_AI
- #undef HK_FEATURE_PRODUCT_ANIMATION
- #undef HK_FEATURE_PRODUCT_CLOTH
- #undef HK_FEATURE_PRODUCT_DESTRUCTION
- #undef HK_FEATURE_PRODUCT_BEHAVIOR
- #define HK_EXCLUDE_FEATURE_SerializeDeprecatedPre700
- #define HK_EXCLUDE_FEATURE_RegisterVersionPatches
- // Vdb needs the reflected classes
- #define HK_EXCLUDE_FEATURE_MemoryTracker
- #define HK_EXCLUDE_FEATURE_hkpAccurateInertiaTensorComputer
- #define HK_EXCLUDE_FEATURE_CompoundShape
- #define HK_EXCLUDE_FEATURE_hkpAabbTreeWorldManager
- #define HK_EXCLUDE_FEATURE_hkpContinuousSimulation
- #define HK_EXCLUDE_FEATURE_hkpKdTreeWorldManager
- #include <Common/Base/Config/hkProductFeatures.cxx>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement