#include <GL\glew.h>\r
\r
#include "Scene.h"\r
+#include "Scene\Lever.h"\r
\r
#include "Graphix\Shader.h"\r
#include "Graphix\Graphix.h"\r
current_world->addObject(new SceneObject(translate(vec3(-5.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "duck", "model_duck_2D.png"));\r
\r
SceneObject* door = new SceneObject(translate(vec3(2.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "door", "model_duck_2D.png");\r
- SceneObject* lever = new SceneObject(translate(vec3(0.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "lever", "model_duck_2D.png");\r
- lever->timeresistant = true;\r
current_world->addObject(door);\r
+ door->startanimation((uint)0, 1.0f);\r
+ door->setAnimationLoop(true);\r
+\r
+ SceneObject* door2 = new SceneObject(translate(vec3(1.f, .4f, 0.f)), vec4(3.0f, 1.f, 0.4f, 1.5f), "door", "model_duck_2D.png");\r
+ current_world->addObject(door2);\r
+ door2->startanimation((uint)0, 1.0f);\r
+ door2->setAnimationLoop(true);\r
+ door2->timeresistant = true;\r
+\r
+ Lever* lever = new Lever(translate(vec3(0.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "lever", "model_duck_2D.png");\r
current_world->addObject(lever);\r
+ lever->startanimation((uint)0, 0.0f);\r
+ lever->setAnimationLoop(false);\r
+ lever->timeresistant = true;\r
+ lever->setup(door);\r
+\r
+ //TODO register door to lever\r
\r
\r
current_world->addObject(new SceneObject(translate(vec3(-5.f, 3.f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "SkyBox", "model_SkyBox_2D.png"));\r
\r
- current_world->addObject(new EventBox(translate(vec3(3.f, .4f, 0.f)),EB_LOSTZONE));\r
+ current_world->addObject(new EventBox(translate(vec3(3.f, .4f, 0.f)), EB_LOSTZONE));\r
//current_world->addObject(new EventBox(translate(vec3(0.f, -5.f, 0.f))*glm::scale(vec3(50.f,1.f,50.f)), EB_LOSTZONE));\r
current_world->addObject(new EventBox(translate(vec3(3.f, .4f, -15.f)), EB_WINZONE));\r
\r
IAnimMesh::IAnimMesh(const aiMesh* mesh, const vec3& scale, bool isConvex) : IMesh(mesh, scale)
{
- currentAnimation = 0;
- time = 0;
- animationSpeed = 1.0f;
+
}
IAnimMesh::~IAnimMesh()
animations.push_back(new Animation(animation));
}
-void IAnimMesh::startanimation(uint index, float speed)
-{
- currentAnimation = index;
- animationSpeed = 1.0f;
- time = 0;
-}
-
-void IAnimMesh::stopanimation()
-{
- animationSpeed = 0;
-}
-
-void IAnimMesh::drawModel(const mat4& _modelMat, drawType _type, const vec4& _color) const
+void IAnimMesh::drawModel(const mat4& _modelMat, drawType _type, const vec4& _color, uint index, double time) const
{
if (animations.empty())
{
- Model::drawModel(_modelMat, _type, _color);
+ Model::drawModel(_modelMat, _type, _color, index, time);
}
else
{
- Animation* anim = animations[currentAnimation];
+ Animation* anim = animations[index];
mat4 mat = anim->getmodelmat(time);
- Model::drawModel(_modelMat * mat, _type, _color);
- }
-}
-
-void IAnimMesh::updateModel(float deltaT)
-{
- if (animations.empty())
- {
- Model::updateModel(deltaT);
- }
- else
- {
- time += animationSpeed * deltaT;
- while (time < 0)
- {
- time = time + animationduration;
- }
- while (time >= animationduration)
- {
- time = time - animationduration;
- }
- Model::updateModel(deltaT);
+ Model::drawModel(_modelMat * mat, _type, _color, index, time);
}
}
\ No newline at end of file
virtual ~IAnimMesh();
void addanimation(aiNodeAnim* animation);
- void startanimation(uint index, float speed);
- void stopanimation();
- virtual void drawModel(const mat4& modelMat, drawType type, const vec4& color) const;
-
- void updateModel(float deltaT);
-
- double animationduration;
+ virtual void drawModel(const mat4& modelMat, drawType type, const vec4& color, uint index, double time) const;
protected:
std::vector<Animation*> animations;
- double time;
- uint currentAnimation;
- float animationSpeed;
};
\ No newline at end of file
{\r
IAnimMesh* tmpIMesh;\r
\r
+ animationduration = scene->mAnimations[0]->mDuration;\r
+\r
for (uint i = 0; i < scene->mNumMeshes; i++)\r
{\r
bool animated = false;\r
tmpModelMatClean = removeScale(tmpModelMat);\r
tmpIMesh = new IAnimMesh(scene->mMeshes[i], _scale* getScale(tmpModelMat));\r
\r
- tmpIMesh->animationduration = scene->mAnimations[0]->mDuration;\r
-\r
for (uint l = 0; l < scene->mNumAnimations; l++)\r
{\r
aiAnimation* tmpanimation = scene->mAnimations[l];\r
}\r
}\r
\r
-void IMetaMesh::drawModel(const mat4& _modelMat, drawType _type, const vec4& _color) const\r
+void IMetaMesh::drawModel(const mat4& _modelMat, drawType _type, const vec4& _color, uint index, double time) const\r
{\r
for (auto i = models.begin(); i != models.end(); ++i)\r
{\r
- i->first->drawModel(_modelMat* i->second, _type, _color*.9f);\r
+ i->first->drawModel(_modelMat* i->second, _type, _color*.9f, index, time);\r
}\r
}\r
\r
// }\r
//}\r
\r
-void IMetaMesh::updateModel(float deltaT)\r
-{\r
- for (auto i = models.begin(); i != models.end(); ++i)\r
- {\r
- i->first->updateModel(deltaT);\r
- }\r
-}\r
-\r
void IMetaMesh::bt_init(bool _isConvex)\r
{\r
if (bt_collision_shape == nullptr)\r
void unbindModel() override;\r
void unbindShader(const Shader* shader) override;\r
\r
- virtual void drawModel(const mat4& modelMat, drawType type = dr_Model, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
+ virtual void drawModel(const mat4& modelMat, drawType type = dr_Model, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f), uint index = 0, double animationtime = 0) const override;\r
//void drawWire(const mat4& modelMat, const vec4& _color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
\r
//void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const override;\r
\r
- void updateModel(float deltaT) override;\r
-\r
virtual void bt_init(bool isConvex = true) override;\r
\r
std::string type2str() const override;\r
\r
Model::Model()\r
{\r
+ animationduration = 0;\r
}\r
\r
Model::~Model()\r
glBindVertexArray(0);\r
}\r
\r
-void Model::drawModel(const mat4& _modelMat, drawType _type, const vec4& _color) const\r
+void Model::drawModel(const mat4& _modelMat, drawType _type, const vec4& _color, uint animation, double time) const\r
{\r
useModel(_modelMat);\r
\r
getBBoxModel()->drawModel(_modelMat*translate(center)*glm::scale(size));\r
break;\r
}\r
+}\r
\r
- \r
+void Model::drawModel(const mat4& _modelMat) const\r
+{\r
+ useModel(_modelMat);\r
+ drawModel();\r
}\r
\r
//void Model::drawModel(const mat4& _modelMat) const\r
return true;\r
}\r
\r
-void Model::updateModel(float deltaT)\r
-{\r
- \r
-}\r
-\r
void Model::box_init(const mat4& _model)\r
{\r
if (vertex == nullptr)\r
virtual void unbindShader(const Shader* shader);\r
\r
/* Draws Model */\r
- virtual void drawModel(const mat4& modelMat, drawType type = dr_Model, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const;\r
+ virtual void drawModel(const mat4& modelMat, drawType type, const vec4& color, uint animation, double time) const;\r
+ void drawModel(const mat4& modelMat) const;\r
//virtual void drawModel(const mat4& modelMat) const;\r
//virtual void drawWire(const mat4& modelMat, const vec4& color) const;\r
//virtual void drawWire(const mat4& modelMat) const;\r
bool loadMesh(const std::string& modelpath, uint mindex = 0);\r
bool loadMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f));\r
\r
- virtual void updateModel(float deltaT);\r
+ double animationduration;\r
\r
class Box\r
{\r
void EventBox::draw(drawTarget _target) const
{
-if (_target == DRAW_Coll)
- collision->drawModel(modelMat, dr_BBox, vec4(.3f,.9f,.9f,1.f));
+ if (_target == DRAW_Coll)
+ collision->drawModel(modelMat, dr_BBox, vec4(.3f,.9f,.9f,1.f), 0, 0);
}
void EventBox::collides(SceneObject* _other, btPersistentManifold* _contactManifold, float _deltaT)
--- /dev/null
+#include "Lever.h"
+
+Lever::Lever(const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath) : SceneObject(_modelMat, _material, _modelpath, texturepath)
+{
+ recipient = nullptr;
+}
+
+Lever::Lever(const mat4& modelMat, const vec4& material, Model* model, string texturepath) : SceneObject(modelMat, material, model, texturepath)
+{
+ recipient = nullptr;
+}
+
+Lever::~Lever()
+{
+
+}
+
+void Lever::setup(SceneObject* object)
+{
+ recipient = object;
+}
+
+void Lever::trigger(bool state)
+{
+ if (turned != state)
+ {
+ turned = state;
+ //TODO add event
+ if (state)
+ {
+ this->startanimation((uint) 0, 1.0f);
+ recipient->startanimation((uint) 0, 1.0f);
+ }
+ else
+ {
+ this->startanimation((uint)0, -1.0f);
+ recipient->startanimation((uint)0, -1.0f);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+#pragma once
+
+#include "../GLM.h"
+
+#include "SceneObject.h"
+
+typedef unsigned int uint;
+
+class Lever : public SceneObject
+{
+public:
+ Lever(const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath);
+ Lever(const mat4& modelMat, const vec4& material, Model* model, string texturepath);
+ ~Lever();
+ void setup(SceneObject* object);
+ void trigger(bool state);
+
+protected:
+ SceneObject* recipient;
+ bool turned;
+};
\ No newline at end of file
if (lookat != nullptr)
timestamps.push(Timestamp(0.0f, _lookat->getModelMat(), lookat->ySpeed));
+ TimeEvent dummy;
+ dummy.time = 0.0f;
+ dummy.object = nullptr;
+ dummy.id = -1;
+ events.push(dummy);
+
bt_collision_configuration = new btDefaultCollisionConfiguration();
bt_dispatcher = new btCollisionDispatcher(bt_collision_configuration);
}
}
+
+ currenttime = max(0.0f, currenttime - deltaT);
+
+
float prev_time = timestamps.top().time;
mat4 prev_mat = timestamps.top().Playermodel;
//unsigned int prev_camera = timestamps.top().CameraX;
- int prev_ySpeed = timestamps.top().ySpeed;
- while (max(0.0f, currenttime - deltaT) < prev_time)
+ float prev_ySpeed = timestamps.top().ySpeed;
+ while (currenttime < prev_time)
{
timestamps.pop();
}
- //TODO revert events
+ while (currenttime < events.top().time)
+ {
+ TimeEvent tmp = events.top();
+ events.pop();
+
+ revertEvent(tmp);
+ }
+
+
//TODO go from keyframe to current time
lookat->setModel(prev_mat);
lookat->ySpeed = prev_ySpeed;
lookat->movable = true;
- //for (auto i = SceneObjects.begin(); i != SceneObjects.end(); ++i)
- //{
- // //(*i)->update(-max(0.0f, currenttime - deltaT));
- //}
-
-
- currenttime = max(0.0f, currenttime - deltaT);
}
camera.updateView(lookat->getPosition()+vec3(0.f,1.f,0.f));
+}
+
+void Scene::addEvent(SceneObject* _object, int _id)
+{
+ TimeEvent newevent;
+ newevent.time = currenttime;
+ newevent.object = _object;
+ newevent.id = _id;
+ events.push(newevent);
+}
+
+void Scene::revertEvent(TimeEvent e)
+{
+ switch (e.id)
+ {
+ case 0:
+ //forward Animation ended
+ e.object->startanimation((uint) 0, -1.0f);
+ e.object->setanimationtime(e.time - currenttime);
+ break;
+
+ case 1:
+ //reverse Animation ended
+ e.object->startanimation((uint) 0, 1.0f);
+ e.object->setanimationtime(e.time - currenttime);
+ break;
+
+ case 2:
+ //Lever triggered
+
+ break;
+ }
}
\ No newline at end of file
class fBufferObject;
//class Camera;
+struct TimeEvent
+{
+ float time;
+ SceneObject* object;
+ int id;
+};
+
class Scene
{
public:
void setView(unsigned int width, unsigned int height, bool updateProjection = true);
+ void addEvent(SceneObject* _object, int _id);
+
protected:
//ViewPort viewPort;
Camera camera;
std::set<const Shader *> ShaderSet;
void drawSceneObjects(drawTarget target = DRAW_Model, bool culling = true) const;
+
+ void revertEvent(TimeEvent e);
float currenttime;
std::stack<Timestamp> timestamps;
+ std::stack<TimeEvent> events;
//std::stack<mat4> PlayerModels;
//std::stack<vec3> PlayerDirections;
collide_group(0),
collide_with(0),
bt_collision_object(new btCollisionObject()),
-move_delta(0)
+move_delta(0),
+AnimationTime(0),
+currentAnimation(0),
+animationSpeed(0),
+loopanimation(true)
{
//Message::info("Error from befor?");
//Graphix::getGlError();
collide_with(0),
bt_collision_object(new btCollisionObject()),
bt_rigid_body(nullptr),
-move_delta(0)
+move_delta(0),
+AnimationTime(0),
+currentAnimation(0),
+animationSpeed(0),
+loopanimation(true)
{
//Message::info("Error from befor?");
//Graphix::getGlError();
}
- model->updateModel(deltaT);
+ updateAnimation(deltaT);
btTransform tmp;
tmp.setFromOpenGLMatrix(value_ptr(modelMat));
case DRAW_Model:
default:
texture->useTexture();
- model->drawModel(modelMat,dr_Model);
+ model->drawModel(modelMat, dr_Model, vec4(0.9f, 0.f, 0.f, 1.f), currentAnimation, AnimationTime);
break;
case DRAW_Wire:
texture->useTexture();
- model->drawModel(modelMat, dr_WireT);
+ model->drawModel(modelMat, dr_WireT, vec4(0.9f, 0.f, 0.f, 1.f), currentAnimation, AnimationTime);
break;
case DRAW_Coll:
if (collision != nullptr)
- collision->drawModel(modelMat, dr_WireC, vec4(0.9f, 0.f, 0.f, 1.f));
+ collision->drawModel(modelMat, dr_WireC, vec4(0.9f, 0.f, 0.f, 1.f), currentAnimation, AnimationTime);
break;
}
/* Draw Object*/
return collide_with;
}
+void SceneObject::startanimation(uint index, float speed)
+{
+ currentAnimation = index;
+ animationSpeed = speed;
+ if (speed >= 0)
+ {
+ AnimationTime = 0;
+ }
+ else
+ {
+ AnimationTime = model->animationduration - 0.01f;
+ }
+}
+
+void SceneObject::setanimationtime(float _time)
+{
+ if (animationSpeed >= 0)
+ {
+ AnimationTime = _time;
+ }
+ else
+ {
+ AnimationTime = model->animationduration - _time;
+ }
+}
+
+void SceneObject::setAnimationLoop(bool loop)
+{
+ loopanimation = loop;
+}
+
+void SceneObject::updateAnimation(float deltaT)
+{
+ if (animationSpeed != 0)
+ {
+ AnimationTime += animationSpeed * deltaT;
+ while (AnimationTime < 0)
+ {
+ if (loopanimation)
+ {
+ AnimationTime = AnimationTime + model->animationduration;
+ }
+ else
+ {
+ AnimationTime = 0;
+ animationSpeed = 0;
+ //TODO add event
+ }
+ }
+ while (AnimationTime >= model->animationduration)
+ {
+ if (loopanimation)
+ {
+ AnimationTime = AnimationTime - model->animationduration;
+ }
+ else
+ {
+ AnimationTime = model->animationduration - 0.01f;
+ animationSpeed = 0;
+ //TODO add event
+ }
+ }
+ }
+}
\ No newline at end of file
#include <btBulletDynamicsCommon.h>
+typedef unsigned int uint;
+
using std::string;
class Scene;
float move_delta;
float yFloorDist;
+ virtual void startanimation(uint index, float speed);
+ virtual void setanimationtime(float time);
+ virtual void setAnimationLoop(bool loop);
bool timeresistant;
bool ignore;
protected:
+ void updateAnimation(float);
+
mat4 modelMat;
btCollisionObject* bt_collision_object;
btRigidBody* bt_rigid_body;
+ double AnimationTime;
+ uint currentAnimation;
+ float animationSpeed;
+ bool loopanimation;
};
<ClCompile Include="Scene\Camera.cpp" />\r
<ClCompile Include="Scene\EventBox.cpp" />\r
<ClCompile Include="Scene\Level.cpp" />\r
+ <ClCompile Include="Scene\Lever.cpp" />\r
<ClCompile Include="Scene\Marvin.cpp" />\r
<ClCompile Include="Scene\Scene.cpp" />\r
<ClCompile Include="Scene\SceneObject.cpp" />\r
<ClInclude Include="Scene\Camera.h" />\r
<ClInclude Include="Scene\EventBox.h" />\r
<ClInclude Include="Scene\Level.h" />\r
+ <ClInclude Include="Scene\Lever.h" />\r
<ClInclude Include="Scene\Marvin.h" />\r
<ClInclude Include="Scene\Scene.h" />\r
<ClInclude Include="Scene\SceneObject.h" />\r
<ClCompile Include="Graphix\Lights\PointLight.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
+ <ClCompile Include="Scene\Lever.cpp">\r
+ <Filter>Source Files</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="Fps.h">\r
<ClInclude Include="Graphix\Lights.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
+ <ClInclude Include="Scene\Lever.h">\r
+ <Filter>Header Files</Filter>\r
+ </ClInclude>\r
</ItemGroup>\r
</Project>
\ No newline at end of file