From: Peter Schaefer Date: Fri, 12 Jun 2015 13:31:47 +0000 (+0200) Subject: jump and fall works X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=02c86f28164a4889081eb41eaead8bde749df9fe;p=cgue_weave.git jump and fall works wrong collision Meshes! --- diff --git a/Weave/Game.cpp b/Weave/Game.cpp index e3c18e5..320b83f 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -48,13 +48,11 @@ Game::Game() : playing(true) // 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 diff --git a/Weave/Scene.h b/Weave/Scene.h index 5405d0b..21acdb1 100644 --- a/Weave/Scene.h +++ b/Weave/Scene.h @@ -5,4 +5,5 @@ #include "Scene/EventBox.h" #include "Scene/Marvin.h" #include "Scene/Sky.h" +#include "Scene/Level.h" diff --git a/Weave/Scene/Level.cpp b/Weave/Scene/Level.cpp new file mode 100644 index 0000000..18566cc --- /dev/null +++ b/Weave/Scene/Level.cpp @@ -0,0 +1,40 @@ +#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 diff --git a/Weave/Scene/Level.h b/Weave/Scene/Level.h new file mode 100644 index 0000000..8caae54 --- /dev/null +++ b/Weave/Scene/Level.h @@ -0,0 +1,17 @@ +#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; +}; + diff --git a/Weave/Scene/Marvin.cpp b/Weave/Scene/Marvin.cpp index 1fe40a5..fe38a2a 100644 --- a/Weave/Scene/Marvin.cpp +++ b/Weave/Scene/Marvin.cpp @@ -36,7 +36,7 @@ void Marvin::update(float deltaT) viewPort.rotateView(rotatex, rotatey); //Jump - if (Events::getJump() && floorBound()) + if (Events::getJump() && yFloorDist<=0) ySpeed += 5.5; int move_x = Events::getMoveX(); diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index 0736c42..283cfbf 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -77,24 +77,11 @@ Scene::~Scene() 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)) { @@ -102,18 +89,6 @@ void Scene::update(float deltaT) } 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) { @@ -122,7 +97,6 @@ void Scene::update(float deltaT) bt_collision_world->performDiscreteCollisionDetection(); - int numManifolds = bt_collision_world->getDispatcher()->getNumManifolds(); //For each contact manifold for (int i = 0; i < numManifolds; i++) { @@ -172,7 +146,6 @@ void Scene::update(float deltaT) currenttime = max(0.0f, currenttime - deltaT); } - } diff --git a/Weave/Scene/SceneObject.cpp b/Weave/Scene/SceneObject.cpp index e76ec52..9659837 100644 --- a/Weave/Scene/SceneObject.cpp +++ b/Weave/Scene/SceneObject.cpp @@ -30,6 +30,7 @@ collision_ignore(false), texture(nullptr), ySpeed(0), yStatic(true), +yFloorDist(INFINITY), ignore(false), newModel(true), collide_group(0), @@ -55,7 +56,7 @@ bt_collision_object(new btCollisionObject()) 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(); @@ -78,6 +79,7 @@ collision_ignore(false), texture(nullptr), ySpeed(0), yStatic(true), +yFloorDist(INFINITY), ignore(false), newModel(false), collide_group(0), @@ -119,10 +121,6 @@ SceneObject::~SceneObject() } -float SceneObject::getFloor() const -{ - return 0; -} void SceneObject::update(float deltaT) { @@ -130,14 +128,13 @@ 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; @@ -146,12 +143,10 @@ void SceneObject::update(float deltaT) } - //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 @@ -189,11 +184,6 @@ void SceneObject::collides(SceneObject* _other, btPersistentManifold* _contactMa } -bool SceneObject::floorBound() const -{ - vec3 pos = getPosition(); - return (pos.y <= getFloor()); -} vec3 SceneObject::getPosition() const { diff --git a/Weave/Scene/SceneObject.h b/Weave/Scene/SceneObject.h index f49c4e6..8642b1a 100644 --- a/Weave/Scene/SceneObject.h +++ b/Weave/Scene/SceneObject.h @@ -36,7 +36,7 @@ public: 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; @@ -66,11 +66,6 @@ public: __declspec(deprecated) bool isEnemy(); - //Floor - bool floorBound() const; - float getFloor() const; - - operator btCollisionObject*() const; short getCollideGroup() const; short getCollideWith() const; @@ -78,6 +73,7 @@ public: //Falling bool yStatic; float ySpeed; + float yFloorDist; bool ignore; diff --git a/Weave/Scene/Sky.cpp b/Weave/Scene/Sky.cpp index 0dec929..604aa67 100644 --- a/Weave/Scene/Sky.cpp +++ b/Weave/Scene/Sky.cpp @@ -16,3 +16,7 @@ Sky::Sky() : SceneObject(new Shader("skybox_VS.hlsl","basicTexture_FS.hlsl"), sc Sky::~Sky() { } + +void Sky::update(float deltaT) +{ +} \ No newline at end of file diff --git a/Weave/Scene/Sky.h b/Weave/Scene/Sky.h index 7b108ed..0fcddd2 100644 --- a/Weave/Scene/Sky.h +++ b/Weave/Scene/Sky.h @@ -11,5 +11,7 @@ class Sky : public: Sky(); ~Sky(); + + virtual void update(float) override; }; diff --git a/Weave/Weave.vcxproj b/Weave/Weave.vcxproj index 2f7d3c8..398fcde 100644 --- a/Weave/Weave.vcxproj +++ b/Weave/Weave.vcxproj @@ -104,6 +104,7 @@ + @@ -131,6 +132,7 @@ + diff --git a/Weave/Weave.vcxproj.filters b/Weave/Weave.vcxproj.filters index bf01bec..b91c173 100644 --- a/Weave/Weave.vcxproj.filters +++ b/Weave/Weave.vcxproj.filters @@ -81,6 +81,9 @@ Source Files + + Source Files + @@ -155,5 +158,8 @@ Header Files + + Header Files + \ No newline at end of file