1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-22 02:39:42 +00:00

Remove raycasting functions from MWWorld::World

This commit is contained in:
Petr Mikheev 2022-11-06 20:49:59 +01:00
parent 7a354d8c78
commit 313df72be0
9 changed files with 23 additions and 50 deletions

View file

@ -333,14 +333,6 @@ namespace MWBase
virtual const MWPhysics::RayCastingInterface* getRayCasting() const = 0;
virtual bool castRay(float x1, float y1, float z1, float x2, float y2, float z2, int mask) = 0;
///< cast a Ray and return true if there is an object in the ray path.
virtual bool castRay(float x1, float y1, float z1, float x2, float y2, float z2) = 0;
virtual bool castRay(const osg::Vec3f& from, const osg::Vec3f& to, int mask, const MWWorld::ConstPtr& ignore)
= 0;
virtual bool castRenderingRay(MWPhysics::RayCastingResult& res, const osg::Vec3f& from, const osg::Vec3f& to,
bool ignorePlayer, bool ignoreActors)
= 0;

View file

@ -10,7 +10,7 @@
#include <components/detournavigator/navigatorutils.hpp>
#include <components/sceneutil/positionattitudetransform.hpp>
#include "../mwphysics/collisiontype.hpp"
#include "../mwphysics/raycasting.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
@ -596,8 +596,8 @@ namespace MWMechanics
osg::Vec3f fallbackDirection = actor.getRefData().getBaseNode()->getAttitude() * osg::Vec3f(0, -1, 0);
osg::Vec3f destination = source + fallbackDirection * (halfExtents.y() + 16);
bool isObstacleDetected = MWBase::Environment::get().getWorld()->castRay(
source.x(), source.y(), source.z(), destination.x(), destination.y(), destination.z(), mask);
const auto* rayCasting = MWBase::Environment::get().getWorld()->getRayCasting();
bool isObstacleDetected = rayCasting->castRay(source, destination, mask).mHit;
if (isObstacleDetected)
return;
@ -606,8 +606,7 @@ namespace MWMechanics
// If we did not hit anything, there is a cliff behind actor.
source = pos + osg::Vec3f(0, 0, 0.75f * halfExtents.z()) + fallbackDirection * (halfExtents.y() + 96);
destination = source - osg::Vec3f(0, 0, 0.75f * halfExtents.z() + 96);
bool isCliffDetected = !MWBase::Environment::get().getWorld()->castRay(
source.x(), source.y(), source.z(), destination.x(), destination.y(), destination.z(), mask);
bool isCliffDetected = !rayCasting->castRay(source, destination, mask).mHit;
if (isCliffDetected)
return;

View file

@ -15,6 +15,8 @@
#include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwphysics/raycasting.hpp"
#include "actorutil.hpp"
#include "creaturestats.hpp"
#include "movement.hpp"
@ -339,8 +341,8 @@ bool MWMechanics::AiPackage::shortcutPath(const osg::Vec3f& startPoint, const os
if (!mShortcutProhibited || (mShortcutFailPos - startPoint).length() >= PATHFIND_SHORTCUT_RETRY_DIST)
{
// check if target is clearly visible
isPathClear = !MWBase::Environment::get().getWorld()->castRay(
startPoint.x(), startPoint.y(), startPoint.z(), endPoint.x(), endPoint.y(), endPoint.z());
isPathClear = !MWBase::Environment::get().getWorld()->getRayCasting()->castRay(
startPoint, endPoint, MWPhysics::CollisionType_World | MWPhysics::CollisionType_Door).mHit;
if (destInLOS != nullptr)
*destInLOS = isPathClear;

View file

@ -18,7 +18,7 @@
#include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwphysics/collisiontype.hpp"
#include "../mwphysics/raycasting.hpp"
#include "actorutil.hpp"
#include "creaturestats.hpp"
@ -81,7 +81,7 @@ namespace MWMechanics
+ direction * std::max(halfExtents.x(), std::max(halfExtents.y(), halfExtents.z()));
const int mask = MWPhysics::CollisionType_World | MWPhysics::CollisionType_HeightMap
| MWPhysics::CollisionType_Door | MWPhysics::CollisionType_Actor;
return MWBase::Environment::get().getWorld()->castRay(position, visibleDestination, mask, actor);
return MWBase::Environment::get().getWorld()->getRayCasting()->castRay(position, visibleDestination, actor, {}, mask).mHit;
}
void stopMovement(const MWWorld::Ptr& actor)

View file

@ -14,7 +14,7 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwphysics/collisiontype.hpp"
#include "../mwphysics/raycasting.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwworld/class.hpp"
@ -252,8 +252,9 @@ namespace MWMechanics
// Add Z offset since path node can overlap with other objects.
// Also ignore doors in raytesting.
const int mask = MWPhysics::CollisionType_World;
bool isPathClear = !MWBase::Environment::get().getWorld()->castRay(
startPoint.x(), startPoint.y(), startPoint.z() + 16, temp.mX, temp.mY, temp.mZ + 16, mask);
bool isPathClear = !MWBase::Environment::get().getWorld()->getRayCasting()->castRay(
osg::Vec3f(startPoint.x(), startPoint.y(), startPoint.z() + 16),
osg::Vec3f(temp.mX, temp.mY, temp.mZ + 16), mask).mHit;
if (isPathClear)
path.pop_front();
}

