// load LVL
- SceneObject* tmp_world = new SceneObject(shader1, mat4(1.f), vec4(4.0f, 1.0f, 1.0f, 2.0f), "level_test.dae", "model_levelTest_2D.jpg");
+ SceneObject* tmp_world = new Level(shader1, "level_test.dae", "model_levelTest_2D.jpg");
- tmp_world->ignore = true;
+ //tmp_world->ignore = true;
current_world->addObject(tmp_world);
- float test = tmp_world->getModel()->getPDistHit(vec3(3.f, 3.f, 4.f), vec3(0.f, -1.f, 0.f));
-
// current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, 1.f, 0.f)), vec4(1.0f, 1.0f, 1.0f, 3.0f), new BBox(), ""));
//Player
#include "Scene/EventBox.h"
#include "Scene/Marvin.h"
#include "Scene/Sky.h"
+#include "Scene/Level.h"
--- /dev/null
+#include "Level.h"
+
+#include "../Graphix/Shader.h"
+#include "../Graphix/Model.h"
+
+#include "../Message.h"
+#include "../GLM.h"
+
+
+Level::Level(Shader* _shader, std::string _modelpath, std::string _texturepath) : SceneObject(_shader, mat4(1.f), vec4(1.f), _modelpath, _texturepath)
+{
+ collide_group = COL_LEVEL;
+ collide_with = COL_MARVIN | COL_ENEMY;
+}
+
+
+Level::~Level()
+{
+}
+
+void Level::collides(SceneObject* _other, btPersistentManifold* _contactManifold)
+{
+ int numContacts = _contactManifold->getNumContacts();
+ //For each contact point in that manifold
+ //double pdist = _contactManifold->getContactPoint(0).getDistance();
+ for (int j = 0; j < numContacts; j++) {
+ //Get the contact information
+ btManifoldPoint& pt = _contactManifold->getContactPoint(j);
+ btVector3 ptN = pt.m_normalWorldOnB;
+ _other->yFloorDist = (double)pt.getDistance() * abs(dot(vec3(0.f, 1.f, 0.f), vec3(ptN.getX(), ptN.getY(), ptN.getZ())));
+ //btVector3 ptA = pt.getPositionWorldOnA();
+ //pdist = min((double)pt.getDistance(), pdist);
+ }
+
+ if (_other->yFloorDist <= 0 && _other->ySpeed<0)
+ _other->ySpeed = 0;
+
+ Message::info((std::string)"Kollision! " + std::to_string(_other->yFloorDist) + " (LVL with " + (std::string)*_other->getModel() + ")");
+
+}
\ No newline at end of file
--- /dev/null
+#pragma once
+#include "SceneObject.h"
+
+#include "../GLM.h"
+
+class Shader;
+
+class Level :
+ public SceneObject
+{
+public:
+ Level(Shader* shader,std::string modelpath, std::string texturepath);
+ ~Level();
+
+ virtual void collides(SceneObject* other, btPersistentManifold* contactManifold) override;
+};
+
viewPort.rotateView(rotatex, rotatey);
//Jump
- if (Events::getJump() && floorBound())
+ if (Events::getJump() && yFloorDist<=0)
ySpeed += 5.5;
int move_x = Events::getMoveX();
void Scene::update(float deltaT)
{
- // XYAchse um den Player
-
if (!Events::getTimeShift())
{
- //int shoot = Events::getAction1();
- //int reset = Events::getAction2();
-
- //Jump
- //if (Events::getJump() && lookat->floorBound())
- // lookat->ySpeed += 5.5;
- //else if (!Events::isKHeld(SDLK_SPACE) && lookat->ySpeed>0)
- // lookat->ySpeed = 0;
-
-
-
if (ceil((currenttime + deltaT) / timestep) > ceil(currenttime / timestep))
{
}
currenttime += deltaT;
-
- //// Zoom auf Player
- //if (Events::getViewZ())
- //{
- //// float dist = 0;
- //// if (lookat!=NULL)
- //// dist = VektorAbs(getViewerPos() - lookat->getPosition());
- //// if (true)
- // view = translate( vec3(0.f,0.f,(float)(5*deltaT *sign(Events::getViewZ()))))*view;
- // //view = view*scale(vec3((float)(1 + deltaT * sign(Events::getViewZ()))));
- //}
-
// Alle Objekte der Scene aktualisieren
for (auto i = SceneObjects.begin(); i != SceneObjects.end(); ++i)
{
bt_collision_world->performDiscreteCollisionDetection();
-
int numManifolds = bt_collision_world->getDispatcher()->getNumManifolds();
//For each contact manifold
for (int i = 0; i < numManifolds; i++) {
currenttime = max(0.0f, currenttime - deltaT);
}
-
}
texture(nullptr),
ySpeed(0),
yStatic(true),
+yFloorDist(INFINITY),
ignore(false),
newModel(true),
collide_group(0),
if (texturepath == "model_duck_2D.png")
{
collide_group = COL_ENEMY;
- collide_with = COL_MARVIN | COL_LEVEL;
+ collide_with = COL_MARVIN;// | COL_LEVEL;
}
//Message::info("Creating SkyBox Shader");
//Graphix::getGlError();
texture(nullptr),
ySpeed(0),
yStatic(true),
+yFloorDist(INFINITY),
ignore(false),
newModel(false),
collide_group(0),
}
-float SceneObject::getFloor() const
-{
- return 0;
-}
void SceneObject::update(float deltaT)
{
//Fallen
if (!yStatic)
{
- vec3 pos = getPosition();
- if (!floorBound() || ySpeed!=0)
+ if (yFloorDist>0 || ySpeed!=0)
{
- if (pos.y + ySpeed*deltaT > getFloor())
+ if (ySpeed*deltaT < yFloorDist || ySpeed>0)
modelMat = translate(vec3(0.f, ySpeed*deltaT, 0.f))*modelMat;
else
{
- modelMat = translate(vec3(0.f, getFloor() - pos.y, 0.f))*modelMat;
+ modelMat = translate(vec3(0.f, yFloorDist, 0.f))*modelMat;
ySpeed = 0; //set to FloorSpeed?
}
ySpeed -= deltaT*YFALL_SPEED;
}
- //modelMat = scale(modelMat, vec3(matter));
- //modelMat = (deltaT * spin) * modelMat; //TODO drehen scheint nicht zu funktionieren
-
btTransform tmp;
tmp.setFromOpenGLMatrix(value_ptr(modelMat));
bt_collision_object->setWorldTransform(tmp);
+ yFloorDist = INFINITY;
}
void SceneObject::draw() const
}
-bool SceneObject::floorBound() const
-{
- vec3 pos = getPosition();
- return (pos.y <= getFloor());
-}
vec3 SceneObject::getPosition() const
{
virtual void update(float);
virtual void draw() const;
- virtual void collides(SceneObject* other, btPersistentManifold* contactManifold = nullptr);
+ virtual void collides(SceneObject* other, btPersistentManifold* contactManifold);
virtual vec3 getPosition() const;
__declspec(deprecated)
bool isEnemy();
- //Floor
- bool floorBound() const;
- float getFloor() const;
-
-
operator btCollisionObject*() const;
short getCollideGroup() const;
short getCollideWith() const;
//Falling
bool yStatic;
float ySpeed;
+ float yFloorDist;
bool ignore;
Sky::~Sky()
{
}
+
+void Sky::update(float deltaT)
+{
+}
\ No newline at end of file
public:
Sky();
~Sky();
+
+ virtual void update(float) override;
};
<ClCompile Include="Graphix\Model\SkyBox.cpp" />
<ClCompile Include="Overlap.cpp" />
<ClCompile Include="Scene\EventBox.cpp" />
+ <ClCompile Include="Scene\Level.cpp" />
<ClCompile Include="Scene\Marvin.cpp" />
<ClCompile Include="Scene\Scene.cpp" />
<ClCompile Include="Scene\SceneObject.cpp" />
<ClInclude Include="Overlap.h" />
<ClInclude Include="Scene.h" />
<ClInclude Include="Scene\EventBox.h" />
+ <ClInclude Include="Scene\Level.h" />
<ClInclude Include="Scene\Marvin.h" />
<ClInclude Include="Scene\Scene.h" />
<ClInclude Include="Scene\SceneObject.h" />
<ClCompile Include="Scene\Timestamp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="Scene\Level.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Fps.h">
<ClInclude Include="Scene\Timestamp.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="Scene\Level.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file