mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 03:15:32 +00:00
Make actor collision box components a struct
This commit is contained in:
parent
11eff02a1d
commit
15291f15d3
6 changed files with 34 additions and 31 deletions
|
@ -20,7 +20,7 @@ namespace MWPhysics
|
|||
|
||||
Actor::Actor(const MWWorld::Ptr& ptr, const Resource::BulletShape* shape, PhysicsTaskScheduler* scheduler)
|
||||
: mStandingOnPtr(nullptr), mCanWaterWalk(false), mWalkingOnWater(false)
|
||||
, mCollisionObject(nullptr), mMeshTranslation(shape->mCollisionBoxTranslate), mHalfExtents(shape->mCollisionBoxHalfExtents)
|
||||
, mCollisionObject(nullptr), mMeshTranslation(shape->mCollisionBox.center), mHalfExtents(shape->mCollisionBox.extents)
|
||||
, mForce(0.f, 0.f, 0.f), mOnGround(true), mOnSlope(false)
|
||||
, mInternalCollisionMode(true)
|
||||
, mExternalCollisionMode(true)
|
||||
|
|
|
@ -645,7 +645,7 @@ namespace MWPhysics
|
|||
osg::ref_ptr<const Resource::BulletShape> shape = mShapeManager->getShape(mesh);
|
||||
|
||||
// Try to get shape from basic model as fallback for creatures
|
||||
if (!ptr.getClass().isNpc() && shape && shape->mCollisionBoxHalfExtents.length2() == 0)
|
||||
if (!ptr.getClass().isNpc() && shape && shape->mCollisionBox.extents.length2() == 0)
|
||||
{
|
||||
const std::string fallbackModel = ptr.getClass().getModel(ptr);
|
||||
if (fallbackModel != mesh)
|
||||
|
|
|
@ -162,8 +162,8 @@ namespace Resource
|
|||
{
|
||||
return compareObjects(lhs.mCollisionShape, rhs.mCollisionShape)
|
||||
&& compareObjects(lhs.mAvoidCollisionShape, rhs.mAvoidCollisionShape)
|
||||
&& lhs.mCollisionBoxHalfExtents == rhs.mCollisionBoxHalfExtents
|
||||
&& lhs.mCollisionBoxTranslate == rhs.mCollisionBoxTranslate
|
||||
&& lhs.mCollisionBox.extents == rhs.mCollisionBox.extents
|
||||
&& lhs.mCollisionBox.center == rhs.mCollisionBox.center
|
||||
&& lhs.mAnimatedShapes == rhs.mAnimatedShapes;
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,8 @@ namespace Resource
|
|||
return stream << "Resource::BulletShape {"
|
||||
<< value.mCollisionShape << ", "
|
||||
<< value.mAvoidCollisionShape << ", "
|
||||
<< "osg::Vec3f {" << value.mCollisionBoxHalfExtents << "}" << ", "
|
||||
<< "osg::Vec3f {" << value.mCollisionBox.extents << "}" << ", "
|
||||
<< "osg::Vec3f {" << value.mCollisionBox.center << "}" << ", "
|
||||
<< value.mAnimatedShapes
|
||||
<< "}";
|
||||
}
|
||||
|
@ -433,8 +434,8 @@ namespace
|
|||
const auto result = mLoader.load(mNifFile);
|
||||
|
||||
Resource::BulletShape expected;
|
||||
expected.mCollisionBoxHalfExtents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBoxTranslate = osg::Vec3f(-1, -2, -3);
|
||||
expected.mCollisionBox.extents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBox.center = osg::Vec3f(-1, -2, -3);
|
||||
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
|
||||
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
||||
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
|
||||
|
@ -458,8 +459,8 @@ namespace
|
|||
const auto result = mLoader.load(mNifFile);
|
||||
|
||||
Resource::BulletShape expected;
|
||||
expected.mCollisionBoxHalfExtents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBoxTranslate = osg::Vec3f(-1, -2, -3);
|
||||
expected.mCollisionBox.extents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBox.center = osg::Vec3f(-1, -2, -3);
|
||||
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
|
||||
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
||||
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
|
||||
|
@ -488,8 +489,8 @@ namespace
|
|||
const auto result = mLoader.load(mNifFile);
|
||||
|
||||
Resource::BulletShape expected;
|
||||
expected.mCollisionBoxHalfExtents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBoxTranslate = osg::Vec3f(-1, -2, -3);
|
||||
expected.mCollisionBox.extents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBox.center = osg::Vec3f(-1, -2, -3);
|
||||
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
|
||||
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
||||
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
|
||||
|
@ -523,8 +524,8 @@ namespace
|
|||
const auto result = mLoader.load(mNifFile);
|
||||
|
||||
Resource::BulletShape expected;
|
||||
expected.mCollisionBoxHalfExtents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBoxTranslate = osg::Vec3f(-1, -2, -3);
|
||||
expected.mCollisionBox.extents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBox.center = osg::Vec3f(-1, -2, -3);
|
||||
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(1, 2, 3)));
|
||||
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
||||
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-1, -2, -3)), box.release());
|
||||
|
@ -558,8 +559,8 @@ namespace
|
|||
const auto result = mLoader.load(mNifFile);
|
||||
|
||||
Resource::BulletShape expected;
|
||||
expected.mCollisionBoxHalfExtents = osg::Vec3f(4, 5, 6);
|
||||
expected.mCollisionBoxTranslate = osg::Vec3f(-4, -5, -6);
|
||||
expected.mCollisionBox.extents = osg::Vec3f(4, 5, 6);
|
||||
expected.mCollisionBox.center = osg::Vec3f(-4, -5, -6);
|
||||
std::unique_ptr<btBoxShape> box(new btBoxShape(btVector3(4, 5, 6)));
|
||||
std::unique_ptr<btCompoundShape> shape(new btCompoundShape);
|
||||
shape->addChildShape(btTransform(btMatrix3x3::getIdentity(), btVector3(-4, -5, -6)), box.release());
|
||||
|
@ -581,8 +582,8 @@ namespace
|
|||
const auto result = mLoader.load(mNifFile);
|
||||
|
||||
Resource::BulletShape expected;
|
||||
expected.mCollisionBoxHalfExtents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBoxTranslate = osg::Vec3f(-1, -2, -3);
|
||||
expected.mCollisionBox.extents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBox.center = osg::Vec3f(-1, -2, -3);
|
||||
|
||||
EXPECT_EQ(*result, expected);
|
||||
}
|
||||
|
@ -615,8 +616,8 @@ namespace
|
|||
const auto result = mLoader.load(mNifFile);
|
||||
|
||||
Resource::BulletShape expected;
|
||||
expected.mCollisionBoxHalfExtents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBoxTranslate = osg::Vec3f(-1, -2, -3);
|
||||
expected.mCollisionBox.extents = osg::Vec3f(1, 2, 3);
|
||||
expected.mCollisionBox.center = osg::Vec3f(-1, -2, -3);
|
||||
|
||||
EXPECT_EQ(*result, expected);
|
||||
}
|
||||
|
|
|
@ -145,12 +145,12 @@ osg::ref_ptr<Resource::BulletShape> BulletNifLoader::load(const Nif::File& nif)
|
|||
{
|
||||
if (findBoundingBox(node, filename))
|
||||
{
|
||||
const btVector3 halfExtents = Misc::Convert::toBullet(mShape->mCollisionBoxHalfExtents);
|
||||
const btVector3 origin = Misc::Convert::toBullet(mShape->mCollisionBoxTranslate);
|
||||
const btVector3 extents = Misc::Convert::toBullet(mShape->mCollisionBox.extents);
|
||||
const btVector3 center = Misc::Convert::toBullet(mShape->mCollisionBox.center);
|
||||
std::unique_ptr<btCompoundShape> compound (new btCompoundShape);
|
||||
std::unique_ptr<btBoxShape> boxShape(new btBoxShape(halfExtents));
|
||||
std::unique_ptr<btBoxShape> boxShape(new btBoxShape(extents));
|
||||
btTransform transform = btTransform::getIdentity();
|
||||
transform.setOrigin(origin);
|
||||
transform.setOrigin(center);
|
||||
compound->addChildShape(transform, boxShape.get());
|
||||
boxShape.release();
|
||||
|
||||
|
@ -208,8 +208,8 @@ bool BulletNifLoader::findBoundingBox(const Nif::Node* node, const std::string&
|
|||
switch (type)
|
||||
{
|
||||
case Nif::NiBoundingVolume::Type::BOX_BV:
|
||||
mShape->mCollisionBoxHalfExtents = node->bounds.box.extents;
|
||||
mShape->mCollisionBoxTranslate = node->bounds.box.center;
|
||||
mShape->mCollisionBox.extents = node->bounds.box.extents;
|
||||
mShape->mCollisionBox.center = node->bounds.box.center;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
|
|
@ -20,8 +20,7 @@ BulletShape::BulletShape()
|
|||
BulletShape::BulletShape(const BulletShape ©, const osg::CopyOp ©op)
|
||||
: mCollisionShape(duplicateCollisionShape(copy.mCollisionShape))
|
||||
, mAvoidCollisionShape(duplicateCollisionShape(copy.mAvoidCollisionShape))
|
||||
, mCollisionBoxHalfExtents(copy.mCollisionBoxHalfExtents)
|
||||
, mCollisionBoxTranslate(copy.mCollisionBoxTranslate)
|
||||
, mCollisionBox(copy.mCollisionBox)
|
||||
, mAnimatedShapes(copy.mAnimatedShapes)
|
||||
{
|
||||
}
|
||||
|
@ -106,8 +105,7 @@ BulletShapeInstance::BulletShapeInstance(osg::ref_ptr<const BulletShape> source)
|
|||
: BulletShape()
|
||||
, mSource(source)
|
||||
{
|
||||
mCollisionBoxHalfExtents = source->mCollisionBoxHalfExtents;
|
||||
mCollisionBoxTranslate = source->mCollisionBoxTranslate;
|
||||
mCollisionBox = source->mCollisionBox;
|
||||
|
||||
mAnimatedShapes = source->mAnimatedShapes;
|
||||
|
||||
|
|
|
@ -27,10 +27,14 @@ namespace Resource
|
|||
btCollisionShape* mCollisionShape;
|
||||
btCollisionShape* mAvoidCollisionShape;
|
||||
|
||||
struct CollisionBox
|
||||
{
|
||||
osg::Vec3f extents;
|
||||
osg::Vec3f center;
|
||||
};
|
||||
// Used for actors. mCollisionShape is used for actors only when we need to autogenerate collision box for creatures.
|
||||
// For now, use one file <-> one resource for simplicity.
|
||||
osg::Vec3f mCollisionBoxHalfExtents;
|
||||
osg::Vec3f mCollisionBoxTranslate;
|
||||
CollisionBox mCollisionBox;
|
||||
|
||||
// Stores animated collision shapes. If any collision nodes in the NIF are animated, then mCollisionShape
|
||||
// will be a btCompoundShape (which consists of one or more child shapes).
|
||||
|
|
Loading…
Reference in a new issue