Components + almost AABB

This commit is contained in:
Adam
2014-03-06 21:32:31 +01:00
parent 54a5a7a113
commit 00584ab397
21 changed files with 401 additions and 11 deletions
+46
View File
@@ -0,0 +1,46 @@
#include "AABB.h"
AABB::AABB(glm::vec3 _volumeVector, glm::vec3 _origin)
{
volumeVector = _volumeVector;
origin = _origin;
CreateBB();
}
void AABB::CreateBB()
{
// Cube 1x1x1, centered on origin
GLfloat vertices[] = {
origin.x - 0.5, origin.y - 0.5, origin.z - 0.5, 1.0,
origin.x + 0.5, origin.y - 0.5, origin.z - 0.5, 1.0,
origin.x + 0.5, origin.y + 0.5, origin.z - 0.5, 1.0,
origin.x - 0.5, origin.y + 0.5, origin.z - 0.5, 1.0,
origin.x - 0.5, origin.y - 0.5, origin.z + 0.5, 1.0,
origin.x + 0.5, origin.y - 0.5, origin.z + 0.5, 1.0,
origin.x + 0.5, origin.y + 0.5, origin.z + 0.5, 1.0,
origin.x - 0.5, origin.y + 0.5, origin.z + 0.5, 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);
glm::vec3 size = glm::vec3(glm::abs(origin.x-volumeVector.x), glm::abs(origin.y-volumeVector.y), glm::abs(origin.z-volumeVector.z));
glm::mat4 transform = glm::translate(glm::mat4(1), origin) * glm::scale(glm::mat4(1), size);
for (int i = 0; i < )
}
+23
View File
@@ -0,0 +1,23 @@
#ifndef AABB_h__
#define AABB_h__
#include <GL/glew.h>
//#define GLFW_INCLUDE_GLU
//#include <GLFW/glfw3.h>
//#include <glext.h>
#include <glm/common.hpp>
#include <glm/gtc/matrix_transform.hpp>
class AABB
{
public:
AABB(glm::vec3, glm::vec3);
void CreateBB(void);
private:
glm::vec3 origin;
glm::vec3 volumeVector; //The vector that defines the volume of the BB, it goes from one corner to the opposite one
};
#endif // !AABB_h__
+10
View File
@@ -0,0 +1,10 @@
#ifndef Color_h__
#define Color_h__
struct Color
{
float r;
float g;
float b;
};
#endif // !Color_h__
+17
View File
@@ -0,0 +1,17 @@
#ifndef Bounds_h__
#define Bounds_h__
#include "Component.h"
#include "AABB.h"
namespace Components
{
struct Bounds : Component
{
AABB BB; //Axis Aligned Bounding Box
};
REGISTER_COMPONENT("Bounds", Bounds);
}
#endif // !Bounds_h__
+18
View File
@@ -0,0 +1,18 @@
#ifndef Camera_h__
#define Camera_h__
#include "Component.h"
namespace Components
{
struct Camera : Component
{
int FOV;
int NearClip;
int FarClip;
};
REGISTER_COMPONENT("Camera", Camera);
}
#endif // !Camera_h__
+18
View File
@@ -0,0 +1,18 @@
#ifndef Collision_h__
#define Collision_h__
#include "Component.h"
#include <vector>
namespace Components
{
struct Collision : Component
{
bool Phantom;
std::vector<int> CollidingEntities;
};
REGISTER_COMPONENT("Collision", Collision);
}
#endif // !Collision_h__
@@ -0,0 +1,20 @@
#ifndef DirectionalLight_h__
#define DirectionalLight_h__
#include "Component.h"
#include "Color.h"
namespace Components
{
struct DirectionalLight : Component
{
float Intensity;
float MaxRange;
float SpecularIntensity;
Color color;
};
REGISTER_COMPONENT("DirectionalLight", DirectionalLight);
}
#endif // !DirectionalLight_h__
+19
View File
@@ -0,0 +1,19 @@
#ifndef Input_h__
#define Input_h__
#include "Component.h"
#include <GLFW/glfw3.h>
namespace Components
{
struct Input : Component
{
int KeyState[GLFW_KEY_LAST];
float MouseState[2];
float dX, dY;
};
REGISTER_COMPONENT("Input", Input);
}
#endif // !Input_h__
+18
View File
@@ -0,0 +1,18 @@
#ifndef Model_h__
#define Model_h__
#include "Component.h"
#include "Color.h"
namespace Components
{
struct Model : Component
{
std::string ModelName;
Color color;
};
REGISTER_COMPONENT("Model", Model);
}
#endif // !Model_h__
@@ -0,0 +1,26 @@
#ifndef ParticleEmitter_h__
#define ParticleEmitter_h__
#include "Component.h"
#include "Color.h"
#include <vector>
namespace Components
{
struct ParticleEmitter : Component
{
int ParticleTemplate;
float SpawnFrequency;
int SpawnCount;
std::vector<Color> ColorSpectrum;
std::vector<float> ScaleSpectrum;
float SpreadAngle;
float LifeTime;
std::vector<float[3]> VelocitySpectrum;
std::vector<float[3]> AngularVelocitySpectrum;
};
REGISTER_COMPONENT("ParticleEmitter", ParticleEmitter);
}
#endif // !ParticleEmitter_h__
+20
View File
@@ -0,0 +1,20 @@
#ifndef PointLight_h__
#define PointLight_h__
#include "Component.h"
#include "Color.h"
namespace Components
{
struct PointLight : Component
{
float Intensity;
float MaxRange;
float SpecularIntensity;
Color color;
};
REGISTER_COMPONENT("PointLight", PointLight);
}
#endif // !PointLight_h__
+16
View File
@@ -0,0 +1,16 @@
#ifndef PowerUp_h__
#define PowerUp_h__
#include "Component.h"
namespace Components
{
struct PowerUp : Component
{
int Speed;
};
REGISTER_COMPONENT("PowerUp", PowerUp);
}
#endif // !PowerUp_h__
+18
View File
@@ -0,0 +1,18 @@
#ifndef SoundEmitter_h__
#define SoundEmitter_h__
#include "Component.h"
namespace Components
{
struct SoundEmitter : Component
{
std::string SoundFile;
float Volume;
float MaxRange;
};
REGISTER_COMPONENT("SoundEmitter", SoundEmitter);
}
#endif // !SoundEmitter_h__
+18
View File
@@ -0,0 +1,18 @@
#ifndef Sprite_h__
#define Sprite_h__
#include "Component.h"
#include "Color.h"
namespace Components
{
struct Sprite : Component
{
std::string SpriteFile;
Color color;
};
REGISTER_COMPONENT("Sprite", Sprite);
}
#endif // !Sprite_h__
+17
View File
@@ -0,0 +1,17 @@
#ifndef Stat_h__
#define Stat_h__
#include "Component.h"
namespace Components
{
struct Stat : Component
{
int Health;
bool Destroyable;
};
REGISTER_COMPONENT("Stat", Stat);
}
#endif // !Stat_h__
+13
View File
@@ -0,0 +1,13 @@
#ifndef Template_h__
#define Template_h__
#include "Component.h"
namespace Components
{
struct Template : Component { };
REGISTER_COMPONENT("Template", Template);
}
#endif // !Template_h__
+8 -6
View File
@@ -2,16 +2,18 @@
#define Transform_h__ #define Transform_h__
#include "Component.h" #include "Component.h"
#include <glm/gtc/quaternion.hpp>
namespace Components namespace Components
{ {
struct Transform : Component struct Transform : Component
{ {
float Position[3]; float Position[3];
}; glm::fquat qtrn; //Quaternion with floats
REGISTER_COMPONENT("Transform", Transform); float Velocity[3];
};
REGISTER_COMPONENT("Transform", Transform);
} }
#endif // Transform_h__ #endif // Transform_h__
+16
View File
@@ -88,6 +88,7 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="AABB.cpp" />
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="Model.cpp" /> <ClCompile Include="Model.cpp" />
<ClCompile Include="Renderer\Renderer.cpp" /> <ClCompile Include="Renderer\Renderer.cpp" />
@@ -101,8 +102,23 @@
<ClCompile Include="Systems\SoundsSystem.cpp" /> <ClCompile Include="Systems\SoundsSystem.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="AABB.h" />
<ClInclude Include="Color.h" />
<ClInclude Include="Component.h" /> <ClInclude Include="Component.h" />
<ClInclude Include="ComponentFactory.h" /> <ClInclude Include="ComponentFactory.h" />
<ClInclude Include="Components\Bounds.h" />
<ClInclude Include="Components\Camera.h" />
<ClInclude Include="Components\Collision.h" />
<ClInclude Include="Components\DirectionalLight.h" />
<ClInclude Include="Components\Input.h" />
<ClInclude Include="Components\Model.h" />
<ClInclude Include="Components\ParticleEmitter.h" />
<ClInclude Include="Components\PointLight.h" />
<ClInclude Include="Components\PowerUp.h" />
<ClInclude Include="Components\SoundEmitter.h" />
<ClInclude Include="Components\Sprite.h" />
<ClInclude Include="Components\Stat.h" />
<ClInclude Include="Components\Template.h" />
<ClInclude Include="Components\Transform.h" /> <ClInclude Include="Components\Transform.h" />
<ClInclude Include="Entity.h" /> <ClInclude Include="Entity.h" />
<ClInclude Include="logging.h" /> <ClInclude Include="logging.h" />
@@ -25,9 +25,8 @@
<ClCompile Include="Systems\SoundsSystem.cpp"> <ClCompile Include="Systems\SoundsSystem.cpp">
<Filter>Systems</Filter> <Filter>Systems</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Model.cpp"> <ClCompile Include="Model.cpp" />
<Filter>Source Files</Filter> <ClCompile Include="AABB.cpp" />
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Component.h" /> <ClInclude Include="Component.h" />
@@ -62,9 +61,48 @@
<ClInclude Include="Components\Transform.h"> <ClInclude Include="Components\Transform.h">
<Filter>Components</Filter> <Filter>Components</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Model.h"> <ClInclude Include="Model.h" />
<Filter>Header Files</Filter> <ClInclude Include="Components\Bounds.h">
<Filter>Components</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Components\Camera.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Collision.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\DirectionalLight.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Input.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Model.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\ParticleEmitter.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\PointLight.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\PowerUp.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Sprite.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Stat.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\Template.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="Components\SoundEmitter.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="AABB.h" />
<ClInclude Include="Color.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Shaders\Fragment.glsl"> <None Include="Shaders\Fragment.glsl">
+17
View File
@@ -0,0 +1,17 @@
#ifndef Transform_h__
#define Transform_h__
#include "Component.h"
namespace Components
{
struct Transform : Component
{
float Position[3];
};
REGISTER_COMPONENT("Transform", Transform);
}
#endif // Transform_h__
View File