diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6f5fffd68c..c39efa6228 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1185,6 +1185,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()); @@ -1558,7 +1576,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); @@ -1567,6 +1585,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); diff --git a/interface/src/Application.h b/interface/src/Application.h index 879f039f8c..27f425752b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -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(); diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 7af42478d5..73f971b7da 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -319,6 +319,7 @@ Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) : _totalPacketsReceived(0), _firstPacketReceivedTime(), _packetsReceivedThisPlayback(0), + _echoSamplesLeft(NULL), _isSendingEchoPing(false), _pingAnalysisPending(false), _pingFramesToRecord(0), diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 881b436bf2..a1175e3b23 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -86,6 +86,7 @@ Avatar::Avatar(Node* owningNode) : _leanScale(0.5f), _pelvisStandingHeight(0.0f), _pelvisFloatingHeight(0.0f), + _scale(1.0f), _distanceToNearestAvatar(std::numeric_limits::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 @@ -331,7 +332,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)); @@ -378,18 +379,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; } @@ -424,8 +425,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; } @@ -434,7 +434,6 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { _speedBrakes = false; } _isThrustOn = (glm::length(_thrust) > EPSILON); - } void Avatar::simulate(float deltaTime, Transmitter* transmitter) { @@ -443,6 +442,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; @@ -528,16 +532,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(); @@ -571,11 +576,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); @@ -592,7 +597,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;} @@ -662,7 +667,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()); @@ -748,7 +753,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime, bool enableHandMovem if (distance < closestDistance) { closestDistance = distance; - if (distance < PERIPERSONAL_RADIUS) { + if (distance < _scale * PERIPERSONAL_RADIUS) { _interactingOther = otherAvatar; } } @@ -1017,7 +1022,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); @@ -1091,7 +1096,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(); } @@ -1222,8 +1227,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); @@ -1390,3 +1395,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); +} + diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 653971c3e5..643a187a67 100755 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -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; diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 868de81bfe..8aaec5b899 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -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; diff --git a/interface/src/Camera.h b/interface/src/Camera.h index 5e0dfaff95..d83a36ee16 100644 --- a/interface/src/Camera.h +++ b/interface/src/Camera.h @@ -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 ); }; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 44d62e695d..cc6f729325 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -128,9 +128,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); @@ -261,13 +261,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; @@ -276,12 +276,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; } @@ -296,16 +296,25 @@ void Head::render(float alpha) { renderMohawk(); renderHeadSphere(); - renderEyeBalls(); + renderEyeBalls(); renderEars(); renderMouth(); renderEyeBrows(); - + if (_renderLookatVectors) { renderLookatVectors(_leftEyePosition, _rightEyePosition, _lookAtPosition); } } +void Head::setScale (float scale) { + _scale = scale; + + delete[] _mohawkTriangleFan; + delete[] _mohawkColors; + createMohawk(); + + resetHairPhysics(); +} void Head::createMohawk() { uint16_t nodeId = 0; @@ -318,7 +327,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]; @@ -326,7 +335,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) @@ -404,7 +413,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(); @@ -415,13 +426,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(); } @@ -434,9 +445,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; @@ -449,7 +460,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; @@ -484,9 +495,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); @@ -505,7 +516,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++) { @@ -553,14 +564,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(); @@ -580,13 +591,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); } @@ -602,13 +615,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); } @@ -626,7 +641,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); @@ -639,7 +654,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); @@ -682,7 +697,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; diff --git a/interface/src/Head.h b/interface/src/Head.h index 3cb41f81ec..1f49854cd7 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -38,7 +38,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; } diff --git a/interface/src/Skeleton.cpp b/interface/src/Skeleton.cpp index 0d166abfa1..49a4ad882d 100644 --- a/interface/src/Skeleton.cpp +++ b/interface/src/Skeleton.cpp @@ -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() { diff --git a/interface/src/Skeleton.h b/interface/src/Skeleton.h index 8d99a80fa6..aaaa6d83c3 100644 --- a/interface/src/Skeleton.h +++ b/interface/src/Skeleton.h @@ -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 diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index ca7220afa8..2801d16748 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -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()) { diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 27a755e03f..e198336f54 100755 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -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); diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 439ec9b5f8..1724b8d73a 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -112,6 +112,7 @@ protected: float _bodyYaw; float _bodyPitch; float _bodyRoll; + float _newScale; // Hand state (are we grabbing something or not) char _handState; diff --git a/libraries/shared/src/PacketHeaders.cpp b/libraries/shared/src/PacketHeaders.cpp index 2345e62ec2..230ca5bacc 100644 --- a/libraries/shared/src/PacketHeaders.cpp +++ b/libraries/shared/src/PacketHeaders.cpp @@ -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; -} \ No newline at end of file +} diff --git a/libraries/voxels/src/AABox.cpp b/libraries/voxels/src/AABox.cpp index 36e65561c3..6a9dd68082 100644 --- a/libraries/voxels/src/AABox.cpp +++ b/libraries/voxels/src/AABox.cpp @@ -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 { diff --git a/libraries/voxels/src/AABox.h b/libraries/voxels/src/AABox.h index 735799cd05..7bb203aaf4 100644 --- a/libraries/voxels/src/AABox.h +++ b/libraries/voxels/src/AABox.h @@ -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; }; diff --git a/libraries/voxels/src/ViewFrustum.cpp b/libraries/voxels/src/ViewFrustum.cpp index 166a2f2126..dd4562cd8d 100644 --- a/libraries/voxels/src/ViewFrustum.cpp +++ b/libraries/voxels/src/ViewFrustum.cpp @@ -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; +} diff --git a/libraries/voxels/src/ViewFrustum.h b/libraries/voxels/src/ViewFrustum.h index 7308d5bb64..e364816c59 100644 --- a/libraries/voxels/src/ViewFrustum.h +++ b/libraries/voxels/src/ViewFrustum.h @@ -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: diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index a20715635f..61a174f90b 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -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; } diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index a92c562a7e..461a723a8a 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -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. diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index d2ea383b8e..b84b374309 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -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) { diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 61f2e13056..9c8e6e7d16 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -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; diff --git a/voxel-server/src/main.cpp b/voxel-server/src/main.cpp index cf59f226db..254b1d2d96 100644 --- a/voxel-server/src/main.cpp +++ b/voxel-server/src/main.cpp @@ -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)) {