collisionz

This commit is contained in:
Adam
2014-03-12 21:30:09 +01:00
parent 5ce795be96
commit 4459f671d5
5 changed files with 62 additions and 14 deletions
@@ -14,3 +14,46 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
}
LOG_INFO("Updating entity %i with parent %i", entity, parent);
}
bool Systems::CollisionSystem::Intersects(EntityID entity1, EntityID entity2)
{
auto bounds1 = m_World->GetComponent<Components::Bounds>(entity1, "Bounds");
auto bounds2 = m_World->GetComponent<Components::Bounds>(entity2, "Bounds");
float width = bounds1->VolumeVector.x;
float height = bounds1->VolumeVector.y;
float depth = bounds1->VolumeVector.z;
GLfloat vertices1[] = {
bounds1->Origin.x - width / 2, bounds1->Origin.y - height / 2, bounds1->Origin.z - depth / 2, 1.0,
bounds1->Origin.x + width / 2, bounds1->Origin.y - height / 2, bounds1->Origin.z - depth / 2, 1.0,
bounds1->Origin.x + width / 2, bounds1->Origin.y + height / 2, bounds1->Origin.z - depth / 2, 1.0,
bounds1->Origin.x - width / 2, bounds1->Origin.y + height / 2, bounds1->Origin.z - depth / 2, 1.0,
bounds1->Origin.x - width / 2, bounds1->Origin.y - height / 2, bounds1->Origin.z + depth / 2, 1.0,
bounds1->Origin.x + width / 2, bounds1->Origin.y - height / 2, bounds1->Origin.z + depth / 2, 1.0,
bounds1->Origin.x + width / 2, bounds1->Origin.y + height / 2, bounds1->Origin.z + depth / 2, 1.0,
bounds1->Origin.x - width / 2, bounds1->Origin.y + height / 2, bounds1->Origin.z + depth / 2, 1.0,
};
GLuint vbo_vertices;
glGenBuffers(1, &vbo_vertices);
glBindBuffer(GL_ARRAY_BUFFER, vbo_vertices);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices1), vertices1, 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);
return true;
}
@@ -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,7 @@ public:
: System(world) { }
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
bool Intersects(EntityID, EntityID);
};
}
+3 -5
View File
@@ -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;
+6 -6
View File
@@ -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