diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 44151cee34..5ed19e6c60 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -243,15 +243,15 @@ int main(int argc, const char* argv[]) { const float MAX_EXPONENT = logf(MAX_REVERB_DISTANCE) / logf(WETNESS_DOUBLING_DISTANCE_FACTOR); const int MAX_EXPONENT_INT = floorf(MAX_EXPONENT); - float DISTANCE_REVERB_LOG_REMAINDER = fmodf(MAX_EXPONENT, MAX_EXPONENT_INT); - + const float DISTANCE_REVERB_LOG_REMAINDER = fmodf(MAX_EXPONENT, MAX_EXPONENT_INT); const float DISTANCE_REVERB_MAX_WETNESS = 1.0f; + const float EFFECT_MIX_RHS = DISTANCE_REVERB_MAX_WETNESS / powf(WETNESS_DOUBLING_DISTANCE_FACTOR, + MAX_EXPONENT_INT); float effectMix = powf(WETNESS_CALC_EXPONENT_BASE, (0.5f * logf(distanceSquareToSource) / logf(WETNESS_CALC_EXPONENT_BASE)) - DISTANCE_REVERB_LOG_REMAINDER); - effectMix *= DISTANCE_REVERB_MAX_WETNESS / (powf(WETNESS_DOUBLING_DISTANCE_FACTOR, - MAX_EXPONENT_INT)); + effectMix *= EFFECT_MIX_RHS; otherAgentFreeVerb->setEffectMix(effectMix); } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1710c85725..95457403b4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1386,7 +1386,7 @@ void Application::initMenu() { optionsMenu->addAction("Noise", this, SLOT(setNoise(bool)), Qt::Key_N)->setCheckable(true); (_gyroLook = optionsMenu->addAction("Gyro Look"))->setCheckable(true); - _gyroLook->setChecked(true); + _gyroLook->setChecked(false); (_mouseLook = optionsMenu->addAction("Mouse Look"))->setCheckable(true); _mouseLook->setChecked(false); (_showHeadMouse = optionsMenu->addAction("Head Mouse"))->setCheckable(true); @@ -1409,6 +1409,8 @@ void Application::initMenu() { _renderAtmosphereOn->setShortcut(Qt::SHIFT | Qt::Key_A); (_renderAvatarsOn = renderMenu->addAction("Avatars"))->setCheckable(true); _renderAvatarsOn->setChecked(true); + (_renderAvatarBalls = renderMenu->addAction("Avatar as Balls"))->setCheckable(true); + _renderAvatarBalls->setChecked(false); (_renderFrameTimerOn = renderMenu->addAction("Show Timer"))->setCheckable(true); _renderFrameTimerOn->setChecked(false); (_renderLookatOn = renderMenu->addAction("Lookat Vectors"))->setCheckable(true); @@ -1965,13 +1967,13 @@ void Application::displaySide(Camera& whichCamera) { if (!avatar->isInitialized()) { avatar->init(); } - avatar->render(false); + avatar->render(false, _renderAvatarBalls->isChecked()); } } agentList->unlock(); // Render my own Avatar - _myAvatar.render(_lookingInMirror->isChecked()); + _myAvatar.render(_lookingInMirror->isChecked(), _renderAvatarBalls->isChecked()); _myAvatar.setDisplayingLookatVectors(_renderLookatOn->isChecked()); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 5c987f0062..15fe56c8f8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -172,6 +172,7 @@ private: QAction* _lookingInMirror; // Are we currently rendering one's own head as if in mirror? QAction* _echoAudioMode; // Are we asking the mixer to echo back our audio? QAction* _gyroLook; // Whether to allow the gyro data from head to move your view + QAction* _renderAvatarBalls; // Switch between voxels and joints/balls for avatar render QAction* _mouseLook; // Whether the have the mouse near edge of screen move your view QAction* _showHeadMouse; // Whether the have the mouse near edge of screen move your view QAction* _transmitterDrives; // Whether to have Transmitter data move/steer the Avatar diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index fbfc9de837..0e8d0114b6 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -927,7 +927,7 @@ void Avatar::setGravity(glm::vec3 gravity) { } } -void Avatar::render(bool lookingInMirror) { +void Avatar::render(bool lookingInMirror, bool renderAvatarBalls) { _cameraPosition = Application::getInstance()->getCamera()->getPosition(); @@ -945,7 +945,7 @@ void Avatar::render(bool lookingInMirror) { renderDiskShadow(_position, glm::vec3(0.0f, 1.0f, 0.0f), 0.1f, 0.2f); // render body - renderBody(lookingInMirror); + renderBody(lookingInMirror, renderAvatarBalls); // if this is my avatar, then render my interactions with the other avatar if (!_owningAgent) { @@ -983,7 +983,7 @@ void Avatar::render(bool lookingInMirror) { glDisable(GL_LIGHTING); glDepthMask(false); if (_keyState == NO_KEY_DOWN) { - textRenderer()->draw(-width/2, 0, _chatMessage.c_str()); + textRenderer()->draw(-width / 2.0f, 0, _chatMessage.c_str()); } else { // rather than using substr and allocating a new string, just replace the last @@ -991,10 +991,10 @@ void Avatar::render(bool lookingInMirror) { int lastIndex = _chatMessage.size() - 1; char lastChar = _chatMessage[lastIndex]; _chatMessage[lastIndex] = '\0'; - textRenderer()->draw(-width/2, 0, _chatMessage.c_str()); + textRenderer()->draw(-width / 2.0f, 0, _chatMessage.c_str()); _chatMessage[lastIndex] = lastChar; glColor3f(0, 1, 0); - textRenderer()->draw(width/2 - lastWidth, 0, _chatMessage.c_str() + lastIndex); + textRenderer()->draw(width / 2.0f - lastWidth, 0, _chatMessage.c_str() + lastIndex); } glEnable(GL_LIGHTING); glDepthMask(true); @@ -1084,7 +1084,7 @@ void Avatar::updateBodyBalls(float deltaTime) { } else { glm::vec3 parentDirection = _bodyBall[ _skeleton.joint[b].parent ].rotation * JOINT_DIRECTION; _bodyBall[b].rotation = rotationBetween(parentDirection, springVector) * - _bodyBall[ _skeleton.joint[b].parent ].rotation; + _bodyBall[ _skeleton.joint[b].parent ].rotation; } } } @@ -1141,119 +1141,90 @@ glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const { return glm::angleAxis(angle * proportion, axis); } -void Avatar::renderBody(bool lookingInMirror) { +void Avatar::renderBody(bool lookingInMirror, bool renderAvatarBalls) { const float RENDER_OPAQUE_BEYOND = 1.0f; // Meters beyond which body is shown opaque const float RENDER_TRANSLUCENT_BEYOND = 0.5f; - // Render the body's voxels - _voxels.render(false); - // Render the body as balls and cones - for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) { - float distanceToCamera = glm::length(_cameraPosition - _bodyBall[b].position); - - float alpha = lookingInMirror ? 1.0f : glm::clamp((distanceToCamera - RENDER_TRANSLUCENT_BEYOND) / - (RENDER_OPAQUE_BEYOND - RENDER_TRANSLUCENT_BEYOND), 0.f, 1.f); - - if (lookingInMirror || _owningAgent) { - alpha = 1.0f; - } - - // Always render other people, and render myself when beyond threshold distance - if (b == BODY_BALL_HEAD_BASE) { // the head is rendered as a special - if (lookingInMirror || _owningAgent || distanceToCamera > RENDER_OPAQUE_BEYOND * 0.5) { - _head.render(lookingInMirror, _cameraPosition, alpha); - } - } else if (_owningAgent || distanceToCamera > RENDER_TRANSLUCENT_BEYOND - || b == BODY_BALL_RIGHT_ELBOW - || b == BODY_BALL_RIGHT_WRIST - || b == BODY_BALL_RIGHT_FINGERTIPS ) { - // Render the body ball sphere - if (_owningAgent || b == BODY_BALL_RIGHT_ELBOW - || b == BODY_BALL_RIGHT_WRIST - || b == BODY_BALL_RIGHT_FINGERTIPS ) { - glColor3f(SKIN_COLOR[0] + _bodyBall[b].touchForce * 0.3f, - SKIN_COLOR[1] - _bodyBall[b].touchForce * 0.2f, - SKIN_COLOR[2] - _bodyBall[b].touchForce * 0.1f); - } else { - glColor4f(SKIN_COLOR[0] + _bodyBall[b].touchForce * 0.3f, - SKIN_COLOR[1] - _bodyBall[b].touchForce * 0.2f, - SKIN_COLOR[2] - _bodyBall[b].touchForce * 0.1f, - alpha); + if (renderAvatarBalls) { + for (int b = 0; b < NUM_AVATAR_BODY_BALLS; b++) { + float distanceToCamera = glm::length(_cameraPosition - _bodyBall[b].position); + + float alpha = lookingInMirror ? 1.0f : glm::clamp((distanceToCamera - RENDER_TRANSLUCENT_BEYOND) / + (RENDER_OPAQUE_BEYOND - RENDER_TRANSLUCENT_BEYOND), 0.f, 1.f); + + if (lookingInMirror || _owningAgent) { + alpha = 1.0f; } - if ((b != BODY_BALL_HEAD_TOP ) - && (b != BODY_BALL_HEAD_BASE )) { - glPushMatrix(); - glTranslatef(_bodyBall[b].position.x, _bodyBall[b].position.y, _bodyBall[b].position.z); - glutSolidSphere(_bodyBall[b].radius, 20.0f, 20.0f); - glPopMatrix(); - } - - // Render the cone connecting this ball to its parent - if (_bodyBall[b].parentBall != BODY_BALL_NULL) { - if ((b != BODY_BALL_HEAD_TOP ) - && (b != BODY_BALL_HEAD_BASE ) - && (b != BODY_BALL_PELVIS ) - && (b != BODY_BALL_TORSO ) - && (b != BODY_BALL_CHEST ) - && (b != BODY_BALL_LEFT_COLLAR ) - && (b != BODY_BALL_LEFT_SHOULDER ) - && (b != BODY_BALL_RIGHT_COLLAR ) - && (b != BODY_BALL_RIGHT_SHOULDER)) { - glColor3fv(DARK_SKIN_COLOR); - - float r1 = _bodyBall[_bodyBall[b].parentBall ].radius * 0.8; - float r2 = _bodyBall[b].radius * 0.8; - if (b == BODY_BALL_HEAD_BASE) { - r1 *= 0.5f; + // Always render other people, and render myself when beyond threshold distance + if (b == BODY_BALL_HEAD_BASE) { // the head is rendered as a special + if (lookingInMirror || _owningAgent || distanceToCamera > RENDER_OPAQUE_BEYOND * 0.5) { + _head.render(lookingInMirror, _cameraPosition, alpha); + } + } else if (_owningAgent || distanceToCamera > RENDER_TRANSLUCENT_BEYOND + || b == BODY_BALL_RIGHT_ELBOW + || b == BODY_BALL_RIGHT_WRIST + || b == BODY_BALL_RIGHT_FINGERTIPS ) { + // Render the body ball sphere + if (_owningAgent || b == BODY_BALL_RIGHT_ELBOW + || b == BODY_BALL_RIGHT_WRIST + || b == BODY_BALL_RIGHT_FINGERTIPS ) { + glColor3f(SKIN_COLOR[0] + _bodyBall[b].touchForce * 0.3f, + SKIN_COLOR[1] - _bodyBall[b].touchForce * 0.2f, + SKIN_COLOR[2] - _bodyBall[b].touchForce * 0.1f); + } else { + glColor4f(SKIN_COLOR[0] + _bodyBall[b].touchForce * 0.3f, + SKIN_COLOR[1] - _bodyBall[b].touchForce * 0.2f, + SKIN_COLOR[2] - _bodyBall[b].touchForce * 0.1f, + alpha); + } + + if ((b != BODY_BALL_HEAD_TOP ) + && (b != BODY_BALL_HEAD_BASE )) { + glPushMatrix(); + glTranslatef(_bodyBall[b].position.x, _bodyBall[b].position.y, _bodyBall[b].position.z); + glutSolidSphere(_bodyBall[b].radius, 20.0f, 20.0f); + glPopMatrix(); + } + + // Render the cone connecting this ball to its parent + if (_bodyBall[b].parentBall != BODY_BALL_NULL) { + if ((b != BODY_BALL_HEAD_TOP ) + && (b != BODY_BALL_HEAD_BASE ) + && (b != BODY_BALL_PELVIS ) + && (b != BODY_BALL_TORSO ) + && (b != BODY_BALL_CHEST ) + && (b != BODY_BALL_LEFT_COLLAR ) + && (b != BODY_BALL_LEFT_SHOULDER ) + && (b != BODY_BALL_RIGHT_COLLAR ) + && (b != BODY_BALL_RIGHT_SHOULDER)) { + glColor3fv(DARK_SKIN_COLOR); + + float r1 = _bodyBall[_bodyBall[b].parentBall ].radius * 0.8; + float r2 = _bodyBall[b].radius * 0.8; + if (b == BODY_BALL_HEAD_BASE) { + r1 *= 0.5f; + } + renderJointConnectingCone + ( + _bodyBall[_bodyBall[b].parentBall].position, + _bodyBall[b].position, r2, r2 + ); } - renderJointConnectingCone - ( - _bodyBall[_bodyBall[b].parentBall].position, - _bodyBall[b].position, r2, r2 - ); } } } - } -} - - - -void Avatar::setHeadFromGyros(glm::vec3* eulerAngles, glm::vec3* angularVelocity, float deltaTime, float smoothingTime) { - // - // Given absolute position and angular velocity information, update the avatar's head angles - // with the goal of fast instantaneous updates that gradually follow the absolute data. - // - // Euler Angle format is (Yaw, Pitch, Roll) in degrees - // - // Angular Velocity is (Yaw, Pitch, Roll) in degrees per second - // - // SMOOTHING_TIME is the time is seconds over which the head should average to the - // absolute eulerAngles passed. - // - // - - if (deltaTime == 0.f) { - // On first sample, set head to absolute position - _head.setYaw (eulerAngles->x); - _head.setPitch(eulerAngles->y); - _head.setRoll (eulerAngles->z); } else { - glm::vec3 angles(_head.getYaw(), _head.getPitch(), _head.getRoll()); - // Increment by detected velocity - angles += (*angularVelocity) * deltaTime; - // Smooth to slowly follow absolute values - angles = ((1.f - deltaTime / smoothingTime) * angles) + (deltaTime / smoothingTime) * (*eulerAngles); - _head.setYaw (angles.x); - _head.setPitch(angles.y); - _head.setRoll (angles.z); - // printLog("Y/P/R: %3.1f, %3.1f, %3.1f\n", angles.x, angles.y, angles.z); + // Render the body's voxels + _voxels.render(false); } } + + + void Avatar::loadData(QSettings* set) { set->beginGroup("Avatar"); @@ -1333,4 +1304,4 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, } glEnd(); -} +} \ No newline at end of file diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index 73ab3ddaba..c1fc353a34 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -88,7 +88,7 @@ public: void updateHeadFromGyros(float frametime, SerialInterface * serialInterface); void updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight); void addBodyYaw(float y) {_bodyYaw += y;}; - void render(bool lookingInMirror); + void render(bool lookingInMirror, bool renderAvatarBalls); //setters void setMousePressed (bool mousePressed ) { _mousePressed = mousePressed;} @@ -202,7 +202,7 @@ private: // private methods... glm::vec3 caclulateAverageEyePosition() { return _head.caclulateAverageEyePosition(); } // get the position smack-dab between the eyes (for lookat) glm::quat computeRotationFromBodyToWorldUp(float proportion = 1.0f) const; - void renderBody(bool lookingInMirror); + void renderBody(bool lookingInMirror, bool renderAvatarBalls); void initializeBodyBalls(); void resetBodyBalls(); void updateBodyBalls( float deltaTime ); @@ -216,7 +216,6 @@ private: void updateCollisionWithVoxels(); void applyCollisionWithScene(const glm::vec3& penetration); void applyCollisionWithOtherAvatar( Avatar * other, float deltaTime ); - void setHeadFromGyros(glm::vec3 * eulerAngles, glm::vec3 * angularVelocity, float deltaTime, float smoothingTime); void checkForMouseRayTouching(); void renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, float radius1, float radius2); }; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 551c5881f5..44a8ef299d 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -104,6 +104,7 @@ void Head::simulate(float deltaTime, bool isMine) { const float HEAD_MOTION_DECAY = 0.00; + /* // Decay head back to center if turned on if (isMine && _returnHeadToCenter) { @@ -121,6 +122,7 @@ void Head::simulate(float deltaTime, bool isMine) { if (fabs(_yaw ) < RETURN_RANGE) { _yaw *= (1.0f - RETURN_STRENGTH * deltaTime); } if (fabs(_roll ) < RETURN_RANGE) { _roll *= (1.0f - RETURN_STRENGTH * deltaTime); } } + */ // decay lean _leanForward *= (1.f - HEAD_MOTION_DECAY * 30 * deltaTime); @@ -151,6 +153,7 @@ void Head::simulate(float deltaTime, bool isMine) { if (USING_PHYSICAL_MOHAWK) { updateHairPhysics(deltaTime); } + } void Head::determineIfLookingAtSomething() {