mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 07:57:30 +02:00
move _velocity into base class. walking on a cube works
This commit is contained in:
parent
31624b85e7
commit
a8b688d540
7 changed files with 23 additions and 31 deletions
|
@ -63,7 +63,6 @@ Avatar::Avatar() :
|
||||||
_skeletonModel(this),
|
_skeletonModel(this),
|
||||||
_skeletonOffset(0.0f),
|
_skeletonOffset(0.0f),
|
||||||
_bodyYawDelta(0.0f),
|
_bodyYawDelta(0.0f),
|
||||||
_velocity(0.0f),
|
|
||||||
_positionDeltaAccumulator(0.0f),
|
_positionDeltaAccumulator(0.0f),
|
||||||
_lastVelocity(0.0f),
|
_lastVelocity(0.0f),
|
||||||
_acceleration(0.0f),
|
_acceleration(0.0f),
|
||||||
|
|
|
@ -155,7 +155,6 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE glm::vec3 getNeckPosition() const;
|
Q_INVOKABLE glm::vec3 getNeckPosition() const;
|
||||||
|
|
||||||
Q_INVOKABLE glm::vec3 getVelocity() const { return _velocity; }
|
|
||||||
Q_INVOKABLE glm::vec3 getAcceleration() const { return _acceleration; }
|
Q_INVOKABLE glm::vec3 getAcceleration() const { return _acceleration; }
|
||||||
Q_INVOKABLE glm::vec3 getAngularVelocity() const { return _angularVelocity; }
|
Q_INVOKABLE glm::vec3 getAngularVelocity() const { return _angularVelocity; }
|
||||||
Q_INVOKABLE glm::vec3 getAngularAcceleration() const { return _angularAcceleration; }
|
Q_INVOKABLE glm::vec3 getAngularAcceleration() const { return _angularAcceleration; }
|
||||||
|
@ -184,8 +183,6 @@ protected:
|
||||||
QVector<Model*> _attachmentModels;
|
QVector<Model*> _attachmentModels;
|
||||||
float _bodyYawDelta;
|
float _bodyYawDelta;
|
||||||
|
|
||||||
glm::vec3 _velocity;
|
|
||||||
|
|
||||||
// These position histories and derivatives are in the world-frame.
|
// These position histories and derivatives are in the world-frame.
|
||||||
// The derivatives are the MEASURED results of all external and internal forces
|
// The derivatives are the MEASURED results of all external and internal forces
|
||||||
// and are therefore READ-ONLY --> motion control of the Avatar is NOT obtained
|
// and are therefore READ-ONLY --> motion control of the Avatar is NOT obtained
|
||||||
|
|
|
@ -181,8 +181,8 @@ void MyAvatar::simulate(float deltaTime) {
|
||||||
{
|
{
|
||||||
PerformanceTimer perfTimer("transform");
|
PerformanceTimer perfTimer("transform");
|
||||||
updateOrientation(deltaTime);
|
updateOrientation(deltaTime);
|
||||||
if (_enablePhysics) {
|
if (isPhysicsEnabled()) {
|
||||||
updatePhysicsPosition(deltaTime);
|
updatePositionWithPhysics(deltaTime);
|
||||||
} else {
|
} else {
|
||||||
updatePosition(deltaTime);
|
updatePosition(deltaTime);
|
||||||
}
|
}
|
||||||
|
@ -1396,21 +1396,25 @@ void MyAvatar::updatePosition(float deltaTime) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MyAvatar::updatePhysicsPosition(float deltaTime) {
|
void MyAvatar::updatePositionWithPhysics(float deltaTime) {
|
||||||
glm::vec3 velocity = _velocity;
|
// bool pushingUp = (_driveKeys[UP] - _driveKeys[DOWN] > 0.0f) || _scriptedMotorVelocity.y > 0.0f;
|
||||||
|
|
||||||
bool pushingUp = (_driveKeys[UP] - _driveKeys[DOWN] > 0.0f) || _scriptedMotorVelocity.y > 0.0f;
|
|
||||||
|
|
||||||
|
// rotate velocity into camera frame
|
||||||
glm::quat rotation = getHead()->getCameraOrientation();
|
glm::quat rotation = getHead()->getCameraOrientation();
|
||||||
glm::vec3 localVelocity = glm::inverse(rotation) * velocity;
|
glm::vec3 localVelocity = glm::inverse(rotation) * _velocity;
|
||||||
|
|
||||||
bool hasFloor = false;
|
bool hasFloor = false;
|
||||||
glm::vec3 newLocalVelocity = applyKeyboardMotor(deltaTime, localVelocity, hasFloor);
|
glm::vec3 newLocalVelocity = applyKeyboardMotor(deltaTime, localVelocity, hasFloor);
|
||||||
newLocalVelocity = applyScriptedMotor(deltaTime, newLocalVelocity);
|
newLocalVelocity = applyScriptedMotor(deltaTime, newLocalVelocity);
|
||||||
|
|
||||||
// rotate back into world-frame
|
// cap avatar speed
|
||||||
velocity = rotation * newLocalVelocity;
|
float speed = glm::length(_velocity);
|
||||||
|
if (speed > MAX_AVATAR_SPEED) {
|
||||||
|
_velocity *= MAX_AVATAR_SPEED / speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// rotate back into world-frame
|
||||||
|
_velocity = rotation * newLocalVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -166,8 +166,6 @@ public slots:
|
||||||
glm::vec3 getThrust() { return _thrust; };
|
glm::vec3 getThrust() { return _thrust; };
|
||||||
void setThrust(glm::vec3 newThrust) { _thrust = newThrust; }
|
void setThrust(glm::vec3 newThrust) { _thrust = newThrust; }
|
||||||
|
|
||||||
void setVelocity(const glm::vec3 velocity) { _velocity = velocity; }
|
|
||||||
|
|
||||||
void updateMotionBehavior();
|
void updateMotionBehavior();
|
||||||
void onToggleRagdoll();
|
void onToggleRagdoll();
|
||||||
|
|
||||||
|
@ -235,7 +233,7 @@ private:
|
||||||
glm::vec3 applyKeyboardMotor(float deltaTime, const glm::vec3& velocity, bool walkingOnFloor);
|
glm::vec3 applyKeyboardMotor(float deltaTime, const glm::vec3& velocity, bool walkingOnFloor);
|
||||||
glm::vec3 applyScriptedMotor(float deltaTime, const glm::vec3& velocity);
|
glm::vec3 applyScriptedMotor(float deltaTime, const glm::vec3& velocity);
|
||||||
void updatePosition(float deltaTime);
|
void updatePosition(float deltaTime);
|
||||||
void updatePhysicsPosition(float deltaTime);
|
void updatePositionWithPhysics(float deltaTime);
|
||||||
void updateCollisionWithAvatars(float deltaTime);
|
void updateCollisionWithAvatars(float deltaTime);
|
||||||
void updateCollisionWithEnvironment(float deltaTime, float radius);
|
void updateCollisionWithEnvironment(float deltaTime, float radius);
|
||||||
void updateCollisionWithVoxels(float deltaTime, float radius);
|
void updateCollisionWithVoxels(float deltaTime, float radius);
|
||||||
|
|
|
@ -55,7 +55,8 @@ AvatarData::AvatarData() :
|
||||||
_billboard(),
|
_billboard(),
|
||||||
_errorLogExpiry(0),
|
_errorLogExpiry(0),
|
||||||
_owningAvatarMixer(),
|
_owningAvatarMixer(),
|
||||||
_lastUpdateTimer()
|
_lastUpdateTimer(),
|
||||||
|
_velocity(0.0f)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,6 +311,8 @@ public:
|
||||||
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
bool tryLockForWrite() { return _lock.tryLockForWrite(); }
|
||||||
void unlock() { _lock.unlock(); }
|
void unlock() { _lock.unlock(); }
|
||||||
|
|
||||||
|
void setVelocity(const glm::vec3 velocity) { _velocity = velocity; }
|
||||||
|
Q_INVOKABLE glm::vec3 getVelocity() const { return _velocity; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void sendAvatarDataPacket();
|
void sendAvatarDataPacket();
|
||||||
|
@ -401,6 +403,8 @@ protected:
|
||||||
virtual void updateJointMappings();
|
virtual void updateJointMappings();
|
||||||
void changeReferential(Referential* ref);
|
void changeReferential(Referential* ref);
|
||||||
|
|
||||||
|
glm::vec3 _velocity;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// privatize the copy constructor and assignment operator so they cannot be called
|
// privatize the copy constructor and assignment operator so they cannot be called
|
||||||
AvatarData(const AvatarData&);
|
AvatarData(const AvatarData&);
|
||||||
|
|
|
@ -284,6 +284,7 @@ void PhysicsEngine::stepSimulation() {
|
||||||
if (_avatarData->isPhysicsEnabled()) {
|
if (_avatarData->isPhysicsEnabled()) {
|
||||||
_avatarGhostObject->setWorldTransform(btTransform(glmToBullet(_avatarData->getOrientation()),
|
_avatarGhostObject->setWorldTransform(btTransform(glmToBullet(_avatarData->getOrientation()),
|
||||||
glmToBullet(_avatarData->getPosition())));
|
glmToBullet(_avatarData->getPosition())));
|
||||||
|
_characterController->setWalkDirection(glmToBullet(_avatarData->getVelocity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const int MAX_NUM_SUBSTEPS = 4;
|
const int MAX_NUM_SUBSTEPS = 4;
|
||||||
|
@ -364,7 +365,7 @@ void PhysicsEngine::computeCollisionEvents() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
// avatar collisions
|
// avatar collisions
|
||||||
btManifoldArray manifoldArray;
|
btManifoldArray manifoldArray;
|
||||||
btBroadphasePairArray& pairArray = _avatarGhostObject->getOverlappingPairCache()->getOverlappingPairArray();
|
btBroadphasePairArray& pairArray = _avatarGhostObject->getOverlappingPairCache()->getOverlappingPairArray();
|
||||||
|
@ -399,7 +400,7 @@ void PhysicsEngine::computeCollisionEvents() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -667,15 +668,3 @@ void PhysicsEngine::setAvatarData(AvatarData *avatarData) {
|
||||||
btGhostPairCallback* ghostPairCallback = new btGhostPairCallback();
|
btGhostPairCallback* ghostPairCallback = new btGhostPairCallback();
|
||||||
_dynamicsWorld->getPairCache()->setInternalGhostPairCallback(ghostPairCallback);
|
_dynamicsWorld->getPairCache()->setInternalGhostPairCallback(ghostPairCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// void PhysicsEngine::setAvatarMotion() {
|
|
||||||
/*
|
|
||||||
float dt = getDeltaTimeMicroseconds() * 0.000001f;
|
|
||||||
btVector3 walkDirection = btVector3(0.0, 0.0, 0.0);
|
|
||||||
btScalar walkVelocity = btScalar(1.1) * 4.0; // 4 km/h -> 1.1 m/s
|
|
||||||
btScalar walkSpeed = walkVelocity * dt;
|
|
||||||
|
|
||||||
_characterController->setWalkDirection(walkDirection*walkSpeed);
|
|
||||||
*/
|
|
||||||
// }
|
|
||||||
|
|
Loading…
Reference in a new issue