From 070a8e6c351ac115c3063615a1a7c8a31ef33a48 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Tue, 21 Sep 2010 18:23:43 +0200 Subject: Double-click teleport: - clean up duplicated (and subtly and needlessly different) code. - keep the camera heading in inter-sim double-click teleport in a hackish way, since SL sims give LookAt info that is kind of random in AgentMovementComplete. --- linden/indra/newview/chatbar_as_cmdline.cpp | 4 +- linden/indra/newview/llagent.cpp | 81 ++++++++++++++--------------- linden/indra/newview/llagent.h | 9 +++- linden/indra/newview/llviewermenu.cpp | 4 +- linden/indra/newview/llviewermessage.cpp | 8 ++- 5 files changed, 58 insertions(+), 48 deletions(-) diff --git a/linden/indra/newview/chatbar_as_cmdline.cpp b/linden/indra/newview/chatbar_as_cmdline.cpp index 59804c0..9359444 100644 --- a/linden/indra/newview/chatbar_as_cmdline.cpp +++ b/linden/indra/newview/chatbar_as_cmdline.cpp @@ -16,7 +16,7 @@ * may be used to endorse or promote products derived from this * software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY MODULAR SYSTEMS AND CONTRIBUTORS “AS IS” + * THIS SOFTWARE IS PROVIDED BY MODULAR SYSTEMS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MODULAR SYSTEMS OR CONTRIBUTORS @@ -331,7 +331,7 @@ bool cmd_line_chat(std::string revised_text, EChatType type) } else if(command == *sCmdLineChatbarTeleportToCam) { - gAgent.teleportViaLocation(gAgent.getCameraPositionGlobal()); + gAgent.teleportViaLocationLookAt(gAgent.getCameraPositionGlobal()); return false; } /*else if(command == *sCmdLineChatbarUndeform) diff --git a/linden/indra/newview/llagent.cpp b/linden/indra/newview/llagent.cpp index 51b6c53..077da53 100644 --- a/linden/indra/newview/llagent.cpp +++ b/linden/indra/newview/llagent.cpp @@ -400,7 +400,8 @@ LLAgent::LLAgent() : mAgentWearablesUpdateSerialNum(0), mWearablesLoaded(FALSE), mTextureCacheQueryID(0), - mAppearanceSerialNum(0) + mAppearanceSerialNum(0), + mbTeleportKeepsLookAt(false) { U32 i; for (i = 0; i < TOTAL_CONTROLS; i++) @@ -6099,16 +6100,21 @@ bool LLAgent::teleportCore(bool is_local) void LLAgent::teleportRequest( const U64& region_handle, - const LLVector3& pos_local) + const LLVector3& pos_local, + bool keep_look_at) { LLViewerRegion* regionp = getRegion(); - + if (!regionp) + { + return; + } // Set last region data for teleport history gAgent.setLastRegionData(regionp->getName(),gAgent.getPositionAgent()); - if(regionp && teleportCore()) + bool is_local = (region_handle == to_region_handle(getPositionGlobal())); + if(teleportCore(is_local)) { - llinfos << "TeleportRequest: '" << region_handle << "':" << pos_local + llinfos << "TeleportLocationRequest: '" << region_handle << "':" << pos_local << llendl; LLMessageSystem* msg = gMessageSystem; msg->newMessage("TeleportLocationRequest"); @@ -6119,6 +6125,10 @@ void LLAgent::teleportRequest( msg->addU64("RegionHandle", region_handle); msg->addVector3("Position", pos_local); LLVector3 look_at(0,1,0); + if (keep_look_at) + { + look_at = LLViewerCamera::getInstance()->getAtAxis(); + } msg->addVector3("LookAt", look_at); sendReliableMessage(); } @@ -6219,46 +6229,29 @@ void LLAgent::teleportViaLocation(const LLVector3d& pos_global) } // [/RLVa:KB] - LLViewerRegion* regionp = getRegion(); - LLSimInfo* info = LLWorldMap::getInstance()->simInfoFromPosGlobal(pos_global); - if(regionp && info) - { - U32 x_pos; - U32 y_pos; - from_region_handle(info->mHandle, &x_pos, &y_pos); - LLVector3 pos_local( - (F32)(pos_global.mdV[VX] - x_pos), - (F32)(pos_global.mdV[VY] - y_pos), - (F32)(pos_global.mdV[VZ])); - teleportRequest(info->mHandle, pos_local); - } - else if(regionp && - teleportCore(regionp->getHandle() == to_region_handle_global((F32)pos_global.mdV[VX], (F32)pos_global.mdV[VY]))) - { - llwarns << "Using deprecated teleportlocationrequest." << llendl; - // send the message - LLMessageSystem* msg = gMessageSystem; - msg->newMessageFast(_PREHASH_TeleportLocationRequest); - msg->nextBlockFast(_PREHASH_AgentData); - msg->addUUIDFast(_PREHASH_AgentID, getID()); - msg->addUUIDFast(_PREHASH_SessionID, getSessionID()); + U64 region_handle = to_region_handle(pos_global); + LLVector3 pos_local = (LLVector3)(pos_global - from_region_handle(region_handle)); + teleportRequest(region_handle, pos_local, false); +} - msg->nextBlockFast(_PREHASH_Info); - F32 width = regionp->getWidth(); - LLVector3 pos(fmod((F32)pos_global.mdV[VX], width), - fmod((F32)pos_global.mdV[VY], width), - (F32)pos_global.mdV[VZ]); - F32 region_x = (F32)(pos_global.mdV[VX]); - F32 region_y = (F32)(pos_global.mdV[VY]); - U64 region_handle = to_region_handle_global(region_x, region_y); - msg->addU64Fast(_PREHASH_RegionHandle, region_handle); - msg->addVector3Fast(_PREHASH_Position, pos); - pos.mV[VX] += 1; - msg->addVector3Fast(_PREHASH_LookAt, pos); - sendReliableMessage(); +// Teleport to global position, but keep facing in the same direction +void LLAgent::teleportViaLocationLookAt(const LLVector3d& pos_global) +{ + // RLVa stuff copied from LLAgent::teleportViaLocation + if ( (rlv_handler_t::isEnabled()) && + ( (gRlvHandler.hasBehaviourExcept(RLV_BHVR_TPLOC, gRlvHandler.getCurrentObject())) || + ( (mAvatarObject.notNull()) && (mAvatarObject->mIsSitting) && + (gRlvHandler.hasBehaviourExcept(RLV_BHVR_UNSIT, gRlvHandler.getCurrentObject()))) ) ) + { + return; } -} + mbTeleportKeepsLookAt = true; + setFocusOnAvatar(FALSE, ANIMATE); // detach camera form avatar, so it keeps direction + U64 region_handle = to_region_handle(pos_global); + LLVector3 pos_local = (LLVector3)(pos_global - from_region_handle(region_handle)); + teleportRequest(region_handle, pos_local, mbTeleportKeepsLookAt); +} void LLAgent::teleportHome() { @@ -6286,6 +6279,10 @@ bool LLAgent::teleportHomeCallback( const LLSD& notification, const LLSD& respon void LLAgent::setTeleportState(ETeleportState state) { mTeleportState = state; + if (mTeleportState == TELEPORT_NONE) + { + mbTeleportKeepsLookAt = false; + } if (mTeleportState > TELEPORT_NONE && gSavedSettings.getBOOL("FreezeTime")) { LLFloaterSnapshot::hide(0); diff --git a/linden/indra/newview/llagent.h b/linden/indra/newview/llagent.h index 3a39448..f1cad9c 100644 --- a/linden/indra/newview/llagent.h +++ b/linden/indra/newview/llagent.h @@ -496,7 +496,8 @@ public: // go to a named location home void teleportRequest( const U64& region_handle, - const LLVector3& pos_local); + const LLVector3& pos_local, + bool keep_look_at); // teleport to a landmark void teleportViaLandmark(const LLUUID& landmark_id); @@ -513,6 +514,9 @@ public: // deprecated. void teleportViaLocation(const LLVector3d& pos_global); + // to a global location, preserving camera rotation + void teleportViaLocationLookAt(const LLVector3d& pos_global); + // cancel the teleport, may or may not be allowed by server void teleportCancel(); @@ -521,6 +525,8 @@ public: const std::string getTeleportSourceSLURL() const { return mTeleportSourceSLURL; } + // whether look-at resets after this teleport + bool getTeleportKeepsLookAt() const { return mbTeleportKeepsLookAt; } // Setting the ability for this avatar to proxy for another avatar. //static void processAddModifyAbility(LLMessageSystem* msg, void**); @@ -781,6 +787,7 @@ public: EDoubleTapRunMode mDoubleTapRunMode; private: + bool mbTeleportKeepsLookAt; bool mbAlwaysRun; // should the avatar run by default rather than walk bool mbRunning; // is the avatar trying to run right now diff --git a/linden/indra/newview/llviewermenu.cpp b/linden/indra/newview/llviewermenu.cpp index fd6e842..71938d9 100644 --- a/linden/indra/newview/llviewermenu.cpp +++ b/linden/indra/newview/llviewermenu.cpp @@ -2576,9 +2576,9 @@ bool handle_go_to_callback(const LLSD& notification, const LLSD& response) if (action == "teleport") { - LLVector3d hips_offset(0.0f, 0.0f, 1.2f); + pos.mdV[VZ] += gAgent.getAvatarObject()->getPelvisToFoot() + 0.2f; gAgent.setControlFlags(AGENT_CONTROL_STAND_UP); - gAgent.teleportViaLocation(pos + hips_offset); + gAgent.teleportViaLocationLookAt(pos); } else if (action == "move") { diff --git a/linden/indra/newview/llviewermessage.cpp b/linden/indra/newview/llviewermessage.cpp index bfd1045..e216c44 100755 --- a/linden/indra/newview/llviewermessage.cpp +++ b/linden/indra/newview/llviewermessage.cpp @@ -3540,6 +3540,12 @@ void process_agent_movement_complete(LLMessageSystem* msg, void**) if( is_teleport ) { + if (gAgent.getTeleportKeepsLookAt()) + { + // *NOTE: the LookAt data we get from the sim here doesn't + // seem to be useful, so get it from the camera instead. + look_at = LLViewerCamera::getInstance()->getAtAxis(); + } // Force the camera back onto the agent, don't animate. gAgent.setFocusOnAvatar(TRUE, FALSE); gAgent.slamLookAt(look_at); @@ -3601,7 +3607,7 @@ void process_agent_movement_complete(LLMessageSystem* msg, void**) { LLTracker::stopTracking(NULL); } - else if ( is_teleport ) + else if ( is_teleport && !gAgent.getTeleportKeepsLookAt() ) { //look at the beacon LLVector3 global_agent_pos = agent_pos; -- cgit v1.1