Merge remote-tracking branch 'origin/master' into LevelSystemAndSuch
Conflicts: include/Core/Engine.h
This commit is contained in:
@@ -8,6 +8,7 @@ find_package(assimp REQUIRED)
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(PNG REQUIRED)
|
||||
find_package(BGFX REQUIRED)
|
||||
find_package(liquidfun REQUIRED)
|
||||
# GLM
|
||||
if(UNIX)
|
||||
find_package(X11 REQUIRED)
|
||||
@@ -23,7 +24,8 @@ include_directories(
|
||||
${assimp_INCLUDE_DIRS}
|
||||
${PNG_INCLUDE_DIRS}
|
||||
${X11_INCLUDE_DIRS}
|
||||
${BGFX_INCLUDE_DIRS}
|
||||
${BGFX_INCLUDE_DIRS}
|
||||
${liquidfun_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
file(GLOB SOURCE_FILES_Core
|
||||
@@ -67,7 +69,7 @@ set(SOURCE_FILES
|
||||
${SOURCE_FILES_Rendering}
|
||||
${SOURCE_FILES_Transform}
|
||||
${SOURCE_FILES_Game}
|
||||
)
|
||||
Physics/PhysicsSystem.cpp ../../include/Physics/PhysicsSystem.h ../../include/Core/CBoxShape.h ../../include/Physics/CPhysics.h ../../include/Physics/EContact.h)
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||
@@ -84,7 +86,8 @@ target_link_libraries(game
|
||||
${assimp_LIBRARIES}
|
||||
${PNG_LIBRARIES}
|
||||
${X11_LIBRARIES}
|
||||
${BGFX_LIBRARIES}
|
||||
${BGFX_LIBRARIES}
|
||||
${liquidfun_LIBRARIES}
|
||||
)
|
||||
|
||||
add_executable(breakout
|
||||
@@ -100,5 +103,6 @@ target_link_libraries(breakout
|
||||
${PNG_LIBRARIES}
|
||||
${X11_LIBRARIES}
|
||||
${BGFX_LIBRARIES}
|
||||
${liquidfun_LIBRARIES}
|
||||
)
|
||||
|
||||
|
||||
@@ -98,21 +98,19 @@ void dd::Renderer::LoadShaders()
|
||||
/*
|
||||
Forward rendering
|
||||
*/
|
||||
|
||||
m_spForward = ResourceManager::Load<ShaderProgram>("Shaders/Forward/");
|
||||
m_spForward->Link();
|
||||
|
||||
/*
|
||||
Screen draw
|
||||
*/
|
||||
|
||||
m_spScreen = ResourceManager::Load<ShaderProgram>("Shaders/Screen/");
|
||||
m_spScreen->Link();
|
||||
}
|
||||
|
||||
void dd::Renderer::CreateBuffers()
|
||||
{
|
||||
m_UnitQuad = CreateQuad();
|
||||
m_ScreenQuad = CreateQuad();
|
||||
m_UnitSphere = ResourceManager::Load<Model>("Models/Core/UnitSphere.obj");
|
||||
|
||||
glGenRenderbuffers(1, &m_rbDepthBuffer);
|
||||
@@ -222,7 +220,7 @@ void dd::Renderer::Draw(RenderQueueCollection& rq)
|
||||
m_spScreen->Bind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_CurrentScreenBuffer);
|
||||
glBindVertexArray(m_UnitQuad);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
glfwSwapBuffers(m_Window);
|
||||
@@ -271,7 +269,7 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
||||
glBindTexture(GL_TEXTURE_2D, m_GDiffuse);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, m_tLighting);
|
||||
glBindVertexArray(m_UnitQuad);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
}
|
||||
|
||||
@@ -330,6 +328,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
if (spriteJob)
|
||||
{
|
||||
glm::mat4 modelMatrix = spriteJob->ModelMatrix;
|
||||
modelMatrix = modelMatrix * glm::scale(glm::vec3(0.5f));
|
||||
MVP = PV * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||
@@ -338,7 +337,7 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->Texture);
|
||||
|
||||
glBindVertexArray(m_UnitQuad);
|
||||
glBindVertexArray(m_ScreenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
continue;
|
||||
|
||||
@@ -68,6 +68,7 @@ void main()
|
||||
//gl_Position = MVP * boneTransform * vec4(Position, 1.0);
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
//TODO: Make sure that boneTransform works here.
|
||||
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
|
||||
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
|
||||
Output.Tangent = Tangent;
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Physics/PhysicsSystem.h"
|
||||
|
||||
|
||||
|
||||
void dd::Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::Initialize()
|
||||
{
|
||||
m_ContactListener = new ContactListener(this);
|
||||
|
||||
m_Gravity = b2Vec2(0.f, -9.82f);
|
||||
m_PhysicsWorld = new b2World(m_Gravity);
|
||||
|
||||
m_TimeStep = 1.f/60.f;
|
||||
m_VelocityIterations = 6;
|
||||
m_PositionIterations = 2;
|
||||
|
||||
|
||||
m_PhysicsWorld->SetContactListener(m_ContactListener);
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
{
|
||||
m_PhysicsWorld->Step(m_TimeStep, m_VelocityIterations, m_PositionIterations);
|
||||
|
||||
for(auto i : m_EntitiesToBodies)
|
||||
{
|
||||
EntityID entity = i.first;
|
||||
b2Body* body = i.second;
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
|
||||
if(m_World->GetEntityParent(entity) == 0) {
|
||||
b2Vec2 position = body->GetPosition();
|
||||
transformComponent->Position.x = position.x;
|
||||
transformComponent->Position.y = position.y;
|
||||
|
||||
float angle = body->GetAngle();
|
||||
|
||||
//TODO: CHECK IF THIS IS CORRECT
|
||||
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
|
||||
}
|
||||
// auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->
|
||||
}
|
||||
}
|
||||
|
||||
void dd::Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void dd::Systems::PhysicsSystem::OnEntityCommit(EntityID entity)
|
||||
{
|
||||
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
if(physicsComponent)
|
||||
CreateBody(entity);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void dd::Systems::PhysicsSystem::OnEntityRemoved(EntityID entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
|
||||
{
|
||||
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
|
||||
if(!physicsComponent){
|
||||
LOG_ERROR("No PhysicsComponent in CreateBody");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
if(!transformComponent) {
|
||||
LOG_ERROR("No TransformComponent in CreateBody");
|
||||
return;
|
||||
}
|
||||
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
|
||||
b2BodyDef bodyDef;
|
||||
bodyDef.position.Set(absoluteTransform.Position.x, absoluteTransform.Position.y);
|
||||
|
||||
|
||||
bodyDef.angle = glm::degrees(-glm::eulerAngles(absoluteTransform.Orientation).z); //TODO: CHECK IF THIS IS CORRECT
|
||||
|
||||
if(physicsComponent->Static)
|
||||
bodyDef.type = b2_staticBody;
|
||||
else
|
||||
bodyDef.type = b2_dynamicBody;
|
||||
|
||||
b2Body* body = m_PhysicsWorld->CreateBody(&bodyDef);
|
||||
|
||||
b2PolygonShape pShape;
|
||||
|
||||
auto boxComponent = m_World->GetComponent<Components::RectangleShape>(entity);
|
||||
if(boxComponent){
|
||||
|
||||
pShape.SetAsBox(absoluteTransform.Scale.x/4, absoluteTransform.Scale.y/4); //TODO: THIS SUCKS DUDE
|
||||
}
|
||||
|
||||
if(physicsComponent->Static){
|
||||
body->CreateFixture(&pShape, 0); //Density kanske ska vara 0 på statiska kroppar
|
||||
}
|
||||
else{
|
||||
//TODO: FIX THIS SHIT INTO COMPONENTS
|
||||
b2FixtureDef fixtureDef;
|
||||
fixtureDef.shape = &pShape;
|
||||
fixtureDef.density = 1.f;
|
||||
fixtureDef.restitution = 1.0f;
|
||||
fixtureDef.friction = 0.3f;
|
||||
body->CreateFixture(&fixtureDef);
|
||||
|
||||
}
|
||||
|
||||
m_EntitiesToBodies.insert(std::make_pair(entity, body));
|
||||
m_BodiesToEntities.insert(std::make_pair(body, entity));
|
||||
}
|
||||
|
||||
dd::Systems::PhysicsSystem::~PhysicsSystem()
|
||||
{
|
||||
if (m_ContactListener != nullptr) {
|
||||
delete m_ContactListener;
|
||||
m_ContactListener = nullptr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user