Merge branch 'havok' of github.com:sippeangelo/Return-to-the-Return-of-Return-Fire-2-Returngeance into havok
Conflicts: src/GameWorld.cpp src/Systems/PhysicsSystem.cpp vs11/Returngeance/Returngeance.vcxproj.filters
This commit is contained in:
@@ -6,9 +6,9 @@
|
|||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Box : Component
|
struct BoxShape : Component
|
||||||
{
|
{
|
||||||
Box()
|
BoxShape()
|
||||||
: Width(1.f), Height(1.f), Depth(1.f){ }
|
: Width(1.f), Height(1.f), Depth(1.f){ }
|
||||||
|
|
||||||
float Width;
|
float Width;
|
||||||
@@ -6,9 +6,9 @@
|
|||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Sphere : Component
|
struct SphereShape : Component
|
||||||
{
|
{
|
||||||
Sphere()
|
SphereShape()
|
||||||
: Radius(1.f){ }
|
: Radius(1.f){ }
|
||||||
|
|
||||||
float Radius;
|
float Radius;
|
||||||
+1
-5
@@ -172,7 +172,7 @@ void GameWorld::Initialize()
|
|||||||
|
|
||||||
auto physics = AddComponent<Components::Physics>(cube, "Physics");
|
auto physics = AddComponent<Components::Physics>(cube, "Physics");
|
||||||
physics->Mass = 100;
|
physics->Mass = 100;
|
||||||
auto box = AddComponent<Components::Box>(cube, "Box");
|
auto box = AddComponent<Components::BoxShape>(cube, "BoxShape");
|
||||||
box->Width = 0.5f;
|
box->Width = 0.5f;
|
||||||
box->Height = 0.5f;
|
box->Height = 0.5f;
|
||||||
box->Depth = 0.5f;
|
box->Depth = 0.5f;
|
||||||
@@ -199,10 +199,6 @@ void GameWorld::RegisterComponents()
|
|||||||
{
|
{
|
||||||
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
||||||
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
||||||
m_ComponentFactory.Register("Sphere", []() { return new Components::Sphere(); });
|
|
||||||
m_ComponentFactory.Register("Box", []() { return new Components::Box (); });
|
|
||||||
m_ComponentFactory.Register("Vehicle", []() { return new Components::Vehicle(); });
|
|
||||||
m_ComponentFactory.Register("Wheel", []() { return new Components::Wheel(); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameWorld::RegisterSystems()
|
void GameWorld::RegisterSystems()
|
||||||
|
|||||||
@@ -1,413 +0,0 @@
|
|||||||
#include "PrecompiledHeader.h"
|
|
||||||
#include "GameWorld.h"
|
|
||||||
|
|
||||||
void GameWorld::Initialize()
|
|
||||||
{
|
|
||||||
World::Initialize();
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj");
|
|
||||||
m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj");
|
|
||||||
|
|
||||||
RegisterComponents();
|
|
||||||
=======
|
|
||||||
>>>>>>> havok
|
|
||||||
|
|
||||||
{
|
|
||||||
auto camera = CreateEntity();
|
|
||||||
auto transform = AddComponent<Components::Transform>(camera, "Transform");
|
|
||||||
transform->Position.z = 20.f;
|
|
||||||
transform->Position.y = 20.f;
|
|
||||||
transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
|
|
||||||
auto cameraComp = AddComponent<Components::Camera>(camera, "Camera");
|
|
||||||
cameraComp->FarClip = 2000.f;
|
|
||||||
AddComponent(camera, "Input");
|
|
||||||
auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering");
|
|
||||||
CommitEntity(camera);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
auto ground = CreateEntity();
|
|
||||||
auto transform = AddComponent<Components::Transform>(ground, "Transform");
|
|
||||||
transform->Position = glm::vec3(0, -5, 0);
|
|
||||||
transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f);
|
|
||||||
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
|
||||||
auto model = AddComponent<Components::Model>(ground, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj";
|
|
||||||
auto box = AddComponent<Components::Box>(ground, "Box");
|
|
||||||
box->Width = 200;
|
|
||||||
box->Height = 5;
|
|
||||||
box->Depth = 200;
|
|
||||||
|
|
||||||
auto physics = AddComponent<Components::Physics>(ground, "Physics");
|
|
||||||
physics->Mass = 10;
|
|
||||||
<<<<<<< HEAD
|
|
||||||
CommitEntity(ground);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto jeep = CreateEntity();
|
|
||||||
auto transform = AddComponent<Components::Transform>(jeep, "Transform");
|
|
||||||
transform->Position = glm::vec3(0, 1, 0);
|
|
||||||
|
|
||||||
auto model = AddComponent<Components::Model>(jeep, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/Chassi/chassi.OBJ";
|
|
||||||
CommitEntity(jeep);
|
|
||||||
|
|
||||||
{
|
|
||||||
auto wheel = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
|
||||||
transform->Position = glm::vec3(1.4f, 0.5546f, -0.9242f);
|
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
|
||||||
CommitEntity(wheel);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto wheel = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
|
||||||
transform->Position = glm::vec3(-1.4f, 0.5546f, -0.9242f);
|
|
||||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
|
||||||
CommitEntity(wheel);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto wheel = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
|
||||||
transform->Position = glm::vec3(0.2726f, 0.2805f, 1.9307f);
|
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
|
||||||
CommitEntity(wheel);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto wheel = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
|
||||||
transform->Position = glm::vec3(-0.2726f, 0.2805f, 1.9307f);
|
|
||||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
|
||||||
CommitEntity(wheel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto TankTest = CreateEntity();
|
|
||||||
auto transform = AddComponent<Components::Transform>(TankTest, "Transform");
|
|
||||||
transform->Position = glm::vec3(1.5f, 0.7f, 5.f);
|
|
||||||
|
|
||||||
auto model = AddComponent<Components::Model>(TankTest, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/tank/Chassi.obj";
|
|
||||||
CommitEntity(TankTest);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 83; i++)
|
|
||||||
{
|
|
||||||
auto light = CreateEntity();
|
|
||||||
auto transform = AddComponent<Components::Transform>(light, "Transform");
|
|
||||||
transform->Position = glm::vec3((float)(2*i)*glm::sin((float)i), 3, (float)(2*i)*glm::cos((float)i));
|
|
||||||
|
|
||||||
auto pointLight = AddComponent<Components::PointLight>(light, "PointLight");
|
|
||||||
pointLight->Specular = glm::vec3(0.1f, 0.1f, 0.1f);
|
|
||||||
pointLight->Diffuse = glm::vec3(0.05f, 0.36f, 1.f);
|
|
||||||
pointLight->constantAttenuation = 0.03f;
|
|
||||||
pointLight->linearAttenuation = 0.009f;
|
|
||||||
pointLight->quadraticAttenuation = 0.07f;
|
|
||||||
pointLight->spotExponent = 0.0f;
|
|
||||||
|
|
||||||
auto model = AddComponent<Components::Model>(light, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj";
|
|
||||||
CommitEntity(light);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 500; i++)
|
|
||||||
{
|
|
||||||
auto ball = CreateEntity();
|
|
||||||
auto transform = AddComponent<Components::Transform>(ball, "Transform");
|
|
||||||
transform->Position = glm::vec3(i/5.f, 5 + i*2, i/5.f);
|
|
||||||
transform->Scale = glm::vec3(1.0f, 1.0f, 1.0f);
|
|
||||||
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
|
||||||
auto model = AddComponent<Components::Model>(ball, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Sphere.obj";
|
|
||||||
auto sphere = AddComponent<Components::Sphere>(ball, "Sphere");
|
|
||||||
sphere->Radius = 0.5;
|
|
||||||
auto physics = AddComponent<Components::Physics>(ball, "Physics");
|
|
||||||
physics->Mass = 1;
|
|
||||||
CommitEntity(ball);
|
|
||||||
=======
|
|
||||||
physics->Static = true;
|
|
||||||
|
|
||||||
CommitEntity(ground);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
auto jeep = CreateEntity();
|
|
||||||
auto transform = AddComponent<Components::Transform>(jeep, "Transform");
|
|
||||||
transform->Position = glm::vec3(0, 2, 0);
|
|
||||||
|
|
||||||
auto physics = AddComponent<Components::Physics>(jeep, "Physics");
|
|
||||||
physics->Mass = 1200;
|
|
||||||
auto box = AddComponent<Components::Box>(jeep, "Box");
|
|
||||||
box->Width = 1.487f;
|
|
||||||
box->Height = 0.727f;
|
|
||||||
box->Depth = 2.594f;
|
|
||||||
auto vehicle = AddComponent<Components::Vehicle>(jeep, "Vehicle");
|
|
||||||
vehicle->TopSpeed = 500.f;
|
|
||||||
vehicle->MaxTorque = 1000.f;
|
|
||||||
AddComponent<Components::Input>(jeep, "Input");
|
|
||||||
|
|
||||||
{
|
|
||||||
auto chassis = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(chassis, "Transform");
|
|
||||||
transform->Position = glm::vec3(0, -0.6577f, 0);
|
|
||||||
auto model = AddComponent<Components::Model>(chassis, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/Chassi/chassi.OBJ";
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto wheel = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
|
||||||
transform->Position = glm::vec3(1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
|
|
||||||
transform->Scale = glm::vec3(1.0f);
|
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
|
||||||
Wheel->AxleID = 0;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.837f;
|
|
||||||
Wheel->Steering = true;
|
|
||||||
Wheel->SuspensionStrength = 50.f;
|
|
||||||
Wheel->Friction = 4.0f;
|
|
||||||
Wheel->ConnectedToHandbrake = true;
|
|
||||||
CommitEntity(wheel);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto wheel = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
|
||||||
transform->Position = glm::vec3(-1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
|
|
||||||
transform->Scale = glm::vec3(1.0f);
|
|
||||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/WheelFront/wheelFront.obj";
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
|
||||||
Wheel->AxleID = 0;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.837f;
|
|
||||||
Wheel->Steering = true;
|
|
||||||
Wheel->SuspensionStrength = 50.f;
|
|
||||||
Wheel->Friction = 4.0f;
|
|
||||||
Wheel->ConnectedToHandbrake = true;
|
|
||||||
CommitEntity(wheel);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto wheel = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
|
||||||
transform->Position = glm::vec3(0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
|
||||||
Wheel->AxleID = 1;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.737f;
|
|
||||||
Wheel->Steering = false;
|
|
||||||
Wheel->SuspensionStrength = 50.f;
|
|
||||||
Wheel->Friction = 4.0f;
|
|
||||||
CommitEntity(wheel);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto wheel = CreateEntity(jeep);
|
|
||||||
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
|
|
||||||
transform->Position = glm::vec3(-0.2726f, 0.2805f - 0.6577f, 1.9307f);
|
|
||||||
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
|
|
||||||
auto model = AddComponent<Components::Model>(wheel, "Model");
|
|
||||||
model->ModelFile = "Models/JeepV2/WheelBack/wheelBack.obj";
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
|
|
||||||
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
|
|
||||||
Wheel->AxleID = 1;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.737f;
|
|
||||||
Wheel->Steering = false;
|
|
||||||
Wheel->SuspensionStrength = 50.f;
|
|
||||||
Wheel->Friction = 4.0f;
|
|
||||||
CommitEntity(wheel);
|
|
||||||
}
|
|
||||||
CommitEntity(jeep);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
{
|
|
||||||
// Front Right Wheel
|
|
||||||
auto ent = CreateEntity(car);
|
|
||||||
auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
|
||||||
transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5);
|
|
||||||
transform->Position = glm::vec3(1.1f, -1.5f, -1.3f);
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(ent, "Wheel");
|
|
||||||
Wheel->Hardpoint = glm::vec3(1.1f, 0.f, -1.3f);// HACK: make into component
|
|
||||||
Wheel->AxleID = 0;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.5f;
|
|
||||||
Wheel->Steering = true;
|
|
||||||
Wheel->SuspensionStrength = 20.f;
|
|
||||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
CommitEntity(ent);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// Front Left Wheel
|
|
||||||
auto ent = CreateEntity(car);
|
|
||||||
auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
|
||||||
transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5);
|
|
||||||
transform->Position = glm::vec3(-1.1f, -1.5f, -1.3f);
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(ent, "Wheel");
|
|
||||||
Wheel->Hardpoint = glm::vec3(-1.1f, 0.f, -1.3f);
|
|
||||||
Wheel->AxleID = 0;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.5f;
|
|
||||||
Wheel->Steering = true;
|
|
||||||
Wheel->SuspensionStrength = 20.f;
|
|
||||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
CommitEntity(ent);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// Back Right Wheel
|
|
||||||
auto ent = CreateEntity(car);
|
|
||||||
auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
|
||||||
transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5);
|
|
||||||
transform->Position = glm::vec3(1.1f, -1.5f, 1.3f);
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(ent, "Wheel");
|
|
||||||
Wheel->Hardpoint = glm::vec3(1.1f, 0.f, 1.3f);
|
|
||||||
Wheel->AxleID = 1;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.5f;
|
|
||||||
Wheel->Steering = false;
|
|
||||||
Wheel->ConnectedToHandbrake = true;
|
|
||||||
Wheel->SuspensionStrength = 20.f;
|
|
||||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
CommitEntity(ent);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
// Back Left Wheel
|
|
||||||
auto ent = CreateEntity(car);
|
|
||||||
auto transform = AddComponent<Components::Transform>(ent, "Transform");
|
|
||||||
transform->Scale = glm::vec3(1)/glm::vec3(3, 1, 5);
|
|
||||||
transform->Position = glm::vec3(-1.1f, -1.5f, 1.3f);
|
|
||||||
auto Wheel = AddComponent<Components::Wheel>(ent, "Wheel");
|
|
||||||
Wheel->Hardpoint = glm::vec3(-1.1f, 0.f, 1.3f);
|
|
||||||
Wheel->AxleID = 1;
|
|
||||||
Wheel->Mass = 10;
|
|
||||||
Wheel->Radius = 0.5f;
|
|
||||||
Wheel->Steering = false;
|
|
||||||
Wheel->ConnectedToHandbrake = true;
|
|
||||||
Wheel->SuspensionStrength = 20.f;
|
|
||||||
auto model = AddComponent<Components::Model>(ent, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
CommitEntity(ent);
|
|
||||||
}
|
|
||||||
|
|
||||||
CommitEntity(car);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
{
|
|
||||||
auto cube = CreateEntity();
|
|
||||||
auto transform = AddComponent<Components::Transform>(cube, "Transform");
|
|
||||||
transform->Position = glm::vec3(20, 10 + i*2, 0);
|
|
||||||
transform->Scale = glm::vec3(1);
|
|
||||||
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
|
|
||||||
auto model = AddComponent<Components::Model>(cube, "Model");
|
|
||||||
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube2.obj";
|
|
||||||
|
|
||||||
auto physics = AddComponent<Components::Physics>(cube, "Physics");
|
|
||||||
physics->Mass = 100;
|
|
||||||
auto box = AddComponent<Components::Box>(cube, "Box");
|
|
||||||
box->Width = 0.5f;
|
|
||||||
box->Height = 0.5f;
|
|
||||||
box->Depth = 0.5f;
|
|
||||||
CommitEntity(cube);
|
|
||||||
>>>>>>> havok
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
auto entity = CreateEntity();
|
|
||||||
AddComponent(entity, "Transform");
|
|
||||||
auto emitter = AddComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
|
||||||
emitter->Path = "Sounds/korvring.wav";
|
|
||||||
emitter->Loop = true;
|
|
||||||
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(emitter);
|
|
||||||
CommitEntity(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameWorld::Update(double dt)
|
|
||||||
{
|
|
||||||
World::Update(dt);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameWorld::RegisterComponents()
|
|
||||||
{
|
|
||||||
<<<<<<< HEAD
|
|
||||||
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
|
||||||
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
|
||||||
=======
|
|
||||||
m_ComponentFactory.Register("Camera", []() { return new Components::Camera(); });
|
|
||||||
m_ComponentFactory.Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
|
|
||||||
m_ComponentFactory.Register("Input", []() { return new Components::Input(); });
|
|
||||||
m_ComponentFactory.Register("Model", []() { return new Components::Model(); });
|
|
||||||
m_ComponentFactory.Register("ParticleEmitter", []() { return new Components::ParticleEmitter(); });
|
|
||||||
m_ComponentFactory.Register("PointLight", []() { return new Components::PointLight(); });
|
|
||||||
m_ComponentFactory.Register("SoundEmitter", []() { return new Components::SoundEmitter(); });
|
|
||||||
m_ComponentFactory.Register("Sprite", []() { return new Components::Sprite(); });
|
|
||||||
m_ComponentFactory.Register("Template", []() { return new Components::Template(); });
|
|
||||||
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
|
|
||||||
m_ComponentFactory.Register("FreeSteering", []() { return new Components::FreeSteering(); });
|
|
||||||
m_ComponentFactory.Register("Physics", []() { return new Components::Physics(); });
|
|
||||||
>>>>>>> havok
|
|
||||||
m_ComponentFactory.Register("Sphere", []() { return new Components::Sphere(); });
|
|
||||||
m_ComponentFactory.Register("Box", []() { return new Components::Box (); });
|
|
||||||
m_ComponentFactory.Register("Vehicle", []() { return new Components::Vehicle(); });
|
|
||||||
m_ComponentFactory.Register("Wheel", []() { return new Components::Wheel(); });
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameWorld::RegisterSystems()
|
|
||||||
{
|
|
||||||
m_SystemFactory.Register("TransformSystem", [this]() { return new Systems::TransformSystem(this); });
|
|
||||||
//m_SystemFactory.Register("LevelGenerationSystem", [this]() { return new Systems::LevelGenerationSystem(this); });
|
|
||||||
m_SystemFactory.Register("InputSystem", [this]() { return new Systems::InputSystem(this, m_Renderer); });
|
|
||||||
//m_SystemFactory.Register("CollisionSystem", [this]() { return new Systems::CollisionSystem(this); });
|
|
||||||
////m_SystemFactory.Register("ParticleSystem", [this]() { return new Systems::ParticleSystem(this); });
|
|
||||||
//m_SystemFactory.Register("PlayerSystem", [this]() { return new Systems::PlayerSystem(this); });
|
|
||||||
m_SystemFactory.Register("FreeSteeringSystem", [this]() { return new Systems::FreeSteeringSystem(this); });
|
|
||||||
m_SystemFactory.Register("SoundSystem", [this]() { return new Systems::SoundSystem(this); });
|
|
||||||
m_SystemFactory.Register("PhysicsSystem", [this]() { return new Systems::PhysicsSystem(this); });
|
|
||||||
m_SystemFactory.Register("RenderSystem", [this]() { return new Systems::RenderSystem(this, m_Renderer); });
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameWorld::AddSystems()
|
|
||||||
{
|
|
||||||
AddSystem("TransformSystem");
|
|
||||||
//AddSystem("LevelGenerationSystem");
|
|
||||||
AddSystem("InputSystem");
|
|
||||||
//AddSystem("CollisionSystem");
|
|
||||||
////AddSystem("ParticleSystem");
|
|
||||||
//AddSystem("PlayerSystem");
|
|
||||||
AddSystem("FreeSteeringSystem");
|
|
||||||
AddSystem("SoundSystem");
|
|
||||||
AddSystem("PhysicsSystem");
|
|
||||||
AddSystem("RenderSystem");
|
|
||||||
}
|
|
||||||
+2
-2
@@ -27,8 +27,8 @@
|
|||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
|
|
||||||
#include "Components/Physics.h"
|
#include "Components/Physics.h"
|
||||||
#include "Components/Sphere.h"
|
#include "Components/SphereShape.h"
|
||||||
#include "Components/Box.h"
|
#include "Components/BoxShape.h"
|
||||||
#include "Components/Vehicle.h"
|
#include "Components/Vehicle.h"
|
||||||
#include "Components/Wheel.h"
|
#include "Components/Wheel.h"
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world)
|
|||||||
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||||
{
|
{
|
||||||
cf->Register("Physics", []() { return new Components::Physics(); });
|
cf->Register("Physics", []() { return new Components::Physics(); });
|
||||||
cf->Register("Box", []() { return new Components::Box(); });
|
cf->Register("BoxShape", []() { return new Components::BoxShape(); });
|
||||||
cf->Register("Sphere", []() { return new Components::Sphere(); });
|
cf->Register("SphereShape", []() { return new Components::SphereShape(); });
|
||||||
cf->Register("Vehicle", []() { return new Components::Vehicle(); });
|
cf->Register("Vehicle", []() { return new Components::Vehicle(); });
|
||||||
cf->Register("Wheel", []() { return new Components::Wheel(); });
|
cf->Register("Wheel", []() { return new Components::Wheel(); });
|
||||||
cf->Register("MeshShape", []() { return new Components::MeshShape(); });
|
cf->Register("MeshShape", []() { return new Components::MeshShape(); });
|
||||||
@@ -182,8 +182,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
if (!physicsComponent)
|
if (!physicsComponent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto sphereComponent = m_World->GetComponent<Components::Sphere >(entity, "Sphere");
|
auto sphereComponent = m_World->GetComponent<Components::SphereShape>(entity, "SphereShape");
|
||||||
auto boxComponent = m_World->GetComponent<Components::Box >(entity, "Box");
|
auto boxComponent = m_World->GetComponent<Components::BoxShape>(entity, "BoxShape");
|
||||||
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape >(entity, "MeshShape");
|
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape >(entity, "MeshShape");
|
||||||
|
|
||||||
hkpShape* shape = nullptr;
|
hkpShape* shape = nullptr;
|
||||||
|
|||||||
@@ -1,426 +0,0 @@
|
|||||||
#include "PrecompiledHeader.h"
|
|
||||||
|
|
||||||
// We’re not using anything product specific yet. We undef these so we don’t get the usual
|
|
||||||
// product initialization for the products.
|
|
||||||
#undef HK_FEATURE_PRODUCT_AI
|
|
||||||
#undef HK_FEATURE_PRODUCT_ANIMATION
|
|
||||||
#undef HK_FEATURE_PRODUCT_CLOTH
|
|
||||||
#undef HK_FEATURE_PRODUCT_DESTRUCTION_2012
|
|
||||||
#undef HK_FEATURE_PRODUCT_DESTRUCTION
|
|
||||||
#undef HK_FEATURE_PRODUCT_BEHAVIOR
|
|
||||||
#undef HK_FEATURE_PRODUCT_PHYSICS_2012
|
|
||||||
//#undef HK_FEATURE_PRODUCT_PHYSICS
|
|
||||||
// Also we’re not using any serialization/versioning so we don’t need any of these.
|
|
||||||
#define HK_EXCLUDE_FEATURE_SerializeDeprecatedPre700
|
|
||||||
#define HK_EXCLUDE_FEATURE_RegisterVersionPatches
|
|
||||||
#define HK_EXCLUDE_FEATURE_RegisterReflectedClasses
|
|
||||||
#define HK_EXCLUDE_FEATURE_MemoryTracker
|
|
||||||
#define HK_CLASSES_FILE "Common/Serialize/classlist/hkClasses.h"
|
|
||||||
#include "Common/Serialize/Util/hkBuiltinTypeRegistry.cxx"
|
|
||||||
#define HK_COMPAT_FILE "Common/Compat/hkCompatVersions.h"
|
|
||||||
// This include generates an initialization function based on the products
|
|
||||||
// and the excluded features.
|
|
||||||
#include <Common/Base/keycode.cxx>
|
|
||||||
#include <Common/Base/Config/hkProductFeatures.cxx>
|
|
||||||
#include "PhysicsSystem.h"
|
|
||||||
#include "World.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world)
|
|
||||||
{
|
|
||||||
m_Accumulator = 0;
|
|
||||||
{
|
|
||||||
hkMemorySystem::FrameInfo finfo(500 * 1024); // Allocate 500KB of Physics solver buffer
|
|
||||||
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
|
||||||
hkBaseSystem::init(memoryRouter, HavokErrorReport);
|
|
||||||
|
|
||||||
|
|
||||||
hkpWorldCinfo worldInfo;
|
|
||||||
worldInfo.setupSolverInfo(hkpWorldCinfo::SOLVER_TYPE_4ITERS_MEDIUM);
|
|
||||||
worldInfo.m_gravity = hkVector4(0.0f, -9.8f, 0.0f);
|
|
||||||
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; // just fix the entity if the object falls off too far
|
|
||||||
|
|
||||||
// You must specify the size of the broad phase - objects should not be simulated outside this region
|
|
||||||
worldInfo.setBroadPhaseWorldSize(10000.0f);
|
|
||||||
m_PhysicsWorld = new hkpWorld(worldInfo);
|
|
||||||
}
|
|
||||||
// Register all collision agents, even though only box - box will be used in this particular example.
|
|
||||||
// It's important to register collision agents before adding any entities to the world.
|
|
||||||
hkpAgentRegisterUtil::registerAllAgents(m_PhysicsWorld->getCollisionDispatcher());
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initialize the visual debugger so we can connect remotely to the simulation
|
|
||||||
// The context must exist beyond the use of the VDB instance, and you can make
|
|
||||||
// whatever contexts you like for your own viewer types.
|
|
||||||
//
|
|
||||||
hkpPhysicsContext* context = new hkpPhysicsContext;
|
|
||||||
hkpPhysicsContext::registerAllPhysicsProcesses(); // all the physics viewers
|
|
||||||
context->addWorld(m_PhysicsWorld); // add the physics world so the viewers can see it
|
|
||||||
SetupVisualDebugger(context);
|
|
||||||
|
|
||||||
//SetupPhysics(m_PhysicsWorld);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
|
||||||
{
|
|
||||||
cf->Register("Physics", []() { return new Components::Physics(); });
|
|
||||||
}
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::Update(double dt)
|
|
||||||
{
|
|
||||||
<<<<<<< HEAD
|
|
||||||
static const double timestep = 1 / 60.0;
|
|
||||||
=======
|
|
||||||
for (auto pair : *m_World->GetEntities())
|
|
||||||
{
|
|
||||||
EntityID entity = pair.first;
|
|
||||||
|
|
||||||
if (m_RigidBodies.find(entity) == m_RigidBodies.end())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
|
||||||
if (!transformComponent)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
|
||||||
if(m_RigidBodies[entity]->isActive())
|
|
||||||
{
|
|
||||||
hkVector4 position(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z);
|
|
||||||
hkQuaternion rotation(transformComponent->Orientation.x, transformComponent->Orientation.y, transformComponent->Orientation.z, transformComponent->Orientation.w);
|
|
||||||
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const double timestep = 1 / 30.0;
|
|
||||||
>>>>>>> havok
|
|
||||||
m_Accumulator += dt;
|
|
||||||
while (m_Accumulator >= timestep)
|
|
||||||
{
|
|
||||||
m_PhysicsWorld->stepDeltaTime(timestep);
|
|
||||||
m_Accumulator -= timestep;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step the visual debugger
|
|
||||||
StepVisualDebugger();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
|
||||||
{
|
|
||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
|
||||||
if (!transformComponent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
|
|
||||||
if (wheelComponent)
|
|
||||||
{
|
|
||||||
EntityID car = m_World->GetEntityParent(entity);
|
|
||||||
if(m_Vehicles.find(car) != m_Vehicles.end())
|
|
||||||
{
|
|
||||||
m_Vehicles[car]->getChassis()->activate();
|
|
||||||
|
|
||||||
hkVector4 hardPoint = m_Vehicles[car]->m_suspension->m_wheelParams[wheelComponent->ID].m_hardpointChassisSpace;
|
|
||||||
hkVector4 suspensionDirection = m_Vehicles[car]->m_suspension->m_wheelParams[wheelComponent->ID].m_directionChassisSpace;
|
|
||||||
hkReal suspensionLength = m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_currentSuspensionLength;
|
|
||||||
glm::vec3 position = glm::vec3(hardPoint(0) + (suspensionDirection(0) * suspensionLength), hardPoint(1) + (suspensionDirection(1) * suspensionLength), hardPoint(2) + (suspensionDirection(2) * suspensionLength));
|
|
||||||
transformComponent->Position = position;
|
|
||||||
|
|
||||||
hkQuaternion steeringOrientation = m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_steeringOrientationChassisSpace;
|
|
||||||
hkReal spinAngle = -m_Vehicles[car]->m_wheelsInfo[wheelComponent->ID].m_spinAngle;
|
|
||||||
glm::quat orientation = glm::quat(steeringOrientation(3), steeringOrientation(0), steeringOrientation(1), steeringOrientation(2)) * glm::angleAxis<float>(spinAngle, glm::vec3(1, 0, 0));
|
|
||||||
transformComponent->Orientation = orientation * wheelComponent->OriginalOrientation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(m_Vehicles.find(entity) != m_Vehicles.end())
|
|
||||||
{
|
|
||||||
if(m_RigidBodies[entity]->isActive())
|
|
||||||
{
|
|
||||||
hkVector4 position = m_RigidBodies[entity]->getPosition();
|
|
||||||
transformComponent->Position = glm::vec3(position(0), position(1), position(2));
|
|
||||||
hkQuaternion orientation = m_RigidBodies[entity]->getRotation();
|
|
||||||
transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// HACK: Vehicle test-controls
|
|
||||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(entity, "Vehicle");
|
|
||||||
auto inputComponent = m_World->GetComponent<Components::Input>(entity, "Input");
|
|
||||||
if (vehicleComponent && inputComponent)
|
|
||||||
{
|
|
||||||
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[entity]->m_deviceStatus;
|
|
||||||
deviceStatus->m_positionY = inputComponent->KeyState[GLFW_KEY_UP] * -1 + inputComponent->KeyState[GLFW_KEY_DOWN] * 1;
|
|
||||||
deviceStatus->m_positionX = inputComponent->KeyState[GLFW_KEY_LEFT] * -1 + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1;
|
|
||||||
deviceStatus->m_handbrakeButtonPressed = inputComponent->KeyState[GLFW_KEY_RIGHT_CONTROL];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|
||||||
{
|
|
||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
|
||||||
if (!transformComponent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
|
|
||||||
auto wheelComponent = m_World->GetComponent<Components::Wheel>(entity, "Wheel");
|
|
||||||
if (wheelComponent)
|
|
||||||
{
|
|
||||||
wheelComponent->ID = m_Wheels.size();
|
|
||||||
wheelComponent->OriginalOrientation = transformComponent->Orientation;
|
|
||||||
m_Wheels.push_back(entity);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity, "Physics");
|
|
||||||
if (!physicsComponent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto sphereComponent = m_World->GetComponent<Components::Sphere >(entity, "Sphere");
|
|
||||||
auto boxComponent = m_World->GetComponent<Components::Box >(entity, "Box");
|
|
||||||
|
|
||||||
|
|
||||||
hkpConvexShape* shape;
|
|
||||||
hkpRigidBodyCinfo rigidBodyInfo;
|
|
||||||
hkMassProperties massProperties;
|
|
||||||
|
|
||||||
if (sphereComponent)
|
|
||||||
{
|
|
||||||
shape = new hkpSphereShape(sphereComponent->Radius);
|
|
||||||
rigidBodyInfo.m_shape = shape;
|
|
||||||
|
|
||||||
if (physicsComponent->Static)
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA;
|
|
||||||
}
|
|
||||||
|
|
||||||
hkpInertiaTensorComputer::computeSphereVolumeMassProperties(sphereComponent->Radius, physicsComponent->Mass, massProperties);
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (boxComponent)
|
|
||||||
{
|
|
||||||
hkReal thickness = 0.05;
|
|
||||||
shape = new hkpBoxShape(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness));
|
|
||||||
rigidBodyInfo.m_shape = shape;
|
|
||||||
if (physicsComponent->Static)
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
|
|
||||||
}
|
|
||||||
hkpInertiaTensorComputer::computeBoxSurfaceMassProperties(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness), physicsComponent->Mass, thickness, massProperties);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rigidBodyInfo.m_position.set(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z);
|
|
||||||
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
|
||||||
rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
|
|
||||||
rigidBodyInfo.m_mass = massProperties.m_mass;
|
|
||||||
|
|
||||||
// Create RigidBody
|
|
||||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
|
||||||
|
|
||||||
|
|
||||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity, "Vehicle");
|
|
||||||
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
|
|
||||||
{
|
|
||||||
for (int i = 0; i < m_Wheels.size(); i++)
|
|
||||||
{
|
|
||||||
if(m_World->GetEntityParent(m_Wheels[i]) != entity)
|
|
||||||
{
|
|
||||||
m_Wheels.erase(m_Wheels.begin() + i);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VehicleSetup vehicleSetup;
|
|
||||||
|
|
||||||
// Create the basic vehicle.
|
|
||||||
m_Vehicles[entity] = new hkpVehicleInstance(rigidBody);
|
|
||||||
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
|
||||||
// Add the vehicle's entities and phantoms to the world
|
|
||||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
|
||||||
|
|
||||||
m_RigidBodies[entity] = rigidBody;
|
|
||||||
|
|
||||||
// The vehicle is an action
|
|
||||||
m_PhysicsWorld->addAction(m_Vehicles[entity]);
|
|
||||||
|
|
||||||
//m_Vehicles[entity]->m_rpm = 0.0f; // Not sure why this one should be here
|
|
||||||
m_Wheels.clear();
|
|
||||||
shape->removeReference();
|
|
||||||
rigidBody->removeReference();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_PhysicsWorld->addEntity(rigidBody);
|
|
||||||
m_RigidBodies[entity] = rigidBody;
|
|
||||||
shape->removeReference();
|
|
||||||
rigidBody->removeReference();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
|
||||||
{
|
|
||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
|
||||||
if (!transformComponent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity, "Physics");
|
|
||||||
if (!physicsComponent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto sphereComponent = m_World->GetComponent<Components::Sphere >(entity, "Sphere");
|
|
||||||
auto boxComponent = m_World->GetComponent<Components::Box >(entity, "Box");
|
|
||||||
|
|
||||||
|
|
||||||
hkpConvexShape* shape;
|
|
||||||
hkpRigidBodyCinfo rigidBodyInfo;
|
|
||||||
hkMassProperties massProperties;
|
|
||||||
|
|
||||||
|
|
||||||
if (sphereComponent)
|
|
||||||
{
|
|
||||||
shape = new hkpSphereShape(sphereComponent->Radius);
|
|
||||||
rigidBodyInfo.m_shape = shape;
|
|
||||||
|
|
||||||
if (physicsComponent->Static)
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_SPHERE_INERTIA;
|
|
||||||
}
|
|
||||||
|
|
||||||
hkpInertiaTensorComputer::computeSphereVolumeMassProperties(sphereComponent->Radius, physicsComponent->Mass, massProperties);
|
|
||||||
|
|
||||||
}
|
|
||||||
else if (boxComponent)
|
|
||||||
{
|
|
||||||
hkReal thickness = 0.05;
|
|
||||||
shape = new hkpBoxShape(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness));
|
|
||||||
rigidBodyInfo.m_shape = shape;
|
|
||||||
if (physicsComponent->Static)
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rigidBodyInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
|
|
||||||
}
|
|
||||||
hkpInertiaTensorComputer::computeBoxSurfaceMassProperties(hkVector4(boxComponent->Width - thickness, boxComponent->Height - thickness, boxComponent->Depth - thickness), physicsComponent->Mass, thickness, massProperties);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rigidBodyInfo.m_position.set(transformComponent->Position.x, transformComponent->Position.y, transformComponent->Position.z);
|
|
||||||
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
|
|
||||||
rigidBodyInfo.m_centerOfMass = massProperties.m_centerOfMass;
|
|
||||||
rigidBodyInfo.m_mass = massProperties.m_mass;
|
|
||||||
|
|
||||||
// Create RigidBody
|
|
||||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
|
||||||
|
|
||||||
|
|
||||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity, "Vehicle");
|
|
||||||
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
|
|
||||||
{
|
|
||||||
VehicleSetup vehicleSetup;
|
|
||||||
|
|
||||||
// Create the basic vehicle.
|
|
||||||
m_Vehicles[entity] = new hkpVehicleInstance(rigidBody);
|
|
||||||
vehicleSetup.buildVehicle(m_PhysicsWorld, *m_Vehicles[entity]);
|
|
||||||
// Add the vehicle's entities and phantoms to the world
|
|
||||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
|
||||||
|
|
||||||
m_RigidBodies[entity] = rigidBody;
|
|
||||||
|
|
||||||
// The vehicle is an action
|
|
||||||
m_PhysicsWorld->addAction(m_Vehicles[entity]);
|
|
||||||
|
|
||||||
//m_Vehicles[entity]->m_rpm = 0.0f; // Not sure why this one should be here
|
|
||||||
|
|
||||||
shape->removeReference();
|
|
||||||
rigidBody->removeReference();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_PhysicsWorld->addEntity(rigidBody);
|
|
||||||
m_RigidBodies[entity] = rigidBody;
|
|
||||||
shape->removeReference();
|
|
||||||
rigidBody->removeReference();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::OnComponentRemoved(std::string type, Component* component)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::SetupVisualDebugger(hkpPhysicsContext* worlds)
|
|
||||||
{
|
|
||||||
// Setup the visual debugger
|
|
||||||
hkArray<hkProcessContext*> contexts;
|
|
||||||
contexts.pushBack(worlds);
|
|
||||||
|
|
||||||
m_VisualDebugger = new hkVisualDebugger(contexts);
|
|
||||||
m_VisualDebugger->serve();
|
|
||||||
|
|
||||||
// Allocate memory for internal profiling information
|
|
||||||
// You can discard this if you do not want Havok profiling information
|
|
||||||
hkMonitorStream& stream = hkMonitorStream::getInstance();
|
|
||||||
stream.resize(500 * 1024); // 500K for timer info
|
|
||||||
stream.reset();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Systems::PhysicsSystem::StepVisualDebugger()
|
|
||||||
{
|
|
||||||
// Step the debugger
|
|
||||||
m_VisualDebugger->step();
|
|
||||||
|
|
||||||
// Reset internal profiling info for next frame
|
|
||||||
hkMonitorStream::getInstance().reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
|
|
||||||
{
|
|
||||||
LOG_INFO("%s", msg);
|
|
||||||
}
|
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
|
|
||||||
|
|
||||||
>>>>>>> havok
|
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
#include "System.h"
|
#include "System.h"
|
||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
#include "Components/Physics.h"
|
#include "Components/Physics.h"
|
||||||
#include "Components/Sphere.h"
|
#include "Components/BoxShape.h"
|
||||||
#include "Components/Box.h"
|
#include "Components/SphereShape.h"
|
||||||
#include "Components/Vehicle.h"
|
#include "Components/Vehicle.h"
|
||||||
#include "Components/Input.h"
|
#include "Components/Input.h"
|
||||||
#include "Components/MeshShape.h"
|
#include "Components/MeshShape.h"
|
||||||
|
|||||||
@@ -121,7 +121,7 @@
|
|||||||
<ClInclude Include="..\..\src\Camera.h" />
|
<ClInclude Include="..\..\src\Camera.h" />
|
||||||
<ClInclude Include="..\..\src\Color.h" />
|
<ClInclude Include="..\..\src\Color.h" />
|
||||||
<ClInclude Include="..\..\src\Component.h" />
|
<ClInclude Include="..\..\src\Component.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Box.h" />
|
<ClInclude Include="..\..\src\Components\BoxShape.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Camera.h" />
|
<ClInclude Include="..\..\src\Components\Camera.h" />
|
||||||
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
|
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
|
||||||
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
|
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
<ClInclude Include="..\..\src\Components\Physics.h" />
|
<ClInclude Include="..\..\src\Components\Physics.h" />
|
||||||
<ClInclude Include="..\..\src\Components\PointLight.h" />
|
<ClInclude Include="..\..\src\Components\PointLight.h" />
|
||||||
<ClInclude Include="..\..\src\Components\SoundEmitter.h" />
|
<ClInclude Include="..\..\src\Components\SoundEmitter.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Sphere.h" />
|
<ClInclude Include="..\..\src\Components\SphereShape.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Sprite.h" />
|
<ClInclude Include="..\..\src\Components\Sprite.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Template.h" />
|
<ClInclude Include="..\..\src\Components\Template.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Transform.h" />
|
<ClInclude Include="..\..\src\Components\Transform.h" />
|
||||||
|
|||||||
@@ -215,12 +215,6 @@
|
|||||||
<ClInclude Include="..\..\src\Sound.h">
|
<ClInclude Include="..\..\src\Sound.h">
|
||||||
<Filter>Audio</Filter>
|
<Filter>Audio</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\Components\Box.h">
|
|
||||||
<Filter>Physics\Components</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\Components\Sphere.h">
|
|
||||||
<Filter>Physics\Components</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\Components\Vehicle.h">
|
<ClInclude Include="..\..\src\Components\Vehicle.h">
|
||||||
<Filter>Physics\Components</Filter>
|
<Filter>Physics\Components</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -230,6 +224,12 @@
|
|||||||
<ClInclude Include="..\..\src\Physics\VehicleSetup.h">
|
<ClInclude Include="..\..\src\Physics\VehicleSetup.h">
|
||||||
<Filter>Physics</Filter>
|
<Filter>Physics</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\BoxShape.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\SphereShape.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\Components\MeshShape.h">
|
<ClInclude Include="..\..\src\Components\MeshShape.h">
|
||||||
<Filter>Physics\Components</Filter>
|
<Filter>Physics\Components</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|||||||
Reference in New Issue
Block a user