mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:03:57 +02:00
Merge branch 'master' of https://github.com/worklist/hifi into pointy
Conflicts: interface/src/avatar/Head.cpp
This commit is contained in:
commit
6c587af6ac
24 changed files with 405 additions and 302 deletions
|
@ -1182,6 +1182,24 @@ void Application::setRenderThirdPerson(bool thirdPerson) {
|
|||
}
|
||||
}
|
||||
|
||||
void Application::increaseAvatarSize() {
|
||||
if (5.0f < _myAvatar.getScale() + 0.05f) {
|
||||
return;
|
||||
}
|
||||
|
||||
_myAvatar.setScale(_myAvatar.getScale() + 0.05f);
|
||||
_myCamera.setScale(_myAvatar.getScale() + 0.05f);
|
||||
}
|
||||
|
||||
void Application::decreaseAvatarSize() {
|
||||
if (_myAvatar.getScale() - 0.05f < 0.15f) {
|
||||
return;
|
||||
}
|
||||
|
||||
_myAvatar.setScale(_myAvatar.getScale() - 0.05f);
|
||||
_myCamera.setScale(_myAvatar.getScale() - 0.05f);
|
||||
}
|
||||
|
||||
void Application::setFrustumOffset(bool frustumOffset) {
|
||||
// reshape so that OpenGL will get the right lens details for the camera of choice
|
||||
resizeGL(_glWidget->width(), _glWidget->height());
|
||||
|
@ -1555,7 +1573,7 @@ void Application::initMenu() {
|
|||
_renderAvatarsOn->setChecked(true);
|
||||
(_renderAvatarBalls = renderMenu->addAction("Avatar as Balls"))->setCheckable(true);
|
||||
_renderAvatarBalls->setChecked(false);
|
||||
renderMenu->addAction("Cycle Voxeltar Mode", _myAvatar.getVoxels(), SLOT(cycleMode()));
|
||||
renderMenu->addAction("Cycle Voxel Mode", _myAvatar.getVoxels(), SLOT(cycleMode()));
|
||||
(_renderFrameTimerOn = renderMenu->addAction("Show Timer"))->setCheckable(true);
|
||||
_renderFrameTimerOn->setChecked(false);
|
||||
(_renderLookatOn = renderMenu->addAction("Lookat Vectors"))->setCheckable(true);
|
||||
|
@ -1564,6 +1582,9 @@ void Application::initMenu() {
|
|||
"First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true);
|
||||
(_manualThirdPerson = renderMenu->addAction(
|
||||
"Third Person", this, SLOT(setRenderThirdPerson(bool))))->setCheckable(true);
|
||||
renderMenu->addAction("Increase Avatar Size", this, SLOT(increaseAvatarSize()), Qt::SHIFT | Qt::Key_Plus);
|
||||
renderMenu->addAction("Decrease Avatar Size", this, SLOT(decreaseAvatarSize()), Qt::SHIFT | Qt::Key_Minus);
|
||||
|
||||
|
||||
QMenu* toolsMenu = menuBar->addMenu("Tools");
|
||||
(_renderStatsOn = toolsMenu->addAction("Stats"))->setCheckable(true);
|
||||
|
|
|
@ -118,6 +118,8 @@ private slots:
|
|||
|
||||
void setRenderFirstPerson(bool firstPerson);
|
||||
void setRenderThirdPerson(bool thirdPerson);
|
||||
void increaseAvatarSize();
|
||||
void decreaseAvatarSize();
|
||||
|
||||
void renderThrustAtVoxel(const glm::vec3& thrust);
|
||||
void renderLineToTouchedVoxel();
|
||||
|
|
|
@ -318,8 +318,8 @@ Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) :
|
|||
_lastAcceleration(0),
|
||||
_totalPacketsReceived(0),
|
||||
_firstPacketReceivedTime(),
|
||||
_echoSamplesLeft(NULL),
|
||||
_packetsReceivedThisPlayback(0),
|
||||
_echoSamplesLeft(NULL),
|
||||
_isSendingEchoPing(false),
|
||||
_pingAnalysisPending(false),
|
||||
_pingFramesToRecord(0),
|
||||
|
|
|
@ -50,6 +50,7 @@ Camera::Camera() {
|
|||
_targetPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_idealPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
_scale = 1.0f;
|
||||
}
|
||||
|
||||
void Camera::update(float deltaTime) {
|
||||
|
@ -91,14 +92,14 @@ void Camera::updateFollowMode(float deltaTime) {
|
|||
|
||||
if (_needsToInitialize || (_tightness == 0.0f)) {
|
||||
_rotation = _targetRotation;
|
||||
_idealPosition = _targetPosition + _rotation * glm::vec3(0.0f, _upShift, _distance);
|
||||
_idealPosition = _targetPosition + _scale * (_rotation * glm::vec3(0.0f, _upShift, _distance));
|
||||
_position = _idealPosition;
|
||||
_needsToInitialize = false;
|
||||
|
||||
} else {
|
||||
// pull rotation towards ideal
|
||||
_rotation = safeMix(_rotation, _targetRotation, t);
|
||||
_idealPosition = _targetPosition + _rotation * glm::vec3(0.0f, _upShift, _distance);
|
||||
_idealPosition = _targetPosition + _scale * (_rotation * glm::vec3(0.0f, _upShift, _distance));
|
||||
_position += (_idealPosition - _position) * t;
|
||||
}
|
||||
}
|
||||
|
@ -174,6 +175,12 @@ void Camera::setEyeOffsetOrientation (const glm::quat& o) {
|
|||
_frustumNeedsReshape = true;
|
||||
}
|
||||
|
||||
void Camera::setScale(float s) {
|
||||
_scale = s;
|
||||
_needsToInitialize = true;
|
||||
_frustumNeedsReshape = true;
|
||||
}
|
||||
|
||||
void Camera::initialize() {
|
||||
_needsToInitialize = true;
|
||||
_modeShift = 0.0;
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
void setFarClip ( float f );
|
||||
void setEyeOffsetPosition ( const glm::vec3& p );
|
||||
void setEyeOffsetOrientation( const glm::quat& o );
|
||||
void setScale ( const float s );
|
||||
|
||||
const glm::vec3& getTargetPosition () { return _targetPosition; }
|
||||
const glm::vec3& getPosition () { return _position; }
|
||||
|
@ -54,10 +55,11 @@ public:
|
|||
CameraMode getMode () { return _mode; }
|
||||
float getFieldOfView () { return _fieldOfView; }
|
||||
float getAspectRatio () { return _aspectRatio; }
|
||||
float getNearClip () { return _nearClip; }
|
||||
float getFarClip () { return _farClip; }
|
||||
float getNearClip () { return _scale * _nearClip; }
|
||||
float getFarClip () { return _scale * _farClip; }
|
||||
const glm::vec3& getEyeOffsetPosition () { return _eyeOffsetPosition; }
|
||||
const glm::quat& getEyeOffsetOrientation () { return _eyeOffsetOrientation; }
|
||||
float getScale () { return _scale; }
|
||||
|
||||
bool getFrustumNeedsReshape(); // call to find out if the view frustum needs to be reshaped
|
||||
void setFrustumWasReshaped(); // call this after reshaping the view frustum.
|
||||
|
@ -90,6 +92,7 @@ private:
|
|||
float _modeShift;
|
||||
float _linearModeShift;
|
||||
float _modeShiftRate;
|
||||
float _scale;
|
||||
|
||||
void updateFollowMode( float deltaTime );
|
||||
};
|
||||
|
|
|
@ -319,14 +319,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) {
|
|||
int voxelsUpdated = 0;
|
||||
bool shouldRender = false; // assume we don't need to render it
|
||||
// if it's colored, we might need to render it!
|
||||
if (node->isColored()) {
|
||||
float distanceToNode = node->distanceToCamera(*Application::getInstance()->getViewFrustum());
|
||||
float boundary = boundaryDistanceForRenderLevel(node->getLevel());
|
||||
float childBoundary = boundaryDistanceForRenderLevel(node->getLevel() + 1);
|
||||
bool inBoundary = (distanceToNode <= boundary);
|
||||
bool inChildBoundary = (distanceToNode <= childBoundary);
|
||||
shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary);
|
||||
}
|
||||
shouldRender = node->calculateShouldRender(Application::getInstance()->getViewFrustum());
|
||||
node->setShouldRender(shouldRender && !node->isStagedForDeletion());
|
||||
// let children figure out their renderness
|
||||
if (!node->isLeaf()) {
|
||||
|
|
|
@ -86,6 +86,7 @@ Avatar::Avatar(Node* owningNode) :
|
|||
_leanScale(0.5f),
|
||||
_pelvisStandingHeight(0.0f),
|
||||
_pelvisFloatingHeight(0.0f),
|
||||
_scale(1.0f),
|
||||
_distanceToNearestAvatar(std::numeric_limits<float>::max()),
|
||||
_gravity(0.0f, -1.0f, 0.0f),
|
||||
_worldUpDirection(DEFAULT_UP_DIRECTION),
|
||||
|
@ -111,9 +112,9 @@ Avatar::Avatar(Node* owningNode) :
|
|||
_skeleton.initialize();
|
||||
|
||||
initializeBodyBalls();
|
||||
|
||||
|
||||
_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;
|
||||
|
@ -145,32 +146,32 @@ void Avatar::initializeBodyBalls() {
|
|||
}
|
||||
|
||||
// specify the radius of each ball
|
||||
_bodyBall[ BODY_BALL_PELVIS ].radius = 0.07;
|
||||
_bodyBall[ BODY_BALL_TORSO ].radius = 0.065;
|
||||
_bodyBall[ BODY_BALL_CHEST ].radius = 0.08;
|
||||
_bodyBall[ BODY_BALL_NECK_BASE ].radius = 0.03;
|
||||
_bodyBall[ BODY_BALL_HEAD_BASE ].radius = 0.07;
|
||||
_bodyBall[ BODY_BALL_LEFT_COLLAR ].radius = 0.04;
|
||||
_bodyBall[ BODY_BALL_LEFT_SHOULDER ].radius = 0.03;
|
||||
_bodyBall[ BODY_BALL_LEFT_ELBOW ].radius = 0.02;
|
||||
_bodyBall[ BODY_BALL_LEFT_WRIST ].radius = 0.02;
|
||||
_bodyBall[ BODY_BALL_LEFT_FINGERTIPS ].radius = 0.01;
|
||||
_bodyBall[ BODY_BALL_RIGHT_COLLAR ].radius = 0.04;
|
||||
_bodyBall[ BODY_BALL_RIGHT_SHOULDER ].radius = 0.03;
|
||||
_bodyBall[ BODY_BALL_RIGHT_ELBOW ].radius = 0.02;
|
||||
_bodyBall[ BODY_BALL_RIGHT_WRIST ].radius = 0.02;
|
||||
_bodyBall[ BODY_BALL_RIGHT_FINGERTIPS ].radius = 0.01;
|
||||
_bodyBall[ BODY_BALL_LEFT_HIP ].radius = 0.04;
|
||||
_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 = 0.03;
|
||||
//_bodyBall[ BODY_BALL_LEFT_MID_THIGH ].radius = BODY_BALL_RADIUS_LEFT_MID_THIGH;
|
||||
|
||||
_bodyBall[ BODY_BALL_LEFT_KNEE ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_LEFT_HEEL ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_LEFT_TOES ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_RIGHT_HIP ].radius = 0.04;
|
||||
_bodyBall[ BODY_BALL_RIGHT_KNEE ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_RIGHT_HEEL ].radius = 0.025;
|
||||
_bodyBall[ BODY_BALL_RIGHT_TOES ].radius = 0.025;
|
||||
_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
|
||||
|
@ -339,7 +340,7 @@ void Avatar::updateFromGyrosAndOrWebcam(bool gyroLook,
|
|||
_head.setCameraFollowsHead(gyroLook);
|
||||
|
||||
// Update torso lean distance based on accelerometer data
|
||||
const float TORSO_LENGTH = 0.5f;
|
||||
const float TORSO_LENGTH = _scale * 0.5f;
|
||||
const float MAX_LEAN = 45.0f;
|
||||
_head.setLeanSideways(glm::clamp(glm::degrees(atanf(estimatedPosition.x * _leanScale / TORSO_LENGTH)),
|
||||
-MAX_LEAN, MAX_LEAN));
|
||||
|
@ -386,18 +387,18 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
|||
const float THRUST_JUMP = 120.f;
|
||||
|
||||
// Add Thrusts from keyboard
|
||||
if (_driveKeys[FWD ]) {_thrust += THRUST_MAG_FWD * deltaTime * front;}
|
||||
if (_driveKeys[BACK ]) {_thrust -= THRUST_MAG_BACK * deltaTime * front;}
|
||||
if (_driveKeys[RIGHT ]) {_thrust += THRUST_MAG_LATERAL * deltaTime * right;}
|
||||
if (_driveKeys[LEFT ]) {_thrust -= THRUST_MAG_LATERAL * deltaTime * right;}
|
||||
if (_driveKeys[UP ]) {_thrust += THRUST_MAG_UP * deltaTime * up;}
|
||||
if (_driveKeys[DOWN ]) {_thrust -= THRUST_MAG_DOWN * deltaTime * up;}
|
||||
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) {
|
||||
_thrust += THRUST_JUMP * up;
|
||||
_thrust += _scale * THRUST_JUMP * up;
|
||||
_shouldJump = false;
|
||||
}
|
||||
|
||||
|
@ -432,8 +433,7 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
|||
}
|
||||
|
||||
// Update speed brake status
|
||||
|
||||
const float MIN_SPEED_BRAKE_VELOCITY = 0.4f;
|
||||
const float MIN_SPEED_BRAKE_VELOCITY = _scale * 0.4f;
|
||||
if ((glm::length(_thrust) == 0.0f) && _isThrustOn && (glm::length(_velocity) > MIN_SPEED_BRAKE_VELOCITY)) {
|
||||
_speedBrakes = true;
|
||||
}
|
||||
|
@ -442,7 +442,6 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) {
|
|||
_speedBrakes = false;
|
||||
}
|
||||
_isThrustOn = (glm::length(_thrust) > EPSILON);
|
||||
|
||||
}
|
||||
|
||||
void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
||||
|
@ -451,6 +450,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
glm::vec3 front = orientation * IDENTITY_FRONT;
|
||||
glm::vec3 right = orientation * IDENTITY_RIGHT;
|
||||
|
||||
//
|
||||
if (!isMyAvatar() && _scale != _newScale) {
|
||||
setScale(_newScale);
|
||||
}
|
||||
|
||||
// Update movement timers
|
||||
if (isMyAvatar()) {
|
||||
_elapsedTimeSinceCollision += deltaTime;
|
||||
|
@ -536,16 +540,17 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
//update the movement of the hand and process handshaking with other avatars...
|
||||
updateHandMovementAndTouching(deltaTime, enableHandMovement);
|
||||
_avatarTouch.simulate(deltaTime);
|
||||
|
||||
|
||||
if (isMyAvatar()) {
|
||||
|
||||
// apply gravity
|
||||
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
|
||||
//
|
||||
_velocity += _gravity * (GRAVITY_EARTH * deltaTime);
|
||||
_position += _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime;
|
||||
//
|
||||
|
||||
_velocity += _scale * _gravity * (GRAVITY_EARTH * deltaTime);
|
||||
_position += _scale * _gravity * (GRAVITY_EARTH * deltaTime) * deltaTime;
|
||||
}
|
||||
|
||||
updateCollisionWithEnvironment();
|
||||
|
@ -579,11 +584,11 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
_bodyRollDelta *= bodySpinMomentum;
|
||||
|
||||
const float MAX_STATIC_FRICTION_VELOCITY = 0.5f;
|
||||
const float STATIC_FRICTION_STRENGTH = 20.f;
|
||||
const float STATIC_FRICTION_STRENGTH = _scale * 20.f;
|
||||
applyStaticFriction(deltaTime, _velocity, MAX_STATIC_FRICTION_VELOCITY, STATIC_FRICTION_STRENGTH);
|
||||
|
||||
const float LINEAR_DAMPING_STRENGTH = 1.0f;
|
||||
const float SPEED_BRAKE_POWER = 10.0f;
|
||||
const float SPEED_BRAKE_POWER = _scale * 10.0f;
|
||||
const float SQUARED_DAMPING_STRENGTH = 0.2f;
|
||||
if (_speedBrakes) {
|
||||
applyDamping(deltaTime, _velocity, LINEAR_DAMPING_STRENGTH * SPEED_BRAKE_POWER, SQUARED_DAMPING_STRENGTH * SPEED_BRAKE_POWER);
|
||||
|
@ -600,7 +605,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
BODY_ROLL_WHILE_TURNING * deltaTime * _speed * _bodyYawDelta)));
|
||||
|
||||
// these forces keep the body upright...
|
||||
const float BODY_UPRIGHT_FORCE = 10.0;
|
||||
const float BODY_UPRIGHT_FORCE = _scale * 10.0;
|
||||
float tiltDecay = BODY_UPRIGHT_FORCE * deltaTime;
|
||||
if (tiltDecay > 1.0f) {tiltDecay = 1.0f;}
|
||||
|
||||
|
@ -670,7 +675,7 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
|
|||
|
||||
_head.setBodyRotation (glm::vec3(_bodyPitch, _bodyYaw, _bodyRoll));
|
||||
_head.setPosition(_bodyBall[ BODY_BALL_HEAD_BASE ].position);
|
||||
_head.setScale (_bodyBall[ BODY_BALL_HEAD_BASE ].radius);
|
||||
_head.setScale(_scale);
|
||||
_head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
|
||||
_head.simulate(deltaTime, isMyAvatar());
|
||||
|
||||
|
@ -756,7 +761,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMovem
|
|||
if (distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
|
||||
if (distance < PERIPERSONAL_RADIUS) {
|
||||
if (distance < _scale * PERIPERSONAL_RADIUS) {
|
||||
_interactingOther = otherAvatar;
|
||||
}
|
||||
}
|
||||
|
@ -1025,7 +1030,7 @@ void Avatar::render(bool lookingInMirror, bool renderAvatarBalls) {
|
|||
}
|
||||
|
||||
// render a simple round on the ground projected down from the avatar's position
|
||||
renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), 0.1f, 0.2f);
|
||||
renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), _scale * 0.1f, 0.2f);
|
||||
|
||||
// render body
|
||||
renderBody(lookingInMirror, renderAvatarBalls);
|
||||
|
@ -1099,7 +1104,7 @@ void Avatar::resetBodyBalls() {
|
|||
|
||||
void Avatar::updateBodyBalls(float deltaTime) {
|
||||
// Check for a large repositioning, and re-initialize balls if this has happened
|
||||
const float BEYOND_BODY_SPRING_RANGE = 2.f;
|
||||
const float BEYOND_BODY_SPRING_RANGE = _scale * 2.f;
|
||||
if (glm::length(_position - _bodyBall[BODY_BALL_PELVIS].position) > BEYOND_BODY_SPRING_RANGE) {
|
||||
resetBodyBalls();
|
||||
}
|
||||
|
@ -1230,8 +1235,8 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const {
|
|||
}
|
||||
|
||||
float Avatar::getBallRenderAlpha(int ball, bool lookingInMirror) const {
|
||||
const float RENDER_OPAQUE_OUTSIDE = 0.25f; // render opaque if greater than this distance
|
||||
const float DO_NOT_RENDER_INSIDE = 0.25f; // do not render if less than this distance
|
||||
const float RENDER_OPAQUE_OUTSIDE = _scale * 0.25f; // render opaque if greater than this distance
|
||||
const float DO_NOT_RENDER_INSIDE = _scale * 0.25f; // do not render if less than this distance
|
||||
float distanceToCamera = glm::length(Application::getInstance()->getCamera()->getPosition() - _bodyBall[ball].position);
|
||||
return (lookingInMirror || !isMyAvatar()) ? 1.0f : glm::clamp(
|
||||
(distanceToCamera - DO_NOT_RENDER_INSIDE) / (RENDER_OPAQUE_OUTSIDE - DO_NOT_RENDER_INSIDE), 0.f, 1.f);
|
||||
|
@ -1398,3 +1403,47 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2,
|
|||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void Avatar::setScale(const float scale) {
|
||||
_scale = scale;
|
||||
_newScale = _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_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;
|
||||
_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();
|
||||
_avatarTouch.setReachableRadius(_scale * PERIPERSONAL_RADIUS);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,30 @@
|
|||
#include "Skeleton.h"
|
||||
#include "Transmitter.h"
|
||||
|
||||
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;
|
||||
|
||||
enum AvatarBodyBallID
|
||||
{
|
||||
|
@ -105,6 +129,7 @@ public:
|
|||
void setGravity (glm::vec3 gravity);
|
||||
void setMouseRay (const glm::vec3 &origin, const glm::vec3 &direction);
|
||||
void setOrientation (const glm::quat& orientation);
|
||||
void setScale (const float scale);
|
||||
|
||||
//getters
|
||||
bool isInitialized () const { return _initialized;}
|
||||
|
@ -118,6 +143,7 @@ public:
|
|||
glm::vec3 getBodyRightDirection () const { return getOrientation() * IDENTITY_RIGHT; }
|
||||
glm::vec3 getBodyUpDirection () const { return getOrientation() * IDENTITY_UP; }
|
||||
glm::vec3 getBodyFrontDirection () const { return getOrientation() * IDENTITY_FRONT; }
|
||||
float getScale () const { return _scale;}
|
||||
const glm::vec3& getVelocity () const { return _velocity;}
|
||||
float getSpeed () const { return _speed;}
|
||||
float getHeight () const { return _height;}
|
||||
|
@ -200,6 +226,7 @@ private:
|
|||
float _pelvisStandingHeight;
|
||||
float _pelvisFloatingHeight;
|
||||
float _pelvisToHeadLength;
|
||||
float _scale;
|
||||
float _height;
|
||||
Balls* _balls;
|
||||
AvatarTouch _avatarTouch;
|
||||
|
|
|
@ -129,9 +129,9 @@ void Head::resetHairPhysics() {
|
|||
glm::vec3 up = getUpDirection();
|
||||
for (int t = 0; t < NUM_HAIR_TUFTS; t ++) {
|
||||
|
||||
_hairTuft[t].length = HAIR_LENGTH;
|
||||
_hairTuft[t].thickness = HAIR_THICKNESS;
|
||||
_hairTuft[t].basePosition = _position + up * _scale * 0.9f;
|
||||
_hairTuft[t].length = _scale * HAIR_LENGTH;
|
||||
_hairTuft[t].thickness = _scale * HAIR_THICKNESS;
|
||||
_hairTuft[t].basePosition = _position + up * _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.9f;
|
||||
_hairTuft[t].midPosition = _hairTuft[t].basePosition + up * _hairTuft[t].length * ONE_HALF;
|
||||
_hairTuft[t].endPosition = _hairTuft[t].midPosition + up * _hairTuft[t].length * ONE_HALF;
|
||||
_hairTuft[t].midVelocity = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
@ -262,13 +262,13 @@ void Head::calculateGeometry() {
|
|||
|
||||
//calculate the eye positions
|
||||
_leftEyePosition = _position
|
||||
- right * _scale * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * EYE_UP_OFFSET
|
||||
+ front * _scale * EYE_FRONT_OFFSET;
|
||||
- right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET
|
||||
+ front * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_FRONT_OFFSET;
|
||||
_rightEyePosition = _position
|
||||
+ right * _scale * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * EYE_UP_OFFSET
|
||||
+ front * _scale * EYE_FRONT_OFFSET;
|
||||
+ right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_RIGHT_OFFSET
|
||||
+ up * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_UP_OFFSET
|
||||
+ front * _scale * BODY_BALL_RADIUS_HEAD_BASE * EYE_FRONT_OFFSET;
|
||||
|
||||
_eyeLevelPosition = _position + up * _scale * EYE_UP_OFFSET;
|
||||
|
||||
|
@ -277,12 +277,12 @@ void Head::calculateGeometry() {
|
|||
_rightEyeBrowPosition = _rightEyePosition;
|
||||
|
||||
//calculate the ear positions
|
||||
_leftEarPosition = _position - right * _scale * EAR_RIGHT_OFFSET;
|
||||
_rightEarPosition = _position + right * _scale * EAR_RIGHT_OFFSET;
|
||||
_leftEarPosition = _position - right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EAR_RIGHT_OFFSET;
|
||||
_rightEarPosition = _position + right * _scale * BODY_BALL_RADIUS_HEAD_BASE * EAR_RIGHT_OFFSET;
|
||||
|
||||
//calculate the mouth position
|
||||
_mouthPosition = _position + up * _scale * MOUTH_UP_OFFSET
|
||||
+ front * _scale;
|
||||
_mouthPosition = _position + up * _scale * BODY_BALL_RADIUS_HEAD_BASE * MOUTH_UP_OFFSET
|
||||
+ front * _scale * BODY_BALL_RADIUS_HEAD_BASE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -309,6 +309,15 @@ void Head::render(float alpha) {
|
|||
}
|
||||
}
|
||||
|
||||
void Head::setScale (float scale) {
|
||||
_scale = scale;
|
||||
|
||||
delete[] _mohawkTriangleFan;
|
||||
delete[] _mohawkColors;
|
||||
createMohawk();
|
||||
|
||||
resetHairPhysics();
|
||||
}
|
||||
|
||||
void Head::createMohawk() {
|
||||
uint16_t nodeId = 0;
|
||||
|
@ -321,7 +330,7 @@ void Head::createMohawk() {
|
|||
}
|
||||
}
|
||||
srand(nodeId);
|
||||
float height = 0.08f + randFloat() * 0.05f;
|
||||
float height = _scale * (0.08f + randFloat() * 0.05f);
|
||||
float variance = 0.03 + randFloat() * 0.03f;
|
||||
const float RAD_PER_TRIANGLE = (2.3f + randFloat() * 0.2f) / (float)MOHAWK_TRIANGLES;
|
||||
_mohawkTriangleFan = new glm::vec3[MOHAWK_TRIANGLES];
|
||||
|
@ -329,7 +338,7 @@ void Head::createMohawk() {
|
|||
_mohawkTriangleFan[0] = glm::vec3(0, 0, 0);
|
||||
glm::vec3 basicColor(randFloat(), randFloat(), randFloat());
|
||||
_mohawkColors[0] = basicColor;
|
||||
|
||||
|
||||
for (int i = 1; i < MOHAWK_TRIANGLES; i++) {
|
||||
_mohawkTriangleFan[i] = glm::vec3((randFloat() - 0.5f) * variance,
|
||||
height * cosf(i * RAD_PER_TRIANGLE - PIf / 2.f)
|
||||
|
@ -407,7 +416,9 @@ glm::quat Head::getCameraOrientation () const {
|
|||
void Head::renderHeadSphere() {
|
||||
glPushMatrix();
|
||||
glTranslatef(_position.x, _position.y, _position.z); //translate to head position
|
||||
glScalef(_scale, _scale, _scale); //scale to head size
|
||||
glScalef(_scale * BODY_BALL_RADIUS_HEAD_BASE,
|
||||
_scale * BODY_BALL_RADIUS_HEAD_BASE,
|
||||
_scale * BODY_BALL_RADIUS_HEAD_BASE); //scale to head size
|
||||
glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha);
|
||||
glutSolidSphere(1, 30, 30);
|
||||
glPopMatrix();
|
||||
|
@ -418,13 +429,13 @@ void Head::renderEars() {
|
|||
glPushMatrix();
|
||||
glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha);
|
||||
glTranslatef(_leftEarPosition.x, _leftEarPosition.y, _leftEarPosition.z);
|
||||
glutSolidSphere(0.02, 30, 30);
|
||||
glutSolidSphere(_scale * 0.02, 30, 30);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glColor4f(_skinColor.x, _skinColor.y, _skinColor.z, _renderAlpha);
|
||||
glTranslatef(_rightEarPosition.x, _rightEarPosition.y, _rightEarPosition.z);
|
||||
glutSolidSphere(0.02, 30, 30);
|
||||
glutSolidSphere(_scale * 0.02, 30, 30);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
|
@ -437,9 +448,9 @@ void Head::renderMouth() {
|
|||
glm::vec3 up = orientation * IDENTITY_UP;
|
||||
glm::vec3 front = orientation * IDENTITY_FRONT;
|
||||
|
||||
glm::vec3 r = right * _scale * (0.30f + s * 0.0014f );
|
||||
glm::vec3 u = up * _scale * (0.05f + s * 0.0040f );
|
||||
glm::vec3 f = front * _scale * 0.09f;
|
||||
glm::vec3 r = right * _scale * BODY_BALL_RADIUS_HEAD_BASE * (0.30f + s * 0.0014f );
|
||||
glm::vec3 u = up * _scale * BODY_BALL_RADIUS_HEAD_BASE * (0.05f + s * 0.0040f );
|
||||
glm::vec3 f = front * _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.09f;
|
||||
|
||||
glm::vec3 middle = _mouthPosition;
|
||||
glm::vec3 leftCorner = _mouthPosition - r * 1.0f;
|
||||
|
@ -452,7 +463,7 @@ void Head::renderMouth() {
|
|||
// constrain all mouth vertices to a sphere slightly larger than the head...
|
||||
const float MOUTH_OFFSET_OFF_FACE = 0.003f;
|
||||
|
||||
float constrainedRadius = _scale + MOUTH_OFFSET_OFF_FACE;
|
||||
float constrainedRadius = _scale * BODY_BALL_RADIUS_HEAD_BASE + MOUTH_OFFSET_OFF_FACE;
|
||||
middle = _position + glm::normalize(middle - _position) * constrainedRadius;
|
||||
leftCorner = _position + glm::normalize(leftCorner - _position) * constrainedRadius;
|
||||
rightCorner = _position + glm::normalize(rightCorner - _position) * constrainedRadius;
|
||||
|
@ -487,9 +498,9 @@ void Head::renderMouth() {
|
|||
|
||||
void Head::renderEyeBrows() {
|
||||
|
||||
float height = _scale * 0.3f + _browAudioLift;
|
||||
float length = _scale * 0.2f;
|
||||
float width = _scale * 0.07f;
|
||||
float height = _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.3f + _browAudioLift;
|
||||
float length = _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.2f;
|
||||
float width = _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.07f;
|
||||
|
||||
glColor3f(0.3f, 0.25f, 0.2f);
|
||||
|
||||
|
@ -508,7 +519,7 @@ void Head::renderEyeBrows() {
|
|||
glm::vec3 r = right * length;
|
||||
glm::vec3 u = up * height;
|
||||
glm::vec3 t = up * (height + width);
|
||||
glm::vec3 f = front * _scale * -0.1f;
|
||||
glm::vec3 f = front * _scale * BODY_BALL_RADIUS_HEAD_BASE * -0.1f;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
||||
|
@ -556,14 +567,14 @@ void Head::renderEyeBalls() {
|
|||
glPushMatrix();
|
||||
glColor3fv(EYEBALL_COLOR);
|
||||
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z);
|
||||
glutSolidSphere(EYEBALL_RADIUS, 30, 30);
|
||||
glutSolidSphere(_scale * EYEBALL_RADIUS, 30, 30);
|
||||
glPopMatrix();
|
||||
|
||||
//render white ball of right eyeball
|
||||
glPushMatrix();
|
||||
glColor3fv(EYEBALL_COLOR);
|
||||
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z);
|
||||
glutSolidSphere(EYEBALL_RADIUS, 30, 30);
|
||||
glutSolidSphere(_scale * EYEBALL_RADIUS, 30, 30);
|
||||
glPopMatrix();
|
||||
|
||||
_irisProgram->bind();
|
||||
|
@ -583,13 +594,15 @@ void Head::renderEyeBalls() {
|
|||
glm::vec3 rotationAxis = glm::axis(rotation);
|
||||
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION);
|
||||
glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris
|
||||
glScalef(_scale * IRIS_RADIUS * 2.0f,
|
||||
_scale * IRIS_RADIUS * 2.0f,
|
||||
_scale * IRIS_RADIUS); // flatten the iris
|
||||
|
||||
// this ugliness is simply to invert the model transform and get the eye position in model space
|
||||
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
|
||||
(Application::getInstance()->getCamera()->getPosition() - _leftEyePosition) +
|
||||
glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f),
|
||||
1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS));
|
||||
glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
|
||||
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / _scale * IRIS_RADIUS));
|
||||
|
||||
glutSolidSphere(0.5f, 15, 15);
|
||||
}
|
||||
|
@ -605,13 +618,15 @@ void Head::renderEyeBalls() {
|
|||
glm::vec3 rotationAxis = glm::axis(rotation);
|
||||
glRotatef(glm::angle(rotation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glTranslatef(0.0f, 0.0f, -IRIS_PROTRUSION);
|
||||
glScalef(IRIS_RADIUS * 2.0f, IRIS_RADIUS * 2.0f, IRIS_RADIUS); // flatten the iris
|
||||
glScalef(_scale * IRIS_RADIUS * 2.0f,
|
||||
_scale * IRIS_RADIUS * 2.0f,
|
||||
_scale * IRIS_RADIUS); // flatten the iris
|
||||
|
||||
// this ugliness is simply to invert the model transform and get the eye position in model space
|
||||
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
|
||||
(Application::getInstance()->getCamera()->getPosition() - _rightEyePosition) +
|
||||
glm::vec3(0.0f, 0.0f, IRIS_PROTRUSION)) * glm::vec3(1.0f / (IRIS_RADIUS * 2.0f),
|
||||
1.0f / (IRIS_RADIUS * 2.0f), 1.0f / IRIS_RADIUS));
|
||||
glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
|
||||
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / _scale * IRIS_RADIUS));
|
||||
|
||||
glutSolidSphere(0.5f, 15, 15);
|
||||
}
|
||||
|
@ -629,7 +644,7 @@ void Head::renderEyeBalls() {
|
|||
glTranslatef(_leftEyePosition.x, _leftEyePosition.y, _leftEyePosition.z); //translate to eyeball position
|
||||
glm::vec3 rotationAxis = glm::axis(orientation);
|
||||
glRotatef(glm::angle(orientation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glScalef(EYELID_RADIUS, EYELID_RADIUS, EYELID_RADIUS);
|
||||
glScalef(_scale * EYELID_RADIUS, _scale * EYELID_RADIUS, _scale * EYELID_RADIUS);
|
||||
glRotatef(-40 - 50 * _leftEyeBlink, 1, 0, 0);
|
||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||
glRotatef(180 * _leftEyeBlink, 1, 0, 0);
|
||||
|
@ -642,7 +657,7 @@ void Head::renderEyeBalls() {
|
|||
glTranslatef(_rightEyePosition.x, _rightEyePosition.y, _rightEyePosition.z); //translate to eyeball position
|
||||
glm::vec3 rotationAxis = glm::axis(orientation);
|
||||
glRotatef(glm::angle(orientation), rotationAxis.x, rotationAxis.y, rotationAxis.z);
|
||||
glScalef(EYELID_RADIUS, EYELID_RADIUS, EYELID_RADIUS);
|
||||
glScalef(_scale * EYELID_RADIUS, _scale * EYELID_RADIUS, _scale * EYELID_RADIUS);
|
||||
glRotatef(-40 - 50 * _rightEyeBlink, 1, 0, 0);
|
||||
Application::getInstance()->getGeometryCache()->renderHemisphere(15, 10);
|
||||
glRotatef(180 * _rightEyeBlink, 1, 0, 0);
|
||||
|
@ -685,7 +700,7 @@ void Head::updateHairPhysics(float deltaTime) {
|
|||
= front * sinf(radian)
|
||||
+ up * cosf(radian);
|
||||
|
||||
_hairTuft[t].basePosition = _position + _scale * 0.9f * baseDirection;
|
||||
_hairTuft[t].basePosition = _position + _scale * BODY_BALL_RADIUS_HEAD_BASE * 0.9f * baseDirection;
|
||||
|
||||
glm::vec3 midAxis = _hairTuft[t].midPosition - _hairTuft[t].basePosition;
|
||||
glm::vec3 endAxis = _hairTuft[t].endPosition - _hairTuft[t].midPosition;
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
void render(float alpha);
|
||||
void renderMohawk();
|
||||
|
||||
void setScale (float scale ) { _scale = scale; }
|
||||
void setScale (float scale );
|
||||
void setPosition (glm::vec3 position ) { _position = position; }
|
||||
void setBodyRotation (glm::vec3 bodyRotation ) { _bodyRotation = bodyRotation; }
|
||||
void setGravity (glm::vec3 gravity ) { _gravity = gravity; }
|
||||
|
|
|
@ -11,10 +11,39 @@
|
|||
const float BODY_SPRING_DEFAULT_TIGHTNESS = 1000.0f;
|
||||
const float FLOATING_HEIGHT = 0.13f;
|
||||
|
||||
Skeleton::Skeleton() {
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_PELVIS = glm::vec3(0.0, 0.0, 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_TORSO = glm::vec3( 0.0, 0.09, -0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_CHEST = glm::vec3( 0.0, 0.09, -0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_NECK_BASE = glm::vec3( 0.0, 0.14, 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_HEAD_BASE = glm::vec3( 0.0, 0.04, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_HEAD_TOP = glm::vec3( 0.0, 0.04, 0.00);
|
||||
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_COLLAR = glm::vec3(-0.06, 0.04, 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_SHOULDER = glm::vec3(-0.05, 0.0 , 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_ELBOW = glm::vec3(-0.16, 0.0 , 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_WRIST = glm::vec3(-0.12, 0.0 , 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_FINGERTIPS = glm::vec3(-0.1, 0.0 , 0.0 );
|
||||
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_COLLAR = glm::vec3( 0.06, 0.04, 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_SHOULDER = glm::vec3( 0.05, 0.0 , 0.01);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_ELBOW = glm::vec3( 0.16, 0.0 , 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_WRIST = glm::vec3( 0.12, 0.0 , 0.0 );
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_FINGERTIPS = glm::vec3( 0.1, 0.0 , 0.0 );
|
||||
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_HIP = glm::vec3(-0.05, 0.0 , 0.02);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_KNEE = glm::vec3( 0.00, -0.25, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_HEEL = glm::vec3( 0.00, -0.23, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_LEFT_TOES = glm::vec3( 0.00, 0.00, -0.06);
|
||||
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_HIP = glm::vec3( 0.05, 0.0 , 0.02);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_KNEE = glm::vec3( 0.00, -0.25, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_HEEL = glm::vec3( 0.00, -0.23, 0.00);
|
||||
const glm::vec3 AVATAR_JOINT_POSITION_RIGHT_TOES = glm::vec3( 0.00, 0.00, -0.06);
|
||||
|
||||
Skeleton::Skeleton() : _floatingHeight(FLOATING_HEIGHT){
|
||||
}
|
||||
|
||||
void Skeleton::initialize() {
|
||||
void Skeleton::initialize() {
|
||||
|
||||
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
|
||||
joint[b].parent = AVATAR_JOINT_NULL;
|
||||
|
@ -60,35 +89,39 @@ void Skeleton::initialize() {
|
|||
joint[ AVATAR_JOINT_RIGHT_HEEL ].parent = AVATAR_JOINT_RIGHT_KNEE;
|
||||
joint[ AVATAR_JOINT_RIGHT_TOES ].parent = AVATAR_JOINT_RIGHT_HEEL;
|
||||
|
||||
setScale(1.0f);
|
||||
}
|
||||
|
||||
void Skeleton::setScale(float scale) {
|
||||
// specify the bind pose position
|
||||
joint[ AVATAR_JOINT_PELVIS ].bindPosePosition = glm::vec3( 0.0, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_TORSO ].bindPosePosition = glm::vec3( 0.0, 0.09, -0.01 );
|
||||
joint[ AVATAR_JOINT_CHEST ].bindPosePosition = glm::vec3( 0.0, 0.09, -0.01 );
|
||||
joint[ AVATAR_JOINT_NECK_BASE ].bindPosePosition = glm::vec3( 0.0, 0.14, 0.01 );
|
||||
joint[ AVATAR_JOINT_HEAD_BASE ].bindPosePosition = glm::vec3( 0.0, 0.04, 0.00 );
|
||||
joint[ AVATAR_JOINT_HEAD_TOP ].bindPosePosition = glm::vec3( 0.0, 0.04, 0.00 );
|
||||
joint[ AVATAR_JOINT_PELVIS ].bindPosePosition = scale * AVATAR_JOINT_POSITION_PELVIS;
|
||||
joint[ AVATAR_JOINT_TORSO ].bindPosePosition = scale * AVATAR_JOINT_POSITION_TORSO;
|
||||
joint[ AVATAR_JOINT_CHEST ].bindPosePosition = scale * AVATAR_JOINT_POSITION_CHEST;
|
||||
joint[ AVATAR_JOINT_NECK_BASE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_NECK_BASE;
|
||||
joint[ AVATAR_JOINT_HEAD_BASE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_HEAD_BASE;
|
||||
joint[ AVATAR_JOINT_HEAD_TOP ].bindPosePosition = scale * AVATAR_JOINT_POSITION_HEAD_TOP;
|
||||
|
||||
joint[ AVATAR_JOINT_LEFT_COLLAR ].bindPosePosition = glm::vec3( -0.06, 0.04, 0.01 );
|
||||
joint[ AVATAR_JOINT_LEFT_SHOULDER ].bindPosePosition = glm::vec3( -0.05, 0.0, 0.01 );
|
||||
joint[ AVATAR_JOINT_LEFT_ELBOW ].bindPosePosition = glm::vec3( -0.16, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_LEFT_WRIST ].bindPosePosition = glm::vec3( -0.12, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].bindPosePosition = glm::vec3( -0.1, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_LEFT_COLLAR ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_COLLAR;
|
||||
joint[ AVATAR_JOINT_LEFT_SHOULDER ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_SHOULDER;
|
||||
joint[ AVATAR_JOINT_LEFT_ELBOW ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_ELBOW;
|
||||
joint[ AVATAR_JOINT_LEFT_WRIST ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_WRIST;
|
||||
joint[ AVATAR_JOINT_LEFT_FINGERTIPS ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_FINGERTIPS;
|
||||
|
||||
joint[ AVATAR_JOINT_RIGHT_COLLAR ].bindPosePosition = glm::vec3( 0.06, 0.04, 0.01 );
|
||||
joint[ AVATAR_JOINT_RIGHT_SHOULDER ].bindPosePosition = glm::vec3( 0.05, 0.0, 0.01 );
|
||||
joint[ AVATAR_JOINT_RIGHT_ELBOW ].bindPosePosition = glm::vec3( 0.16, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_RIGHT_WRIST ].bindPosePosition = glm::vec3( 0.12, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].bindPosePosition = glm::vec3( 0.1, 0.0, 0.0 );
|
||||
joint[ AVATAR_JOINT_RIGHT_COLLAR ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_COLLAR;
|
||||
joint[ AVATAR_JOINT_RIGHT_SHOULDER ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_SHOULDER;
|
||||
joint[ AVATAR_JOINT_RIGHT_ELBOW ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_ELBOW;
|
||||
joint[ AVATAR_JOINT_RIGHT_WRIST ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_WRIST;
|
||||
joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_FINGERTIPS;
|
||||
|
||||
joint[ AVATAR_JOINT_LEFT_HIP ].bindPosePosition = glm::vec3( -0.05, 0.0, 0.02 );
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].bindPosePosition = glm::vec3( 0.00, -0.25, 0.00 );
|
||||
joint[ AVATAR_JOINT_LEFT_HEEL ].bindPosePosition = glm::vec3( 0.00, -0.23, 0.00 );
|
||||
joint[ AVATAR_JOINT_LEFT_TOES ].bindPosePosition = glm::vec3( 0.00, 0.00, -0.06 );
|
||||
joint[ AVATAR_JOINT_LEFT_HIP ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_HIP;
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_KNEE;
|
||||
joint[ AVATAR_JOINT_LEFT_HEEL ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_HEEL;
|
||||
joint[ AVATAR_JOINT_LEFT_TOES ].bindPosePosition = scale * AVATAR_JOINT_POSITION_LEFT_TOES;
|
||||
|
||||
joint[ AVATAR_JOINT_RIGHT_HIP ].bindPosePosition = glm::vec3( 0.05, 0.0, 0.02 );
|
||||
joint[ AVATAR_JOINT_RIGHT_KNEE ].bindPosePosition = glm::vec3( 0.00, -0.25, 0.00 );
|
||||
joint[ AVATAR_JOINT_RIGHT_HEEL ].bindPosePosition = glm::vec3( 0.00, -0.23, 0.00 );
|
||||
joint[ AVATAR_JOINT_RIGHT_TOES ].bindPosePosition = glm::vec3( 0.00, 0.00, -0.06 );
|
||||
joint[ AVATAR_JOINT_RIGHT_HIP ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_HIP;
|
||||
joint[ AVATAR_JOINT_RIGHT_KNEE ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_KNEE;
|
||||
joint[ AVATAR_JOINT_RIGHT_HEEL ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_HEEL;
|
||||
joint[ AVATAR_JOINT_RIGHT_TOES ].bindPosePosition = scale * AVATAR_JOINT_POSITION_RIGHT_TOES;
|
||||
|
||||
// calculate bone length, absolute bind positions/rotations
|
||||
for (int b = 0; b < NUM_AVATAR_JOINTS; b++) {
|
||||
|
@ -99,12 +132,14 @@ void Skeleton::initialize() {
|
|||
joint[b].absoluteBindPoseRotation = glm::quat();
|
||||
} else {
|
||||
joint[b].absoluteBindPosePosition = joint[ joint[b].parent ].absoluteBindPosePosition +
|
||||
joint[b].bindPosePosition;
|
||||
joint[b].bindPosePosition;
|
||||
glm::vec3 parentDirection = joint[ joint[b].parent ].absoluteBindPoseRotation * JOINT_DIRECTION;
|
||||
joint[b].absoluteBindPoseRotation = rotationBetween(parentDirection, joint[b].bindPosePosition) *
|
||||
joint[ joint[b].parent ].absoluteBindPoseRotation;
|
||||
joint[ joint[b].parent ].absoluteBindPoseRotation;
|
||||
}
|
||||
}
|
||||
|
||||
_floatingHeight = scale * FLOATING_HEIGHT;
|
||||
}
|
||||
|
||||
// calculate positions and rotations of all bones by traversing the skeleton tree:
|
||||
|
@ -151,7 +186,7 @@ float Skeleton::getPelvisStandingHeight() {
|
|||
float Skeleton::getPelvisFloatingHeight() {
|
||||
return joint[ AVATAR_JOINT_LEFT_HEEL ].length +
|
||||
joint[ AVATAR_JOINT_LEFT_KNEE ].length +
|
||||
FLOATING_HEIGHT;
|
||||
_floatingHeight;
|
||||
}
|
||||
|
||||
float Skeleton::getPelvisToHeadLength() {
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
Skeleton();
|
||||
|
||||
void initialize();
|
||||
void setScale(float scale);
|
||||
void update(float deltaTime, const glm::quat&, glm::vec3 position);
|
||||
void render();
|
||||
|
||||
|
@ -72,7 +73,8 @@ public:
|
|||
float length; // the length of vector connecting the joint and its parent
|
||||
};
|
||||
|
||||
AvatarJoint joint[ NUM_AVATAR_JOINTS ];
|
||||
};
|
||||
AvatarJoint joint[ NUM_AVATAR_JOINTS ];
|
||||
float _floatingHeight;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@ AvatarData::AvatarData(Node* owningNode) :
|
|||
_bodyYaw(-90.0),
|
||||
_bodyPitch(0.0),
|
||||
_bodyRoll(0.0),
|
||||
_newScale(1.0f),
|
||||
_handState(0),
|
||||
_cameraPosition(0,0,0),
|
||||
_cameraOrientation(),
|
||||
|
@ -71,6 +72,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) {
|
|||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyYaw);
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch);
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll);
|
||||
destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _newScale);
|
||||
|
||||
// Head rotation (NOTE: This needs to become a quaternion to save two bytes)
|
||||
destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_yaw);
|
||||
|
@ -197,7 +199,8 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) {
|
|||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyYaw);
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyPitch);
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &_bodyRoll);
|
||||
|
||||
sourceBuffer += unpackFloatRatioFromTwoByte( sourceBuffer, _newScale);
|
||||
|
||||
// Head rotation (NOTE: This needs to become a quaternion to save two bytes)
|
||||
float headYaw, headPitch, headRoll;
|
||||
sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*) sourceBuffer, &headYaw);
|
||||
|
|
|
@ -112,6 +112,7 @@ protected:
|
|||
float _bodyYaw;
|
||||
float _bodyPitch;
|
||||
float _bodyRoll;
|
||||
float _newScale;
|
||||
|
||||
// Hand state (are we grabbing something or not)
|
||||
char _handState;
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
|
||||
PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
||||
switch (type) {
|
||||
case PACKET_TYPE_HEAD_DATA:
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
|
@ -60,4 +63,4 @@ int numBytesForPacketHeader(unsigned char* packetHeader) {
|
|||
|
||||
// currently this need not be dynamic - there are 2 bytes for each packet header
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,11 +13,28 @@
|
|||
#include "AABox.h"
|
||||
#include "GeometryUtil.h"
|
||||
|
||||
AABox::AABox(const glm::vec3& corner, float size) : _corner(corner), _size(size, size, size), _topFarLeft(_corner + _size)
|
||||
{
|
||||
};
|
||||
|
||||
AABox::AABox(const glm::vec3& corner, float x, float y, float z) : _corner(corner), _size(x, y, z), _topFarLeft(_corner + _size)
|
||||
{
|
||||
};
|
||||
|
||||
AABox::AABox(const glm::vec3& corner, const glm::vec3& size) : _corner(corner), _size(size), _topFarLeft(_corner + _size)
|
||||
{
|
||||
};
|
||||
|
||||
AABox::AABox() : _corner(0,0,0), _size(0,0,0), _topFarLeft(0,0,0)
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
void AABox::scale(float scale) {
|
||||
_corner = _corner * scale;
|
||||
_size = _size * scale;
|
||||
_center = _center * scale;
|
||||
_topFarLeft = _topFarLeft * scale;
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,6 +77,7 @@ void AABox::setBox(const glm::vec3& corner, const glm::vec3& size) {
|
|||
_corner.z -= _size.z;
|
||||
}
|
||||
_center = _corner + (_size * 0.5f);
|
||||
_topFarLeft = _corner + _size;
|
||||
}
|
||||
|
||||
glm::vec3 AABox::getVertexP(const glm::vec3& normal) const {
|
||||
|
|
|
@ -41,11 +41,11 @@ class AABox
|
|||
|
||||
public:
|
||||
|
||||
AABox(const glm::vec3& corner, float size) : _corner(corner), _size(size, size, size) { };
|
||||
AABox(const glm::vec3& corner, float x, float y, float z) : _corner(corner), _size(x, y, z) { };
|
||||
AABox(const glm::vec3& corner, const glm::vec3& size) : _corner(corner), _size(size) { };
|
||||
AABox() : _corner(0,0,0), _size(0,0,0) { }
|
||||
~AABox() { }
|
||||
AABox(const glm::vec3& corner, float size);
|
||||
AABox(const glm::vec3& corner, float x, float y, float z);
|
||||
AABox(const glm::vec3& corner, const glm::vec3& size);
|
||||
AABox();
|
||||
~AABox() {};
|
||||
|
||||
void setBox(const glm::vec3& corner, float x, float y, float z) { setBox(corner,glm::vec3(x,y,z)); };
|
||||
void setBox(const glm::vec3& corner, const glm::vec3& size);
|
||||
|
@ -56,9 +56,10 @@ public:
|
|||
|
||||
void scale(float scale);
|
||||
|
||||
const glm::vec3& getCorner() const { return _corner; };
|
||||
const glm::vec3& getSize() const { return _size; };
|
||||
const glm::vec3& getCenter() const { return _center; };
|
||||
const glm::vec3& getCorner() const { return _corner; };
|
||||
const glm::vec3& getSize() const { return _size; };
|
||||
const glm::vec3& getCenter() const { return _center; };
|
||||
const glm::vec3& getTopFarLeft() const { return _topFarLeft; };
|
||||
|
||||
glm::vec3 getVertex(BoxVertex vertex) const;
|
||||
|
||||
|
@ -81,6 +82,7 @@ private:
|
|||
glm::vec3 _corner;
|
||||
glm::vec3 _center;
|
||||
glm::vec3 _size;
|
||||
glm::vec3 _topFarLeft;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -530,8 +530,8 @@ const int hullVertexLookup[MAX_POSSIBLE_COMBINATIONS][MAX_PROJECTED_POLYGON_VERT
|
|||
};
|
||||
|
||||
VoxelProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const {
|
||||
glm::vec3 bottomNearRight = box.getCorner();
|
||||
glm::vec3 topFarLeft = box.getCorner() + box.getSize();
|
||||
const glm::vec3& bottomNearRight = box.getCorner();
|
||||
const glm::vec3& topFarLeft = box.getTopFarLeft();
|
||||
int lookUp = ((_position.x < bottomNearRight.x) ) // 1 = right | compute 6-bit
|
||||
+ ((_position.x > topFarLeft.x ) << 1) // 2 = left | code to
|
||||
+ ((_position.y < bottomNearRight.y) << 2) // 4 = bottom | classify camera
|
||||
|
@ -539,8 +539,6 @@ VoxelProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const {
|
|||
+ ((_position.z < bottomNearRight.z) << 4) // 16 = front/near | the 6 defining
|
||||
+ ((_position.z > topFarLeft.z ) << 5); // 32 = back/far | planes
|
||||
|
||||
//printLog(">>>>>>>>> ViewFrustum::getProjectedPolygon() lookup=%d\n",lookUp);
|
||||
|
||||
int vertexCount = hullVertexLookup[lookUp][0]; //look up number of vertices
|
||||
|
||||
VoxelProjectedPolygon projectedPolygon(vertexCount);
|
||||
|
@ -593,3 +591,40 @@ VoxelProjectedPolygon ViewFrustum::getProjectedPolygon(const AABox& box) const {
|
|||
projectedPolygon.setProjectionType(lookUp); // remember the projection type
|
||||
return projectedPolygon;
|
||||
}
|
||||
|
||||
|
||||
// Similar strategy to getProjectedPolygon() we use the knowledge of camera position relative to the
|
||||
// axis-aligned voxels to determine which of the voxels vertices must be the furthest. No need for
|
||||
// squares and square-roots. Just compares.
|
||||
glm::vec3 ViewFrustum::getFurthestPointFromCamera(const AABox& box) const {
|
||||
const glm::vec3& center = box.getCenter();
|
||||
const glm::vec3& bottomNearRight = box.getCorner();
|
||||
const glm::vec3& topFarLeft = box.getTopFarLeft();
|
||||
|
||||
glm::vec3 furthestPoint;
|
||||
if (_position.x < center.x) {
|
||||
// we are to the right of the center, so the left edge is furthest
|
||||
furthestPoint.x = topFarLeft.x;
|
||||
} else {
|
||||
// we are to the left of the center, so the right edge is furthest (at center ok too)
|
||||
furthestPoint.x = bottomNearRight.x;
|
||||
}
|
||||
|
||||
if (_position.y < center.y) {
|
||||
// we are below of the center, so the top edge is furthest
|
||||
furthestPoint.y = topFarLeft.y;
|
||||
} else {
|
||||
// we are above the center, so the lower edge is furthest (at center ok too)
|
||||
furthestPoint.y = bottomNearRight.y;
|
||||
}
|
||||
|
||||
if (_position.z < center.z) {
|
||||
// we are to the near side of the center, so the far side edge is furthest
|
||||
furthestPoint.z = topFarLeft.z;
|
||||
} else {
|
||||
// we are to the far side of the center, so the near side edge is furthest (at center ok too)
|
||||
furthestPoint.z = bottomNearRight.z;
|
||||
}
|
||||
|
||||
return furthestPoint;
|
||||
}
|
||||
|
|
|
@ -90,6 +90,7 @@ public:
|
|||
|
||||
glm::vec2 projectPoint(glm::vec3 point, bool& pointInView) const;
|
||||
VoxelProjectedPolygon getProjectedPolygon(const AABox& box) const;
|
||||
glm::vec3 getFurthestPointFromCamera(const AABox& box) const;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -335,11 +335,42 @@ ViewFrustum::location VoxelNode::inFrustum(const ViewFrustum& viewFrustum) const
|
|||
return viewFrustum.boxInFrustum(box);
|
||||
}
|
||||
|
||||
// There are two types of nodes for which we want to "render"
|
||||
// 1) Leaves that are in the LOD
|
||||
// 2) Non-leaves are more complicated though... usually you don't want to render them, but if their children
|
||||
// wouldn't be rendered, then you do want to render them. But sometimes they have some children that ARE
|
||||
// in the LOD, and others that are not. In this case we want to render the parent, and none of the children.
|
||||
//
|
||||
// Since, if we know the camera position and orientation, we can know which of the corners is the "furthest"
|
||||
// corner. We can use we can use this corner as our "voxel position" to do our distance calculations off of.
|
||||
// By doing this, we don't need to test each child voxel's position vs the LOD boundary
|
||||
bool VoxelNode::calculateShouldRender(const ViewFrustum* viewFrustum, int boundaryLevelAdjust) const {
|
||||
bool shouldRender = false;
|
||||
if (isColored()) {
|
||||
float furthestDistance = furthestDistanceToCamera(*viewFrustum);
|
||||
float boundary = boundaryDistanceForRenderLevel(getLevel() + boundaryLevelAdjust);
|
||||
float childBoundary = boundaryDistanceForRenderLevel(getLevel() + 1 + boundaryLevelAdjust);
|
||||
bool inBoundary = (furthestDistance <= boundary);
|
||||
bool inChildBoundary = (furthestDistance <= childBoundary);
|
||||
shouldRender = (isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary);
|
||||
}
|
||||
return shouldRender;
|
||||
}
|
||||
|
||||
// Calculates the distance to the furthest point of the voxel to the camera
|
||||
float VoxelNode::furthestDistanceToCamera(const ViewFrustum& viewFrustum) const {
|
||||
AABox box = getAABox();
|
||||
box.scale(TREE_SCALE);
|
||||
glm::vec3 furthestPoint = viewFrustum.getFurthestPointFromCamera(box);
|
||||
glm::vec3 temp = viewFrustum.getPosition() - furthestPoint;
|
||||
float distanceToVoxelCenter = sqrtf(glm::dot(temp, temp));
|
||||
return distanceToVoxelCenter;
|
||||
}
|
||||
|
||||
float VoxelNode::distanceToCamera(const ViewFrustum& viewFrustum) const {
|
||||
glm::vec3 center = _box.getCenter() * (float)TREE_SCALE;
|
||||
glm::vec3 temp = viewFrustum.getPosition() - center;
|
||||
float distanceSquared = glm::dot(temp, temp);
|
||||
float distanceToVoxelCenter = sqrtf(distanceSquared);
|
||||
float distanceToVoxelCenter = sqrtf(glm::dot(temp, temp));
|
||||
return distanceToVoxelCenter;
|
||||
}
|
||||
|
||||
|
@ -351,7 +382,6 @@ float VoxelNode::distanceSquareToPoint(const glm::vec3& point) const {
|
|||
|
||||
float VoxelNode::distanceToPoint(const glm::vec3& point) const {
|
||||
glm::vec3 temp = point - _box.getCenter();
|
||||
float distanceSquare = glm::dot(temp, temp);
|
||||
float distance = sqrtf(distanceSquare);
|
||||
float distance = sqrtf(glm::dot(temp, temp));
|
||||
return distance;
|
||||
}
|
||||
|
|
|
@ -70,6 +70,9 @@ public:
|
|||
bool isInView(const ViewFrustum& viewFrustum) const;
|
||||
ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const;
|
||||
float distanceToCamera(const ViewFrustum& viewFrustum) const;
|
||||
float furthestDistanceToCamera(const ViewFrustum& viewFrustum) const;
|
||||
|
||||
bool calculateShouldRender(const ViewFrustum* viewFrustum, int boundaryLevelAdjust = 0) const;
|
||||
|
||||
// points are assumed to be in Voxel Coordinates (not TREE_SCALE'd)
|
||||
float distanceSquareToPoint(const glm::vec3& point) const; // when you don't need the actual distance, use this.
|
||||
|
|
|
@ -891,17 +891,6 @@ void VoxelTree::createSphere(float radius, float xc, float yc, float zc, float v
|
|||
}
|
||||
}
|
||||
|
||||
int VoxelTree::searchForColoredNodes(int maxSearchLevel, VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag,
|
||||
bool deltaViewFrustum, const ViewFrustum* lastViewFrustum) {
|
||||
|
||||
// call the recursive version, this will add all found colored node roots to the bag
|
||||
int currentSearchLevel = 0;
|
||||
|
||||
int levelReached = searchForColoredNodesRecursion(maxSearchLevel, currentSearchLevel, rootNode,
|
||||
viewFrustum, bag, deltaViewFrustum, lastViewFrustum);
|
||||
return levelReached;
|
||||
}
|
||||
|
||||
// combines the ray cast arguments into a single object
|
||||
class RayArgs {
|
||||
public:
|
||||
|
@ -1014,88 +1003,6 @@ bool VoxelTree::findCapsulePenetration(const glm::vec3& start, const glm::vec3&
|
|||
return args.found;
|
||||
}
|
||||
|
||||
int VoxelTree::searchForColoredNodesRecursion(int maxSearchLevel, int& currentSearchLevel,
|
||||
VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag,
|
||||
bool deltaViewFrustum, const ViewFrustum* lastViewFrustum) {
|
||||
|
||||
// Keep track of how deep we've searched.
|
||||
currentSearchLevel++;
|
||||
|
||||
// If we've passed our max Search Level, then stop searching. return last level searched
|
||||
if (currentSearchLevel > maxSearchLevel) {
|
||||
return currentSearchLevel-1;
|
||||
}
|
||||
|
||||
// If we're at a node that is out of view, then we can return, because no nodes below us will be in view!
|
||||
if (!node->isInView(viewFrustum)) {
|
||||
return currentSearchLevel;
|
||||
}
|
||||
|
||||
// Ok, this is a little tricky, each child may have been deeper than the others, so we need to track
|
||||
// how deep each child went. And we actually return the maximum of each child. We use these variables below
|
||||
// when we recurse the children.
|
||||
int thisLevel = currentSearchLevel;
|
||||
int maxChildLevel = thisLevel;
|
||||
|
||||
VoxelNode* inViewChildren[NUMBER_OF_CHILDREN];
|
||||
float distancesToChildren[NUMBER_OF_CHILDREN];
|
||||
int positionOfChildren[NUMBER_OF_CHILDREN];
|
||||
int inViewCount = 0;
|
||||
int inViewNotLeafCount = 0;
|
||||
int inViewWithColorCount = 0;
|
||||
|
||||
// for each child node, check to see if they exist, are colored, and in view, and if so
|
||||
// add them to our distance ordered array of children
|
||||
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
|
||||
VoxelNode* childNode = node->getChildAtIndex(i);
|
||||
bool childIsColored = (childNode && childNode->isColored());
|
||||
bool childIsInView = (childNode && childNode->isInView(viewFrustum));
|
||||
bool childIsLeaf = (childNode && childNode->isLeaf());
|
||||
|
||||
if (childIsInView) {
|
||||
|
||||
// track children in view as existing and not a leaf
|
||||
if (!childIsLeaf) {
|
||||
inViewNotLeafCount++;
|
||||
}
|
||||
|
||||
// track children with actual color
|
||||
if (childIsColored) {
|
||||
inViewWithColorCount++;
|
||||
}
|
||||
|
||||
float distance = childNode->distanceToCamera(viewFrustum);
|
||||
|
||||
if (distance < boundaryDistanceForRenderLevel(*childNode->getOctalCode() + 1)) {
|
||||
inViewCount = insertIntoSortedArrays((void*)childNode, distance, i,
|
||||
(void**)&inViewChildren, (float*)&distancesToChildren,
|
||||
(int*)&positionOfChildren, inViewCount, NUMBER_OF_CHILDREN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we have children with color, then we do want to add this node (and it's descendants) to the bag to be written
|
||||
// we don't need to dig deeper.
|
||||
//
|
||||
// XXXBHG - this might be a good time to look at colors and add them to a dictionary? But we're not planning
|
||||
// on scanning the whole tree, so we won't actually see all the colors, so maybe no point in that.
|
||||
if (inViewWithColorCount) {
|
||||
bag.insert(node);
|
||||
} else {
|
||||
// at this point, we need to iterate the children who are in view, even if not colored
|
||||
// and we need to determine if there's a deeper tree below them that we care about. We will iterate
|
||||
// these based on which tree is closer.
|
||||
for (int i = 0; i < inViewCount; i++) {
|
||||
VoxelNode* childNode = inViewChildren[i];
|
||||
thisLevel = currentSearchLevel; // reset this, since the children will munge it up
|
||||
int childLevelReached = searchForColoredNodesRecursion(maxSearchLevel, thisLevel, childNode, viewFrustum, bag,
|
||||
deltaViewFrustum, lastViewFrustum);
|
||||
maxChildLevel = std::max(maxChildLevel, childLevelReached);
|
||||
}
|
||||
}
|
||||
return maxChildLevel;
|
||||
}
|
||||
|
||||
int VoxelTree::encodeTreeBitstream(VoxelNode* node, unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag,
|
||||
EncodeBitstreamParams& params) const {
|
||||
|
||||
|
@ -1344,19 +1251,10 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
|
|||
} // wants occlusion culling & isLeaf()
|
||||
|
||||
|
||||
// There are two types of nodes for which we want to send colors:
|
||||
// 1) Leaves - obviously
|
||||
// 2) Non-leaves who's children would be visible but are beyond our LOD.
|
||||
bool isLeafOrLOD = childNode->isLeaf();
|
||||
if (params.viewFrustum && childNode->isColored() && !childNode->isLeaf()) {
|
||||
int childLevel = childNode->getLevel();
|
||||
float childBoundary = boundaryDistanceForRenderLevel(childLevel + params.boundaryLevelAdjust);
|
||||
float grandChildBoundary = boundaryDistanceForRenderLevel(childLevel + 1 + params.boundaryLevelAdjust);
|
||||
isLeafOrLOD = ((distance <= childBoundary) && !(distance <= grandChildBoundary));
|
||||
}
|
||||
bool shouldRender = childNode->calculateShouldRender(params.viewFrustum, params.boundaryLevelAdjust);
|
||||
|
||||
// track children with actual color, only if the child wasn't previously in view!
|
||||
if (childNode && isLeafOrLOD && childNode->isColored() && !childIsOccluded) {
|
||||
if (shouldRender && !childIsOccluded) {
|
||||
bool childWasInView = false;
|
||||
|
||||
if (childNode && params.deltaViewFrustum && params.lastViewFrustum) {
|
||||
|
@ -1368,7 +1266,7 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp
|
|||
} else {
|
||||
childWasInView = location == ViewFrustum::INSIDE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If our child wasn't in view (or we're ignoring wasInView) then we add it to our sending items
|
||||
if (!childWasInView) {
|
||||
|
|
|
@ -123,9 +123,6 @@ public:
|
|||
int encodeTreeBitstream(VoxelNode* node, unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag,
|
||||
EncodeBitstreamParams& params) const;
|
||||
|
||||
int searchForColoredNodes(int maxSearchLevel, VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag,
|
||||
bool deltaViewFrustum = false, const ViewFrustum* lastViewFrustum = NULL);
|
||||
|
||||
bool isDirty() const { return _isDirty; };
|
||||
void clearDirtyBit() { _isDirty = false; };
|
||||
void setDirtyBit() { _isDirty = true; };
|
||||
|
@ -171,10 +168,6 @@ private:
|
|||
int encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag,
|
||||
EncodeBitstreamParams& params, int& currentEncodeLevel) const;
|
||||
|
||||
int searchForColoredNodesRecursion(int maxSearchLevel, int& currentSearchLevel,
|
||||
VoxelNode* node, const ViewFrustum& viewFrustum, VoxelNodeBag& bag,
|
||||
bool deltaViewFrustum, const ViewFrustum* lastViewFrustum);
|
||||
|
||||
static bool countVoxelsOperation(VoxelNode* node, void* extraData);
|
||||
|
||||
VoxelNode* nodeForOctalCode(VoxelNode* ancestorNode, unsigned char* needleCode, VoxelNode** parentOfFoundNode) const;
|
||||
|
|
|
@ -60,7 +60,6 @@ bool wantLocalDomain = false;
|
|||
bool wantColorRandomizer = false;
|
||||
bool debugVoxelSending = false;
|
||||
bool shouldShowAnimationDebug = false;
|
||||
bool wantSearchForColoredNodes = false;
|
||||
|
||||
EnvironmentData environmentData[3];
|
||||
|
||||
|
@ -121,8 +120,6 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
|
|||
|
||||
pthread_mutex_lock(&::treeLock);
|
||||
|
||||
int maxLevelReached = 0;
|
||||
uint64_t start = usecTimestampNow();
|
||||
int truePacketsSent = 0;
|
||||
int trueBytesSent = 0;
|
||||
|
||||
|
@ -200,38 +197,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList,
|
|||
nodeData->map.erase();
|
||||
}
|
||||
|
||||
// For now, we're going to disable the "search for colored nodes" because that strategy doesn't work when we support
|
||||
// deletion of nodes. Instead if we just start at the root we get the correct behavior we want. We are keeping this
|
||||
// code for now because we want to be able to go back to it and find a solution to support both. The search method
|
||||
// helps improve overall bitrate performance.
|
||||
if (::wantSearchForColoredNodes) {
|
||||
// If the bag was empty, then send everything in view, not just the delta
|
||||
maxLevelReached = serverTree.searchForColoredNodes(INT_MAX, serverTree.rootNode, nodeData->getCurrentViewFrustum(),
|
||||
nodeData->nodeBag, wantDelta, lastViewFrustum);
|
||||
|
||||
// if nothing was found in view, send the root node.
|
||||
if (nodeData->nodeBag.isEmpty()){
|
||||
nodeData->nodeBag.insert(serverTree.rootNode);
|
||||
}
|
||||
nodeData->setViewSent(false);
|
||||
} else {
|
||||
nodeData->nodeBag.insert(serverTree.rootNode);
|
||||
}
|
||||
}
|
||||
uint64_t end = usecTimestampNow();
|
||||
int elapsedmsec = (end - start)/1000;
|
||||
if (elapsedmsec > 100) {
|
||||
if (elapsedmsec > 1000) {
|
||||
int elapsedsec = (end - start)/1000000;
|
||||
printf("WARNING! searchForColoredNodes() took %d seconds to identify %d nodes at level %d\n",
|
||||
elapsedsec, nodeData->nodeBag.count(), maxLevelReached);
|
||||
} else {
|
||||
printf("WARNING! searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d\n",
|
||||
elapsedmsec, nodeData->nodeBag.count(), maxLevelReached);
|
||||
}
|
||||
} else if (::debugVoxelSending) {
|
||||
printf("searchForColoredNodes() took %d milliseconds to identify %d nodes at level %d\n",
|
||||
elapsedmsec, nodeData->nodeBag.count(), maxLevelReached);
|
||||
nodeData->nodeBag.insert(serverTree.rootNode);
|
||||
}
|
||||
|
||||
// If we have something in our nodeBag, then turn them into packets and send them out...
|
||||
|
@ -438,10 +404,6 @@ int main(int argc, const char * argv[]) {
|
|||
::wantColorRandomizer = cmdOptionExists(argc, argv, WANT_COLOR_RANDOMIZER);
|
||||
printf("wantColorRandomizer=%s\n", debug::valueOf(::wantColorRandomizer));
|
||||
|
||||
const char* WANT_SEARCH_FOR_NODES = "--wantSearchForColoredNodes";
|
||||
::wantSearchForColoredNodes = cmdOptionExists(argc, argv, WANT_SEARCH_FOR_NODES);
|
||||
printf("wantSearchForColoredNodes=%s\n", debug::valueOf(::wantSearchForColoredNodes));
|
||||
|
||||
// By default we will voxel persist, if you want to disable this, then pass in this parameter
|
||||
const char* NO_VOXEL_PERSIST = "--NoVoxelPersist";
|
||||
if (cmdOptionExists(argc, argv, NO_VOXEL_PERSIST)) {
|
||||
|
|
Loading…
Reference in a new issue