Avatar can follow but don't look at the same point for the moment

This commit is contained in:
atlante45 2013-07-25 16:14:47 -07:00
parent 68194f2037
commit f3c87b81ec
3 changed files with 47 additions and 5 deletions

View file

@ -3421,7 +3421,6 @@ void Application::toggleFollowMode() {
eyePositionIgnored, eyePositionIgnored,
nodeIDIgnored); nodeIDIgnored);
qDebug("[DEBUG] toggleFollowMode() %d\n", leadingAvatar);
_myAvatar.follow(leadingAvatar); _myAvatar.follow(leadingAvatar);
} }

View file

@ -405,6 +405,32 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
_shouldJump = false; _shouldJump = false;
} }
// Add thrusts from leading avatar
if (_leadingAvatar != NULL) {
glm::vec3 toTarget = _leadingAvatar->getPosition() - _position;
if (.5f < up.x * toTarget.x + up.y * toTarget.y + up.z * toTarget.z) {
_thrust += _scale * THRUST_MAG_UP * deltaTime * up;
} else if (up.x * toTarget.x + up.y * toTarget.y + up.z * toTarget.z < -.5f) {
_thrust -= _scale * THRUST_MAG_UP * deltaTime * up;
}
if (glm::length(_position - _leadingAvatar->getPosition()) > _scale * _stringLength) {
_thrust += _scale * THRUST_MAG_FWD * deltaTime * front;
} else {
toTarget = _leadingAvatar->getHead().getLookAtPosition();
}
float yawAngle = angleBetween(front, glm::vec3(toTarget.x, 0.f, toTarget.z));
if (yawAngle < -10.f || 10.f < yawAngle){
if (right.x * toTarget.x + right.y * toTarget.y + right.z * toTarget.z > 0) {
_bodyYawDelta -= YAW_MAG * deltaTime;
} else {
_bodyYawDelta += YAW_MAG * deltaTime;
}
}
}
// Add thrusts from Transmitter // Add thrusts from Transmitter
if (transmitter) { if (transmitter) {
transmitter->checkForLostTransmitter(); transmitter->checkForLostTransmitter();
@ -448,9 +474,15 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
} }
void Avatar::follow(Avatar* leadingAvatar) { void Avatar::follow(Avatar* leadingAvatar) {
_leadingAvatar = leadingAvatar; const float MAX_STRING_LENGTH = 2;
qDebug("[DEBUG] %d\n", _leadingAvatar); _leadingAvatar = leadingAvatar;
if (_leadingAvatar != NULL) {
_stringLength = glm::length(_position - _leadingAvatar->getPosition()) / _scale;
if (_stringLength > MAX_STRING_LENGTH) {
_stringLength = MAX_STRING_LENGTH;
}
}
} }
void Avatar::simulate(float deltaTime, Transmitter* transmitter) { void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
@ -482,6 +514,13 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
updateThrust(deltaTime, transmitter); updateThrust(deltaTime, transmitter);
} }
// Ajust, scale, thrust and lookAt position when following an other avatar
if (isMyAvatar() && _leadingAvatar && _scale != _leadingAvatar->getScale()) {
float scale = 0.95f * _scale + 0.05f * _leadingAvatar->getScale();
setScale(scale);
Application::getInstance()->getCamera()->setScale(scale);
}
// copy velocity so we can use it later for acceleration // copy velocity so we can use it later for acceleration
glm::vec3 oldVelocity = getVelocity(); glm::vec3 oldVelocity = getVelocity();
@ -688,6 +727,8 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
_head.simulate(deltaTime, isMyAvatar()); _head.simulate(deltaTime, isMyAvatar());
// use speed and angular velocity to determine walking vs. standing // use speed and angular velocity to determine walking vs. standing
if (_speed + fabs(_bodyYawDelta) > 0.2) { if (_speed + fabs(_bodyYawDelta) > 0.2) {
_mode = AVATAR_MODE_WALKING; _mode = AVATAR_MODE_WALKING;

View file

@ -253,7 +253,9 @@ private:
glm::vec3 _lastCollisionPosition; glm::vec3 _lastCollisionPosition;
bool _speedBrakes; bool _speedBrakes;
bool _isThrustOn; bool _isThrustOn;
Avatar* _leadingAvatar; Avatar* _leadingAvatar;
float _stringLength;
AvatarVoxelSystem _voxels; AvatarVoxelSystem _voxels;