mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-07 21:40:11 +00:00
Merge branch 'forlua' into 'master'
Simple Physics API modification for Lua See merge request OpenMW/openmw!1216 (cherry picked from commit d88494c90b501d0832ae0330a0ca81d8b8e5aa50) 02dd055a Save hitObject in castSphere() just like in castRay() 0793d0bf Allow to override collision mask and group for castSphere() as for castRay()
This commit is contained in:
parent
9fabf99250
commit
e760a6c7e6
@ -10,7 +10,8 @@ enum CollisionType {
|
||||
CollisionType_Actor = 1<<2,
|
||||
CollisionType_HeightMap = 1<<3,
|
||||
CollisionType_Projectile = 1<<4,
|
||||
CollisionType_Water = 1<<5
|
||||
CollisionType_Water = 1<<5,
|
||||
CollisionType_Default = CollisionType_World|CollisionType_HeightMap|CollisionType_Actor|CollisionType_Door
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -348,11 +348,11 @@ namespace MWPhysics
|
||||
return result;
|
||||
}
|
||||
|
||||
RayCastingResult PhysicsSystem::castSphere(const osg::Vec3f &from, const osg::Vec3f &to, float radius) const
|
||||
RayCastingResult PhysicsSystem::castSphere(const osg::Vec3f &from, const osg::Vec3f &to, float radius, int mask, int group) const
|
||||
{
|
||||
btCollisionWorld::ClosestConvexResultCallback callback(Misc::Convert::toBullet(from), Misc::Convert::toBullet(to));
|
||||
callback.m_collisionFilterGroup = 0xff;
|
||||
callback.m_collisionFilterMask = CollisionType_World|CollisionType_HeightMap|CollisionType_Door;
|
||||
callback.m_collisionFilterGroup = group;
|
||||
callback.m_collisionFilterMask = mask;
|
||||
|
||||
btSphereShape shape(radius);
|
||||
const btQuaternion btrot = btQuaternion::getIdentity();
|
||||
@ -368,6 +368,8 @@ namespace MWPhysics
|
||||
{
|
||||
result.mHitPos = Misc::Convert::toOsg(callback.m_hitPointWorld);
|
||||
result.mHitNormal = Misc::Convert::toOsg(callback.m_hitNormalWorld);
|
||||
if (auto* ptrHolder = static_cast<PtrHolder*>(callback.m_hitCollisionObject->getUserPointer()))
|
||||
result.mHitObject = ptrHolder->getPtr();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -186,9 +186,10 @@ namespace MWPhysics
|
||||
/// @param me Optional, a Ptr to ignore in the list of results. targets are actors to filter for, ignoring all other actors.
|
||||
RayCastingResult castRay(const osg::Vec3f &from, const osg::Vec3f &to, const MWWorld::ConstPtr& ignore = MWWorld::ConstPtr(),
|
||||
const std::vector<MWWorld::Ptr>& targets = std::vector<MWWorld::Ptr>(),
|
||||
int mask = CollisionType_World|CollisionType_HeightMap|CollisionType_Actor|CollisionType_Door, int group=0xff) const override;
|
||||
int mask = CollisionType_Default, int group=0xff) const override;
|
||||
|
||||
RayCastingResult castSphere(const osg::Vec3f& from, const osg::Vec3f& to, float radius) const override;
|
||||
RayCastingResult castSphere(const osg::Vec3f& from, const osg::Vec3f& to, float radius,
|
||||
int mask = CollisionType_Default, int group=0xff) const override;
|
||||
|
||||
/// Return true if actor1 can see actor2.
|
||||
bool getLineOfSight(const MWWorld::ConstPtr& actor1, const MWWorld::ConstPtr& actor2) const override;
|
||||
|
@ -29,9 +29,10 @@ namespace MWPhysics
|
||||
/// @param me Optional, a Ptr to ignore in the list of results. targets are actors to filter for, ignoring all other actors.
|
||||
virtual RayCastingResult castRay(const osg::Vec3f &from, const osg::Vec3f &to, const MWWorld::ConstPtr& ignore = MWWorld::ConstPtr(),
|
||||
const std::vector<MWWorld::Ptr>& targets = std::vector<MWWorld::Ptr>(),
|
||||
int mask = CollisionType_World|CollisionType_HeightMap|CollisionType_Actor|CollisionType_Door, int group=0xff) const = 0;
|
||||
int mask = CollisionType_Default, int group=0xff) const = 0;
|
||||
|
||||
virtual RayCastingResult castSphere(const osg::Vec3f& from, const osg::Vec3f& to, float radius) const = 0;
|
||||
virtual RayCastingResult castSphere(const osg::Vec3f& from, const osg::Vec3f& to, float radius,
|
||||
int mask = CollisionType_Default, int group=0xff) const = 0;
|
||||
|
||||
/// Return true if actor1 can see actor2.
|
||||
virtual bool getLineOfSight(const MWWorld::ConstPtr& actor1, const MWWorld::ConstPtr& actor2) const = 0;
|
||||
|
@ -251,6 +251,7 @@ namespace MWRender
|
||||
|
||||
const float cameraObstacleLimit = 5.0f;
|
||||
const float focalObstacleLimit = 10.f;
|
||||
const int collisionType = (MWPhysics::CollisionType::CollisionType_Default & ~MWPhysics::CollisionType::CollisionType_Actor);
|
||||
|
||||
const auto* rayCasting = MWBase::Environment::get().getWorld()->getRayCasting();
|
||||
|
||||
@ -260,7 +261,7 @@ namespace MWRender
|
||||
float offsetLen = focalOffset.length();
|
||||
if (offsetLen > 0)
|
||||
{
|
||||
MWPhysics::RayCastingResult result = rayCasting->castSphere(focal - focalOffset, focal, focalObstacleLimit);
|
||||
MWPhysics::RayCastingResult result = rayCasting->castSphere(focal - focalOffset, focal, focalObstacleLimit, collisionType);
|
||||
if (result.mHit)
|
||||
{
|
||||
double adjustmentCoef = -(result.mHitPos + result.mHitNormal * focalObstacleLimit - focal).length() / offsetLen;
|
||||
@ -274,7 +275,7 @@ namespace MWRender
|
||||
mCameraDistance = std::min(mCameraDistance, mMaxNextCameraDistance);
|
||||
osg::Vec3d cameraPos;
|
||||
getPosition(focal, cameraPos);
|
||||
MWPhysics::RayCastingResult result = rayCasting->castSphere(focal, cameraPos, cameraObstacleLimit);
|
||||
MWPhysics::RayCastingResult result = rayCasting->castSphere(focal, cameraPos, cameraObstacleLimit, collisionType);
|
||||
if (result.mHit)
|
||||
mCameraDistance = (result.mHitPos + result.mHitNormal * cameraObstacleLimit - focal).length();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user