summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authormajortom6 <tombarrett@siu.edu>2017-02-19 08:06:37 -0600
committerTom Barrett <tombarrett@siu.edu>2017-03-07 13:23:41 -0600
commit2cc21176467d4501adb7bfb9ee03eb9a2a7d14f2 (patch)
treee12ceac7024bdc697f1ed4adc1a1ece4a82489fc /inc
parent74c6854fd8dcbaee736ac0421805ff1e03c4a1e2 (diff)
-removed all references to sdl_rect and location and now everything now uses our own class rectangle
-standardization of tab spaces to 8 is now in effect -refractoring of graphicsobjects.hpp
Diffstat (limited to 'inc')
-rw-r--r--inc/camera.hpp57
-rw-r--r--inc/constants.hpp27
-rw-r--r--inc/creature.hpp76
-rw-r--r--inc/dna.hpp29
-rw-r--r--inc/entity.hpp36
-rw-r--r--inc/event.hpp15
-rw-r--r--inc/functions.hpp8
-rw-r--r--inc/geoshader.hpp30
-rw-r--r--inc/graphicsobjects.hpp149
-rw-r--r--inc/list.hpp1
-rw-r--r--inc/quadtree.hpp1
-rw-r--r--inc/rectangle.hpp15
-rw-r--r--inc/resource.hpp2
13 files changed, 191 insertions, 255 deletions
diff --git a/inc/camera.hpp b/inc/camera.hpp
new file mode 100644
index 0000000..62ae837
--- /dev/null
+++ b/inc/camera.hpp
@@ -0,0 +1,57 @@
+#ifndef camera_h
+#define camera_h
+
+struct Camera
+{
+ public:
+ Camera(const glm::vec3& pos, float fov, float aspect, float zNear, float zFar){
+ this->pos = pos;
+ this->forward = glm::vec3(0.0f, 0.0f, -1.0f);
+ this->up = glm::vec3(0.0f, 1.0f, 0.0f);
+ this->projection = glm::perspective(fov, aspect, zNear, zFar);
+ }
+
+ inline glm::mat4 GetViewProjection() const {
+ return projection * glm::lookAt(pos, pos + forward, up);
+ }
+
+ void MoveForward(){
+ pos += forward * amt;
+ }
+
+ void MoveBackward(){
+ pos += forward * -amt;
+ }
+
+ void MoveRight(){
+ pos += -glm::cross(up, forward) * amt;
+ }
+
+ void MoveLeft(){
+ pos += glm::cross(up, forward) * amt;
+ }
+
+ void MoveUp(){
+ pos += glm::vec3(0,.2,0);
+ }
+
+ void MoveDown(){
+ pos -= glm::vec3(0,.2,0);
+ }
+
+ void Pitch(float angle){
+ glm::vec3 right = glm::normalize(glm::cross(up, forward));
+
+ forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0)));
+ up = glm::normalize(glm::cross(forward, right));
+ }
+
+ private:
+ float amt = .2;
+ glm::mat4 projection;
+ glm::vec3 pos;
+ glm::vec3 forward;
+ glm::vec3 up;
+};
+
+#endif
diff --git a/inc/constants.hpp b/inc/constants.hpp
index 646d987..7d53134 100644
--- a/inc/constants.hpp
+++ b/inc/constants.hpp
@@ -1,14 +1,14 @@
#ifndef constants_h
#define constants_h
-const int CREATURES = 10;
-const int RESOURCES = 100;
-const int MINIMUM_RESOURCES = 800;
-const int WINDOW_X = 1000;
-const int WINDOW_Y = 1000;
+const int CREATURES = 10;
+const int RESOURCES = 100;
+const int MINIMUM_RESOURCES = 800;
+const int WINDOW_X = 1000;
+const int WINDOW_Y = 1000;
-const int CREATURE_TYPE = 1;
-const int RESOURCE_TYPE = 2;
+const int CREATURE_TYPE = 1;
+const int RESOURCE_TYPE = 2;
const int CREATURE_MAX_HEALTH = 1000;
const int CREATURE_REACH = 1;
@@ -20,10 +20,13 @@ const int CREATURE_EXP_AGE = 1000000;
const int CREATURE_SIZE_MAX = 10;
const float CREATURE_SPEED = .1;
-const int RESOURCE_SIZE_START = 1;
-const int RESOURCE_SIZE_MAX = 4;
-const int RESOURCE_AMOUNT_START = 100;
-const int RESOURCE_AMOUNT_MAX = 200;
-const int RESOURCE_GROW = 1;
+const int RESOURCE_SIZE_STAR = 1;
+const int RESOURCE_SIZE_MAX = 4;
+const int RESOURCE_AMOUNT_START = 100;
+const int RESOURCE_AMOUNT_MAX = 200;
+const int RESOURCE_GROW = 1;
+
+const int NUM_SHADERS = 3;
+const int NUM_UNIFORMS = 3;
#endif
diff --git a/inc/creature.hpp b/inc/creature.hpp
index 1bc6f49..99226b3 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -2,53 +2,51 @@
#define creature_h
#include <SDL2/SDL.h>
-#include <vector>
#include <list>
-#include <algorithm>
#include "entity.hpp"
-#include "constants.hpp"
#include "functions.hpp"
#include "dna.hpp"
class Creature: public Entity
{
- public:
- Creature(Location t, Dna D);
- void Behavior();
- void Action();
- void Priority();
- void setTarget();
- void checkTarget();
- void moveTowards(Location t);
- void impregnate(Dna D);
- void giveN(std::list<Entity*> n){N = n;};
-
- Dna getDNA(){return mine;};
- Dna getChildDNA(){return childs;};
- int getHealth(){return health;};
- int getBestSense(){return mine.bestSense;};
- bool getGender(){return gender;};
- bool getPregnancyReady(){return pregnancyReady;};
- void hadPregnancy(){pregnate = pregnancyReady = false;};
-
- private:
- Location wTarget;
- Entity *target;
- std::list<Entity*> N;
- Dna mine;
- Dna childs;
-
- int health;
- int amountAte;
- int pregnancyTime;
- int age;
-
- bool hungry;
- bool pregnancyReady;
- bool able;
- bool hasTarget;
- bool wander;
+ public:
+ Creature(Rectangle t, DNA D);
+
+ void Behavior();
+ void Action();
+ void Priority();
+ void setTarget();
+ void checkTarget();
+ void moveTowards(Rectangle t);
+ void impregnate(DNA D);
+ void giveNearMe(std::list<Entity*> n){nearMe = n;};
+
+ DNA getDNA(){return myDNA;};
+ DNA getChildsDNA(){return childsDNA;};
+ int getHealth(){return health;};
+ int getBestSense(){return myDNA.bestSense;};
+ bool getGender(){return gender;};
+ bool getPregnancyReady(){return pregnancyReady;};
+ void hadPregnancy(){pregnate = pregnancyReady = false;};
+
+ private:
+ Rectangle wTarget;
+ Entity* target;
+ std::list<Entity*> nearMe;
+ DNA myDNA;
+ DNA childsDNA;
+
+ int health;
+ int amountAte;
+ int pregnancyTime;
+ int age;
+
+ bool hungry;
+ bool pregnancyReady;
+ bool able;
+ bool hasTarget;
+ bool wander;
};
#endif
diff --git a/inc/dna.hpp b/inc/dna.hpp
index dc46b64..d7312f6 100644
--- a/inc/dna.hpp
+++ b/inc/dna.hpp
@@ -3,20 +3,23 @@
#include "constants.hpp"
-class Dna
+class DNA
{
- public:
- Dna();
- Dna combine(Dna D);
- int maxHealth;
- float speed;
- int reach;
- int bestSense;
- int bite;
- int amountToGrow;
- int expectedPregnancyTime;
- int expectedAge;
- int sizeMax;
+ public:
+ DNA();
+
+ DNA combine(DNA D);
+
+ int maxHealth;
+ int reach;
+ int bestSense;
+ int bite;
+ int amountToGrow;
+ int expectedPregnancyTime;
+ int expectedAge;
+ int sizeMax;
+
+ float speed;
};
#endif
diff --git a/inc/entity.hpp b/inc/entity.hpp
index 50f9b06..259849f 100644
--- a/inc/entity.hpp
+++ b/inc/entity.hpp
@@ -5,27 +5,29 @@
#include "dna.hpp"
#include "graphicsobjects.hpp"
+#include "rectangle.hpp"
class Entity
{
- public:
- void Place();
-
- int getType(){return type;};
- virtual bool getGender(void){};
- virtual int getAmount(void){};
- Location getLocation(){return L;};
-
- virtual void eat(int bite){};
- virtual void impregnate(Dna D){};
- GraphicsData getGFXD(){return gfxData;};
- GraphicsData gfxData;
+ public:
+ void Place();
+
+ virtual void eat(int bite){};
+ virtual void impregnate(DNA D){};
- protected:
- int type;
- int gender;
- bool pregnate;
- Location L;
+ int getType(){return type;};
+ virtual bool getGender(void){};
+ virtual int getAmount(void){};
+ Rectangle getRectangle(){return L;};
+ GraphicsData getGFXD(){return gfxData;};
+
+
+ protected:
+ int type;
+ int gender;
+ bool pregnate;
+ Rectangle L;
+ GraphicsData gfxData;
};
#endif
diff --git a/inc/event.hpp b/inc/event.hpp
index c1d528e..3a0a868 100644
--- a/inc/event.hpp
+++ b/inc/event.hpp
@@ -5,13 +5,14 @@
class Event
{
- public:
- Event();
- int Poll();
- void off();
- bool gRun();
- SDL_Event& gEvent();
- int gEventType();
+ public:
+ Event();
+
+ int Poll();
+ void off();
+ bool gRun();
+ SDL_Event& gEvent();
+ int gEventType();
private:
bool run;
diff --git a/inc/functions.hpp b/inc/functions.hpp
index ce072e2..15cb94a 100644
--- a/inc/functions.hpp
+++ b/inc/functions.hpp
@@ -1,14 +1,14 @@
#ifndef functions_h
#define functions_h
-#include "graphicsobjects.hpp"
+#include "rectangle.hpp"
-static double Distance(Location A, Location B){
- return sqrt( pow(A.x-B.x,2) + pow(A.y-B.y,2));
+static double Distance(Rectangle A, Rectangle B){
+ return sqrt(pow(A.x-B.x,2) + pow(A.y-B.y,2));
}
static int map(int x, int inMin, int inMax, int outMin, int outMax){
- return (x-inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
+ return (x-inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
#endif
diff --git a/inc/geoshader.hpp b/inc/geoshader.hpp
index f8be43b..65e2fc3 100644
--- a/inc/geoshader.hpp
+++ b/inc/geoshader.hpp
@@ -3,29 +3,27 @@
#include <string>
#include <GL/glew.h>
-#include "graphicsobjects.hpp"
-//#define GLSL(src) "#version 150 core\n" #src
+#include "constants.hpp"
+#include "graphicsobjects.hpp"
class GeoShader
{
- public:
- GeoShader(const std::string& fileName);
+ public:
+ GeoShader(const std::string& fileName);
- void Bind();
- void Update(const Transform& transform, const Camera& camera);
- virtual ~GeoShader();
- GLuint m_program;
+ void Bind();
+ void Update(const Transform& transform, const Camera& camera);
+ virtual ~GeoShader();
+ GLuint m_program;
- private:
- static const unsigned int NUM_SHADERS = 3;
- static const unsigned int NUM_UNIFORMS = 3;
- std::string LoadShader(const std::string& fileName);
- void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage);
- GLuint CreateShader(const std::string& text, GLenum shaderType);
+ private:
+ std::string LoadShader(const std::string& fileName);
+ void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage);
+ GLuint CreateShader(const std::string& text, GLenum shaderType);
- GLuint m_shaders[NUM_SHADERS];
- GLuint m_uniforms[NUM_UNIFORMS];
+ GLuint m_shaders[NUM_SHADERS];
+ GLuint m_uniforms[NUM_UNIFORMS];
};
#endif
diff --git a/inc/graphicsobjects.hpp b/inc/graphicsobjects.hpp
index 66e3fc3..de85467 100644
--- a/inc/graphicsobjects.hpp
+++ b/inc/graphicsobjects.hpp
@@ -4,82 +4,7 @@
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
-
-struct Camera
-{
-public:
- Camera(const glm::vec3& pos, float fov, float aspect, float zNear, float zFar)
- {
- this->pos = pos;
- this->forward = glm::vec3(0.0f, 0.0f, -1.0f);
- this->up = glm::vec3(0.0f, 1.0f, 0.0f);
- this->projection = glm::perspective(fov, aspect, zNear, zFar);
- }
-
- inline glm::mat4 GetViewProjection() const
- {
- return projection * glm::lookAt(pos, pos + forward, up);
- }
-
- void MoveForward()
- {
- pos += forward * amt;
- }
-
- void MoveBackward()
- {
- pos += forward * -amt;
- }
-
- void MoveRight()
- {
- pos += -glm::cross(up, forward) * amt;
- }
-
- void MoveLeft()
- {
- pos += glm::cross(up, forward) * amt;
- }
-
- void MoveUp()
- {
- //pos += glm::cross(up, forward) * amt;
- pos += glm::vec3(0,.2,0);
- }
-
- void MoveDown()
- {
- //pos += glm::cross(up, forward) * amt;
- pos -= glm::vec3(0,.2,0);
- }
-
- void Pitch(float angle)
- {
- glm::vec3 right = glm::normalize(glm::cross(up, forward));
-
- forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0)));
- up = glm::normalize(glm::cross(forward, right));
- }
-
- /*void RotateY(float angle)
- {
- static const glm::vec3 UP(0.0f, 1.0f, 0.0f);
-
- glm::mat4 rotation = glm::rotate(angle, UP);
-
- forward = glm::vec3(glm::normalize(rotation * glm::vec4(forward, 0.0)));
- up = glm::vec3(glm::normalize(rotation * glm::vec4(up, 0.0)));
- }*/
-
-private:
- float amt = .2;
- //glm::vec3 speed = glm::vec3(0,0,0.2);
- glm::mat4 projection;
- glm::vec3 pos;
- glm::vec3 forward;
- glm::vec3 up;
-};
-
+#include "camera.hpp"
struct Transform
@@ -109,7 +34,7 @@ public:
glm::mat4 VP = camera.GetViewProjection();
glm::mat4 M = GetModel();
- return VP * M;//camera.GetViewProjection() * GetModel();
+ return VP * M;
}
inline glm::vec3* GetPos() { return &pos; }
@@ -126,32 +51,6 @@ private:
glm::vec3 scale;
};
-
-
-
-
-
-class Location
-{
- public:
- Location(float x1, float y1){x=x1;y=y1; w=5; h=5;};
- Location(){x=y=0; w=5; h=5;};
-
- float getX(){
- return x;
- }
-
- float getY(){
- return y;
- }
-
- float x;
- float y;
- float w;
- float h;
-};
-
-
class GraphicsData
{
public:
@@ -162,8 +61,6 @@ class GraphicsData
float g;
float b;
float sides;
- //float theret[6];
- //float* ret[6];
GraphicsData(){
this->x = 0;
@@ -194,44 +91,4 @@ class GraphicsData
};
-
-class Rectangle
-{
- public:
- Rectangle(float x1, float y1, float wid, float heit){x=x1;y=y1;width=wid; height=heit;};
- Rectangle(){x=y=width=height=0;};
-
-
- void setX(float x1){
- x=x1;
- }
-
- void setY(float y1){
- y=y1;
- }
-
-
-
- float getX(){
- return x;
- }
-
- float getY(){
- return y;
- }
-
- float getWidth(){
- return width;
- }
-
- float getHeight(){
- return height;
- }
-
- float x;
- float y;
- float width;
- float height;
-};
-
-#endif \ No newline at end of file
+#endif
diff --git a/inc/list.hpp b/inc/list.hpp
index 7758fac..14a824c 100644
--- a/inc/list.hpp
+++ b/inc/list.hpp
@@ -10,6 +10,7 @@
#include "resource.hpp"
#include "window.hpp"
#include "constants.hpp"
+#include "rectangle.hpp"
#include "quadtree.hpp"
class List
diff --git a/inc/quadtree.hpp b/inc/quadtree.hpp
index 2c23c67..fab20da 100644
--- a/inc/quadtree.hpp
+++ b/inc/quadtree.hpp
@@ -8,6 +8,7 @@
#include "creature.hpp"
#include "resource.hpp"
#include "entity.hpp"
+#include "rectangle.hpp"
#include "graphicsobjects.hpp"
class Quadtree {
diff --git a/inc/rectangle.hpp b/inc/rectangle.hpp
new file mode 100644
index 0000000..9e5ef9b
--- /dev/null
+++ b/inc/rectangle.hpp
@@ -0,0 +1,15 @@
+#ifndef rectangle_h
+#define rectangle_h
+
+class Rectangle
+{
+ public:
+ Rectangle(){x=y=w=h=0;};
+ Rectangle(float x1, float y1, float w1, float h1){x=x1;y=y1;w=w1;h1=h;};
+ float x;
+ float y;
+ float w;
+ float h;
+};
+
+#endif
diff --git a/inc/resource.hpp b/inc/resource.hpp
index ce8ef5b..252b086 100644
--- a/inc/resource.hpp
+++ b/inc/resource.hpp
@@ -7,7 +7,7 @@
class Resource: public Entity
{
public:
- Resource(Location L);
+ Resource(Rectangle t);
int getAmount(){return amount;};
void grow();
void eat(int bite);