forked from teamnwah/openmw-tes3coop
dropping on the ground
This commit is contained in:
parent
49b1d5e127
commit
cd04911f3c
3 changed files with 31 additions and 1 deletions
|
@ -122,6 +122,22 @@ namespace MWWorld
|
|||
return !(result.first == "");
|
||||
}
|
||||
|
||||
std::pair<bool, Ogre::Vector3>
|
||||
PhysicsSystem::castRay(const Ogre::Vector3 &orig, const Ogre::Vector3 &dir, float len)
|
||||
{
|
||||
Ogre::Ray ray = Ogre::Ray(orig, dir);
|
||||
Ogre::Vector3 to = ray.getPoint(len);
|
||||
|
||||
btVector3 btFrom = btVector3(orig.x, orig.y, orig.z);
|
||||
btVector3 btTo = btVector3(to.x, to.y, to.z);
|
||||
|
||||
std::pair<std::string, float> test = mEngine->rayTest(btFrom, btTo);
|
||||
if (test.first == "") {
|
||||
return std::make_pair(false, Ogre::Vector3());
|
||||
}
|
||||
return std::make_pair(true, ray.getPoint(len * test.second));
|
||||
}
|
||||
|
||||
std::pair<bool, Ogre::Vector3> PhysicsSystem::castRay(float mouseX, float mouseY)
|
||||
{
|
||||
Ogre::Ray ray = mRender.getCamera()->getCameraToViewportRay(
|
||||
|
|
|
@ -54,6 +54,9 @@ namespace MWWorld
|
|||
// cast ray, return true if it hit something
|
||||
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to);
|
||||
|
||||
std::pair<bool, Ogre::Vector3>
|
||||
castRay(const Ogre::Vector3 &orig, const Ogre::Vector3 &dir, float len);
|
||||
|
||||
std::pair<bool, Ogre::Vector3> castRay(float mouseX, float mouseY);
|
||||
///< cast ray from the mouse, return true if it hit something and the first result (in OGRE coordinates)
|
||||
|
||||
|
|
|
@ -1057,9 +1057,20 @@ namespace MWWorld
|
|||
{
|
||||
MWWorld::Ptr::CellStore* cell = getPlayer().getPlayer().getCell();
|
||||
|
||||
ESM::Position &pos =
|
||||
ESM::Position pos =
|
||||
getPlayer().getPlayer().getRefData().getPosition();
|
||||
|
||||
Ogre::Vector3 orig =
|
||||
Ogre::Vector3(pos.pos[0], pos.pos[1], pos.pos[2]);
|
||||
Ogre::Vector3 dir = Ogre::Vector3(0, 0, -1);
|
||||
|
||||
float len = (pos.pos[2] >= 0) ? pos.pos[2] : -pos.pos[2];
|
||||
len += 100.0;
|
||||
|
||||
std::pair<bool, Ogre::Vector3> hit =
|
||||
mPhysics->castRay(orig, dir, len);
|
||||
pos.pos[2] = hit.second.z;
|
||||
|
||||
/// \todo fix item dropping at player object center position
|
||||
placeObject(object, *cell, pos);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue