From f5d03a16c1dede5e7ddc3a4f2af38917740d66b4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 23 Aug 2013 07:01:30 -0700 Subject: [PATCH] Rename getFacedObject and getFacedHandle for melee hits --- apps/openmw/mwbase/world.hpp | 7 ++++--- apps/openmw/mwclass/npc.cpp | 3 ++- apps/openmw/mwworld/physicssystem.cpp | 5 ++++- apps/openmw/mwworld/physicssystem.hpp | 7 ++++--- apps/openmw/mwworld/worldimp.cpp | 9 +++++---- apps/openmw/mwworld/worldimp.hpp | 7 ++++--- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index aa5a38e6d6..6ca900a4d3 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -220,9 +220,10 @@ namespace MWBase virtual MWWorld::Ptr getFacedObject() = 0; ///< Return pointer to the object the player is looking at, if it is within activation range - /// Returns a pointer to the object the provided object is facing (if within the - /// specified distance). This will attempt to use the "Bip01 Head" node as a basis. - virtual MWWorld::Ptr getFacedObject(const MWWorld::Ptr &ptr, float distance) = 0; + /// Returns a pointer to the object the provided object would hit (if within the + /// specified distance), and the point where the hit occurs. This will attempt to + /// use the "Head" node as a basis. + virtual std::pair getHitContact(const MWWorld::Ptr &ptr, float distance) = 0; virtual void adjustPosition (const MWWorld::Ptr& ptr) = 0; ///< Adjust position after load to be on ground. Must be called after model load. diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index d9c1da77bf..073d1b1b92 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -332,7 +332,8 @@ namespace MWClass float dist = 100.0f * (!weapon.isEmpty() ? weapon.get()->mBase->mData.mReach : gmst.find("fHandToHandReach")->getFloat()); - MWWorld::Ptr victim = world->getFacedObject(ptr, dist); + // TODO: Use second to work out the hit angle and where to spawn the blood effect + MWWorld::Ptr victim = world->getHitContact(ptr, dist).first; if(victim.isEmpty()) // Didn't hit anything return; diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 33ba7101eb..9fa8db782a 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -311,7 +311,10 @@ namespace MWWorld return results; } - std::pair PhysicsSystem::getFacedHandle(const Ogre::Vector3 &origin_, const Ogre::Quaternion &orient_, float queryDistance) + std::pair PhysicsSystem::getHitContact(const std::string &name, + const Ogre::Vector3 &origin_, + const Ogre::Quaternion &orient_, + float queryDistance) { btVector3 origin(origin_.x, origin_.y, origin_.z); diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 669eb74bd6..f76b4d29c7 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -57,9 +57,10 @@ namespace MWWorld Ogre::Vector3 traceDown(const MWWorld::Ptr &ptr); std::pair getFacedHandle (MWWorld::World& world, float queryDistance); - std::pair getFacedHandle(const Ogre::Vector3 &origin, - const Ogre::Quaternion &orientation, - float queryDistance); + std::pair getHitContact(const std::string &name, + const Ogre::Vector3 &origin, + const Ogre::Quaternion &orientation, + float queryDistance); std::vector < std::pair > getFacedHandles (float queryDistance); std::vector < std::pair > getFacedHandles (float mouseX, float mouseY, float queryDistance); diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 950f005659..eee9c7a199 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -784,7 +784,7 @@ namespace MWWorld return object; } - MWWorld::Ptr World::getFacedObject(const MWWorld::Ptr &ptr, float distance) + std::pair World::getHitContact(const MWWorld::Ptr &ptr, float distance) { const ESM::Position &posdata = ptr.getRefData().getPosition(); Ogre::Vector3 pos(posdata.pos); @@ -799,11 +799,12 @@ namespace MWWorld pos += node->_getDerivedPosition(); } - std::pair result = mPhysics->getFacedHandle(pos, rot, distance); + std::pair result = mPhysics->getHitContact(ptr.getRefData().getHandle(), + pos, rot, distance); if(result.first.empty()) - return MWWorld::Ptr(); + return std::make_pair(MWWorld::Ptr(), Ogre::Vector3(0.0f)); - return searchPtrViaHandle(result.first); + return std::make_pair(searchPtrViaHandle(result.first), result.second); } void World::deleteObject (const Ptr& ptr) diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index b8a9a4e829..71391239b3 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -252,9 +252,10 @@ namespace MWWorld virtual MWWorld::Ptr getFacedObject(); ///< Return pointer to the object the player is looking at, if it is within activation range - /// Returns a pointer to the object the provided object is facing (if within the - /// specified distance). This will attempt to use the "Bip01 Head" node as a basis. - virtual MWWorld::Ptr getFacedObject(const MWWorld::Ptr &ptr, float distance); + /// Returns a pointer to the object the provided object would hit (if within the + /// specified distance), and the point where the hit occurs. This will attempt to + /// use the "Head" node as a basis. + virtual std::pair getHitContact(const MWWorld::Ptr &ptr, float distance); virtual void deleteObject (const Ptr& ptr);