SHOW:
|
|
- or go back to the newest paste.
| 1 | #include "precompiled.h" | |
| 2 | #include "PhysicsManager.h" | |
| 3 | #include "Player.h" | |
| 4 | #include "Scenery.h" | |
| 5 | ||
| 6 | namespace PhysicsManager{
| |
| 7 | ||
| 8 | Player *ref_player; | |
| 9 | std::vector<Scenery> scenery; | |
| 10 | ||
| 11 | hkpWorld *world; | |
| 12 | ||
| 13 | void HK_CALL errorReport(const char* msg, void* userContext) | |
| 14 | {
| |
| 15 | printf("%s", msg);
| |
| 16 | } | |
| 17 | void HK_CALL PhysicsManager::Init_Havok(){
| |
| 18 | ||
| 19 | hkMallocAllocator baseMalloc; | |
| 20 | // Need to have memory allocated for the solver. Allocate 1mb for it. | |
| 21 | hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault( &baseMalloc, hkMemorySystem::FrameInfo(1024 * 1024) ); | |
| 22 | hkBaseSystem::init( memoryRouter, errorReport ); | |
| 23 | } | |
| 24 | void HK_CALL PhysicsManager::Cleanup_Havok(){
| |
| 25 | ||
| 26 | hkBaseSystem::quit(); | |
| 27 | hkMemoryInitUtil::quit(); | |
| 28 | } | |
| 29 | ||
| 30 | ||
| 31 | void HK_CALL PhysicsManager::createWorld(){
| |
| 32 | ||
| 33 | // Set world properties. | |
| 34 | hkpWorldCinfo info; | |
| 35 | ||
| 36 | world = new hkpWorld( hkpWorldCinfo() ); | |
| 37 | ||
| 38 | // Register all collision agents | |
| 39 | // It's important to register collision agents before adding any entities to the world. | |
| 40 | hkpAgentRegisterUtil::registerAllAgents( world->getCollisionDispatcher() ); | |
| 41 | } | |
| 42 | void HK_CALL PhysicsManager::cleanupWorld(){
| |
| 43 | // Release the reference on the world | |
| 44 | world->removeReference(); | |
| 45 | } | |
| 46 | ||
| 47 | void HK_CALL PhysicsManager::add_RigidBody_Player( Player &p ){
| |
| 48 | hkpRigidBody* rigidBody; | |
| 49 | {
| |
| 50 | // Create the box. | |
| 51 | hkVector4 halfExtents; | |
| 52 | //halfExtents.set(0.5f, 1.0f, 1.5f); | |
| 53 | glm::vec3 ex = p.Get_Extents(); | |
| 54 | halfExtents.set( ex.x, ex.y, ex.z ); | |
| 55 | ||
| 56 | hkpBoxShape* boxShape = new hkpBoxShape(halfExtents); | |
| 57 | ||
| 58 | hkpRigidBodyCinfo bodyCinfo; | |
| 59 | bodyCinfo.m_shape = boxShape; | |
| 60 | ||
| 61 | // Calculate the mass properties for the shape | |
| 62 | const hkReal boxMass = 10.0f; | |
| 63 | hkpMassProperties massProperties; | |
| 64 | hkpInertiaTensorComputer::computeShapeVolumeMassProperties(boxShape, boxMass, massProperties); | |
| 65 | bodyCinfo.setMassProperties(massProperties); | |
| 66 | ||
| 67 | // Elasticity (value between 0 and 1.99, default = 0.4) | |
| 68 | bodyCinfo.m_restitution = (hkReal) 0.4; | |
| 69 | ||
| 70 | // Set our start position. | |
| 71 | glm::vec3 pos = p.GetPosition(); | |
| 72 | bodyCinfo.m_position = hkVector4( pos.x, pos.y, pos.z, 1 ); | |
| 73 | ||
| 74 | // Create the rigid body | |
| 75 | rigidBody = new hkpRigidBody(bodyCinfo); | |
| 76 | rigidBody->setName( "player" ); | |
| 77 | ||
| 78 | // No longer need the reference on the boxShape, as the rigidBody now owns it | |
| 79 | boxShape->removeReference(); | |
| 80 | } | |
| 81 | ||
| 82 | // Add the rigidBody to the world | |
| 83 | world->addEntity(rigidBody); | |
| 84 | ||
| 85 | // No longer need the ref of rigidBody - as the world now owns it | |
| 86 | rigidBody->removeReference(); | |
| 87 | ||
| 88 | } | |
| 89 | void HK_CALL PhysicsManager::add_RigidBody_Scenery( Scenery &s ){
| |
| 90 | hkpRigidBody* rigidBody; | |
| 91 | {
| |
| 92 | ||
| 93 | glm::vec3 ex = s.Get_Extents(); | |
| 94 | glm::vec4 pos = s.GetPosition(); | |
| 95 | ||
| 96 | // Create the box. | |
| 97 | hkpBoxShape* boxShape = new hkpBoxShape(hkVector4(ex.x, ex.y, ex.z)); | |
| 98 | ||
| 99 | ||
| 100 | // Create info. | |
| 101 | hkpRigidBodyCinfo bodyCinfo; | |
| 102 | bodyCinfo.m_shape = boxShape; | |
| 103 | ||
| 104 | // Calculate the mass properties for the shape | |
| 105 | const hkReal boxMass = 10.0f; | |
| 106 | hkpMassProperties massProperties; | |
| 107 | hkpInertiaTensorComputer::computeShapeVolumeMassProperties(boxShape, boxMass, massProperties); | |
| 108 | bodyCinfo.setMassProperties(massProperties); | |
| 109 | ||
| 110 | // Elasticity (value between 0 and 1.99, default = 0.4) | |
| 111 | bodyCinfo.m_restitution = (hkReal) 1.9; | |
| 112 | ||
| 113 | // Set our start position. | |
| 114 | bodyCinfo.m_position = hkVector4( pos.x, pos.y, pos.z, pos.w ); | |
| 115 | ||
| 116 | // Create the rigid body | |
| 117 | rigidBody = new hkpRigidBody(bodyCinfo); | |
| 118 | rigidBody->setName( s.GetName().c_str() ); | |
| 119 | ||
| 120 | // No longer need the reference on the boxShape, as the rigidBody now owns it | |
| 121 | boxShape->removeReference(); | |
| 122 | } | |
| 123 | ||
| 124 | // Add the rigidBody to the world | |
| 125 | world->addEntity(rigidBody); | |
| 126 | ||
| 127 | // No longer need the ref of rigidBody - as the world now owns it | |
| 128 | rigidBody->removeReference(); | |
| 129 | } | |
| 130 | void HK_CALL PhysicsManager::add_Body(){
| |
| 131 | ||
| 132 | } | |
| 133 | ||
| 134 | void HK_CALL PhysicsManager::Update( GLdouble time ){}
| |
| 135 | ||
| 136 | void HK_CALL PhysicsManager::Update_Transforms( vector<Scenery*> &sv ){
| |
| 137 | for( int c = 0; c < sv.size(); c++ ){
| |
| 138 | ||
| 139 | } | |
| 140 | } | |
| 141 | ||
| 142 | } | |
| 143 | ||
| 144 | // [id=keycode] | |
| 145 | - | // Keycode |
| 145 | + | |
| 146 | ||
| 147 | // [id=productfeatures] | |
| 148 | - | // Productfeatures |
| 148 | + | |
| 149 | // that we don't get the usual initialization for these products. | |
| 150 | ||
| 151 | #undef HK_FEATURE_PRODUCT_AI | |
| 152 | #undef HK_FEATURE_PRODUCT_ANIMATION | |
| 153 | #undef HK_FEATURE_PRODUCT_CLOTH | |
| 154 | #undef HK_FEATURE_PRODUCT_DESTRUCTION | |
| 155 | #undef HK_FEATURE_PRODUCT_BEHAVIOR | |
| 156 | #define HK_EXCLUDE_FEATURE_SerializeDeprecatedPre700 | |
| 157 | - | // Also we're not using any serialization/versioning so we don't need any of these. |
| 157 | + | |
| 158 | ||
| 159 | // Vdb needs the reflected classes | |
| 160 | - | //#define HK_EXCLUDE_FEATURE_RegisterReflectedClasses |
| 160 | + | |
| 161 | #define HK_EXCLUDE_FEATURE_hkpAccurateInertiaTensorComputer | |
| 162 | #define HK_EXCLUDE_FEATURE_CompoundShape | |
| 163 | - | // This include generates an initialization function based on the products |
| 163 | + | |
| 164 | - | // and the excluded features. |
| 164 | + | #define HK_EXCLUDE_FEATURE_hkpAabbTreeWorldManager |
| 165 | #define HK_EXCLUDE_FEATURE_hkpContinuousSimulation | |
| 166 | #define HK_EXCLUDE_FEATURE_hkpKdTreeWorldManager | |
| 167 | ||
| 168 | #include <Common/Base/Config/hkProductFeatures.cxx> |