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,
nodeIDIgnored);
qDebug("[DEBUG] toggleFollowMode() %d\n", leadingAvatar);
_myAvatar.follow(leadingAvatar);
}

View file

@ -404,6 +404,32 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
_thrust += _scale * THRUST_JUMP * up;
_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
if (transmitter) {
@ -448,9 +474,15 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
}
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) {
@ -481,6 +513,13 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
if (isMyAvatar()) {
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
glm::vec3 oldVelocity = getVelocity();
@ -687,7 +726,9 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
_head.setScale(_scale);
_head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
_head.simulate(deltaTime, isMyAvatar());
// use speed and angular velocity to determine walking vs. standing
if (_speed + fabs(_bodyYawDelta) > 0.2) {
_mode = AVATAR_MODE_WALKING;

View file

@ -253,8 +253,10 @@ private:
glm::vec3 _lastCollisionPosition;
bool _speedBrakes;
bool _isThrustOn;
Avatar* _leadingAvatar;
float _stringLength;
AvatarVoxelSystem _voxels;
// private methods...