mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +02:00
more prep for shifting avatar during HMD motion
This commit is contained in:
parent
24c2f538a4
commit
43aac813da
5 changed files with 27 additions and 12 deletions
|
@ -114,7 +114,6 @@ MyAvatar::MyAvatar(RigPointer rig) :
|
|||
,_hmdAtRestDetector(glm::vec3(0), glm::quat())
|
||||
#else
|
||||
,_avatarOffsetFromHMD(0.0f)
|
||||
,_hmdVelocity(0.0f)
|
||||
#endif // OLD_HMD_TRACKER
|
||||
{
|
||||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) {
|
||||
|
@ -375,9 +374,16 @@ void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) {
|
|||
}
|
||||
|
||||
followHMD(deltaTime);
|
||||
#else
|
||||
// TODO adebug BOOKMARK -- this is where we need to add the new code for HMD_TRACKER
|
||||
#endif // OLD_HMD_TRACKER
|
||||
}
|
||||
|
||||
glm::vec3 MyAvatar::getHMDCorrectionVelocity() const {
|
||||
// TODO: impelement this
|
||||
return Vectors::ZERO;
|
||||
}
|
||||
|
||||
#ifdef OLD_HMD_TRACKER
|
||||
void MyAvatar::beginFollowingHMD() {
|
||||
// begin homing toward derived body position.
|
||||
|
@ -433,10 +439,6 @@ void MyAvatar::followHMD(float deltaTime) {
|
|||
_bodySensorMatrix = createMatFromQuatAndPos(rot, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
void MyAvatar::harvestHMDOffset(glm::vec3 offset) {
|
||||
|
||||
}
|
||||
#endif // USE_OLD
|
||||
|
||||
|
@ -1292,7 +1294,7 @@ void MyAvatar::prepareForPhysicsSimulation() {
|
|||
relayDriveKeysToCharacterController();
|
||||
_characterController.setTargetVelocity(getTargetVelocity());
|
||||
_characterController.setAvatarPositionAndOrientation(getPosition(), getOrientation());
|
||||
//_characterController.setHMDVelocity(hmdVelocity);
|
||||
_characterController.setHMDVelocity(getHMDCorrectionVelocity());
|
||||
}
|
||||
|
||||
void MyAvatar::harvestResultsFromPhysicsSimulation() {
|
||||
|
@ -1301,6 +1303,9 @@ void MyAvatar::harvestResultsFromPhysicsSimulation() {
|
|||
_characterController.getAvatarPositionAndOrientation(position, orientation);
|
||||
nextAttitude(position, orientation);
|
||||
setVelocity(_characterController.getLinearVelocity());
|
||||
|
||||
// adebug TODO: harvest HMD shift here
|
||||
//glm::vec3 hmdShift = _characterController.getHMDShift();
|
||||
}
|
||||
|
||||
QString MyAvatar::getScriptedMotorFrame() const {
|
||||
|
|
|
@ -76,6 +76,8 @@ public:
|
|||
// as it moves through the world.
|
||||
void updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix);
|
||||
|
||||
glm::vec3 getHMDCorrectionVelocity() const;
|
||||
|
||||
// best called at end of main loop, just before rendering.
|
||||
// update sensor to world matrix from current body position and hmd sensor.
|
||||
// This is so the correct camera can be used for rendering.
|
||||
|
@ -272,8 +274,6 @@ private:
|
|||
void beginFollowingHMD();
|
||||
bool shouldFollowHMD() const;
|
||||
void followHMD(float deltaTime);
|
||||
#else
|
||||
void harvestHMDOffset(glm::vec3 offset);
|
||||
#endif
|
||||
|
||||
bool cameraInsideHead() const;
|
||||
|
@ -376,7 +376,6 @@ private:
|
|||
bool _lastIsMoving { false };
|
||||
#else
|
||||
glm::vec3 _avatarOffsetFromHMD;
|
||||
glm::vec3 _hmdVelocity;
|
||||
#endif // OLD_HMD_TRACKER
|
||||
};
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include <BulletCollision/CollisionDispatch/btCollisionWorld.h>
|
||||
#include <LinearMath/btDefaultMotionState.h>
|
||||
|
||||
#include <BulletUtil.h>
|
||||
#include <GLMHelpers.h>
|
||||
#include <PhysicsLogging.h>
|
||||
#include <PhysicsCollisionGroups.h>
|
||||
|
@ -161,6 +160,17 @@ void MyCharacterController::playerStep(btCollisionWorld* dynaWorld, btScalar dt)
|
|||
_rigidBody->setLinearVelocity(actualVelocity + tau * velocityCorrection);
|
||||
}
|
||||
}
|
||||
|
||||
// Rather than add _hmdVelocity to the velocity of the RigidBody, we explicitly teleport
|
||||
// the RigidBody forward according to the formula: distance = rate * time
|
||||
if (_hmdVelocity.length2() > 0.0f) {
|
||||
btTransform bodyTransform = _rigidBody->getWorldTransform();
|
||||
bodyTransform.setOrigin(bodyTransform.getOrigin() + dt * _hmdVelocity);
|
||||
_rigidBody->setWorldTransform(bodyTransform);
|
||||
}
|
||||
// MyAvatar will ask us how far we stepped for HMD motion, which will depend on how
|
||||
// much time has accumulated in _lastStepDuration.
|
||||
_lastStepDuration += dt;
|
||||
}
|
||||
|
||||
void MyCharacterController::jump() {
|
||||
|
@ -390,6 +400,7 @@ void MyCharacterController::preSimulation() {
|
|||
}
|
||||
}
|
||||
}
|
||||
_lastStepDuration = 0.0f;
|
||||
}
|
||||
|
||||
void MyCharacterController::postSimulation() {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <btBulletDynamicsCommon.h>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <BulletUtil.h>
|
||||
#include <CharacterController.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
|
@ -48,7 +49,6 @@ public:
|
|||
// overrides from CharacterController
|
||||
virtual void preSimulation() override;
|
||||
virtual void postSimulation() override;
|
||||
virtual void incrementSimulationTime(btScalar timeStep) override { _lastStepDuration += timeStep; }
|
||||
|
||||
bool isHovering() const { return _isHovering; }
|
||||
void setHovering(bool enabled);
|
||||
|
@ -65,6 +65,7 @@ public:
|
|||
|
||||
void setTargetVelocity(const glm::vec3& velocity);
|
||||
void setHMDVelocity(const glm::vec3& velocity);
|
||||
glm::vec3 getHMDShift() const { return _lastStepDuration * bulletToGLM(_hmdVelocity); }
|
||||
|
||||
glm::vec3 getLinearVelocity() const;
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ public:
|
|||
|
||||
virtual void updateShapeIfNecessary() = 0;
|
||||
virtual void preSimulation() = 0;
|
||||
virtual void incrementSimulationTime(btScalar stepTime) = 0;
|
||||
virtual void postSimulation() = 0;
|
||||
|
||||
virtual void setWalkDirection(const btVector3 &walkDirection) { assert(false); }
|
||||
|
|
Loading…
Reference in a new issue