Physics!!!!!1111oneoneonetwo

This commit is contained in:
ViktorLjung
2014-04-06 03:39:50 +02:00
parent d6fc82c91e
commit 1d0747076f
12 changed files with 373 additions and 18 deletions
+113 -6
View File
@@ -10,24 +10,115 @@ void GameWorld::Initialize()
auto camera = CreateEntity();
transform = AddComponent<Components::Transform>(camera, "Transform");
transform->Position.y = 10.f;
transform->Position.z = 150.f;
transform->Position.y = 100.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");
auto terrain = CreateEntity();
transform = AddComponent<Components::Transform>(terrain, "Transform");
transform->Scale = glm::vec3(.05f);
model = AddComponent<Components::Model>(terrain, "Model");
model->ModelFile = "Models/terrain/terrain.obj";
transform->Scale = glm::vec3(1000.0f);
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, glm::pi<float>()/20.f));
model = AddComponent<Components::Model>(terrain, "Model");
model->ModelFile = "Models/PhysicsTest/Plane.obj";
auto physics = AddComponent<Components::Physics>(terrain, "Physics");
auto Box = AddComponent<Components::BoxShape>(terrain, "BoxShape");
Box->Width = 1;
Box->Height = 0;
Box->Depth = 1;
physics->Friction = 0.5f;
auto tank = CreateEntity();
terrain = CreateEntity();
transform = AddComponent<Components::Transform>(terrain, "Transform");
transform->Scale = glm::vec3(1000.0f);
transform->Position = glm::vec3(-500, 0, 0);
transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, -glm::pi<float>() / 20.f));
model = AddComponent<Components::Model>(terrain, "Model");
model->ModelFile = "Models/PhysicsTest/Plane.obj";
physics = AddComponent<Components::Physics>(terrain, "Physics");
Box = AddComponent<Components::BoxShape>(terrain, "BoxShape");
Box->Width = 1;
Box->Height = 0;
Box->Depth = 1;
physics->Friction = 0.5f;
auto Boxed = CreateEntity();
transform = AddComponent<Components::Transform>(Boxed, "Transform");
transform->Position.y = 100.f;
transform->Position.x = 4.f;
transform->Scale = glm::vec3(5.0f);
model = AddComponent<Components::Model>(Boxed, "Model");
model->ModelFile = "Models/PhysicsTest/Cube.obj";
physics = AddComponent<Components::Physics>(Boxed, "Physics");
physics->Mass = 10;
physics->Friction = 0.5f;
Box = AddComponent<Components::BoxShape>(Boxed, "BoxShape");
Box->Width = 1;
Box->Height = 1;
Box->Depth = 1;
for (int i = 0; i < 20; i++)
{
auto Sphered = CreateEntity();
transform = AddComponent<Components::Transform>(Sphered, "Transform");
transform->Position.y = 15.f;
transform->Position.x = 4.f;
transform->Scale = glm::vec3(1.0f);
model = AddComponent<Components::Model>(Sphered, "Model");
model->ModelFile = "Models/PhysicsTest/Sphere.obj";
physics = AddComponent<Components::Physics>(Sphered, "Physics");
physics->Mass = 100;
physics->Friction = 0.5f;
auto sphere = AddComponent<Components::SphereShape>(Sphered, "SphereShape");
sphere->Radius = 1;
sphere->RollingFriction = 0.5f;
{
auto tank_top = CreateEntity(Sphered);
transform = AddComponent<Components::Transform>(tank_top, "Transform");
transform->Scale = glm::vec3(1.0f/100.f);
model = AddComponent<Components::Model>(tank_top, "Model");
model->ModelFile = "Models/tank/tank_top.obj";
{
auto tank_barrel = CreateEntity(tank_top);
transform = AddComponent<Components::Transform>(tank_barrel, "Transform");
model = AddComponent<Components::Model>(tank_barrel, "Model");
model->ModelFile = "Models/tank/tank_barrel.obj";
}
}
}
/*auto tank = CreateEntity();
transform = AddComponent<Components::Transform>(tank, "Transform");
transform->Position.y = 10.f;
transform->Position.x = 4.f;
transform->Scale = glm::vec3(.01f);
model = AddComponent<Components::Model>(tank, "Model");
model->ModelFile = "Models/tank/tank_base.obj";
physics = AddComponent<Components::Physics>(tank, "Physics");
physics->Mass = 100;
physics->Friction = 0.5f;*/
/*auto sphere = AddComponent<Components::SphereShape>(tank, "SphereShape");
sphere->Radius = 10.*(1.f / .01f);
sphere->RollingFriction = 0.5f;*/
/*
Box = AddComponent<Components::BoxShape>(tank, "BoxShape");
Box->Width = 100;
Box->Height = 50;
Box->Depth = 100;*/
/*
{
auto tank_top = CreateEntity(tank);
transform = AddComponent<Components::Transform>(tank_top, "Transform");
@@ -41,7 +132,8 @@ void GameWorld::Initialize()
model = AddComponent<Components::Model>(tank_barrel, "Model");
model->ModelFile = "Models/tank/tank_barrel.obj";
}
}
}*/
//auto light = CreateEntity();
//transform = AddComponent<Components::Transform>(light, "Transform");
@@ -72,6 +164,11 @@ void GameWorld::RegisterComponents()
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("SphereShape", []() { return new Components::SphereShape(); });
m_ComponentFactory.Register("BoxShape", []() { return new Components::BoxShape(); });
m_ComponentFactory.Register("Physics", []() { return new Components::Physics(); });
}
void GameWorld::RegisterSystems()
@@ -84,7 +181,12 @@ void GameWorld::RegisterSystems()
//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()
@@ -97,5 +199,10 @@ void GameWorld::AddSystems()
//AddSystem("PlayerSystem");
AddSystem("FreeSteeringSystem");
//AddSystem("SoundSystem");
AddSystem("PhysicsSystem");
AddSystem("RenderSystem");
}