From 1caac90e932702c6c1055708843a91b64e64f3ad Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 21 Sep 2025 12:14:50 +0200 Subject: [PATCH] Add btVector3 -> osg::Vec3f helper --- apps/components_tests/nifloader/testbulletnifloader.cpp | 4 ++-- apps/openmw/mwworld/projectilemanager.cpp | 2 +- apps/openmw/mwworld/scene.cpp | 4 ++-- components/misc/convert.hpp | 5 +++++ components/resource/bulletshapemanager.cpp | 7 +++---- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/components_tests/nifloader/testbulletnifloader.cpp b/apps/components_tests/nifloader/testbulletnifloader.cpp index e6d2656b52..9b73f6f2c0 100644 --- a/apps/components_tests/nifloader/testbulletnifloader.cpp +++ b/apps/components_tests/nifloader/testbulletnifloader.cpp @@ -1,6 +1,7 @@ #include "../nif/node.hpp" #include +#include #include #include #include @@ -300,8 +301,7 @@ namespace void copy(const btTransform& src, Nif::NiTransform& dst) { - dst.mTranslation = osg::Vec3f(static_cast(src.getOrigin().x()), static_cast(src.getOrigin().y()), - static_cast(src.getOrigin().z())); + dst.mTranslation = Misc::Convert::makeOsgVec3f(src.getOrigin()); for (int row = 0; row < 3; ++row) for (int column = 0; column < 3; ++column) dst.mRotation.mValues[row][column] = static_cast(src.getBasis().getRow(row)[column]); diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 1186316bb1..9535d9987a 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -581,7 +581,7 @@ namespace MWWorld assert(target != caster); MWMechanics::CastSpell cast(caster, target); - cast.mHitPosition = !active ? Misc::Convert::toOsg(projectile->getHitPosition()) : pos; + cast.mHitPosition = !active ? Misc::Convert::makeOsgVec3f(projectile->getHitPosition()) : pos; cast.mId = magicBoltState.mSpellId; cast.mSourceName = magicBoltState.mSourceName; cast.mItem = magicBoltState.mItem; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 7e55bc8ba9..3bb76c5215 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -178,13 +178,13 @@ namespace const btTransform closedDoorTransform( Misc::Convert::makeBulletQuaternion(ptr.getCellRef().getPosition()), transform.getOrigin()); - const auto start = Misc::Convert::toOsg(closedDoorTransform(center + toPoint)); + const auto start = Misc::Convert::makeOsgVec3f(closedDoorTransform(center + toPoint)); const auto startPoint = physics.castRay(start, start - osg::Vec3f(0, 0, 1000), { ptr }, {}, MWPhysics::CollisionType_World | MWPhysics::CollisionType_HeightMap | MWPhysics::CollisionType_Water); const auto connectionStart = startPoint.mHit ? startPoint.mHitPos : start; - const auto end = Misc::Convert::toOsg(closedDoorTransform(center - toPoint)); + const auto end = Misc::Convert::makeOsgVec3f(closedDoorTransform(center - toPoint)); const auto endPoint = physics.castRay(end, end - osg::Vec3f(0, 0, 1000), { ptr }, {}, MWPhysics::CollisionType_World | MWPhysics::CollisionType_HeightMap | MWPhysics::CollisionType_Water); diff --git a/components/misc/convert.hpp b/components/misc/convert.hpp index be469c6a62..2ed0baeaee 100644 --- a/components/misc/convert.hpp +++ b/components/misc/convert.hpp @@ -37,6 +37,11 @@ namespace Misc::Convert return osg::Vec3d(vec.x(), vec.y(), vec.z()); } + inline osg::Vec3f makeOsgVec3f(const btVector3& vec) + { + return toOsg(vec); + } + inline osg::Quat toOsg(const btQuaternion& quat) { return osg::Quat(quat.x(), quat.y(), quat.z(), quat.w()); diff --git a/components/resource/bulletshapemanager.cpp b/components/resource/bulletshapemanager.cpp index 58ef3252ea..94b22564a9 100644 --- a/components/resource/bulletshapemanager.cpp +++ b/components/resource/bulletshapemanager.cpp @@ -9,6 +9,7 @@ #include +#include #include #include #include @@ -37,14 +38,12 @@ namespace Resource void setMatrix(const osg::Matrixf& matrix) { mMatrix = matrix; } - inline btVector3 toBullet(const osg::Vec3f& vec) { return btVector3(vec.x(), vec.y(), vec.z()); } - void inline operator()(const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3, bool /*temp*/ = false) // Note: unused temp argument left here for OSG versions less than 3.5.6 { if (mTriMesh) - mTriMesh->addTriangle( - toBullet(mMatrix.preMult(v1)), toBullet(mMatrix.preMult(v2)), toBullet(mMatrix.preMult(v3))); + mTriMesh->addTriangle(Misc::Convert::toBullet(mMatrix.preMult(v1)), + Misc::Convert::toBullet(mMatrix.preMult(v2)), Misc::Convert::toBullet(mMatrix.preMult(v3))); } btTriangleMesh* mTriMesh;