1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-11-30 03:34:37 +00:00

Add btVector3 -> osg::Vec3f helper

This commit is contained in:
Evil Eye 2025-09-21 12:14:50 +02:00
parent b845e07ad6
commit 1caac90e93
5 changed files with 13 additions and 9 deletions

View file

@ -1,6 +1,7 @@
#include "../nif/node.hpp" #include "../nif/node.hpp"
#include <components/bullethelpers/processtrianglecallback.hpp> #include <components/bullethelpers/processtrianglecallback.hpp>
#include <components/misc/convert.hpp>
#include <components/nif/data.hpp> #include <components/nif/data.hpp>
#include <components/nif/extra.hpp> #include <components/nif/extra.hpp>
#include <components/nif/node.hpp> #include <components/nif/node.hpp>
@ -300,8 +301,7 @@ namespace
void copy(const btTransform& src, Nif::NiTransform& dst) void copy(const btTransform& src, Nif::NiTransform& dst)
{ {
dst.mTranslation = osg::Vec3f(static_cast<float>(src.getOrigin().x()), static_cast<float>(src.getOrigin().y()), dst.mTranslation = Misc::Convert::makeOsgVec3f(src.getOrigin());
static_cast<float>(src.getOrigin().z()));
for (int row = 0; row < 3; ++row) for (int row = 0; row < 3; ++row)
for (int column = 0; column < 3; ++column) for (int column = 0; column < 3; ++column)
dst.mRotation.mValues[row][column] = static_cast<float>(src.getBasis().getRow(row)[column]); dst.mRotation.mValues[row][column] = static_cast<float>(src.getBasis().getRow(row)[column]);

View file

@ -581,7 +581,7 @@ namespace MWWorld
assert(target != caster); assert(target != caster);
MWMechanics::CastSpell cast(caster, target); 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.mId = magicBoltState.mSpellId;
cast.mSourceName = magicBoltState.mSourceName; cast.mSourceName = magicBoltState.mSourceName;
cast.mItem = magicBoltState.mItem; cast.mItem = magicBoltState.mItem;

View file

@ -178,13 +178,13 @@ namespace
const btTransform closedDoorTransform( const btTransform closedDoorTransform(
Misc::Convert::makeBulletQuaternion(ptr.getCellRef().getPosition()), transform.getOrigin()); 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 }, {}, const auto startPoint = physics.castRay(start, start - osg::Vec3f(0, 0, 1000), { ptr }, {},
MWPhysics::CollisionType_World | MWPhysics::CollisionType_HeightMap MWPhysics::CollisionType_World | MWPhysics::CollisionType_HeightMap
| MWPhysics::CollisionType_Water); | MWPhysics::CollisionType_Water);
const auto connectionStart = startPoint.mHit ? startPoint.mHitPos : start; 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 }, {}, const auto endPoint = physics.castRay(end, end - osg::Vec3f(0, 0, 1000), { ptr }, {},
MWPhysics::CollisionType_World | MWPhysics::CollisionType_HeightMap MWPhysics::CollisionType_World | MWPhysics::CollisionType_HeightMap
| MWPhysics::CollisionType_Water); | MWPhysics::CollisionType_Water);

View file

@ -37,6 +37,11 @@ namespace Misc::Convert
return osg::Vec3d(vec.x(), vec.y(), vec.z()); 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) inline osg::Quat toOsg(const btQuaternion& quat)
{ {
return osg::Quat(quat.x(), quat.y(), quat.z(), quat.w()); return osg::Quat(quat.x(), quat.y(), quat.z(), quat.w());

View file

@ -9,6 +9,7 @@
#include <BulletCollision/CollisionShapes/btTriangleMesh.h> #include <BulletCollision/CollisionShapes/btTriangleMesh.h>
#include <components/misc/convert.hpp>
#include <components/misc/osguservalues.hpp> #include <components/misc/osguservalues.hpp>
#include <components/misc/pathhelpers.hpp> #include <components/misc/pathhelpers.hpp>
#include <components/sceneutil/visitor.hpp> #include <components/sceneutil/visitor.hpp>
@ -37,14 +38,12 @@ namespace Resource
void setMatrix(const osg::Matrixf& matrix) { mMatrix = matrix; } 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, 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 bool /*temp*/ = false) // Note: unused temp argument left here for OSG versions less than 3.5.6
{ {
if (mTriMesh) if (mTriMesh)
mTriMesh->addTriangle( mTriMesh->addTriangle(Misc::Convert::toBullet(mMatrix.preMult(v1)),
toBullet(mMatrix.preMult(v1)), toBullet(mMatrix.preMult(v2)), toBullet(mMatrix.preMult(v3))); Misc::Convert::toBullet(mMatrix.preMult(v2)), Misc::Convert::toBullet(mMatrix.preMult(v3)));
} }
btTriangleMesh* mTriMesh; btTriangleMesh* mTriMesh;