From ee1e5d16fcef5c2e4596f4ffc2f48cc7f3ebb22c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 1 May 2013 22:03:57 -0700 Subject: [PATCH] Avatars are now slowed down when they get near other avatars, for easy fine positioning. --- interface/src/Avatar.cpp | 22 ++++++++++++++++------ interface/src/main.cpp | 20 ++++++-------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 53ba706604..402af33c55 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -324,7 +324,16 @@ void Avatar::setMousePressed( bool d ) { void Avatar::simulate(float deltaTime) { - float nearestAvatarDistance = 1000000.f; + float nearestAvatarDistance = std::numeric_limits::max(); + +//keep this - I'm still using it to test things.... +/* +//TEST +static float tt = 0.0f; +tt += deltaTime * 2.0f; +//_head.leanSideways = 0.01 * sin( tt ); +_head.leanForward = 0.02 * sin( tt * 0.8 ); +*/ // update balls if (_balls) { _balls->simulate(deltaTime); } @@ -346,8 +355,7 @@ void Avatar::simulate(float deltaTime) { // all the other avatars for potential interactions... if ( _isMine ) { - float closestDistance = 10000.0f; - + AgentList* agentList = AgentList::getInstance(); for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { @@ -467,9 +475,11 @@ void Avatar::simulate(float deltaTime) { // decay velocity _velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); - // If other avatars nearby, damp velocity much more! - if (_isMine && (nearestAvatarDistance < 3.f)) { - _velocity *= (1.0 - fmin(10.f * glm::length(_velocity) * deltaTime, 1.0)); + // If someone is near, damp velocity as a function of closeness + const float AVATAR_BRAKING_RANGE = 1.2f; + const float AVATAR_BRAKING_STRENGTH = 25.f; + if (_isMine && (nearestAvatarDistance < AVATAR_BRAKING_RANGE )) { + _velocity *= (1.f - deltaTime * AVATAR_BRAKING_STRENGTH * (AVATAR_BRAKING_RANGE - nearestAvatarDistance)); } // update head information diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 055bf73c85..ce15eb07c4 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -221,23 +221,15 @@ void displayStats(void) if (::menuOn == 0) { statsVerticalOffset = 8; } - // bitmap chars are about 10 pels high - char legend[] = "/ - toggle this display, Q - exit, H - show head, M - show hand, T - test audio"; - drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, legend); - char legend2[] = "* - toggle stars, & - toggle paint mode, '-' - send erase all, '%' - send add scene"; - drawtext(10, statsVerticalOffset + 32, 0.10f, 0, 1.0, 0, legend2); - - glm::vec3 avatarPos = myAvatar.getPosition(); - char stats[200]; - sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ", - FPS, packetsPerSecond, bytesPerSecond, avatarPos.x,avatarPos.y,avatarPos.z); - drawtext(10, statsVerticalOffset + 49, 0.10f, 0, 1.0, 0, stats); + sprintf(stats, "%3.0f FPS, %d Pkts/sec, %3.2f Mbps", + FPS, packetsPerSecond, (float)bytesPerSecond * 8.f / 1000000.f); + drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats); std::stringstream voxelStats; voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered() << " Updated: " << voxels.getVoxelsUpdated(); - drawtext(10, statsVerticalOffset + 70, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); + drawtext(10, statsVerticalOffset + 230, 0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); voxelStats.str(""); voxelStats << "Voxels Created: " << voxels.getVoxelsCreated() << " (" << voxels.getVoxelsCreatedPerSecondAverage() @@ -251,7 +243,7 @@ void displayStats(void) voxelStats.str(""); voxelStats << "Voxels Bytes Read: " << voxels.getVoxelsBytesRead() - << " (" << voxels.getVoxelsBytesReadPerSecondAverage() << " Bps)"; + << " (" << voxels.getVoxelsBytesReadPerSecondAverage() * 8.f / 1000000.f << " Mbps)"; drawtext(10, statsVerticalOffset + 290,0.10f, 0, 1.0, 0, (char *)voxelStats.str().c_str()); voxelStats.str(""); @@ -1633,7 +1625,7 @@ int main(int argc, const char * argv[]) } // Handle Local Domain testing with the --local command line - if (true || cmdOptionExists(argc, argv, "--local")) { + if (cmdOptionExists(argc, argv, "--local")) { printLog("Local Domain MODE!\n"); int ip = getLocalAddress(); sprintf(DOMAIN_IP,"%d.%d.%d.%d", (ip & 0xFF), ((ip >> 8) & 0xFF),((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF));