From 0e2934647c2fd212a0f0d511da8602c9715d7254 Mon Sep 17 00:00:00 2001 From: Tleety Date: Sun, 1 Jun 2014 03:01:37 +0200 Subject: [PATCH] Added a movable tree or somthing dunno lol tired-. --- assets | 2 +- src/GameWorld.cpp | 53 +++++++++++++++++++++++++++-------- src/Systems/PhysicsSystem.cpp | 8 ++++-- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/assets b/assets index d5c5a86..50ee6f8 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit d5c5a867134f72ff078af1110f622647e6b7b4cd +Subproject commit 50ee6f805f9b8493450366b3a4a771da16350423 diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 09e535c..6eedc97 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -324,33 +324,64 @@ void GameWorld::Initialize() { auto tree = CreateEntity(); auto transform = AddComponent(tree); - transform->Position = glm::vec3(0, -10, 0); - auto model = AddComponent(tree); - model->ModelFile = "Models/Tree/Stem/Stem.obj"; + transform->Position = glm::vec3(0, 10, 0); + auto physics = AddComponent(tree); physics->Mass = 100.f; physics->Static = false; + //physics->LinearDamping = 3.f; physics->CalculateCenterOfMass = true; + { - auto leafs = CreateEntity(tree); - auto transform = AddComponent(leafs); - auto model = AddComponent(leafs); - model->ModelFile = "Models/Tree/Leafs/Leafs.obj"; - model->Transparent = true; - CommitEntity(leafs); + auto stem = CreateEntity(tree); + auto transform = AddComponent(stem); + transform->Position = glm::vec3(0, -2.40906f, 0); + auto model = AddComponent(stem); + model->ModelFile = "Models/Tree/Stem/Stem.obj"; + } + + { + auto leafs = CreateEntity(tree); + auto transform = AddComponent(leafs); + transform->Position = glm::vec3(0, -2.45511f, 0); + auto model = AddComponent(leafs); + model->ModelFile = "Models/Tree/Leafs/Leafs.obj"; + model->Transparent = true; + CommitEntity(leafs); } { + auto shape = CreateEntity(tree); + auto transform = AddComponent(shape); + transform->Position = glm::vec3(0.f, 0.f, 0.f); + auto mesh = AddComponent(shape); + mesh->ResourceName = "Models/Tree/Collision/Collision.obj"; + + CommitEntity(shape); + } + + /*{ auto shape = CreateEntity(tree); auto transform = AddComponent(shape); auto box = AddComponent(shape); - transform->Position = glm::vec3(0.f, 0.f, 2.29552f); + transform->Position = glm::vec3(0.f, 0, 0.f); box->Width = 0.296f; box->Height = 2.511f; box->Depth = 0.296f; CommitEntity(shape); - } + } + + { + auto shape = CreateEntity(tree); + auto transform = AddComponent(shape); + auto sphere = AddComponent(shape); + transform->Position = glm::vec3(0, 2.04506f, 0.f); + sphere->Radius = 1.389f; + + CommitEntity(shape); + }*/ + CommitEntity(tree); } diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 4d8b8ed..d1c5104 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -80,7 +80,7 @@ void Systems::PhysicsSystem::Initialize() worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // You must specify the size of the broad phase - objects should not be simulated outside this region - worldInfo.setBroadPhaseWorldSize(1500.0f); + worldInfo.setBroadPhaseWorldSize(500.0f); m_PhysicsWorld = new hkpWorld(worldInfo); // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks @@ -376,6 +376,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; if(physicsComponent->CalculateCenterOfMass) physicsComponent->CenterOfMass = HKVECTOR4_TO_GLMVEC3(massProperties.m_centerOfMass); + rigidBodyInfo.m_centerOfMass = GLMVEC3_TO_HKVECTOR4(physicsComponent->CenterOfMass); rigidBodyInfo.m_mass = massProperties.m_mass; rigidBodyInfo.m_linearVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialLinearVelocity); @@ -389,7 +390,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity; rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity; rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith); - rigidBodyInfo.m_enableDeactivation = false; + rigidBodyInfo.m_enableDeactivation = true;; } // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); @@ -521,7 +522,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity ) rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity; rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity; rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith); - rigidBodyInfo.m_enableDeactivation = false; + rigidBodyInfo.m_enableDeactivation = true; } // Create RigidBody hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); @@ -770,6 +771,7 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event ) if(m_RigidBodies.find(event.Entity) != m_RigidBodies.end()) { m_PhysicsWorld->markForWrite(); + m_RigidBodies[event.Entity]->activate(); m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity)); auto transformComponent = m_World->GetComponent(event.Entity);