Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
if (parent != 0)
|
||||
/*if (parent != 0)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
auto parentTransform = m_World->GetComponent<Components::Transform>(parent, "Transform");
|
||||
@@ -11,6 +11,115 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
||||
transform->Position[0] += parentTransform->Position[0];
|
||||
transform->Position[1] += parentTransform->Position[1];
|
||||
transform->Position[2] += parentTransform->Position[2];
|
||||
}*/
|
||||
|
||||
auto collisionComponent = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
if (!collisionComponent)
|
||||
return;
|
||||
|
||||
// Clear old collisions
|
||||
collisionComponent->CollidingEntities.clear();
|
||||
|
||||
auto entities = m_World->GetEntities();
|
||||
|
||||
for (auto pair : *entities) {
|
||||
EntityID entity2 = pair.first;
|
||||
EntityID parent2 = pair.second;
|
||||
|
||||
// Check if entity2 is a child of entity
|
||||
/*auto currentParent = parent;
|
||||
bool childOfEntity2 = false;
|
||||
while (currentParent != 0) {
|
||||
if (currentParent == entity2) {
|
||||
childOfEntity2 = true;
|
||||
break;
|
||||
}
|
||||
currentParent = entities[currentParent];
|
||||
}
|
||||
if (childOfEntity2)
|
||||
continue;*/
|
||||
|
||||
// Check if we're the parent to entity2
|
||||
|
||||
//pair.first, pair.second;
|
||||
if(entity == entity2)
|
||||
break;
|
||||
Intersects(entity, entity2);
|
||||
}
|
||||
LOG_INFO("Updating entity %i with parent %i", entity, parent);
|
||||
}
|
||||
|
||||
void Systems::CollisionSystem::Intersects(EntityID aEntity, EntityID bEntity)
|
||||
{
|
||||
auto aTransform = m_World->GetComponent<Components::Transform>(aEntity, "Transform");
|
||||
if(aTransform == nullptr)
|
||||
return;
|
||||
auto bTransform = m_World->GetComponent<Components::Transform>(bEntity, "Transform");
|
||||
if(bTransform == nullptr)
|
||||
return;
|
||||
|
||||
auto aCollisionComponent = m_World->GetComponent<Components::Collision>(aEntity, "Collision");
|
||||
if(aCollisionComponent == nullptr)
|
||||
return;
|
||||
auto bCollisionComponent = m_World->GetComponent<Components::Collision>(bEntity, "Collision");
|
||||
if(bCollisionComponent == nullptr)
|
||||
return;
|
||||
|
||||
|
||||
auto aBounds = m_World->GetComponent<Components::Bounds>(aEntity, "Bounds");
|
||||
|
||||
auto bBounds = m_World->GetComponent<Components::Bounds>(bEntity, "Bounds");
|
||||
|
||||
glm::vec3 aPos = aTransform->Position + (aBounds->Origin * aTransform->Scale);
|
||||
glm::vec3 bPos = bTransform->Position + (bBounds->Origin * bTransform->Scale);
|
||||
|
||||
glm::vec3 aMax = aPos + aBounds->VolumeVector * aTransform->Scale;
|
||||
glm::vec3 aMin = aPos - aBounds->VolumeVector * aTransform->Scale;
|
||||
glm::vec3 bMax = bPos + bBounds->VolumeVector * bTransform->Scale;
|
||||
glm::vec3 bMin = bPos - bBounds->VolumeVector * bTransform->Scale;
|
||||
|
||||
if (aMin.x <= bMax.x && bMin.x <= aMax.x) {
|
||||
if (aMin.y <= bMax.y && bMin.y <= aMax.y) {
|
||||
if (aMin.z <= bMax.z && bMin.z <= aMax.z) {
|
||||
aCollisionComponent->CollidingEntities.push_back(aEntity);
|
||||
bCollisionComponent->CollidingEntities.push_back(bEntity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Systems::CollisionSystem::CreateBoundingBox(std::shared_ptr<Components::Bounds> bounds)
|
||||
{
|
||||
float width = abs(bounds->VolumeVector.x);
|
||||
float height = abs(bounds->VolumeVector.y);
|
||||
float depth = abs(bounds->VolumeVector.z);
|
||||
|
||||
GLfloat vertices[] = {
|
||||
bounds->Origin.x - width, bounds->Origin.y - height, bounds->Origin.z - depth, 1.0,
|
||||
bounds->Origin.x + width, bounds->Origin.y - height, bounds->Origin.z - depth, 1.0,
|
||||
bounds->Origin.x + width, bounds->Origin.y + height, bounds->Origin.z - depth, 1.0,
|
||||
bounds->Origin.x - width, bounds->Origin.y + height, bounds->Origin.z - depth, 1.0,
|
||||
bounds->Origin.x - width, bounds->Origin.y - height, bounds->Origin.z + depth, 1.0,
|
||||
bounds->Origin.x + width, bounds->Origin.y - height, bounds->Origin.z + depth, 1.0,
|
||||
bounds->Origin.x + width, bounds->Origin.y + height, bounds->Origin.z + depth, 1.0,
|
||||
bounds->Origin.x - width, bounds->Origin.y + height, bounds->Origin.z + depth, 1.0,
|
||||
};
|
||||
|
||||
GLuint vbo_vertices;
|
||||
glGenBuffers(1, &vbo_vertices);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_vertices);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
GLushort elements[] = {
|
||||
0, 1, 2, 3,
|
||||
4, 5, 6, 7,
|
||||
0, 4, 1, 5,
|
||||
2, 6, 3, 7
|
||||
};
|
||||
GLuint ibo_elements;
|
||||
glGenBuffers(1, &ibo_elements);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_elements);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
}
|
||||
@@ -3,8 +3,11 @@
|
||||
|
||||
#include "System.h"
|
||||
#include "logging.h"
|
||||
#include <glew-1.10.0/include/GL/glew.h>
|
||||
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Components/Bounds.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
@@ -16,6 +19,8 @@ public:
|
||||
: System(world) { }
|
||||
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void Intersects(EntityID, EntityID);
|
||||
void CreateBoundingBox(std::shared_ptr<Components::Bounds>);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -59,8 +59,16 @@ void Systems::PlayerSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
//---------------------------------------------------------------------
|
||||
// TOUCHING THIS CODE MIGHT COUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
}
|
||||
|
||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
if(collision->CollidingEntities.size() > 0) {
|
||||
// DO STUFF
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
name = m_World->GetProperty<std::string>(entity, "Name");
|
||||
if (name == "PlayerShip")
|
||||
{
|
||||
|
||||
@@ -6,8 +6,11 @@
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Input.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "logging.h"
|
||||
|
||||
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
|
||||
@@ -30,11 +30,12 @@ void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID p
|
||||
|
||||
// Debug draw bounds
|
||||
#ifdef DEBUG
|
||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||
if (bounds != nullptr) {
|
||||
glm::vec3 origin = transformComponent->Position + (transformComponent->Scale * bounds->Origin);
|
||||
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
|
||||
m_Renderer->AddAABBToDraw(origin, volumeVector);
|
||||
m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/Camera.h"
|
||||
#include "Components/Bounds.h"
|
||||
#include "Components/Collision.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
namespace Systems
|
||||
|
||||
@@ -6,9 +6,7 @@
|
||||
#include "Components/SoundEmitter.h"
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <windows.h>
|
||||
#include <vector>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
namespace Systems
|
||||
@@ -30,11 +28,11 @@ private:
|
||||
|
||||
//File-info
|
||||
char type[4];
|
||||
DWORD size, chunkSize;
|
||||
unsigned long size, chunkSize;
|
||||
short formatType, channels;
|
||||
DWORD sampleRate, avgBytesPerSec;
|
||||
unsigned long sampleRate, avgBytesPerSec;
|
||||
short bytesPerSample, bitsPerSample;
|
||||
DWORD dataSize;
|
||||
unsigned long dataSize;
|
||||
|
||||
|
||||
std::map<Component*, ALuint> m_Source;
|
||||
|
||||
@@ -103,7 +103,7 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(&size, sizeof(DWORD), 1, fp);
|
||||
fread(&size, sizeof(unsigned long), 1, fp);
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if(type[0]!='W' || type[1]!='A' || type[2]!='V' || type[3]!='E') {
|
||||
LOG_ERROR("ERROR: Not WAVE-file");
|
||||
@@ -117,11 +117,11 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
|
||||
}
|
||||
|
||||
//READ THE DATA FROM WAVE-FILE
|
||||
fread(&chunkSize, sizeof(DWORD), 1, fp);
|
||||
fread(&chunkSize, sizeof(unsigned long), 1, fp);
|
||||
fread(&formatType, sizeof(short), 1, fp);
|
||||
fread(&channels, sizeof(short), 1, fp);
|
||||
fread(&sampleRate, sizeof(DWORD), 1, fp);
|
||||
fread(&avgBytesPerSec, sizeof(DWORD), 1, fp);
|
||||
fread(&sampleRate, sizeof(unsigned long), 1, fp);
|
||||
fread(&avgBytesPerSec, sizeof(unsigned long), 1, fp);
|
||||
fread(&bytesPerSample, sizeof(short), 1, fp);
|
||||
fread(&bitsPerSample, sizeof(short), 1, fp);
|
||||
|
||||
@@ -132,10 +132,10 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(&dataSize, sizeof(DWORD), 1, fp);
|
||||
fread(&dataSize, sizeof(unsigned long), 1, fp);
|
||||
|
||||
unsigned char* buf = new unsigned char[dataSize];
|
||||
fread(buf, sizeof(BYTE), dataSize, fp);
|
||||
fread(buf, sizeof(unsigned char), dataSize, fp);
|
||||
fclose(fp);
|
||||
|
||||
// Create buffer
|
||||
|
||||
Reference in New Issue
Block a user