View file

@ -222,6 +222,7 @@ namespace MWPhysics
const MWWorld::ConstPtr& ignore = MWWorld::ConstPtr(),
const std::vector<MWWorld::Ptr>& targets = std::vector<MWWorld::Ptr>(), int mask = CollisionType_Default,
int group = 0xff) const override;
using RayCastingInterface::castRay;
RayCastingResult castSphere(const osg::Vec3f& from, const osg::Vec3f& to, float radius,
int mask = CollisionType_Default, int group = 0xff) const override;

View file

@ -34,6 +34,11 @@ namespace MWPhysics
const std::vector<MWWorld::Ptr>& targets = std::vector<MWWorld::Ptr>(), int mask = CollisionType_Default,
int group = 0xff) const = 0;
RayCastingResult castRay(const osg::Vec3f& from, const osg::Vec3f& to, int mask) const
{
return castRay(from, to, MWWorld::ConstPtr(), std::vector<MWWorld::Ptr>(), mask);
}
virtual RayCastingResult castSphere(const osg::Vec3f& from, const osg::Vec3f& to, float radius,
int mask = CollisionType_Default, int group = 0xff) const = 0;

View file

@ -1412,7 +1412,7 @@ namespace MWWorld
targetPos = pos + (orientation * osg::Vec3f(1, 0, 0)) * distance;
// destination is free
if (!castRay(pos.x(), pos.y(), pos.z(), targetPos.x(), targetPos.y(), targetPos.z()))
if (!mPhysics->castRay(pos, targetPos, MWPhysics::CollisionType_World | MWPhysics::CollisionType_Door).mHit)
break;
}
@ -1479,7 +1479,8 @@ namespace MWWorld
// check if spawn point is safe, fall back to another direction if not
spawnPoint.z() += 30; // move up a little to account for slopes, will snap down later
if (!castRay(spawnPoint.x(), spawnPoint.y(), spawnPoint.z(), pos.x(), pos.y(), pos.z() + 20))
if (!mPhysics->castRay(spawnPoint, osg::Vec3f(pos.x(), pos.y(), pos.z() + 20),
MWPhysics::CollisionType_World | MWPhysics::CollisionType_Door).mHit)
{
// safe
break;
@ -1568,27 +1569,6 @@ namespace MWWorld
return mPhysics.get();
}
bool World::castRay(float x1, float y1, float z1, float x2, float y2, float z2)
{
int mask = MWPhysics::CollisionType_World | MWPhysics::CollisionType_Door;
bool result = castRay(x1, y1, z1, x2, y2, z2, mask);
return result;
}
bool World::castRay(float x1, float y1, float z1, float x2, float y2, float z2, int mask)
{
osg::Vec3f a(x1, y1, z1);
osg::Vec3f b(x2, y2, z2);
MWPhysics::RayCastingResult result = mPhysics->castRay(a, b, MWWorld::Ptr(), std::vector<MWWorld::Ptr>(), mask);
return result.mHit;
}
bool World::castRay(const osg::Vec3f& from, const osg::Vec3f& to, int mask, const MWWorld::ConstPtr& ignore)
{
return mPhysics->castRay(from, to, ignore, std::vector<MWWorld::Ptr>(), mask).mHit;
}
bool World::rotateDoor(const Ptr door, MWWorld::DoorState state, float duration)
{
const ESM::Position& objPos = door.getRefData().getPosition();

View file

@ -421,13 +421,6 @@ namespace MWWorld
const MWPhysics::RayCastingInterface* getRayCasting() const override;
bool castRay(float x1, float y1, float z1, float x2, float y2, float z2, int mask) override;
///< cast a Ray and return true if there is an object in the ray path.
bool castRay(float x1, float y1, float z1, float x2, float y2, float z2) override;
bool castRay(const osg::Vec3f& from, const osg::Vec3f& to, int mask, const MWWorld::ConstPtr& ignore) override;
bool castRenderingRay(MWPhysics::RayCastingResult& res, const osg::Vec3f& from, const osg::Vec3f& to,
bool ignorePlayer, bool ignoreActors) override;