mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 03:42:48 +01:00
Use MotionState to move projectiles
This commit is contained in:
parent
5d6e3598ca
commit
a3e924ff3c
@ -1,5 +1,7 @@
|
||||
#include "objects/GameObject.hpp"
|
||||
|
||||
#include <data/Clump.hpp>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
@ -40,3 +42,21 @@ glm::mat4 GameObject::getTimeAdjustedTransform(float alpha) const {
|
||||
t = t * glm::mat4_cast(glm::slerp(_lastRotation, getRotation(), alpha));
|
||||
return t;
|
||||
}
|
||||
|
||||
void GameObject::updateTransform(const glm::vec3& pos, const glm::quat& rot) {
|
||||
_lastPosition = position;
|
||||
_lastRotation = rotation;
|
||||
position = pos;
|
||||
rotation = rot;
|
||||
|
||||
const auto& clump = getClump();
|
||||
const auto& atomic = getAtomic();
|
||||
if (clump) {
|
||||
clump->getFrame()->setRotation(glm::mat3_cast(rot));
|
||||
clump->getFrame()->setTranslation(pos);
|
||||
}
|
||||
if (atomic) {
|
||||
atomic->getFrame()->setRotation(glm::mat3_cast(rot));
|
||||
atomic->getFrame()->setTranslation(pos);
|
||||
}
|
||||
}
|
||||
|
@ -270,12 +270,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void updateTransform(const glm::vec3& pos, const glm::quat& rot) {
|
||||
_lastPosition = position;
|
||||
_lastRotation = rotation;
|
||||
position = pos;
|
||||
rotation = rot;
|
||||
}
|
||||
void updateTransform(const glm::vec3& pos, const glm::quat& rot);
|
||||
|
||||
private:
|
||||
ObjectLifetime lifetime = GameObject::UnknownLifetime;
|
||||
|
@ -270,11 +270,3 @@ void InstanceObject::setSolid(bool solid) {
|
||||
}
|
||||
body->getBulletBody()->setCollisionFlags(flags);
|
||||
}
|
||||
|
||||
void InstanceObject::updateTransform(const glm::vec3& pos,
|
||||
const glm::quat& rot) {
|
||||
position = pos;
|
||||
rotation = rot;
|
||||
getAtomic()->getFrame()->setRotation(glm::mat3_cast(rot));
|
||||
getAtomic()->getFrame()->setTranslation(pos);
|
||||
}
|
||||
|
@ -86,8 +86,6 @@ public:
|
||||
float getHealth() const {
|
||||
return health;
|
||||
}
|
||||
|
||||
void updateTransform(const glm::vec3& pos, const glm::quat& rot) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -117,8 +117,9 @@ void ProjectileObject::cleanup() {
|
||||
|
||||
ProjectileObject::ProjectileObject(GameWorld* world, const glm::vec3& position,
|
||||
const ProjectileObject::ProjectileInfo& info)
|
||||
: GameObject(world, position, glm::quat{1.0f,0.0f,0.0f,0.0f}, nullptr)
|
||||
, _info(info) {
|
||||
: GameObject(world, position, glm::quat{1.0f, 0.0f, 0.0f, 0.0f}, nullptr)
|
||||
, _info(info)
|
||||
, _motionState(this) {
|
||||
_shape = std::make_unique<btSphereShape>(0.45f);
|
||||
btVector3 inertia(0.f, 0.f, 0.f);
|
||||
_shape->calculateLocalInertia(1.f, inertia);
|
||||
@ -130,6 +131,7 @@ ProjectileObject::ProjectileObject(GameWorld* world, const glm::vec3& position,
|
||||
ws.setOrigin(btVector3(position.x, position.y, position.z));
|
||||
riginfo.m_startWorldTransform = ws;
|
||||
riginfo.m_mass = 1.f;
|
||||
riginfo.m_motionState = &_motionState;
|
||||
|
||||
_body = std::make_unique<btRigidBody>(riginfo);
|
||||
_body->setUserPointer(this);
|
||||
@ -173,12 +175,6 @@ ProjectileObject::~ProjectileObject() {
|
||||
void ProjectileObject::tick(float dt) {
|
||||
if (_body == nullptr) return;
|
||||
|
||||
auto& bttr = _body->getWorldTransform();
|
||||
position = {bttr.getOrigin().x(), bttr.getOrigin().y(),
|
||||
bttr.getOrigin().z()};
|
||||
auto r = bttr.getRotation();
|
||||
rotation = {r.x(), r.y(), r.z(), r.w()};
|
||||
|
||||
_info.time -= dt;
|
||||
|
||||
if (_ghostBody) {
|
||||
|
@ -1,13 +1,12 @@
|
||||
#ifndef _RWENGINE_PROJECTILEOBJECT_HPP_
|
||||
#define _RWENGINE_PROJECTILEOBJECT_HPP_
|
||||
|
||||
#include <dynamics/CollisionInstance.hpp>
|
||||
#include <objects/GameObject.hpp>
|
||||
#include "render/VisualFX.hpp"
|
||||
|
||||
|
||||
class GameWorld;
|
||||
class btPairCachingGhostObject;
|
||||
class btRigidBody;
|
||||
class btSphereShape;
|
||||
struct WeaponData;
|
||||
|
||||
@ -51,6 +50,8 @@ private:
|
||||
/** Used for RPGs and Molotov collision detection */
|
||||
std::unique_ptr<btPairCachingGhostObject> _ghostBody;
|
||||
|
||||
GameObjectMotionState _motionState;
|
||||
|
||||
bool _exploded = false;
|
||||
|
||||
void checkPhysicsContact();
|
||||
|
@ -309,14 +309,6 @@ void VehicleObject::setRotation(const glm::quat& orientation) {
|
||||
GameObject::setRotation(orientation);
|
||||
}
|
||||
|
||||
void VehicleObject::updateTransform(const glm::vec3& pos,
|
||||
const glm::quat& rot) {
|
||||
position = pos;
|
||||
rotation = rot;
|
||||
getClump()->getFrame()->setRotation(glm::mat3_cast(rot));
|
||||
getClump()->getFrame()->setTranslation(pos);
|
||||
}
|
||||
|
||||
void VehicleObject::setExtraEnabled(size_t extra, bool enabled) {
|
||||
auto atomic = extras_.at(extra);
|
||||
if (!atomic) {
|
||||
|
@ -106,8 +106,6 @@ public:
|
||||
|
||||
glm::vec3 getCenterOffset() override;
|
||||
|
||||
void updateTransform(const glm::vec3& pos, const glm::quat& rot) override;
|
||||
|
||||
VehicleModelInfo* getVehicle() const {
|
||||
return getModelInfo<VehicleModelInfo>();
|
||||
}
|
||||
|
@ -339,9 +339,8 @@ void ObjectRenderer::renderCutsceneObject(CutsceneObject* cutscene,
|
||||
|
||||
void ObjectRenderer::renderProjectile(ProjectileObject* projectile,
|
||||
RenderList& outList) {
|
||||
glm::mat4 modelMatrix = projectile->getTimeAdjustedTransform(m_renderAlpha);
|
||||
const auto& atomic = projectile->getAtomic();
|
||||
renderAtomic(atomic.get(), modelMatrix, nullptr, outList);
|
||||
renderAtomic(atomic.get(), glm::mat4(1.0f), nullptr, outList);
|
||||
}
|
||||
|
||||
void ObjectRenderer::buildRenderList(GameObject* object, RenderList& outList) {
|
||||
|
Loading…
Reference in New Issue
Block a user