1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 18:35:20 +00:00

using real player sight angles on ray cast

This commit is contained in:
greye 2012-08-17 15:07:12 +04:00
parent 0e6e141fd4
commit 4f10138a04

View File

@ -16,8 +16,6 @@
#include "ptr.hpp" #include "ptr.hpp"
#include "class.hpp" #include "class.hpp"
#include <stdio.h>
using namespace Ogre; using namespace Ogre;
namespace MWWorld namespace MWWorld
{ {
@ -46,28 +44,36 @@ namespace MWWorld
std::pair<std::string, float> PhysicsSystem::getFacedHandle (MWWorld::World& world) std::pair<std::string, float> PhysicsSystem::getFacedHandle (MWWorld::World& world)
{ {
//get a ray pointing to the center of the viewport btVector3 dir(0, 1, 0);
Ray centerRay = mRender.getCamera()->getCameraToViewportRay( dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
mRender.getViewport()->getWidth()/2, dir = dir.rotate(btVector3(0, 0, 1), mPlayerData.yaw);
mRender.getViewport()->getHeight()/2); dir.setX(-dir.x());
//let's avoid the capsule shape of the player.
centerRay.setOrigin(centerRay.getOrigin() + 20*centerRay.getDirection());
btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y);
btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y);
return mEngine->rayTest(from,to); btVector3 origin(
mPlayerData.eyepos.x,
mPlayerData.eyepos.y,
mPlayerData.eyepos.z);
origin += dir * 5;
btVector3 dest = origin + dir * 500;
return mEngine->rayTest(origin, dest);
} }
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects () std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects ()
{ {
//get a ray pointing to the center of the viewport btVector3 dir(0, 1, 0);
Ray centerRay = mRender.getCamera()->getCameraToViewportRay( dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
mRender.getViewport()->getWidth()/2, dir = dir.rotate(btVector3(0, 0, 1), mPlayerData.yaw);
mRender.getViewport()->getHeight()/2); dir.setX(-dir.x());
btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y);
btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y);
return mEngine->rayTest2(from,to); btVector3 origin(
mPlayerData.eyepos.x,
mPlayerData.eyepos.y,
mPlayerData.eyepos.z);
origin += dir * 5;
btVector3 dest = origin + dir * 500;
return mEngine->rayTest2(origin, dest);
} }
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects (float mouseX, float mouseY) std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects (float mouseX, float mouseY)