void Events::keymotion()
{
- axis(move_x, SDLK_w, SDLK_s);
- axis(move_y, SDLK_a, SDLK_d);
+ axis(move_x, SDLK_a, SDLK_d);
+ axis(move_y, SDLK_w, SDLK_s);
+
}
void Events::padmotion()
{
srand((int)time(NULL));
// Hauptfenster
- Scene* tmp_Scene = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 60, 0.1f, 100, vec3(0.0f, 0.0f, -3.0f));
+ Scene* tmp_Scene = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 45, 0.1f, 10, vec3(0.0f, 0.0f, -2.0f));
layer[0] = tmp_Scene;
//Allg Shader
// //cout << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << endl;
//}
//ein Gegner
- //tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(1.f, -2.f, 2.f)), "../models/sphere/sphere.dae", "../Textures/game_box.png"));
+ tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(1.f, 0.f, 1.f)), "cow/cow.dae", "model_cow.jpg"));
//tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(-1.f, 2.f, -2.f)), "../models/box/box.dae", "../Textures/sky_withstars.png"));
//tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(1.f, 3.f, -2.f)), "../models/cow/cow.dae", "../models/cow/texture.jpg"));
}
}*/
Scene::Scene(unsigned int x, unsigned int y, unsigned int width, unsigned int height, float fovy, float zNear, float zFar, vec3 pos, SceneObject* _lookat) :
- viewPort(new ViewPort(x, y, width, height)),
+viewPort(new ViewPort(x, y, width, height, fovy, zNear, zFar)),
projection(perspective(fovy, (float)width / height, zNear, zFar)),
view(translate(pos)),
SceneObjects(new list<SceneObject*>),
}
Scene::Scene(Scene* _Scene, unsigned int x, unsigned int y, unsigned int width, unsigned int height, float fovy, float zNear, float zFar, vec3 pos, SceneObject* _lookat) :
- viewPort(new ViewPort(x, y, width, height)),
+viewPort(new ViewPort(x, y, width, height, fovy, zNear, zFar)),
projection(perspective(fovy, (float)width / height, zNear, zFar)),
view(translate(pos)),
SceneObjects(_Scene->SceneObjects),
vec3 pos;
//Focus auf Player
-
- if (lookat->getMatter()<1e-2)
- {
- Message::error("GameOver");
+ if (lookat != NULL){
+ pos = lookat->getPosition();
+ view = view*translate(-pos);
}
+
int move_x = Events::getMoveX();
int move_y = Events::getMoveY();
//int shoot = Events::getAction1();
//int reset = Events::getAction2();
- //cout << move_x << " " << move_y << endl;
-
if (move_x)
- lookat->turn(0.3f *move_x, vec3(0.f, 1.f, 0.f));
+ lookat->move(0.03f *move_x * vec3(1.f, 0.f, 0.f));
if (move_y)
- lookat->turn(0.3f *move_y, vec3(1.f, 0.f, 0.f));
- //if (shoot)
- //{
- // vec3 direction = lookat->push(vec3(0.f, 0.f, shoot*0.1f));
- // //SceneObjects->push_back(self->copy();)
- //}
- //if (reset)
- // lookat->stop();
+ lookat->move(0.03f *move_y * vec3(0.f, 0.f, 1.f));
// XYAchse um den Player
- if (Events::getViewX() || Events::getViewY())
- {
- if (lookat!=NULL)
- view = translate(view,lookat->getPosition());
- pos = (vec3)view[3];
- view = rotate(deltaT * 70, vec3(sign(Events::getViewX()), sign(Events::getViewY()), 0.0f))*view;
- view = translate(pos - (vec3)view[3])*view;
- if (lookat != NULL)
- view = translate(view, -lookat->getPosition());
- // TODO Kamera wieder an die richtige Stelle schieben
- }
+ viewPort->rotateView(.3f*Events::getViewX(), .3f*Events::getViewY());
+ //int view_x = Events::getViewX();
+ //int view_y = Events::getViewY();
+
+ //if ( view_x || view_y)
+ //{
+ // //TODO Limit Rotation
+ // view = view * rotate(0.3f, vec3(view_y ,view_x, 0.f));
+ //}
//// Zoom auf Player
// //view = view*scale(vec3((float)(1 + deltaT * sign(Events::getViewZ()))));
//}
- if (lookat != NULL)
- pos = lookat->getPosition();
// Alle Objekte der Scene aktualisieren
if (newObjects)
{
(*i)->collisions(*j);
}
}
- for (auto i = SceneObjects->begin(); i != SceneObjects->end(); ++i)
- {
- if ((*i)->isEnemy() && (*i)->getMatter() < lookat->getMatter())
- (*i)->useTextureSave();
- else if ((*i)->isEnemy() && (*i)->getMatter() >= lookat->getMatter())
- (*i)->useTextureDanger();
- if ((*i)->getMatter() < 1.e-3 && newObjects)
- {
- //SceneObjects->erase(i);
-// delete (*i);
- }
- }
+
}
if (lookat != NULL)
- view = translate(view,pos - lookat->getPosition());
+ view = view*translate(lookat->getPosition());
}
for (auto i = ShaderSet->cbegin(); i != ShaderSet->cend(); ++i)
{
- (*i)->useShader();
- glUniformMatrix4fv((*i)->getUniformLocation("projection"), 1, false, value_ptr(projection));
- glUniformMatrix4fv((*i)->getUniformLocation("view"), 1, false, value_ptr(view));
+ viewPort->bindView(*i,lookat->getPosition()+vec3(0.0f,1.0f,0.0f));
+ //(*i)->useShader();
+ //glUniformMatrix4fv((*i)->getUniformLocation("projection"), 1, false, value_ptr(projection));
+ //glUniformMatrix4fv((*i)->getUniformLocation("view"), 1, false, value_ptr(view));
}
projection = _projection * projection;
}*/
-void Scene::setViewPort(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
-{
- viewPort = new ViewPort(x, y, width, height);
-}
+//void Scene::setViewPort(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
+//{
+// viewPort = new ViewPort(x, y, width, height);
+//}
void Scene::setLookAt(SceneObject* _lookat)
{
SceneList* getSceneObjects();
- void setViewPort(unsigned int, unsigned int, unsigned int, unsigned int);
+// void setViewPort(unsigned int, unsigned int, unsigned int, unsigned int);
// void setProjection(mat4 _projection);
void setProjection(float fovy, float aspect, float zNear, float zFar);
Model(_modelpath),
model(_model),
shader(_shader),
-speed(_speed),
-matter(_matter),
-atack(_atack),
-spin(1.0f),
-direction(_direction),
-matterDiff(0),
mainScene(NULL),
collision_ignore(false),
-isenemy(false),
texture(nullptr)
{
modelID = _shader->getUniformLocation("model");
- model = scale(model, vec3(pow(matter,1./3)));
if (texturepath!="")
texture = new Texture(texturepath);
void SceneObject::update(float deltaT)
{
- //Direction & Speed
- model = translate(deltaT * speed * direction)*model;
- //Matter Difference
- if (abs(matterDiff)>1e-3)
- {
- float nmatter = (deltaT * matterDiff * MODEL_contractionspeed + matter);
- //cout << faktor << endl;
- model = scale(model, vec3(pow(nmatter / matter, 1. / 3)));
- matterDiff -= deltaT * matterDiff * MODEL_contractionspeed;
- matter = nmatter;
- }
- else if (matterDiff != 0)
- {
- float nmatter = (matterDiff + matter);
- model = scale(model, vec3(pow(nmatter / matter, 1. / 3)));
- matterDiff = 0;
- matter = nmatter;
- }
//model = scale(model, vec3(matter));
//model = (deltaT * spin) * model; //TODO drehen scheint nicht zu funktionieren
- // Im Ramen bleiben
- vec3 pos = getPosition();
- if (fabs(pos.x) > BOX_size && direction.x*pos.x > 0){
- direction.x *= -1;
- }
- else if (fabs(pos.y) > BOX_size && direction.y*pos.y > 0){
- direction.y *= -1;
- }
- else if (fabs(pos.z) > BOX_size && direction.z*pos.z > 0){
- direction.z *= -1;
- }
}
void SceneObject::draw() const
if (collision_ignore || _other->collision_ignore)
return;
- float otherM = _other->getMatter();
- float diff = VektorAbs(getPosition() - _other->getPosition()) - pow(matter, 1. / 3) - pow(otherM, 1. / 3);
- if (diff < 0)
- {
- float mass = matter - pow(pow(matter, 1. / 3) + diff / 2, 3) + otherM - pow(pow(otherM, 1. / 3) + diff / 2, 3);
-
- if (matter>_other->getMatter())
- {
- _other->setMatter(otherM - mass);
- setMatter(matter + mass);
- }
- else
- {
- _other->setMatter(otherM + mass);
- setMatter(matter - mass);
- }
- }
}
vec3 SceneObject::getPosition() const{
return vec3(model[3]);
}
-vec3 SceneObject::push(vec3& _direction, float _matter)
-{
- vec3 direct = normalize(vec3(model * vec4(_direction, 0.f)));
- float dir_len = VektorAbs(_direction);
- if (dir_len > 0)
- {
- //SceneObject* copy = this->copy();
- //mainScene->addObject(copy);
- //copy->setModel(translate(getPosition() - direct * (float)(1.25*pow(matter*_matter, 1. / 3) + pow(matter, 1. / 3))));
- //copy->direction = direct * dir_len / -_matter;
- //copy->setMatter(_matter*matter*.1);
- //copy->matterDiff = _matter*matter*.9;
- //copy->setEnemy(true);
-
- //delete copy->texture;
- //copy->texture = new Texture("../Textures/enemy.png");
-
- direction += direct * dir_len;
- matterDiff -= _matter * matter;
- }
- return direct;
-}
-
-void SceneObject::stop()
-{
- push(vec3(inverse(model)*vec4(-direction,0)));
- direction = vec3(0.f);
-}
void SceneObject::setModel(mat4& _model){
model = _model;
model = model * rotate(degree, axis);
}
-void SceneObject::setDirection(vec3& _direction)
-{
- direction = _direction;
+void SceneObject::move(vec3& dist){
+ model = model * translate(dist);
}
+
void SceneObject::setCollision(bool _col)
{
collision_ignore = !_col;
//
-float SceneObject::getMatter()
-{
- return matter;
-}
-
void SceneObject::setMainScene(Scene* _scene)
{
mainScene = _scene;
}
-void SceneObject::setMatter(float _matter)
-{
- model = scale(model, vec3(pow(_matter / matter,1./3)));
- matter = _matter;
-}
-
-
-void SceneObject::setTextureSave(string texture)
-{
- default_save = new Texture(texture);
-}
-void SceneObject::setTextureDanger(string texture)
-{
- default_danger = new Texture(texture);
-}
-
-void SceneObject::useTextureSave()
-{
- texture = default_save;
-}
-void SceneObject::useTextureDanger()
-{
- texture = default_danger;
-}
-
-void SceneObject::setEnemy(bool _isenemy)
-{
- isenemy = _isenemy;
-}
Shader* SceneObject::getShader()
{
return shader;
}
-
-bool SceneObject::isEnemy()
-{
- return isenemy;
-}
-
-Texture* SceneObject::default_danger = nullptr;
-Texture* SceneObject::default_save = nullptr;
-
virtual void collisions(SceneObject*);
virtual vec3 getPosition() const;
- virtual void setDirection(vec3&);
-
- virtual vec3 push(vec3&, float = 0.1f);
-
- virtual void stop();
virtual void setModel(mat4&);
- virtual void turn(float, vec3&);
+ virtual void turn(float degree, vec3& axis);
+ virtual void move(vec3& dist);
//virtual bool operator==(SceneObject);
void setMainScene(Scene *);
- float getMatter();
-
void setCollision(bool);
- static void setTextureSave(string texture);
- static void setTextureDanger(string texture);
-
- void useTextureSave();
- void useTextureDanger();
-
Shader* getShader();
void setEnemy(bool isenemy);
bool collision_ignore;
- //virtual SceneObject* copy();
-
- float matter;
- float speed;
- float atack;
-
- float matterDiff;
-
- vec3 direction;
- mat4 spin;
-
Texture* texture;
- bool isenemy;
-
-private:
-
- static Texture* default_danger;
- static Texture* default_save;
-
-
};
#include "ViewPort.h"
#include <GL\glew.h>
+#include "GLM.h"
+#include "Shader.h"
-ViewPort::ViewPort(unsigned int _x, unsigned int _y, unsigned int _width, unsigned int _height) : xpos(_x), ypos(_y), width(_width), height(_height)
+#define VIEW_TOP_LIM 60.f
+#define VIEW_BOT_LIM -30.f
+
+
+ViewPort::ViewPort(unsigned int _x, unsigned int _y, unsigned int _width, unsigned int _height, float fovy, float zNear, float zFar) :
+ xpos(_x),
+ ypos(_y),
+ width(_width),
+ height(_height),
+ projection(perspective(fovy, (float)width / height, zNear, zFar)),
+ view_angle_x(0),
+ view_angle_y(0),
+ view_dist(2)
{
+ rotateView(0.f, 0.f);
}
glViewport(xpos, ypos, width, height);
}
+void ViewPort::bindView(Shader* shader) const{
+ shader->useShader();
+ glUniformMatrix4fv(shader->getUniformLocation("projection"), 1, false, value_ptr(projection));
+ glUniformMatrix4fv(shader->getUniformLocation("view"), 1, false, value_ptr(view));
+}
+
+void ViewPort::bindView(Shader* shader, vec3 pos) const{
+ shader->useShader();
+ glUniformMatrix4fv(shader->getUniformLocation("projection"), 1, false, value_ptr(projection));
+ glUniformMatrix4fv(shader->getUniformLocation("view"), 1, false, value_ptr(translate(view,-pos)));
+}
+
+void ViewPort::rotateView(float angle_x, float angle_y){
+
+ if (angle_y || angle_x){
+
+ view_angle_x += angle_x;
+ view_angle_y += angle_y;
+
+ //Y-Limits
+ if (view_angle_y > VIEW_TOP_LIM)
+ view_angle_y = VIEW_TOP_LIM;
+
+ if (view_angle_y < VIEW_BOT_LIM)
+ view_angle_y = VIEW_BOT_LIM;
+
+ view = translate(vec3(0.f, 0.f, -view_dist))*rotate(view_angle_y / 50, vec3(1.f, 0.f, 0.f))*rotate(view_angle_x / 50, vec3(0.f, 1.f, 0.f));
+
+ }
+
+}
+
unsigned int ViewPort::getXPos() const
{
return xpos;
#pragma once
-#include "Drawable.h"
+//#include "Drawable.h"
+#include "GLM.h"
+
+class Shader;
class ViewPort
{
public:
- ViewPort(unsigned int, unsigned int, unsigned int, unsigned int);
+ ViewPort(unsigned int x, unsigned int y, unsigned int width, unsigned int height, float fovy, float zNear, float zFar);
~ViewPort();
void useViewPort() const;
+ void bindView(Shader* shader) const;
+ void bindView(Shader* shader, vec3 lookat) const;
+
+ void rotateView(float angle_x, float angle_y);
+
unsigned int getXPos() const;
unsigned int getYPos() const;
unsigned int getWidth() const;
unsigned int xpos;
unsigned int ypos;
+ mat4 projection;
+ mat4 view;
+
+ float view_dist;
+ float view_angle_x;
+ float view_angle_y;
+
};