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

@ -57,9 +57,7 @@ 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) :
@ -169,9 +164,6 @@ void Avatar::initializeBodyBalls() {
_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;
@ -207,8 +199,6 @@ void Avatar::initializeBodyBalls() {
_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;
// 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);
@ -235,10 +225,6 @@ void Avatar::initializeBodyBalls() {
_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);
// specify the parent BALL for each ball
_bodyBall[BODY_BALL_PELVIS].parentBall = BODY_BALL_NULL;
_bodyBall[BODY_BALL_TORSO].parentBall = BODY_BALL_PELVIS;
@ -257,25 +243,13 @@ void Avatar::initializeBodyBalls() {
_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;
*/
}
Avatar::~Avatar() {
@ -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;
@ -784,11 +751,7 @@ void Avatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) {
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);
}
}
}
@ -949,9 +912,6 @@ void Avatar::setScale(const float scale) {
_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_MID_THIGH ].radius = _scale * BODY_BALL_RADIUS_LEFT_MID_THIGH;
_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;

View file

@ -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);
@ -157,7 +155,6 @@ public:
Hand& getHand() {return _hand; }
glm::quat getOrientation() const;
glm::quat getWorldAlignedOrientation() const;
AvatarVoxelSystem* getVoxels() { return &_voxels; }
// get/set avatar data
@ -180,19 +177,18 @@ 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;
@ -221,7 +217,6 @@ protected:
bool _isCollisionsOn;
Avatar* _leadingAvatar;
float _stringLength;
AvatarVoxelSystem _voxels;
// protected methods...

View file

@ -30,6 +30,7 @@ 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;
@ -56,7 +57,7 @@ MyAvatar::MyAvatar(Node* owningNode) :
_driveKeys[i] = false;
}
_collisionRadius = _height * 0.125f;
_collisionRadius = _height * COLLISION_RADIUS_SCALE;
}
void MyAvatar::reset() {
@ -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);
@ -187,7 +187,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) {
updateCollisionWithSphere(_TEST_bigSpherePosition, _TEST_bigSphereRadius, deltaTime);
@ -237,7 +236,9 @@ void MyAvatar::simulate(float deltaTime, Transmitter* transmitter, float gyroCam
// 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);
@ -332,10 +333,8 @@ void MyAvatar::updateFromGyrosAndOrWebcam(bool gyroLook,
glm::vec3 estimatedPosition, estimatedRotation;
if (gyros->isActive()) {
estimatedRotation = gyros->getEstimatedRotation();
} else if (webcam->isActive()) {
estimatedRotation = webcam->getEstimatedRotation();
} else if (_leadingAvatar) {
_head.getFace().clearFrame();
return;
@ -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);
@ -797,14 +786,14 @@ 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;
(_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();
}

View file

@ -24,8 +24,8 @@ public:
// 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 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);