mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:48:09 +02:00
a few small fixes on the avatar springs
This commit is contained in:
parent
e638805bd7
commit
265fcc6095
4 changed files with 38 additions and 47 deletions
|
@ -1,9 +1,9 @@
|
||||||
//-----------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Created by Jeffrey Ventrella and added as a utility
|
// Created by Jeffrey Ventrella for High Fidelity.
|
||||||
// class for High Fidelity Code base, April 2013
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
//
|
//
|
||||||
//-----------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
@ -30,8 +30,9 @@ void Camera::update()
|
||||||
{
|
{
|
||||||
double radian = ( yaw / 180.0 ) * PIE;
|
double radian = ( yaw / 180.0 ) * PIE;
|
||||||
|
|
||||||
|
//these need to be checked to make sure they correspond to the cordinate system.
|
||||||
double x = distance * -sin( radian );
|
double x = distance * -sin( radian );
|
||||||
double z = distance * cos( radian );
|
double z = distance * cos( radian );
|
||||||
double y = up;
|
double y = up;
|
||||||
|
|
||||||
position = targetPosition + glm::vec3( x, y, z );
|
position = targetPosition + glm::vec3( x, y, z );
|
||||||
|
|
|
@ -378,18 +378,18 @@ void Head::simulate(float deltaTime) {
|
||||||
avatar.thrust -= up * THRUST_MAG;
|
avatar.thrust -= up * THRUST_MAG;
|
||||||
}
|
}
|
||||||
if (driveKeys[ROT_RIGHT]) {
|
if (driveKeys[ROT_RIGHT]) {
|
||||||
avatar.yawDelta -= YAW_MAG * deltaTime;
|
bodyYawDelta -= YAW_MAG * deltaTime;
|
||||||
}
|
}
|
||||||
if (driveKeys[ROT_LEFT]) {
|
if (driveKeys[ROT_LEFT]) {
|
||||||
avatar.yawDelta += YAW_MAG * deltaTime;
|
bodyYawDelta += YAW_MAG * deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
avatar.yaw += avatar.yawDelta * deltaTime;
|
bodyYaw += bodyYawDelta * deltaTime;
|
||||||
|
|
||||||
Yaw = avatar.yaw;
|
Yaw = bodyYaw;
|
||||||
|
|
||||||
const float TEST_YAW_DECAY = 5.0;
|
const float TEST_YAW_DECAY = 5.0;
|
||||||
avatar.yawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime );
|
bodyYawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime );
|
||||||
|
|
||||||
avatar.velocity += glm::dvec3( avatar.thrust * deltaTime );
|
avatar.velocity += glm::dvec3( avatar.thrust * deltaTime );
|
||||||
|
|
||||||
|
@ -633,7 +633,7 @@ void Head::renderHead( int faceToFace, int isMine ) {
|
||||||
|
|
||||||
//glRotatef(Yaw, 0, 1, 0);
|
//glRotatef(Yaw, 0, 1, 0);
|
||||||
|
|
||||||
glRotatef( avatar.yaw, 0, 1, 0);
|
glRotatef( bodyYaw, 0, 1, 0);
|
||||||
|
|
||||||
//hand->render(1);
|
//hand->render(1);
|
||||||
|
|
||||||
|
@ -789,11 +789,11 @@ void Head::initializeAvatar() {
|
||||||
|
|
||||||
closestOtherAvatar = 0;
|
closestOtherAvatar = 0;
|
||||||
|
|
||||||
avatar.yaw = -90.0;
|
bodyYaw = -90.0;
|
||||||
avatar.pitch = 0.0;
|
bodyPitch = 0.0;
|
||||||
avatar.roll = 0.0;
|
bodyRoll = 0.0;
|
||||||
|
|
||||||
avatar.yawDelta = 0.0;
|
bodyYawDelta = 0.0;
|
||||||
|
|
||||||
for (int b=0; b<NUM_AVATAR_BONES; b++) {
|
for (int b=0; b<NUM_AVATAR_BONES; b++) {
|
||||||
avatar.bone[b].position = glm::vec3( 0.0, 0.0, 0.0 );
|
avatar.bone[b].position = glm::vec3( 0.0, 0.0, 0.0 );
|
||||||
|
@ -902,12 +902,13 @@ void Head::calculateBoneLengths() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Head::updateAvatarSkeleton() {
|
void Head::updateAvatarSkeleton() {
|
||||||
//----------------------------------
|
//----------------------------------
|
||||||
// rotate...
|
// rotate...
|
||||||
//----------------------------------
|
//----------------------------------
|
||||||
avatar.orientation.setToIdentity();
|
avatar.orientation.setToIdentity();
|
||||||
avatar.orientation.yaw( avatar.yaw );
|
avatar.orientation.yaw( bodyYaw );
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
// calculate positions of all bones by traversing the skeleton tree:
|
// calculate positions of all bones by traversing the skeleton tree:
|
||||||
|
@ -947,9 +948,6 @@ void Head::updateAvatarSprings( float deltaTime ) {
|
||||||
if ( avatar.bone[b].parent == AVATAR_BONE_NULL ) {
|
if ( avatar.bone[b].parent == AVATAR_BONE_NULL ) {
|
||||||
springVector -= position;
|
springVector -= position;
|
||||||
}
|
}
|
||||||
else if ( avatar.bone[b].parent == AVATAR_BONE_PELVIS_SPINE ) {
|
|
||||||
springVector -= position;
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
springVector -= avatar.bone[ avatar.bone[b].parent ].springyPosition;
|
springVector -= avatar.bone[ avatar.bone[b].parent ].springyPosition;
|
||||||
}
|
}
|
||||||
|
@ -967,7 +965,6 @@ void Head::updateAvatarSprings( float deltaTime ) {
|
||||||
|
|
||||||
avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * springToBodyTightness * deltaTime;
|
avatar.bone[b].springyVelocity += ( avatar.bone[b].position - avatar.bone[b].springyPosition ) * springToBodyTightness * deltaTime;
|
||||||
|
|
||||||
|
|
||||||
float decay = 1.0 - springVelocityDecay * deltaTime;
|
float decay = 1.0 - springVelocityDecay * deltaTime;
|
||||||
|
|
||||||
if ( decay > 0.0 ) {
|
if ( decay > 0.0 ) {
|
||||||
|
@ -982,7 +979,7 @@ void Head::updateAvatarSprings( float deltaTime ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
float Head::getBodyYaw() {
|
float Head::getBodyYaw() {
|
||||||
return avatar.yaw;
|
return bodyYaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 Head::getHeadLookatDirection() {
|
glm::vec3 Head::getHeadLookatDirection() {
|
||||||
|
@ -1035,14 +1032,10 @@ glm::vec3 Head::getBodyPosition() {
|
||||||
void Head::updateHandMovement() {
|
void Head::updateHandMovement() {
|
||||||
glm::vec3 transformedHandMovement;
|
glm::vec3 transformedHandMovement;
|
||||||
|
|
||||||
|
transformedHandMovement
|
||||||
transformedHandMovement.x = -glm::dot( movedHandOffset, avatar.orientation.getRight () );
|
= avatar.orientation.getRight() * -movedHandOffset.x
|
||||||
transformedHandMovement.y = -glm::dot( movedHandOffset, avatar.orientation.getUp () );
|
+ avatar.orientation.getUp() * -movedHandOffset.y
|
||||||
transformedHandMovement.z = -glm::dot( movedHandOffset, avatar.orientation.getFront () );
|
+ avatar.orientation.getFront() * -movedHandOffset.y * 0.4;
|
||||||
|
|
||||||
|
|
||||||
//transformedHandMovement = glm::vec3( 0.0f, 0.0f, 0.0f );
|
|
||||||
|
|
||||||
|
|
||||||
//if holding hands, add a pull to the hand...
|
//if holding hands, add a pull to the hand...
|
||||||
if ( usingSprings ) {
|
if ( usingSprings ) {
|
||||||
|
@ -1056,7 +1049,6 @@ void Head::updateHandMovement() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement;
|
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement;
|
||||||
glm::vec3 armVector = avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
glm::vec3 armVector = avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position;
|
||||||
armVector -= avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
armVector -= avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||||
|
@ -1068,14 +1060,14 @@ void Head::updateHandMovement() {
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------
|
||||||
// if right hand is being dragged beyond maximum arm length...
|
// if right hand is being dragged beyond maximum arm length...
|
||||||
//-------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------
|
||||||
if ( distance > avatar.maxArmLength ) {
|
if ( distance > avatar.maxArmLength ) {
|
||||||
//-------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------
|
||||||
// reset right hand to be constrained to maximum arm length
|
// reset right hand to be constrained to maximum arm length
|
||||||
//-------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------
|
||||||
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
avatar.bone[ AVATAR_BONE_RIGHT_HAND ].position = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||||
glm::vec3 armNormal = armVector / distance;
|
glm::vec3 armNormal = armVector / distance;
|
||||||
armVector = armNormal * (float)avatar.maxArmLength;
|
armVector = armNormal * avatar.maxArmLength;
|
||||||
distance = avatar.maxArmLength;
|
distance = avatar.maxArmLength;
|
||||||
glm::vec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
glm::vec3 constrainedPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||||
constrainedPosition += armVector;
|
constrainedPosition += armVector;
|
||||||
|
@ -1087,8 +1079,8 @@ void Head::updateHandMovement() {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
glm::vec3 newElbowPosition = avatar.bone[ AVATAR_BONE_RIGHT_SHOULDER ].position;
|
||||||
newElbowPosition += armVector * (float)ONE_HALF;
|
newElbowPosition += armVector * (float)ONE_HALF;
|
||||||
glm::vec3 perpendicular = glm::vec3( -armVector.y, armVector.x, armVector.z );
|
glm::vec3 perpendicular = glm::cross( avatar.orientation.getFront(), armVector );
|
||||||
newElbowPosition += perpendicular * (float)( ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF );
|
newElbowPosition += perpendicular * ( 1.0 - ( avatar.maxArmLength / distance ) ) * ONE_HALF;
|
||||||
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition;
|
avatar.bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -120,10 +120,6 @@ struct Avatar
|
||||||
{
|
{
|
||||||
glm::dvec3 velocity;
|
glm::dvec3 velocity;
|
||||||
glm::vec3 thrust;
|
glm::vec3 thrust;
|
||||||
float yaw;
|
|
||||||
float pitch;
|
|
||||||
float roll;
|
|
||||||
float yawDelta;
|
|
||||||
float maxArmLength;
|
float maxArmLength;
|
||||||
Orientation orientation;
|
Orientation orientation;
|
||||||
AvatarBone bone[ NUM_AVATAR_BONES ];
|
AvatarBone bone[ NUM_AVATAR_BONES ];
|
||||||
|
@ -236,8 +232,11 @@ class Head : public AgentData {
|
||||||
float browAudioLift;
|
float browAudioLift;
|
||||||
|
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
//glm::vec3 velocity;
|
|
||||||
//glm::vec3 thrust;
|
float bodyYaw;
|
||||||
|
float bodyPitch;
|
||||||
|
float bodyRoll;
|
||||||
|
float bodyYawDelta;
|
||||||
|
|
||||||
float closeEnoughToInteract;
|
float closeEnoughToInteract;
|
||||||
int closestOtherAvatar;
|
int closestOtherAvatar;
|
||||||
|
|
|
@ -1234,14 +1234,13 @@ void idle(void)
|
||||||
|
|
||||||
// Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time
|
// Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time
|
||||||
|
|
||||||
if (diffclock(&lastTimeIdle, &check) > IDLE_SIMULATE_MSECS)
|
if (diffclock(&lastTimeIdle, &check) > IDLE_SIMULATE_MSECS) {
|
||||||
{
|
|
||||||
// If mouse is being dragged, update hand movement in the avatar
|
// If mouse is being dragged, update hand movement in the avatar
|
||||||
if ( mousePressed == 1 )
|
if ( mousePressed == 1 ) {
|
||||||
{
|
|
||||||
float xOffset = ( mouseX - mouseStartX ) / (double)WIDTH;
|
float xOffset = ( mouseX - mouseStartX ) / ( WIDTH * ONE_HALF );
|
||||||
float yOffset = ( mouseY - mouseStartY ) / (double)HEIGHT;
|
float yOffset = ( mouseY - mouseStartY ) / ( HEIGHT * ONE_HALF );
|
||||||
|
|
||||||
float leftRight = xOffset;
|
float leftRight = xOffset;
|
||||||
float downUp = yOffset;
|
float downUp = yOffset;
|
||||||
float backFront = 0.0;
|
float backFront = 0.0;
|
||||||
|
|
Loading…
Reference in a new issue