From: Peter Schaefer Date: Sun, 14 Jun 2015 08:41:32 +0000 (+0200) Subject: Falling and walking against the lvl works X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=2637d19c53d31f75883c90a890bd9fe6b975d303;p=cgue_weave.git Falling and walking against the lvl works still wrong CollideMeshes --- diff --git a/Weave/Scene/Level.cpp b/Weave/Scene/Level.cpp index 18566cc..03f67a2 100644 --- a/Weave/Scene/Level.cpp +++ b/Weave/Scene/Level.cpp @@ -22,19 +22,30 @@ 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++) { + float 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); + btVector3 ptA = pt.getPositionWorldOnA(); + btVector3 ptB = pt.getPositionWorldOnB(); + vec3 ptAg(ptA.getX(), ptA.getY(), ptA.getZ()); + vec3 ptBg(ptB.getX(), ptB.getY(), ptB.getZ()); + vec3 normal = normalize(ptAg - ptBg); + pdist = pt.getDistance(); + + //btVector3 ptN = pt.m_normalWorldOnB; + //vec3 normal = vec3(ptN.getX(), ptN.getY(), ptN.getZ()); + _other->yFloorDist = pdist * normal[1]; + + if (normal[1] <= .6f && pdist<0) + _other->move(-pdist * vec3(normal[0], 0.f, normal[2])); + } 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() + ")"); + //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/SceneObject.cpp b/Weave/Scene/SceneObject.cpp index 9659837..3ff9454 100644 --- a/Weave/Scene/SceneObject.cpp +++ b/Weave/Scene/SceneObject.cpp @@ -179,8 +179,8 @@ void SceneObject::collides(SceneObject* _other, btPersistentManifold* _contactMa pdist = min((double)pt.getDistance(),pdist); } - if (!ignore && !_other->ignore && pdist <= 0) - Message::info((std::string)"Kollision! " + std::to_string(pdist) + " (" + (std::string)*model + " with " + (std::string)*_other->getModel() + ")"); +// if (!ignore && !_other->ignore && pdist <= 0) +// Message::info((std::string)"Kollision! " + std::to_string(pdist) + " (" + (std::string)*model + " with " + (std::string)*_other->getModel() + ")"); }