Style and spacing changes in MyAvatar/Avatar classes.

This commit is contained in:
LionTurtle 2013-08-21 16:32:06 -07:00
parent a6109d411b
commit e252d3b2ac
4 changed files with 423 additions and 480 deletions

View file

@ -27,39 +27,37 @@
using namespace std;
const bool BALLS_ON = false;
const bool USING_AVATAR_GRAVITY = true;
const glm::vec3 DEFAULT_UP_DIRECTION (0.0f, 1.0f, 0.0f);
const float YAW_MAG = 500.0;
const float MY_HAND_HOLDING_PULL = 0.2;
const float YOUR_HAND_HOLDING_PULL = 1.0;
const bool BALLS_ON = false;
const bool USING_AVATAR_GRAVITY = true;
const glm::vec3 DEFAULT_UP_DIRECTION(0.0f, 1.0f, 0.0f);
const float YAW_MAG = 500.0;
const float MY_HAND_HOLDING_PULL = 0.2;
const float YOUR_HAND_HOLDING_PULL = 1.0;
const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f;
const float BODY_SPRING_FORCE = 300.0f;
const float BODY_SPRING_DECAY = 16.0f;
const float COLLISION_RADIUS_SCALAR = 1.2; //pertains to avatar-to-avatar collisions
const float COLLISION_BALL_FORCE = 200.0; //pertains to avatar-to-avatar collisions
const float COLLISION_BODY_FORCE = 30.0; //pertains to avatar-to-avatar collisions
const float HEAD_ROTATION_SCALE = 0.70;
const float HEAD_ROLL_SCALE = 0.40;
const float HEAD_MAX_PITCH = 45;
const float HEAD_MIN_PITCH = -45;
const float HEAD_MAX_YAW = 85;
const float HEAD_MIN_YAW = -85;
const float PERIPERSONAL_RADIUS = 1.0f;
const float AVATAR_BRAKING_STRENGTH = 40.0f;
const float MOUSE_RAY_TOUCH_RANGE = 0.01f;
const float FLOATING_HEIGHT = 0.13f;
const bool USING_HEAD_LEAN = false;
const float LEAN_SENSITIVITY = 0.15;
const float LEAN_MAX = 0.45;
const float LEAN_AVERAGING = 10.0;
const float HEAD_RATE_MAX = 50.f;
const float SKIN_COLOR[] = {1.0, 0.84, 0.66};
const float DARK_SKIN_COLOR[] = {0.9, 0.78, 0.63};
const int NUM_BODY_CONE_SIDES = 9;
const float BODY_SPRING_FORCE = 300.0f;
const float BODY_SPRING_DECAY = 16.0f;
const float COLLISION_RADIUS_SCALAR = 1.2; // pertains to avatar-to-avatar collisions
const float COLLISION_BALL_FORCE = 200.0; // pertains to avatar-to-avatar collisions
const float COLLISION_BODY_FORCE = 30.0; // pertains to avatar-to-avatar collisions
const float HEAD_ROTATION_SCALE = 0.70;
const float HEAD_ROLL_SCALE = 0.40;
const float HEAD_MAX_PITCH = 45;
const float HEAD_MIN_PITCH = -45;
const float HEAD_MAX_YAW = 85;
const float HEAD_MIN_YAW = -85;
const float PERIPERSONAL_RADIUS = 1.0f;
const float AVATAR_BRAKING_STRENGTH = 40.0f;
const float MOUSE_RAY_TOUCH_RANGE = 0.01f;
const float FLOATING_HEIGHT = 0.13f;
const bool USING_HEAD_LEAN = false;
const float LEAN_SENSITIVITY = 0.15;
const float LEAN_MAX = 0.45;
const float LEAN_AVERAGING = 10.0;
const float HEAD_RATE_MAX = 50.f;
const float SKIN_COLOR[] = {1.0, 0.84, 0.66};
const float DARK_SKIN_COLOR[] = {0.9, 0.78, 0.63};
const int NUM_BODY_CONE_SIDES = 9;
const bool usingBigSphereCollisionTest = true;
const float chatMessageScale = 0.0015;
const float chatMessageHeight = 0.20;
@ -79,10 +77,7 @@ void Avatar::sendAvatarVoxelURLMessage(const QUrl& url) {
message.append((const char*)&ownerID, sizeof(ownerID));
message.append(url.toEncoded());
Application::controlledBroadcastToNodes((unsigned char*)message.data(),
message.size(),
&NODE_TYPE_AVATAR_MIXER,
1);
Application::controlledBroadcastToNodes((unsigned char*)message.data(), message.size(), &NODE_TYPE_AVATAR_MIXER, 1);
}
Avatar::Avatar(Node* owningNode) :
@ -120,12 +115,12 @@ Avatar::Avatar(Node* owningNode) :
initializeBodyBalls();
_height = _skeleton.getHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius + _bodyBall[ BODY_BALL_HEAD_BASE ].radius;
_height = _skeleton.getHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius + _bodyBall[BODY_BALL_HEAD_BASE].radius;
_maxArmLength = _skeleton.getArmLength();
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
_pelvisToHeadLength = _skeleton.getPelvisToHeadLength();
_maxArmLength = _skeleton.getArmLength();
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius;
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius;
_pelvisToHeadLength = _skeleton.getPelvisToHeadLength();
_avatarTouch.setReachableRadius(PERIPERSONAL_RADIUS);
@ -142,140 +137,119 @@ void Avatar::initializeBodyBalls() {
_ballSpringsInitialized = false; //this gets set to true on the first update pass...
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
_bodyBall[b].parentJoint = AVATAR_JOINT_NULL;
_bodyBall[b].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[b].position = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[b].velocity = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[b].radius = 0.0;
_bodyBall[b].touchForce = 0.0;
_bodyBall[b].isCollidable = true;
_bodyBall[b].parentJoint = AVATAR_JOINT_NULL;
_bodyBall[b].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[b].position = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[b].velocity = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[b].radius = 0.0;
_bodyBall[b].touchForce = 0.0;
_bodyBall[b].isCollidable = true;
_bodyBall[b].jointTightness = BODY_SPRING_DEFAULT_TIGHTNESS;
}
// specify the radius of each ball
_bodyBall[ BODY_BALL_PELVIS ].radius = BODY_BALL_RADIUS_PELVIS;
_bodyBall[ BODY_BALL_TORSO ].radius = BODY_BALL_RADIUS_TORSO;
_bodyBall[ BODY_BALL_CHEST ].radius = BODY_BALL_RADIUS_CHEST;
_bodyBall[ BODY_BALL_NECK_BASE ].radius = BODY_BALL_RADIUS_NECK_BASE;
_bodyBall[ BODY_BALL_HEAD_BASE ].radius = BODY_BALL_RADIUS_HEAD_BASE;
_bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = BODY_BALL_RADIUS_LEFT_COLLAR;
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = BODY_BALL_RADIUS_LEFT_SHOULDER;
_bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = BODY_BALL_RADIUS_LEFT_ELBOW;
_bodyBall[ BODY_BALL_LEFT_WRIST ].radius = BODY_BALL_RADIUS_LEFT_WRIST;
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = BODY_BALL_RADIUS_LEFT_FINGERTIPS;
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = BODY_BALL_RADIUS_RIGHT_COLLAR;
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = BODY_BALL_RADIUS_RIGHT_SHOULDER;
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = BODY_BALL_RADIUS_RIGHT_ELBOW;
_bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = BODY_BALL_RADIUS_RIGHT_WRIST;
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
_bodyBall[ BODY_BALL_LEFT_HIP ].radius = BODY_BALL_RADIUS_LEFT_HIP;
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].radius = BODY_BALL_RADIUS_LEFT_MID_THIGH;
_bodyBall[ BODY_BALL_LEFT_KNEE ].radius = BODY_BALL_RADIUS_LEFT_KNEE;
_bodyBall[ BODY_BALL_LEFT_HEEL ].radius = BODY_BALL_RADIUS_LEFT_HEEL;
_bodyBall[ BODY_BALL_LEFT_TOES ].radius = BODY_BALL_RADIUS_LEFT_TOES;
_bodyBall[ BODY_BALL_RIGHT_HIP ].radius = BODY_BALL_RADIUS_RIGHT_HIP;
_bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = BODY_BALL_RADIUS_RIGHT_KNEE;
_bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = BODY_BALL_RADIUS_RIGHT_HEEL;
_bodyBall[ BODY_BALL_RIGHT_TOES ].radius = BODY_BALL_RADIUS_RIGHT_TOES;
_bodyBall[BODY_BALL_PELVIS].radius = BODY_BALL_RADIUS_PELVIS;
_bodyBall[BODY_BALL_TORSO].radius = BODY_BALL_RADIUS_TORSO;
_bodyBall[BODY_BALL_CHEST].radius = BODY_BALL_RADIUS_CHEST;
_bodyBall[BODY_BALL_NECK_BASE].radius = BODY_BALL_RADIUS_NECK_BASE;
_bodyBall[BODY_BALL_HEAD_BASE].radius = BODY_BALL_RADIUS_HEAD_BASE;
_bodyBall[BODY_BALL_LEFT_COLLAR].radius = BODY_BALL_RADIUS_LEFT_COLLAR;
_bodyBall[BODY_BALL_LEFT_SHOULDER].radius = BODY_BALL_RADIUS_LEFT_SHOULDER;
_bodyBall[BODY_BALL_LEFT_ELBOW].radius = BODY_BALL_RADIUS_LEFT_ELBOW;
_bodyBall[BODY_BALL_LEFT_WRIST].radius = BODY_BALL_RADIUS_LEFT_WRIST;
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].radius = BODY_BALL_RADIUS_LEFT_FINGERTIPS;
_bodyBall[BODY_BALL_RIGHT_COLLAR].radius = BODY_BALL_RADIUS_RIGHT_COLLAR;
_bodyBall[BODY_BALL_RIGHT_SHOULDER].radius = BODY_BALL_RADIUS_RIGHT_SHOULDER;
_bodyBall[BODY_BALL_RIGHT_ELBOW].radius = BODY_BALL_RADIUS_RIGHT_ELBOW;
_bodyBall[BODY_BALL_RIGHT_WRIST].radius = BODY_BALL_RADIUS_RIGHT_WRIST;
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].radius = BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
_bodyBall[BODY_BALL_LEFT_HIP].radius = BODY_BALL_RADIUS_LEFT_HIP;
_bodyBall[BODY_BALL_LEFT_KNEE].radius = BODY_BALL_RADIUS_LEFT_KNEE;
_bodyBall[BODY_BALL_LEFT_HEEL].radius = BODY_BALL_RADIUS_LEFT_HEEL;
_bodyBall[BODY_BALL_LEFT_TOES].radius = BODY_BALL_RADIUS_LEFT_TOES;
_bodyBall[BODY_BALL_RIGHT_HIP].radius = BODY_BALL_RADIUS_RIGHT_HIP;
_bodyBall[BODY_BALL_RIGHT_KNEE].radius = BODY_BALL_RADIUS_RIGHT_KNEE;
_bodyBall[BODY_BALL_RIGHT_HEEL].radius = BODY_BALL_RADIUS_RIGHT_HEEL;
_bodyBall[BODY_BALL_RIGHT_TOES].radius = BODY_BALL_RADIUS_RIGHT_TOES;
// specify the parent joint for each ball
_bodyBall[ BODY_BALL_PELVIS ].parentJoint = AVATAR_JOINT_PELVIS;
_bodyBall[ BODY_BALL_TORSO ].parentJoint = AVATAR_JOINT_TORSO;
_bodyBall[ BODY_BALL_CHEST ].parentJoint = AVATAR_JOINT_CHEST;
_bodyBall[ BODY_BALL_NECK_BASE ].parentJoint = AVATAR_JOINT_NECK_BASE;
_bodyBall[ BODY_BALL_HEAD_BASE ].parentJoint = AVATAR_JOINT_HEAD_BASE;
_bodyBall[ BODY_BALL_HEAD_TOP ].parentJoint = AVATAR_JOINT_HEAD_TOP;
_bodyBall[ BODY_BALL_LEFT_COLLAR ].parentJoint = AVATAR_JOINT_LEFT_COLLAR;
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].parentJoint = AVATAR_JOINT_LEFT_SHOULDER;
_bodyBall[ BODY_BALL_LEFT_ELBOW ].parentJoint = AVATAR_JOINT_LEFT_ELBOW;
_bodyBall[ BODY_BALL_LEFT_WRIST ].parentJoint = AVATAR_JOINT_LEFT_WRIST;
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].parentJoint = AVATAR_JOINT_LEFT_FINGERTIPS;
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].parentJoint = AVATAR_JOINT_RIGHT_COLLAR;
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].parentJoint = AVATAR_JOINT_RIGHT_SHOULDER;
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].parentJoint = AVATAR_JOINT_RIGHT_ELBOW;
_bodyBall[ BODY_BALL_RIGHT_WRIST ].parentJoint = AVATAR_JOINT_RIGHT_WRIST;
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].parentJoint = AVATAR_JOINT_RIGHT_FINGERTIPS;
_bodyBall[ BODY_BALL_LEFT_HIP ].parentJoint = AVATAR_JOINT_LEFT_HIP;
_bodyBall[ BODY_BALL_LEFT_KNEE ].parentJoint = AVATAR_JOINT_LEFT_KNEE;
_bodyBall[ BODY_BALL_LEFT_HEEL ].parentJoint = AVATAR_JOINT_LEFT_HEEL;
_bodyBall[ BODY_BALL_LEFT_TOES ].parentJoint = AVATAR_JOINT_LEFT_TOES;
_bodyBall[ BODY_BALL_RIGHT_HIP ].parentJoint = AVATAR_JOINT_RIGHT_HIP;
_bodyBall[ BODY_BALL_RIGHT_KNEE ].parentJoint = AVATAR_JOINT_RIGHT_KNEE;
_bodyBall[ BODY_BALL_RIGHT_HEEL ].parentJoint = AVATAR_JOINT_RIGHT_HEEL;
_bodyBall[ BODY_BALL_RIGHT_TOES ].parentJoint = AVATAR_JOINT_RIGHT_TOES;
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].parentJoint = AVATAR_JOINT_LEFT_HIP;
_bodyBall[BODY_BALL_PELVIS].parentJoint = AVATAR_JOINT_PELVIS;
_bodyBall[BODY_BALL_TORSO].parentJoint = AVATAR_JOINT_TORSO;
_bodyBall[BODY_BALL_CHEST].parentJoint = AVATAR_JOINT_CHEST;
_bodyBall[BODY_BALL_NECK_BASE].parentJoint = AVATAR_JOINT_NECK_BASE;
_bodyBall[BODY_BALL_HEAD_BASE].parentJoint = AVATAR_JOINT_HEAD_BASE;
_bodyBall[BODY_BALL_HEAD_TOP].parentJoint = AVATAR_JOINT_HEAD_TOP;
_bodyBall[BODY_BALL_LEFT_COLLAR].parentJoint = AVATAR_JOINT_LEFT_COLLAR;
_bodyBall[BODY_BALL_LEFT_SHOULDER].parentJoint = AVATAR_JOINT_LEFT_SHOULDER;
_bodyBall[BODY_BALL_LEFT_ELBOW].parentJoint = AVATAR_JOINT_LEFT_ELBOW;
_bodyBall[BODY_BALL_LEFT_WRIST].parentJoint = AVATAR_JOINT_LEFT_WRIST;
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].parentJoint = AVATAR_JOINT_LEFT_FINGERTIPS;
_bodyBall[BODY_BALL_RIGHT_COLLAR].parentJoint = AVATAR_JOINT_RIGHT_COLLAR;
_bodyBall[BODY_BALL_RIGHT_SHOULDER].parentJoint = AVATAR_JOINT_RIGHT_SHOULDER;
_bodyBall[BODY_BALL_RIGHT_ELBOW].parentJoint = AVATAR_JOINT_RIGHT_ELBOW;
_bodyBall[BODY_BALL_RIGHT_WRIST].parentJoint = AVATAR_JOINT_RIGHT_WRIST;
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].parentJoint = AVATAR_JOINT_RIGHT_FINGERTIPS;
_bodyBall[BODY_BALL_LEFT_HIP].parentJoint = AVATAR_JOINT_LEFT_HIP;
_bodyBall[BODY_BALL_LEFT_KNEE].parentJoint = AVATAR_JOINT_LEFT_KNEE;
_bodyBall[BODY_BALL_LEFT_HEEL].parentJoint = AVATAR_JOINT_LEFT_HEEL;
_bodyBall[BODY_BALL_LEFT_TOES].parentJoint = AVATAR_JOINT_LEFT_TOES;
_bodyBall[BODY_BALL_RIGHT_HIP].parentJoint = AVATAR_JOINT_RIGHT_HIP;
_bodyBall[BODY_BALL_RIGHT_KNEE].parentJoint = AVATAR_JOINT_RIGHT_KNEE;
_bodyBall[BODY_BALL_RIGHT_HEEL].parentJoint = AVATAR_JOINT_RIGHT_HEEL;
_bodyBall[BODY_BALL_RIGHT_TOES].parentJoint = AVATAR_JOINT_RIGHT_TOES;
// specify the parent offset for each ball
_bodyBall[ BODY_BALL_PELVIS ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_TORSO ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_CHEST ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_NECK_BASE ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_HEAD_BASE ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_HEAD_TOP ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_LEFT_COLLAR ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_LEFT_ELBOW ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_LEFT_WRIST ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_RIGHT_WRIST ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_LEFT_HIP ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_LEFT_KNEE ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_LEFT_HEEL ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_LEFT_TOES ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_RIGHT_HIP ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_RIGHT_KNEE ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_RIGHT_HEEL ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[ BODY_BALL_RIGHT_TOES ].parentOffset = glm::vec3(0.0, 0.0, 0.0);
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].parentOffset = glm::vec3(-0.1, -0.1, 0.0);
_bodyBall[BODY_BALL_PELVIS].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_TORSO].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_CHEST].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_NECK_BASE].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_HEAD_BASE].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_HEAD_TOP].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_LEFT_COLLAR].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_LEFT_SHOULDER].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_LEFT_ELBOW].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_LEFT_WRIST].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_RIGHT_COLLAR].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_RIGHT_SHOULDER].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_RIGHT_ELBOW].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_RIGHT_WRIST].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_LEFT_HIP].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_LEFT_KNEE].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_LEFT_HEEL].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_LEFT_TOES].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_RIGHT_HIP].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_RIGHT_KNEE].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_RIGHT_HEEL].parentOffset = glm::vec3(0.0, 0.0, 0.0);
_bodyBall[BODY_BALL_RIGHT_TOES].parentOffset = glm::vec3(0.0, 0.0, 0.0);
// specify the parent BALL for each ball
_bodyBall[ BODY_BALL_PELVIS ].parentBall = BODY_BALL_NULL;
_bodyBall[ BODY_BALL_TORSO ].parentBall = BODY_BALL_PELVIS;
_bodyBall[ BODY_BALL_CHEST ].parentBall = BODY_BALL_TORSO;
_bodyBall[ BODY_BALL_NECK_BASE ].parentBall = BODY_BALL_CHEST;
_bodyBall[ BODY_BALL_HEAD_BASE ].parentBall = BODY_BALL_NECK_BASE;
_bodyBall[ BODY_BALL_HEAD_TOP ].parentBall = BODY_BALL_HEAD_BASE;
_bodyBall[ BODY_BALL_LEFT_COLLAR ].parentBall = BODY_BALL_CHEST;
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].parentBall = BODY_BALL_LEFT_COLLAR;
_bodyBall[ BODY_BALL_LEFT_ELBOW ].parentBall = BODY_BALL_LEFT_SHOULDER;
_bodyBall[ BODY_BALL_LEFT_WRIST ].parentBall = BODY_BALL_LEFT_ELBOW;
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].parentBall = BODY_BALL_LEFT_WRIST;
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].parentBall = BODY_BALL_CHEST;
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].parentBall = BODY_BALL_RIGHT_COLLAR;
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].parentBall = BODY_BALL_RIGHT_SHOULDER;
_bodyBall[ BODY_BALL_RIGHT_WRIST ].parentBall = BODY_BALL_RIGHT_ELBOW;
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].parentBall = BODY_BALL_RIGHT_WRIST;
_bodyBall[ BODY_BALL_LEFT_HIP ].parentBall = BODY_BALL_PELVIS;
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].parentBall = BODY_BALL_LEFT_HIP;
//_bodyBall[ BODY_BALL_LEFT_KNEE ].parentBall = BODY_BALL_LEFT_MID_THIGH;
_bodyBall[ BODY_BALL_LEFT_KNEE ].parentBall = BODY_BALL_LEFT_HIP;
_bodyBall[ BODY_BALL_LEFT_HEEL ].parentBall = BODY_BALL_LEFT_KNEE;
_bodyBall[ BODY_BALL_LEFT_TOES ].parentBall = BODY_BALL_LEFT_HEEL;
_bodyBall[ BODY_BALL_RIGHT_HIP ].parentBall = BODY_BALL_PELVIS;
_bodyBall[ BODY_BALL_RIGHT_KNEE ].parentBall = BODY_BALL_RIGHT_HIP;
_bodyBall[ BODY_BALL_RIGHT_HEEL ].parentBall = BODY_BALL_RIGHT_KNEE;
_bodyBall[ BODY_BALL_RIGHT_TOES ].parentBall = BODY_BALL_RIGHT_HEEL;
/*
// to aid in hand-shaking and hand-holding, the right hand is not collidable
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].isCollidable = false;
_bodyBall[ BODY_BALL_RIGHT_WRIST ].isCollidable = false;
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].isCollidable = false;
*/
_bodyBall[BODY_BALL_PELVIS].parentBall = BODY_BALL_NULL;
_bodyBall[BODY_BALL_TORSO].parentBall = BODY_BALL_PELVIS;
_bodyBall[BODY_BALL_CHEST].parentBall = BODY_BALL_TORSO;
_bodyBall[BODY_BALL_NECK_BASE].parentBall = BODY_BALL_CHEST;
_bodyBall[BODY_BALL_HEAD_BASE].parentBall = BODY_BALL_NECK_BASE;
_bodyBall[BODY_BALL_HEAD_TOP].parentBall = BODY_BALL_HEAD_BASE;
_bodyBall[BODY_BALL_LEFT_COLLAR].parentBall = BODY_BALL_CHEST;
_bodyBall[BODY_BALL_LEFT_SHOULDER].parentBall = BODY_BALL_LEFT_COLLAR;
_bodyBall[BODY_BALL_LEFT_ELBOW].parentBall = BODY_BALL_LEFT_SHOULDER;
_bodyBall[BODY_BALL_LEFT_WRIST].parentBall = BODY_BALL_LEFT_ELBOW;
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].parentBall = BODY_BALL_LEFT_WRIST;
_bodyBall[BODY_BALL_RIGHT_COLLAR].parentBall = BODY_BALL_CHEST;
_bodyBall[BODY_BALL_RIGHT_SHOULDER].parentBall = BODY_BALL_RIGHT_COLLAR;
_bodyBall[BODY_BALL_RIGHT_ELBOW].parentBall = BODY_BALL_RIGHT_SHOULDER;
_bodyBall[BODY_BALL_RIGHT_WRIST].parentBall = BODY_BALL_RIGHT_ELBOW;
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].parentBall = BODY_BALL_RIGHT_WRIST;
_bodyBall[BODY_BALL_LEFT_HIP].parentBall = BODY_BALL_PELVIS;
_bodyBall[BODY_BALL_LEFT_KNEE].parentBall = BODY_BALL_LEFT_HIP;
_bodyBall[BODY_BALL_LEFT_HEEL].parentBall = BODY_BALL_LEFT_KNEE;
_bodyBall[BODY_BALL_LEFT_TOES].parentBall = BODY_BALL_LEFT_HEEL;
_bodyBall[BODY_BALL_RIGHT_HIP].parentBall = BODY_BALL_PELVIS;
_bodyBall[BODY_BALL_RIGHT_KNEE].parentBall = BODY_BALL_RIGHT_HIP;
_bodyBall[BODY_BALL_RIGHT_HEEL].parentBall = BODY_BALL_RIGHT_KNEE;
_bodyBall[BODY_BALL_RIGHT_TOES].parentBall = BODY_BALL_RIGHT_HEEL;
}
Avatar::~Avatar() {
@ -364,12 +338,12 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCamer
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
glm::vec3 targetPosition
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
glm::vec3 parentTargetPosition
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
_bodyBall[b].springLength = glm::length(targetPosition - parentTargetPosition);
}
@ -400,26 +374,26 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCamer
right * _head.getLeanSideways() +
front * _head.getLeanForward();
_bodyBall[ BODY_BALL_TORSO ].position += headLean * 0.1f;
_bodyBall[ BODY_BALL_CHEST ].position += headLean * 0.4f;
_bodyBall[ BODY_BALL_NECK_BASE ].position += headLean * 0.7f;
_bodyBall[ BODY_BALL_HEAD_BASE ].position += headLean * 1.0f;
_bodyBall[BODY_BALL_TORSO].position += headLean * 0.1f;
_bodyBall[BODY_BALL_CHEST].position += headLean * 0.4f;
_bodyBall[BODY_BALL_NECK_BASE].position += headLean * 0.7f;
_bodyBall[BODY_BALL_HEAD_BASE].position += headLean * 1.0f;
_bodyBall[ BODY_BALL_LEFT_COLLAR ].position += headLean * 0.6f;
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].position += headLean * 0.6f;
_bodyBall[ BODY_BALL_LEFT_ELBOW ].position += headLean * 0.2f;
_bodyBall[ BODY_BALL_LEFT_WRIST ].position += headLean * 0.1f;
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].position += headLean * 0.0f;
_bodyBall[BODY_BALL_LEFT_COLLAR].position += headLean * 0.6f;
_bodyBall[BODY_BALL_LEFT_SHOULDER].position += headLean * 0.6f;
_bodyBall[BODY_BALL_LEFT_ELBOW].position += headLean * 0.2f;
_bodyBall[BODY_BALL_LEFT_WRIST].position += headLean * 0.1f;
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].position += headLean * 0.0f;
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].position += headLean * 0.6f;
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].position += headLean * 0.6f;
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].position += headLean * 0.2f;
_bodyBall[ BODY_BALL_RIGHT_WRIST ].position += headLean * 0.1f;
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].position += headLean * 0.0f;
_bodyBall[BODY_BALL_RIGHT_COLLAR].position += headLean * 0.6f;
_bodyBall[BODY_BALL_RIGHT_SHOULDER].position += headLean * 0.6f;
_bodyBall[BODY_BALL_RIGHT_ELBOW].position += headLean * 0.2f;
_bodyBall[BODY_BALL_RIGHT_WRIST].position += headLean * 0.1f;
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].position += headLean * 0.0f;
}
}
_head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
_head.setBodyRotation(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
_head.setPosition(_bodyBall[ BODY_BALL_HEAD_BASE ].position);
_head.setScale(_scale);
_head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
@ -441,7 +415,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCamer
}
void Avatar::setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction ) {
void Avatar::setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction) {
_mouseRayOrigin = origin;
_mouseRayDirection = direction;
}
@ -452,16 +426,16 @@ void Avatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMovem
// reset hand and arm positions according to hand movement
glm::vec3 right = orientation * IDENTITY_RIGHT;
glm::vec3 up = orientation * IDENTITY_UP;
glm::vec3 up = orientation * IDENTITY_UP;
glm::vec3 front = orientation * IDENTITY_FRONT;
if (enableHandMovement) {
glm::vec3 transformedHandMovement =
right * _movedHandOffset.x * 2.0f +
up * -_movedHandOffset.y * 2.0f +
right * _movedHandOffset.x * 2.0f +
up * -_movedHandOffset.y * 2.0f +
front * -_movedHandOffset.y * 2.0f;
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement;
_skeleton.joint[AVATAR_JOINT_RIGHT_FINGERTIPS].position += transformedHandMovement;
}
//constrain right arm length and re-adjust elbow position as it bends
@ -517,7 +491,7 @@ void Avatar::render(bool lookingInMirror, bool renderAvatarBalls) {
// render sphere when far away
const float MAX_ANGLE = 10.f;
glm::vec3 toTarget = _position - Application::getInstance()->getAvatar()->getPosition();
glm::vec3 delta = _height * (_head.getCameraOrientation() * IDENTITY_UP) / 2.f;
glm::vec3 delta = _height * (_head.getCameraOrientation() * IDENTITY_UP) / 2.f;
float angle = abs(angleBetween(toTarget + delta, toTarget - delta));
if (angle < MAX_ANGLE) {
@ -629,8 +603,8 @@ void Avatar::updateBodyBalls(float deltaTime) {
// apply tightness force - (causing ball position to be close to skeleton joint position)
glm::vec3 targetPosition
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
_bodyBall[b].velocity += (targetPosition - _bodyBall[b].position) * _bodyBall[b].jointTightness * deltaTime;
@ -642,13 +616,6 @@ void Avatar::updateBodyBalls(float deltaTime) {
_bodyBall[b].velocity = glm::vec3(0.0f, 0.0f, 0.0f);
}
/*
// apply forces from touch...
if (_bodyBall[b].touchForce > 0.0) {
_bodyBall[b].velocity += _mouseRayDirection * _bodyBall[b].touchForce * 0.7f;
}
*/
// update position by velocity...
_bodyBall[b].position += _bodyBall[b].velocity * deltaTime;
@ -768,27 +735,23 @@ void Avatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) {
// Render the cone connecting this ball to its parent
if (_bodyBall[b].parentBall != BODY_BALL_NULL) {
if ((b != BODY_BALL_HEAD_TOP )
&& (b != BODY_BALL_HEAD_BASE )
&& (b != BODY_BALL_PELVIS )
&& (b != BODY_BALL_TORSO )
&& (b != BODY_BALL_CHEST )
&& (b != BODY_BALL_LEFT_COLLAR )
&& (b != BODY_BALL_LEFT_SHOULDER )
&& (b != BODY_BALL_RIGHT_COLLAR )
&& (b != BODY_BALL_RIGHT_SHOULDER)) {
if ((b != BODY_BALL_HEAD_TOP)
&& (b != BODY_BALL_HEAD_BASE)
&& (b != BODY_BALL_PELVIS)
&& (b != BODY_BALL_TORSO)
&& (b != BODY_BALL_CHEST)
&& (b != BODY_BALL_LEFT_COLLAR)
&& (b != BODY_BALL_LEFT_SHOULDER)
&& (b != BODY_BALL_RIGHT_COLLAR)
&& (b != BODY_BALL_RIGHT_SHOULDER)) {
glColor3fv(DARK_SKIN_COLOR);
float r1 = _bodyBall[_bodyBall[b].parentBall ].radius * 0.8;
float r1 = _bodyBall[_bodyBall[b].parentBall].radius * 0.8;
float r2 = _bodyBall[b].radius * 0.8;
if (b == BODY_BALL_HEAD_BASE) {
r1 *= 0.5f;
}
renderJointConnectingCone
(
_bodyBall[_bodyBall[b].parentBall].position,
_bodyBall[b].position, r2, r2
);
renderJointConnectingCone(_bodyBall[_bodyBall[b].parentBall].position, _bodyBall[b].position, r2, r2);
}
}
}
@ -808,9 +771,9 @@ void Avatar::loadData(QSettings* settings) {
settings->beginGroup("Avatar");
// in case settings is corrupt or missing loadSetting() will check for NaN
_bodyYaw = loadSetting(settings, "bodyYaw" , 0.0f);
_bodyPitch = loadSetting(settings, "bodyPitch", 0.0f);
_bodyRoll = loadSetting(settings, "bodyRoll" , 0.0f);
_bodyYaw = loadSetting(settings, "bodyYaw", 0.0f);
_bodyPitch = loadSetting(settings, "bodyPitch", 0.0f);
_bodyRoll = loadSetting(settings, "bodyRoll", 0.0f);
_position.x = loadSetting(settings, "position_x", 0.0f);
_position.y = loadSetting(settings, "position_y", 0.0f);
_position.z = loadSetting(settings, "position_z", 0.0f);
@ -834,9 +797,9 @@ void Avatar::getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, gl
void Avatar::saveData(QSettings* set) {
set->beginGroup("Avatar");
set->setValue("bodyYaw", _bodyYaw);
set->setValue("bodyYaw", _bodyYaw);
set->setValue("bodyPitch", _bodyPitch);
set->setValue("bodyRoll", _bodyRoll);
set->setValue("bodyRoll", _bodyRoll);
set->setValue("position_x", _position.x);
set->setValue("position_y", _position.y);
@ -933,39 +896,36 @@ void Avatar::setScale(const float scale) {
_skeleton.setScale(_scale);
// specify the new radius of each ball
_bodyBall[ BODY_BALL_PELVIS ].radius = _scale * BODY_BALL_RADIUS_PELVIS;
_bodyBall[ BODY_BALL_TORSO ].radius = _scale * BODY_BALL_RADIUS_TORSO;
_bodyBall[ BODY_BALL_CHEST ].radius = _scale * BODY_BALL_RADIUS_CHEST;
_bodyBall[ BODY_BALL_NECK_BASE ].radius = _scale * BODY_BALL_RADIUS_NECK_BASE;
_bodyBall[ BODY_BALL_HEAD_BASE ].radius = _scale * BODY_BALL_RADIUS_HEAD_BASE;
_bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = _scale * BODY_BALL_RADIUS_LEFT_COLLAR;
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = _scale * BODY_BALL_RADIUS_LEFT_SHOULDER;
_bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = _scale * BODY_BALL_RADIUS_LEFT_ELBOW;
_bodyBall[ BODY_BALL_LEFT_WRIST ].radius = _scale * BODY_BALL_RADIUS_LEFT_WRIST;
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = _scale * BODY_BALL_RADIUS_LEFT_FINGERTIPS;
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = _scale * BODY_BALL_RADIUS_RIGHT_COLLAR;
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = _scale * BODY_BALL_RADIUS_RIGHT_SHOULDER;
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = _scale * BODY_BALL_RADIUS_RIGHT_ELBOW;
_bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = _scale * BODY_BALL_RADIUS_RIGHT_WRIST;
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = _scale * BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
_bodyBall[ BODY_BALL_LEFT_HIP ].radius = _scale * BODY_BALL_RADIUS_LEFT_HIP;
_bodyBall[BODY_BALL_PELVIS].radius = _scale * BODY_BALL_RADIUS_PELVIS;
_bodyBall[BODY_BALL_TORSO].radius = _scale * BODY_BALL_RADIUS_TORSO;
_bodyBall[BODY_BALL_CHEST].radius = _scale * BODY_BALL_RADIUS_CHEST;
_bodyBall[BODY_BALL_NECK_BASE].radius = _scale * BODY_BALL_RADIUS_NECK_BASE;
_bodyBall[BODY_BALL_HEAD_BASE].radius = _scale * BODY_BALL_RADIUS_HEAD_BASE;
_bodyBall[BODY_BALL_LEFT_COLLAR].radius = _scale * BODY_BALL_RADIUS_LEFT_COLLAR;
_bodyBall[BODY_BALL_LEFT_SHOULDER].radius = _scale * BODY_BALL_RADIUS_LEFT_SHOULDER;
_bodyBall[BODY_BALL_LEFT_ELBOW].radius = _scale * BODY_BALL_RADIUS_LEFT_ELBOW;
_bodyBall[BODY_BALL_LEFT_WRIST].radius = _scale * BODY_BALL_RADIUS_LEFT_WRIST;
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].radius = _scale * BODY_BALL_RADIUS_LEFT_FINGERTIPS;
_bodyBall[BODY_BALL_RIGHT_COLLAR].radius = _scale * BODY_BALL_RADIUS_RIGHT_COLLAR;
_bodyBall[BODY_BALL_RIGHT_SHOULDER].radius = _scale * BODY_BALL_RADIUS_RIGHT_SHOULDER;
_bodyBall[BODY_BALL_RIGHT_ELBOW].radius = _scale * BODY_BALL_RADIUS_RIGHT_ELBOW;
_bodyBall[BODY_BALL_RIGHT_WRIST].radius = _scale * BODY_BALL_RADIUS_RIGHT_WRIST;
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].radius = _scale * BODY_BALL_RADIUS_RIGHT_FINGERTIPS;
_bodyBall[BODY_BALL_LEFT_HIP].radius = _scale * BODY_BALL_RADIUS_LEFT_HIP;
_bodyBall[BODY_BALL_LEFT_KNEE].radius = _scale * BODY_BALL_RADIUS_LEFT_KNEE;
_bodyBall[BODY_BALL_LEFT_HEEL].radius = _scale * BODY_BALL_RADIUS_LEFT_HEEL;
_bodyBall[BODY_BALL_LEFT_TOES].radius = _scale * BODY_BALL_RADIUS_LEFT_TOES;
_bodyBall[BODY_BALL_RIGHT_HIP].radius = _scale * BODY_BALL_RADIUS_RIGHT_HIP;
_bodyBall[BODY_BALL_RIGHT_KNEE].radius = _scale * BODY_BALL_RADIUS_RIGHT_KNEE;
_bodyBall[BODY_BALL_RIGHT_HEEL].radius = _scale * BODY_BALL_RADIUS_RIGHT_HEEL;
_bodyBall[BODY_BALL_RIGHT_TOES].radius = _scale * BODY_BALL_RADIUS_RIGHT_TOES;
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].radius = _scale * BODY_BALL_RADIUS_LEFT_MID_THIGH;
_height = _skeleton.getHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius + _bodyBall[BODY_BALL_HEAD_BASE].radius;
_bodyBall[ BODY_BALL_LEFT_KNEE ].radius = _scale * BODY_BALL_RADIUS_LEFT_KNEE;
_bodyBall[ BODY_BALL_LEFT_HEEL ].radius = _scale * BODY_BALL_RADIUS_LEFT_HEEL;
_bodyBall[ BODY_BALL_LEFT_TOES ].radius = _scale * BODY_BALL_RADIUS_LEFT_TOES;
_bodyBall[ BODY_BALL_RIGHT_HIP ].radius = _scale * BODY_BALL_RADIUS_RIGHT_HIP;
_bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = _scale * BODY_BALL_RADIUS_RIGHT_KNEE;
_bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = _scale * BODY_BALL_RADIUS_RIGHT_HEEL;
_bodyBall[ BODY_BALL_RIGHT_TOES ].radius = _scale * BODY_BALL_RADIUS_RIGHT_TOES;
_height = _skeleton.getHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius + _bodyBall[ BODY_BALL_HEAD_BASE ].radius;
_maxArmLength = _skeleton.getArmLength();
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[ BODY_BALL_LEFT_HEEL ].radius;
_pelvisToHeadLength = _skeleton.getPelvisToHeadLength();
_maxArmLength = _skeleton.getArmLength();
_pelvisStandingHeight = _skeleton.getPelvisStandingHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius;
_pelvisFloatingHeight = _skeleton.getPelvisFloatingHeight() + _bodyBall[BODY_BALL_LEFT_HEEL].radius;
_pelvisToHeadLength = _skeleton.getPelvisToHeadLength();
_avatarTouch.setReachableRadius(_scale * PERIPERSONAL_RADIUS);
}

View file

@ -27,36 +27,36 @@
#include "world.h"
static const float MAX_SCALE = 1000.f;
static const float MIN_SCALE = .005f;
static const float SCALING_RATIO = .05f;
static const float SMOOTHING_RATIO = .05f; // 0 < ratio < 1
static const float MAX_SCALE = 1000.f;
static const float MIN_SCALE = .005f;
static const float SCALING_RATIO = .05f;
static const float SMOOTHING_RATIO = .05f; // 0 < ratio < 1
static const float RESCALING_TOLERANCE = .02f;
const float BODY_BALL_RADIUS_PELVIS = 0.07;
const float BODY_BALL_RADIUS_TORSO = 0.065;
const float BODY_BALL_RADIUS_CHEST = 0.08;
const float BODY_BALL_RADIUS_NECK_BASE = 0.03;
const float BODY_BALL_RADIUS_HEAD_BASE = 0.07;
const float BODY_BALL_RADIUS_LEFT_COLLAR = 0.04;
const float BODY_BALL_RADIUS_LEFT_SHOULDER = 0.03;
const float BODY_BALL_RADIUS_LEFT_ELBOW = 0.02;
const float BODY_BALL_RADIUS_LEFT_WRIST = 0.02;
const float BODY_BALL_RADIUS_LEFT_FINGERTIPS = 0.01;
const float BODY_BALL_RADIUS_RIGHT_COLLAR = 0.04;
const float BODY_BALL_RADIUS_RIGHT_SHOULDER = 0.03;
const float BODY_BALL_RADIUS_RIGHT_ELBOW = 0.02;
const float BODY_BALL_RADIUS_RIGHT_WRIST = 0.02;
const float BODY_BALL_RADIUS_PELVIS = 0.07;
const float BODY_BALL_RADIUS_TORSO = 0.065;
const float BODY_BALL_RADIUS_CHEST = 0.08;
const float BODY_BALL_RADIUS_NECK_BASE = 0.03;
const float BODY_BALL_RADIUS_HEAD_BASE = 0.07;
const float BODY_BALL_RADIUS_LEFT_COLLAR = 0.04;
const float BODY_BALL_RADIUS_LEFT_SHOULDER = 0.03;
const float BODY_BALL_RADIUS_LEFT_ELBOW = 0.02;
const float BODY_BALL_RADIUS_LEFT_WRIST = 0.02;
const float BODY_BALL_RADIUS_LEFT_FINGERTIPS = 0.01;
const float BODY_BALL_RADIUS_RIGHT_COLLAR = 0.04;
const float BODY_BALL_RADIUS_RIGHT_SHOULDER = 0.03;
const float BODY_BALL_RADIUS_RIGHT_ELBOW = 0.02;
const float BODY_BALL_RADIUS_RIGHT_WRIST = 0.02;
const float BODY_BALL_RADIUS_RIGHT_FINGERTIPS = 0.01;
const float BODY_BALL_RADIUS_LEFT_HIP = 0.04;
const float BODY_BALL_RADIUS_LEFT_MID_THIGH = 0.03;
const float BODY_BALL_RADIUS_LEFT_KNEE = 0.025;
const float BODY_BALL_RADIUS_LEFT_HEEL = 0.025;
const float BODY_BALL_RADIUS_LEFT_TOES = 0.025;
const float BODY_BALL_RADIUS_RIGHT_HIP = 0.04;
const float BODY_BALL_RADIUS_RIGHT_KNEE = 0.025;
const float BODY_BALL_RADIUS_RIGHT_HEEL = 0.025;
const float BODY_BALL_RADIUS_RIGHT_TOES = 0.025;
const float BODY_BALL_RADIUS_LEFT_HIP = 0.04;
const float BODY_BALL_RADIUS_LEFT_MID_THIGH = 0.03;
const float BODY_BALL_RADIUS_LEFT_KNEE = 0.025;
const float BODY_BALL_RADIUS_LEFT_HEEL = 0.025;
const float BODY_BALL_RADIUS_LEFT_TOES = 0.025;
const float BODY_BALL_RADIUS_RIGHT_HIP = 0.04;
const float BODY_BALL_RADIUS_RIGHT_KNEE = 0.025;
const float BODY_BALL_RADIUS_RIGHT_HEEL = 0.025;
const float BODY_BALL_RADIUS_RIGHT_TOES = 0.025;
extern const bool usingBigSphereCollisionTest;
@ -89,9 +89,6 @@ enum AvatarBodyBallID {
BODY_BALL_RIGHT_KNEE,
BODY_BALL_RIGHT_HEEL,
BODY_BALL_RIGHT_TOES,
//TEST!
//BODY_BALL_LEFT_MID_THIGH,
NUM_AVATAR_BODY_BALLS
};
@ -131,6 +128,7 @@ const glm::vec3 START_LOCATION(0.485f * TREE_SCALE, 0.f, 0.5f * TREE_SCALE);
class Avatar : public AvatarData {
Q_OBJECT
public:
static void sendAvatarVoxelURLMessage(const QUrl& url);
@ -143,28 +141,27 @@ public:
void render(bool lookingInMirror, bool renderAvatarBalls);
//setters
void setDisplayingLookatVectors(bool displayingLookatVectors) { _head.setRenderLookatVectors(displayingLookatVectors);}
void setMouseRay (const glm::vec3 &origin, const glm::vec3 &direction);
void setDisplayingLookatVectors(bool displayingLookatVectors) { _head.setRenderLookatVectors(displayingLookatVectors); }
void setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction);
//getters
bool isInitialized () const { return _initialized;}
const Skeleton& getSkeleton () const { return _skeleton;}
float getHeadYawRate () const { return _head.yawRate;}
const glm::vec3& getHeadJointPosition () const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position;}
float getScale () const { return _scale;}
const glm::vec3& getVelocity () const { return _velocity;}
Head& getHead () {return _head; }
Hand& getHand () {return _hand; }
glm::quat getOrientation () const;
glm::quat getWorldAlignedOrientation() const;
bool isInitialized() const { return _initialized; }
const Skeleton& getSkeleton() const { return _skeleton; }
float getHeadYawRate() const { return _head.yawRate; }
const glm::vec3& getHeadJointPosition() const { return _skeleton.joint[ AVATAR_JOINT_HEAD_BASE ].position; }
float getScale() const { return _scale; }
const glm::vec3& getVelocity() const { return _velocity; }
Head& getHead() {return _head; }
Hand& getHand() {return _hand; }
glm::quat getOrientation() const;
glm::quat getWorldAlignedOrientation() const;
AvatarVoxelSystem* getVoxels() { return &_voxels; }
// get/set avatar data
void saveData(QSettings* set);
void loadData(QSettings* set);
// Get the position/rotation of a single body ball
// Get the position/rotation of a single body ball
void getBodyBallTransform(AvatarJointID jointID, glm::vec3& position, glm::quat& rotation) const;
static void renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, float radius1, float radius2);
@ -180,59 +177,57 @@ public slots:
protected:
struct AvatarBall
{
AvatarJointID parentJoint; // the skeletal joint that serves as a reference for determining the position
glm::vec3 parentOffset; // a 3D vector in the frame of reference of the parent skeletal joint
AvatarBodyBallID parentBall; // the ball to which this ball is constrained for spring forces
glm::vec3 position; // the actual dynamic position of the ball at any given time
glm::quat rotation; // the rotation of the ball
glm::vec3 velocity; // the velocity of the ball
float springLength; // the ideal length of the spring between this ball and its parentBall
float jointTightness; // how tightly the ball position attempts to stay at its ideal position (determined by parentOffset)
float radius; // the radius of the ball
bool isCollidable; // whether or not the ball responds to collisions
float touchForce; // a scalar determining the amount that the cursor (or hand) is penetrating the ball
struct AvatarBall {
AvatarJointID parentJoint; /// the skeletal joint that serves as a reference for determining the position
glm::vec3 parentOffset; /// a 3D vector in the frame of reference of the parent skeletal joint
AvatarBodyBallID parentBall; /// the ball to which this ball is constrained for spring forces
glm::vec3 position; /// the actual dynamic position of the ball at any given time
glm::quat rotation; /// the rotation of the ball
glm::vec3 velocity; /// the velocity of the ball
float springLength; /// the ideal length of the spring between this ball and its parentBall
float jointTightness; /// how tightly the ball position attempts to stay at its ideal position (determined by parentOffset)
float radius; /// the radius of the ball
bool isCollidable; /// whether or not the ball responds to collisions
float touchForce; /// a scalar determining the amount that the cursor (or hand) is penetrating the ball
};
Head _head;
Hand _hand;
Skeleton _skeleton;
bool _ballSpringsInitialized;
float _TEST_bigSphereRadius;
glm::vec3 _TEST_bigSpherePosition;
float _bodyYawDelta;
glm::vec3 _movedHandOffset;
AvatarBall _bodyBall[ NUM_AVATAR_BODY_BALLS ];
AvatarMode _mode;
glm::vec3 _velocity;
glm::vec3 _thrust;
float _speed;
float _leanScale;
float _pelvisFloatingHeight;
float _pelvisToHeadLength;
float _scale;
float _height;
Balls* _balls;
Head _head;
Hand _hand;
Skeleton _skeleton;
bool _ballSpringsInitialized;
float _TEST_bigSphereRadius;
glm::vec3 _TEST_bigSpherePosition;
float _bodyYawDelta;
glm::vec3 _movedHandOffset;
AvatarBall _bodyBall[ NUM_AVATAR_BODY_BALLS ];
AvatarMode _mode;
glm::vec3 _velocity;
glm::vec3 _thrust;
float _speed;
float _leanScale;
float _pelvisFloatingHeight;
float _pelvisToHeadLength;
float _scale;
float _height;
Balls* _balls;
AvatarTouch _avatarTouch;
glm::vec3 _worldUpDirection;
glm::vec3 _mouseRayOrigin;
glm::vec3 _mouseRayDirection;
bool _isCollisionsOn;
Avatar* _leadingAvatar;
float _stringLength;
glm::vec3 _worldUpDirection;
glm::vec3 _mouseRayOrigin;
glm::vec3 _mouseRayDirection;
bool _isCollisionsOn;
Avatar* _leadingAvatar;
float _stringLength;
AvatarVoxelSystem _voxels;
// protected methods...
glm::vec3 getBodyRightDirection () const { return getOrientation() * IDENTITY_RIGHT; }
glm::vec3 getBodyUpDirection () const { return getOrientation() * IDENTITY_UP; }
glm::vec3 getBodyFrontDirection () const { return getOrientation() * IDENTITY_FRONT; }
glm::vec3 getBodyRightDirection() const { return getOrientation() * IDENTITY_RIGHT; }
glm::vec3 getBodyUpDirection() const { return getOrientation() * IDENTITY_UP; }
glm::vec3 getBodyFrontDirection() const { return getOrientation() * IDENTITY_FRONT; }
glm::quat computeRotationFromBodyToWorldUp(float proportion = 1.0f) const;
void updateCollisionWithSphere( glm::vec3 position, float radius, float deltaTime );
void updateBodyBalls( float deltaTime );
void updateArmIKAndConstraints( float deltaTime );
void setScale (const float scale);
void updateCollisionWithSphere(glm::vec3 position, float radius, float deltaTime);
void updateBodyBalls(float deltaTime);
void updateArmIKAndConstraints(float deltaTime);
void setScale(const float scale);
private:
@ -240,10 +235,10 @@ private:
Avatar(const Avatar&);
Avatar& operator= (const Avatar&);
bool _initialized;
glm::vec3 _handHoldingPosition;
float _maxArmLength;
float _pelvisStandingHeight;
bool _initialized;
glm::vec3 _handHoldingPosition;
float _maxArmLength;
float _pelvisStandingHeight;
// private methods...
glm::vec3 calculateAverageEyePosition() { return _head.calculateAverageEyePosition(); } // get the position smack-dab between the eyes (for lookat)

View file

@ -24,17 +24,18 @@
using namespace std;
const bool USING_AVATAR_GRAVITY = true;
const glm::vec3 DEFAULT_UP_DIRECTION (0.0f, 1.0f, 0.0f);
const float YAW_MAG = 500.0;
const float COLLISION_RADIUS_SCALAR = 1.2; //pertains to avatar-to-avatar collisions
const float COLLISION_BALL_FORCE = 200.0; //pertains to avatar-to-avatar collisions
const float COLLISION_BODY_FORCE = 30.0; //pertains to avatar-to-avatar collisions
const float PERIPERSONAL_RADIUS = 1.0f;
const float MOUSE_RAY_TOUCH_RANGE = 0.01f;
const bool USING_HEAD_LEAN = false;
const float SKIN_COLOR[] = {1.0, 0.84, 0.66};
const float DARK_SKIN_COLOR[] = {0.9, 0.78, 0.63};
const bool USING_AVATAR_GRAVITY = true;
const glm::vec3 DEFAULT_UP_DIRECTION(0.0f, 1.0f, 0.0f);
const float YAW_MAG = 500.0;
const float COLLISION_RADIUS_SCALAR = 1.2; // pertains to avatar-to-avatar collisions
const float COLLISION_BALL_FORCE = 200.0; // pertains to avatar-to-avatar collisions
const float COLLISION_BODY_FORCE = 30.0; // pertains to avatar-to-avatar collisions
const float COLLISION_RADIUS_SCALE = 0.125f;
const float PERIPERSONAL_RADIUS = 1.0f;
const float MOUSE_RAY_TOUCH_RANGE = 0.01f;
const bool USING_HEAD_LEAN = false;
const float SKIN_COLOR[] = {1.0, 0.84, 0.66};
const float DARK_SKIN_COLOR[] = {0.9, 0.78, 0.63};
MyAvatar::MyAvatar(Node* owningNode) :
Avatar(owningNode),
@ -56,7 +57,7 @@ MyAvatar::MyAvatar(Node* owningNode) :
_driveKeys[i] = false;
}
_collisionRadius = _height * 0.125f;
_collisionRadius = _height * COLLISION_RADIUS_SCALE;
}
void MyAvatar::reset() {
@ -105,7 +106,7 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
// calculate speed
_speed = glm::length(_velocity);
//figure out if the mouse cursor is over any body spheres...
// figure out if the mouse cursor is over any body spheres...
checkForMouseRayTouching();
// update balls
@ -136,17 +137,17 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
// update avatar skeleton
_skeleton.update(deltaTime, getOrientation(), _position);
//determine the lengths of the body springs now that we have updated the skeleton at least once
// determine the lengths of the body springs now that we have updated the skeleton at least once
if (!_ballSpringsInitialized) {
for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) {
glm::vec3 targetPosition
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
glm::vec3 parentTargetPosition
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
= _skeleton.joint[_bodyBall[b].parentJoint].position
+ _skeleton.joint[_bodyBall[b].parentJoint].rotation * _bodyBall[b].parentOffset;
_bodyBall[b].springLength = glm::length(targetPosition - parentTargetPosition);
}
@ -154,7 +155,7 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
_ballSpringsInitialized = true;
}
//update the movement of the hand and process handshaking with other avatars...
// update the movement of the hand and process handshaking with other avatars...
updateHandMovementAndTouching(deltaTime, enableHandMovement);
_avatarTouch.simulate(deltaTime);
@ -162,7 +163,6 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
if (USING_AVATAR_GRAVITY) {
// For gravity, always move the avatar by the amount driven by gravity, so that the collision
// routines will detect it and collide every frame when pulled by gravity to a surface
//
const float MIN_DISTANCE_AFTER_COLLISION_FOR_GRAVITY = 0.02f;
if (glm::length(_position - _lastCollisionPosition) > MIN_DISTANCE_AFTER_COLLISION_FOR_GRAVITY) {
_velocity += _scale * _gravity * (GRAVITY_EARTH * deltaTime);
@ -176,7 +176,7 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
_collisionRadius = myCamera->getAspectRatio() * (myCamera->getNearClip() / cos(myCamera->getFieldOfView() / 2.f));
_collisionRadius *= COLLISION_RADIUS_SCALAR;
} else {
_collisionRadius = _height * .125f;
_collisionRadius = _height * COLLISION_RADIUS_SCALE;
}
updateCollisionWithEnvironment(deltaTime);
@ -186,7 +186,6 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
// update body balls
updateBodyBalls(deltaTime);
// test for avatar collision response with the big sphere
if (usingBigSphereCollisionTest && _isCollisionsOn) {
@ -198,15 +197,15 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
// update body yaw by body yaw delta
orientation = orientation * glm::quat(glm::radians(
glm::vec3(_bodyPitchDelta, _bodyYawDelta, _bodyRollDelta) * deltaTime));
glm::vec3(_bodyPitchDelta, _bodyYawDelta, _bodyRollDelta) * deltaTime));
// decay body rotation momentum
const float BODY_SPIN_FRICTION = 7.5f;
float bodySpinMomentum = 1.0 - BODY_SPIN_FRICTION * deltaTime;
if (bodySpinMomentum < 0.0f) { bodySpinMomentum = 0.0f; }
if (bodySpinMomentum < 0.0f) { bodySpinMomentum = 0.0f; }
_bodyPitchDelta *= bodySpinMomentum;
_bodyYawDelta *= bodySpinMomentum;
_bodyRollDelta *= bodySpinMomentum;
_bodyYawDelta *= bodySpinMomentum;
_bodyRollDelta *= bodySpinMomentum;
float MINIMUM_ROTATION_RATE = 2.0f;
if (fabs(_bodyYawDelta) < MINIMUM_ROTATION_RATE) { _bodyYawDelta = 0.f; }
@ -226,18 +225,20 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
applyDamping(deltaTime, _velocity, LINEAR_DAMPING_STRENGTH, SQUARED_DAMPING_STRENGTH);
}
//pitch and roll the body as a function of forward speed and turning delta
const float BODY_PITCH_WHILE_WALKING = -20.0;
const float BODY_ROLL_WHILE_TURNING = 0.2;
// pitch and roll the body as a function of forward speed and turning delta
const float BODY_PITCH_WHILE_WALKING = -20.0;
const float BODY_ROLL_WHILE_TURNING = 0.2;
float forwardComponentOfVelocity = glm::dot(getBodyFrontDirection(), _velocity);
orientation = orientation * glm::quat(glm::radians(glm::vec3(
BODY_PITCH_WHILE_WALKING * deltaTime * forwardComponentOfVelocity, 0.0f,
BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta)));
BODY_PITCH_WHILE_WALKING * deltaTime * forwardComponentOfVelocity, 0.0f,
BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta)));
// these forces keep the body upright...
const float BODY_UPRIGHT_FORCE = _scale * 10.0;
float tiltDecay = BODY_UPRIGHT_FORCE * deltaTime;
if (tiltDecay > 1.0f) {tiltDecay = 1.0f;}
if (tiltDecay > 1.0f) {
tiltDecay = 1.0f;
}
// update the euler angles
setOrientation(orientation);
@ -245,7 +246,7 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
//the following will be used to make the avatar upright no matter what gravity is
setOrientation(computeRotationFromBodyToWorldUp(tiltDecay) * orientation);
// Compute instantaneous acceleration
// Compute instantaneous acceleration
float forwardAcceleration = glm::length(glm::dot(getBodyFrontDirection(), getVelocity() - oldVelocity)) / deltaTime;
const float ACCELERATION_PITCH_DECAY = 0.4f;
const float ACCELERATION_YAW_DECAY = 0.4f;
@ -283,26 +284,26 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
right * _head.getLeanSideways() +
front * _head.getLeanForward();
_bodyBall[ BODY_BALL_TORSO ].position += headLean * 0.1f;
_bodyBall[ BODY_BALL_CHEST ].position += headLean * 0.4f;
_bodyBall[ BODY_BALL_NECK_BASE ].position += headLean * 0.7f;
_bodyBall[ BODY_BALL_HEAD_BASE ].position += headLean * 1.0f;
_bodyBall[BODY_BALL_TORSO].position += headLean * 0.1f;
_bodyBall[BODY_BALL_CHEST].position += headLean * 0.4f;
_bodyBall[BODY_BALL_NECK_BASE].position += headLean * 0.7f;
_bodyBall[BODY_BALL_HEAD_BASE].position += headLean * 1.0f;
_bodyBall[ BODY_BALL_LEFT_COLLAR ].position += headLean * 0.6f;
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].position += headLean * 0.6f;
_bodyBall[ BODY_BALL_LEFT_ELBOW ].position += headLean * 0.2f;
_bodyBall[ BODY_BALL_LEFT_WRIST ].position += headLean * 0.1f;
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].position += headLean * 0.0f;
_bodyBall[BODY_BALL_LEFT_COLLAR].position += headLean * 0.6f;
_bodyBall[BODY_BALL_LEFT_SHOULDER].position += headLean * 0.6f;
_bodyBall[BODY_BALL_LEFT_ELBOW].position += headLean * 0.2f;
_bodyBall[BODY_BALL_LEFT_WRIST].position += headLean * 0.1f;
_bodyBall[BODY_BALL_LEFT_FINGERTIPS].position += headLean * 0.0f;
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].position += headLean * 0.6f;
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].position += headLean * 0.6f;
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].position += headLean * 0.2f;
_bodyBall[ BODY_BALL_RIGHT_WRIST ].position += headLean * 0.1f;
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].position += headLean * 0.0f;
_bodyBall[BODY_BALL_RIGHT_COLLAR].position += headLean * 0.6f;
_bodyBall[BODY_BALL_RIGHT_SHOULDER].position += headLean * 0.6f;
_bodyBall[BODY_BALL_RIGHT_ELBOW].position += headLean * 0.2f;
_bodyBall[BODY_BALL_RIGHT_WRIST].position += headLean * 0.1f;
_bodyBall[BODY_BALL_RIGHT_FINGERTIPS].position += headLean * 0.0f;
}
}
_head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
_head.setBodyRotation(glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
_head.setPosition(_bodyBall[ BODY_BALL_HEAD_BASE ].position);
_head.setScale(_scale);
_head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
@ -326,16 +327,14 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
// Update avatar head rotation with sensor data
void MyAvatar::updateFromGyrosAndOrWebcam(bool gyroLook,
float pitchFromTouch) {
float pitchFromTouch) {
SerialInterface* gyros = Application::getInstance()->getSerialHeadSensor();
Webcam* webcam = Application::getInstance()->getWebcam();
glm::vec3 estimatedPosition, estimatedRotation;
if (gyros->isActive()) {
estimatedRotation = gyros->getEstimatedRotation();
} else if (webcam->isActive()) {
estimatedRotation = webcam->getEstimatedRotation();
} else if (_leadingAvatar) {
_head.getFace().clearFrame();
return;
@ -529,13 +528,13 @@ void MyAvatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) {
continue;
}
}
// Always render other people, and render myself when beyond threshold distance
// Always render other people, and render myself when beyond threshold distance
if (b == BODY_BALL_HEAD_BASE) { // the head is rendered as a special
if (alpha > 0.0f) {
_head.render(alpha);
}
} else if (alpha > 0.0f) {
// Render the body ball sphere
// Render the body ball sphere
if (b == BODY_BALL_RIGHT_ELBOW
|| b == BODY_BALL_RIGHT_WRIST
|| b == BODY_BALL_RIGHT_FINGERTIPS ) {
@ -559,18 +558,18 @@ void MyAvatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) {
// Render the cone connecting this ball to its parent
if (_bodyBall[b].parentBall != BODY_BALL_NULL) {
if ((b != BODY_BALL_HEAD_TOP )
&& (b != BODY_BALL_HEAD_BASE )
&& (b != BODY_BALL_PELVIS )
&& (b != BODY_BALL_TORSO )
&& (b != BODY_BALL_CHEST )
&& (b != BODY_BALL_LEFT_COLLAR )
&& (b != BODY_BALL_LEFT_SHOULDER )
&& (b != BODY_BALL_RIGHT_COLLAR )
&& (b != BODY_BALL_RIGHT_SHOULDER)) {
if ((b != BODY_BALL_HEAD_TOP)
&& (b != BODY_BALL_HEAD_BASE)
&& (b != BODY_BALL_PELVIS)
&& (b != BODY_BALL_TORSO)
&& (b != BODY_BALL_CHEST)
&& (b != BODY_BALL_LEFT_COLLAR)
&& (b != BODY_BALL_LEFT_SHOULDER)
&& (b != BODY_BALL_RIGHT_COLLAR)
&& (b != BODY_BALL_RIGHT_SHOULDER)) {
glColor3fv(DARK_SKIN_COLOR);
float r1 = _bodyBall[_bodyBall[b].parentBall ].radius * 0.8;
float r1 = _bodyBall[_bodyBall[b].parentBall].radius * 0.8;
float r2 = _bodyBall[b].radius * 0.8;
if (b == BODY_BALL_HEAD_BASE) {
r1 *= 0.5f;
@ -611,14 +610,14 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) {
const float THRUST_JUMP = 120.f;
// Add Thrusts from keyboard
if (_driveKeys[FWD ]) {_thrust += _scale * THRUST_MAG_FWD * deltaTime * front;}
if (_driveKeys[BACK ]) {_thrust -= _scale * THRUST_MAG_BACK * deltaTime * front;}
if (_driveKeys[RIGHT ]) {_thrust += _scale * THRUST_MAG_LATERAL * deltaTime * right;}
if (_driveKeys[LEFT ]) {_thrust -= _scale * THRUST_MAG_LATERAL * deltaTime * right;}
if (_driveKeys[UP ]) {_thrust += _scale * THRUST_MAG_UP * deltaTime * up;}
if (_driveKeys[DOWN ]) {_thrust -= _scale * THRUST_MAG_DOWN * deltaTime * up;}
if (_driveKeys[ROT_RIGHT]) {_bodyYawDelta -= YAW_MAG * deltaTime;}
if (_driveKeys[ROT_LEFT ]) {_bodyYawDelta += YAW_MAG * deltaTime;}
if (_driveKeys[FWD]) {_thrust += _scale * THRUST_MAG_FWD * deltaTime * front;}
if (_driveKeys[BACK]) {_thrust -= _scale * THRUST_MAG_BACK * deltaTime * front;}
if (_driveKeys[RIGHT]) {_thrust += _scale * THRUST_MAG_LATERAL * deltaTime * right;}
if (_driveKeys[LEFT]) {_thrust -= _scale * THRUST_MAG_LATERAL * deltaTime * right;}
if (_driveKeys[UP]) {_thrust += _scale * THRUST_MAG_UP * deltaTime * up;}
if (_driveKeys[DOWN]) {_thrust -= _scale * THRUST_MAG_DOWN * deltaTime * up;}
if (_driveKeys[ROT_RIGHT]) {_bodyYawDelta -= YAW_MAG * deltaTime;}
if (_driveKeys[ROT_LEFT]) {_bodyYawDelta += YAW_MAG * deltaTime;}
// Add one time jumping force if requested
if (_shouldJump) {
@ -628,10 +627,10 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) {
// Add thrusts from leading avatar
const float FOLLOWING_RATE = 0.02f;
const float MIN_YAW = 5.0f;
const float MIN_PITCH = 1.0f;
const float PITCH_RATE = 0.1f;
const float FOLLOWING_RATE = 0.02f;
const float MIN_YAW = 5.0f;
const float MIN_PITCH = 1.0f;
const float PITCH_RATE = 0.1f;
const float MIN_YAW_BEFORE_PITCH = 30.0f;
if (_leadingAvatar != NULL) {
@ -715,13 +714,13 @@ void MyAvatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMov
// reset hand and arm positions according to hand movement
glm::vec3 right = orientation * IDENTITY_RIGHT;
glm::vec3 up = orientation * IDENTITY_UP;
glm::vec3 up = orientation * IDENTITY_UP;
glm::vec3 front = orientation * IDENTITY_FRONT;
if (enableHandMovement) {
glm::vec3 transformedHandMovement =
right * _movedHandOffset.x * 2.0f +
up * -_movedHandOffset.y * 2.0f +
up * -_movedHandOffset.y * 2.0f +
front * -_movedHandOffset.y * 2.0f;
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += transformedHandMovement;
@ -759,7 +758,7 @@ void MyAvatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMov
_avatarTouch.setYourBodyPosition(_interactingOther->_position);
_avatarTouch.setYourHandPosition(_interactingOther->_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].position);
_avatarTouch.setYourOrientation (_interactingOther->getOrientation());
_avatarTouch.setYourHandState (_interactingOther->_handState);
_avatarTouch.setYourHandState(_interactingOther->_handState);
//if hand-holding is initiated by either avatar, turn on hand-holding...
if (_avatarTouch.getHandsCloseEnoughToGrasp()) {
@ -779,16 +778,6 @@ void MyAvatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMov
float distanceBetweenOurHands = glm::length(vectorFromMyHandToYourHand);
/*
// if my arm can no longer reach the other hand, turn off hand-holding
if (!_avatarTouch.getAbleToReachOtherAvatar()) {
_avatarTouch.setHoldingHands(false);
}
if (distanceBetweenOurHands > _maxArmLength) {
_avatarTouch.setHoldingHands(false);
}
*/
// if neither of us are grasping, turn off hand-holding
if ((_handState != HAND_STATE_GRASPING ) && (_interactingOther->_handState != HAND_STATE_GRASPING)) {
_avatarTouch.setHoldingHands(false);
@ -796,15 +785,15 @@ void MyAvatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMov
//if holding hands, apply the appropriate forces
if (_avatarTouch.getHoldingHands()) {
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position +=
(
_interactingOther->_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position
- _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position
) * 0.5f;
_skeleton.joint[AVATAR_JOINT_RIGHT_FINGERTIPS ].position +=
(_interactingOther->_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position
- _skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position) * 0.5f;
const float MAX_FORCE = 1.0f;
const float FORCE_RATIO = 10.0f;
if (distanceBetweenOurHands > 0.3) {
float force = 10.0f * deltaTime;
if (force > 1.0f) {force = 1.0f;}
float force = min(MAX_FORCE, FORCE_RATIO * deltaTime);
_velocity += vectorFromMyHandToYourHand * force;
}
}
@ -818,8 +807,7 @@ void MyAvatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMov
for (size_t i = 0; i < getHand().getPalms().size(); ++i) {
PalmData& palm = getHand().getPalms()[i];
if (palm.isActive()) {
if (!anyHandsFound
|| palm.getRawPosition().x > rightMostHand.x) {
if (!anyHandsFound || palm.getRawPosition().x > rightMostHand.x) {
_skeleton.joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = palm.getPosition();
rightMostHand = palm.getRawPosition();
}
@ -854,8 +842,8 @@ void MyAvatar::updateCollisionWithEnvironment(float deltaTime) {
const float ENVIRONMENT_COLLISION_FREQUENCY = 0.05f;
glm::vec3 penetration;
if (Application::getInstance()->getEnvironment()->findCapsulePenetration(
_position - up * (_pelvisFloatingHeight - radius),
_position + up * (_height - _pelvisFloatingHeight + radius), radius, penetration)) {
_position - up * (_pelvisFloatingHeight - radius),
_position + up * (_height - _pelvisFloatingHeight + radius), radius, penetration)) {
_lastCollisionPosition = _position;
updateCollisionSound(penetration, deltaTime, ENVIRONMENT_COLLISION_FREQUENCY);
applyHardCollision(penetration, ENVIRONMENT_SURFACE_ELASTICITY, ENVIRONMENT_SURFACE_DAMPING);
@ -870,8 +858,8 @@ void MyAvatar::updateCollisionWithVoxels(float deltaTime) {
const float VOXEL_COLLISION_FREQUENCY = 0.5f;
glm::vec3 penetration;
if (Application::getInstance()->getVoxels()->findCapsulePenetration(
_position - glm::vec3(0.0f, _pelvisFloatingHeight - radius, 0.0f),
_position + glm::vec3(0.0f, _height - _pelvisFloatingHeight + radius, 0.0f), radius, penetration)) {
_position - glm::vec3(0.0f, _pelvisFloatingHeight - radius, 0.0f),
_position + glm::vec3(0.0f, _height - _pelvisFloatingHeight + radius, 0.0f), radius, penetration)) {
_lastCollisionPosition = _position;
updateCollisionSound(penetration, deltaTime, VOXEL_COLLISION_FREQUENCY);
applyHardCollision(penetration, VOXEL_ELASTICITY, VOXEL_DAMPING);

View file

@ -22,28 +22,28 @@ public:
void renderScreenTint(ScreenTintLayer layer, Camera& whichCamera);
// setters
void setMousePressed (bool mousePressed ) { _mousePressed = mousePressed;}
void setMovedHandOffset (glm::vec3 movedHandOffset ) { _movedHandOffset = movedHandOffset;}
void setThrust (glm::vec3 newThrust ) { _thrust = newThrust; };
void setVelocity (const glm::vec3 velocity ) { _velocity = velocity; };
void setLeanScale (float scale ) { _leanScale = scale;}
void setGravity (glm::vec3 gravity);
void setOrientation (const glm::quat& orientation);
void setNewScale (const float scale);
void setWantCollisionsOn (bool wantCollisionsOn ) { _isCollisionsOn = wantCollisionsOn; }
void setMousePressed(bool mousePressed) { _mousePressed = mousePressed; }
void setMovedHandOffset(glm::vec3 movedHandOffset) { _movedHandOffset = movedHandOffset; }
void setThrust(glm::vec3 newThrust) { _thrust = newThrust; }
void setVelocity(const glm::vec3 velocity) { _velocity = velocity; }
void setLeanScale(float scale) { _leanScale = scale; }
void setGravity(glm::vec3 gravity);
void setOrientation(const glm::quat& orientation);
void setNewScale(const float scale);
void setWantCollisionsOn(bool wantCollisionsOn) { _isCollisionsOn = wantCollisionsOn; }
// getters
float getNewScale () const { return _newScale;}
float getSpeed () const { return _speed;}
AvatarMode getMode () const { return _mode;}
float getLeanScale () const { return _leanScale;}
float getElapsedTimeStopped () const { return _elapsedTimeStopped;}
float getElapsedTimeMoving () const { return _elapsedTimeMoving;}
float getAbsoluteHeadYaw () const;
const glm::vec3& getMouseRayOrigin () const { return _mouseRayOrigin; }
const glm::vec3& getMouseRayDirection () const { return _mouseRayDirection; }
Avatar* getLeadingAvatar () const { return _leadingAvatar; }
glm::vec3 getGravity () const { return _gravity; }
float getNewScale() const { return _newScale; }
float getSpeed() const { return _speed; }
AvatarMode getMode() const { return _mode; }
float getLeanScale() const { return _leanScale; }
float getElapsedTimeStopped() const { return _elapsedTimeStopped; }
float getElapsedTimeMoving() const { return _elapsedTimeMoving; }
float getAbsoluteHeadYaw() const;
const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
Avatar* getLeadingAvatar() const { return _leadingAvatar; }
glm::vec3 getGravity() const { return _gravity; }
glm::vec3 getUprightHeadPosition() const;
glm::vec3 getUprightEyeLevelPosition() const;
@ -57,21 +57,21 @@ public:
glm::vec3 getThrust() { return _thrust; };
private:
bool _mousePressed;
float _bodyPitchDelta;
float _bodyRollDelta;
bool _shouldJump;
int _driveKeys[MAX_DRIVE_KEYS];
glm::vec3 _gravity;
float _distanceToNearestAvatar; // How close is the nearest avatar?
Avatar* _interactingOther;
float _elapsedTimeMoving; // Timers to drive camera transitions when moving
float _elapsedTimeStopped;
float _elapsedTimeSinceCollision;
glm::vec3 _lastCollisionPosition;
bool _speedBrakes;
bool _isThrustOn;
float _collisionRadius;
bool _mousePressed;
float _bodyPitchDelta;
float _bodyRollDelta;
bool _shouldJump;
int _driveKeys[MAX_DRIVE_KEYS];
glm::vec3 _gravity;
float _distanceToNearestAvatar; // How close is the nearest avatar?
Avatar* _interactingOther;
float _elapsedTimeMoving; // Timers to drive camera transitions when moving
float _elapsedTimeStopped;
float _elapsedTimeSinceCollision;
glm::vec3 _lastCollisionPosition;
bool _speedBrakes;
bool _isThrustOn;
float _collisionRadius;
// private methods
float getBallRenderAlpha(int ball, bool lookingInMirror) const;