mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 16:15:31 +00:00
Use mesh collision box instead of node bounding sphere for projectile
size. The bounding sphere is much bigger than the mesh.
This commit is contained in:
parent
d984d13b1c
commit
6e969ca3fa
5 changed files with 22 additions and 13 deletions
|
@ -682,9 +682,14 @@ namespace MWPhysics
|
|||
mActors.emplace(ptr, std::move(actor));
|
||||
}
|
||||
|
||||
int PhysicsSystem::addProjectile (const MWWorld::Ptr& caster, const osg::Vec3f& position, float radius, bool canTraverseWater)
|
||||
int PhysicsSystem::addProjectile (const MWWorld::Ptr& caster, const osg::Vec3f& position, const std::string& mesh, bool computeRadius, bool canTraverseWater)
|
||||
{
|
||||
osg::ref_ptr<Resource::BulletShapeInstance> shapeInstance = mShapeManager->getInstance(mesh);
|
||||
assert(shapeInstance);
|
||||
float radius = computeRadius ? shapeInstance->mCollisionBox.extents.length() / 2.f : 1.f;
|
||||
|
||||
mProjectileId++;
|
||||
|
||||
auto projectile = std::make_shared<Projectile>(caster, position, radius, canTraverseWater, mTaskScheduler.get(), this);
|
||||
mProjectiles.emplace(mProjectileId, std::move(projectile));
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ namespace MWPhysics
|
|||
void addObject (const MWWorld::Ptr& ptr, const std::string& mesh, osg::Quat rotation, int collisionType = CollisionType_World);
|
||||
void addActor (const MWWorld::Ptr& ptr, const std::string& mesh);
|
||||
|
||||
int addProjectile(const MWWorld::Ptr& caster, const osg::Vec3f& position, float radius, bool canTraverseWater);
|
||||
int addProjectile(const MWWorld::Ptr& caster, const osg::Vec3f& position, const std::string& mesh, bool computeRadius, bool canTraverseWater);
|
||||
void updateProjectile(const int projectileId, const osg::Vec3f &position) const;
|
||||
void removeProjectile(const int projectileId);
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ namespace MWWorld
|
|||
};
|
||||
|
||||
|
||||
float ProjectileManager::createModel(State &state, const std::string &model, const osg::Vec3f& pos, const osg::Quat& orient,
|
||||
void ProjectileManager::createModel(State &state, const std::string &model, const osg::Vec3f& pos, const osg::Quat& orient,
|
||||
bool rotate, bool createLight, osg::Vec4 lightDiffuseColor, std::string texture)
|
||||
{
|
||||
state.mNode = new osg::PositionAttitudeTransform;
|
||||
|
@ -253,7 +253,6 @@ namespace MWWorld
|
|||
state.mNode->accept(assignVisitor);
|
||||
|
||||
MWRender::overrideFirstRootTexture(texture, mResourceSystem, projectile);
|
||||
return projectile->getBound().radius();
|
||||
}
|
||||
|
||||
void ProjectileManager::update(State& state, float duration)
|
||||
|
@ -308,7 +307,8 @@ namespace MWWorld
|
|||
|
||||
osg::Vec4 lightDiffuseColor = getMagicBoltLightDiffuseColor(state.mEffects);
|
||||
|
||||
const auto radius = createModel(state, ptr.getClass().getModel(ptr), pos, orient, true, true, lightDiffuseColor, texture);
|
||||
auto model = ptr.getClass().getModel(ptr);
|
||||
createModel(state, model, pos, orient, true, true, lightDiffuseColor, texture);
|
||||
|
||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||
for (const std::string &soundid : state.mSoundIds)
|
||||
|
@ -319,7 +319,10 @@ namespace MWWorld
|
|||
state.mSounds.push_back(sound);
|
||||
}
|
||||
|
||||
state.mProjectileId = mPhysics->addProjectile(caster, pos, radius, false);
|
||||
// in case there are multiple effects, the model is a dummy without geometry. Use the second effect for physics shape
|
||||
if (state.mIdMagic.size() > 1)
|
||||
model = "meshes\\" + MWBase::Environment::get().getWorld()->getStore().get<ESM::Weapon>().find(state.mIdMagic.at(1))->mModel;
|
||||
state.mProjectileId = mPhysics->addProjectile(caster, pos, model, true, false);
|
||||
state.mToDelete = false;
|
||||
mMagicBolts.push_back(state);
|
||||
}
|
||||
|
@ -339,11 +342,12 @@ namespace MWWorld
|
|||
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), projectile.getCellRef().getRefId());
|
||||
MWWorld::Ptr ptr = ref.getPtr();
|
||||
|
||||
createModel(state, ptr.getClass().getModel(ptr), pos, orient, false, false, osg::Vec4(0,0,0,0));
|
||||
const auto model = ptr.getClass().getModel(ptr);
|
||||
createModel(state, model, pos, orient, false, false, osg::Vec4(0,0,0,0));
|
||||
if (!ptr.getClass().getEnchantment(ptr).empty())
|
||||
SceneUtil::addEnchantedGlow(state.mNode, mResourceSystem, ptr.getClass().getEnchantmentColor(ptr));
|
||||
|
||||
state.mProjectileId = mPhysics->addProjectile(actor, pos, 1.f, true);
|
||||
state.mProjectileId = mPhysics->addProjectile(actor, pos, model, false, true);
|
||||
state.mToDelete = false;
|
||||
mProjectiles.push_back(state);
|
||||
}
|
||||
|
@ -629,7 +633,7 @@ namespace MWWorld
|
|||
int weaponType = ptr.get<ESM::Weapon>()->mBase->mData.mType;
|
||||
state.mThrown = MWMechanics::getWeaponType(weaponType)->mWeaponClass == ESM::WeaponType::Thrown;
|
||||
|
||||
state.mProjectileId = mPhysics->addProjectile(state.getCaster(), osg::Vec3f(esm.mPosition), 1.f, true);
|
||||
state.mProjectileId = mPhysics->addProjectile(state.getCaster(), osg::Vec3f(esm.mPosition), model, false, true);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
@ -681,8 +685,8 @@ namespace MWWorld
|
|||
}
|
||||
|
||||
osg::Vec4 lightDiffuseColor = getMagicBoltLightDiffuseColor(state.mEffects);
|
||||
const auto radius = createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), true, true, lightDiffuseColor, texture);
|
||||
state.mProjectileId = mPhysics->addProjectile(state.getCaster(), osg::Vec3f(esm.mPosition), radius, false);
|
||||
createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), true, true, lightDiffuseColor, texture);
|
||||
state.mProjectileId = mPhysics->addProjectile(state.getCaster(), osg::Vec3f(esm.mPosition), model, true, false);
|
||||
|
||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||
for (const std::string &soundid : state.mSoundIds)
|
||||
|
|
|
@ -130,7 +130,7 @@ namespace MWWorld
|
|||
void moveProjectiles(float dt);
|
||||
void moveMagicBolts(float dt);
|
||||
|
||||
float createModel (State& state, const std::string& model, const osg::Vec3f& pos, const osg::Quat& orient,
|
||||
void createModel (State& state, const std::string& model, const osg::Vec3f& pos, const osg::Quat& orient,
|
||||
bool rotate, bool createLight, osg::Vec4 lightDiffuseColor, std::string texture = "");
|
||||
void update (State& state, float duration);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace Resource
|
|||
osg::Vec3f extents;
|
||||
osg::Vec3f center;
|
||||
};
|
||||
// Used for actors. mCollisionShape is used for actors only when we need to autogenerate collision box for creatures.
|
||||
// Used for actors and projectiles. mCollisionShape is used for actors only when we need to autogenerate collision box for creatures.
|
||||
// For now, use one file <-> one resource for simplicity.
|
||||
CollisionBox mCollisionBox;
|
||||
|
||||
|
|
Loading…
Reference in a new issue