From 2f8b9cbf2b6da9e3914ce898e64b27894c5259a8 Mon Sep 17 00:00:00 2001 From: Teravus Ovares (Dan Olivares) Date: Tue, 8 Dec 2009 11:28:13 -0500 Subject: * Commit some sit code that's commented out for now. --- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 228 +++++++++++++++++++++-- 1 file changed, 215 insertions(+), 13 deletions(-) (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 24840d4..7cdbd4b 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -124,6 +124,7 @@ namespace OpenSim.Region.Framework.Scenes private Vector3? m_forceToApply; private uint m_requestedSitTargetID; private UUID m_requestedSitTargetUUID; + private Vector3 m_requestedSitOffset; private SendCourseLocationsMethod m_sendCourseLocationsMethod; private bool m_startAnimationSet; @@ -1663,11 +1664,11 @@ namespace OpenSim.Region.Framework.Scenes return targetPart; } - private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset) + private void SendSitResponse(IClientAPI remoteClient, UUID targetID, Vector3 offset, Quaternion pSitOrientation) { bool autopilot = true; Vector3 pos = new Vector3(); - Quaternion sitOrientation = Quaternion.Identity; + Quaternion sitOrientation = pSitOrientation; Vector3 cameraEyeOffset = Vector3.Zero; Vector3 cameraAtOffset = Vector3.Zero; bool forceMouselook = false; @@ -1766,12 +1767,17 @@ namespace OpenSim.Region.Framework.Scenes m_nextSitAnimation = part.SitAnimation; } m_requestedSitTargetID = part.LocalId; - //m_requestedSitOffset = offset; - //offset.X += part.Scale.X;// *offset.X; - //offset.Y += part.Scale.Y;// * offset.Y; - //offset.Z += part.Scale.Z;// * offset.Z; - //m_requestedSitOffset = offset; + m_requestedSitOffset = offset; + m_requestedSitTargetUUID = targetID; + m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); + + if (m_scene.PhysicsScene.SupportsRayCast()) + { + //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback()); + //SitRayCastAvatarPosition(part); + //return; + } } else { @@ -1779,14 +1785,201 @@ namespace OpenSim.Region.Framework.Scenes m_log.Warn("Sit requested on unknown object: " + targetID.ToString()); } - if (m_scene.PhysicsScene.SupportsRayCast()) + + + SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); + } + /* + public void SitRayCastAvatarPosition(SceneObjectPart part) + { + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = AbsolutePosition; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionResponse); + } + + public void SitRayCastAvatarPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) + { + SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); + if (part != null) { - //m_scene.PhysicsScene.RaycastWorld(Vector3.Zero,Vector3.Zero, 0.01f,new RaycastCallback()); + if (hitYN) + { + if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) + { + SitRaycastFindEdge(collisionPoint, normal); + m_log.DebugFormat("[SIT]: Raycast Avatar Position succeeded at point: {0}, normal:{1}", collisionPoint, normal ); + } + else + { + SitRayCastAvatarPositionCameraZ(part); + } + } + else + { + SitRayCastAvatarPositionCameraZ(part); + } + } + else + { + ControllingClient.SendAlertMessage("Sit position no longer exists"); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; } - SendSitResponse(remoteClient, targetID, offset); } - + + public void SitRayCastAvatarPositionCameraZ(SceneObjectPart part) + { + // Next, try to raycast from the camera Z position + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = AbsolutePosition; StartRayCastPosition.Z = CameraPosition.Z; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastAvatarPositionCameraZResponse); + } + + public void SitRayCastAvatarPositionCameraZResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) + { + SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); + if (part != null) + { + if (hitYN) + { + if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) + { + SitRaycastFindEdge(collisionPoint, normal); + m_log.DebugFormat("[SIT]: Raycast Avatar Position + CameraZ succeeded at point: {0}, normal:{1}", collisionPoint, normal); + } + else + { + SitRayCastCameraPosition(part); + } + } + else + { + SitRayCastCameraPosition(part); + } + } + else + { + ControllingClient.SendAlertMessage("Sit position no longer exists"); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + + } + + public void SitRayCastCameraPosition(SceneObjectPart part) + { + // Next, try to raycast from the camera position + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = CameraPosition; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastCameraPositionResponse); + } + + public void SitRayCastCameraPositionResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) + { + SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); + if (part != null) + { + if (hitYN) + { + if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) + { + SitRaycastFindEdge(collisionPoint, normal); + m_log.DebugFormat("[SIT]: Raycast Camera Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); + } + else + { + SitRayHorizontal(part); + } + } + else + { + SitRayHorizontal(part); + } + } + else + { + ControllingClient.SendAlertMessage("Sit position no longer exists"); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + + } + + public void SitRayHorizontal(SceneObjectPart part) + { + // Next, try to raycast from the avatar position to fwd + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = CameraPosition; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastHorizontalResponse); + } + + public void SitRayCastHorizontalResponse(bool hitYN, Vector3 collisionPoint, uint localid, float pdistance, Vector3 normal) + { + SceneObjectPart part = FindNextAvailableSitTarget(m_requestedSitTargetUUID); + if (part != null) + { + if (hitYN) + { + if (collisionPoint.ApproxEquals(m_requestedSitOffset + part.AbsolutePosition, 0.2f)) + { + SitRaycastFindEdge(collisionPoint, normal); + m_log.DebugFormat("[SIT]: Raycast Horizontal Position succeeded at point: {0}, normal:{1}", collisionPoint, normal); + // Next, try to raycast from the camera position + Vector3 EndRayCastPosition = part.AbsolutePosition + m_requestedSitOffset; + Vector3 StartRayCastPosition = CameraPosition; + Vector3 direction = Vector3.Normalize(EndRayCastPosition - StartRayCastPosition); + float distance = Vector3.Distance(EndRayCastPosition, StartRayCastPosition); + //m_scene.PhysicsScene.RaycastWorld(StartRayCastPosition, direction, distance, SitRayCastResponseAvatarPosition); + } + else + { + ControllingClient.SendAlertMessage("Sit position not accessable."); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + } + else + { + ControllingClient.SendAlertMessage("Sit position not accessable."); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + } + else + { + ControllingClient.SendAlertMessage("Sit position no longer exists"); + m_requestedSitTargetUUID = UUID.Zero; + m_requestedSitTargetID = 0; + m_requestedSitOffset = Vector3.Zero; + } + + } + + private void SitRaycastFindEdge(Vector3 collisionPoint, Vector3 collisionNormal) + { + int i = 0; + //throw new NotImplementedException(); + //m_requestedSitTargetUUID = UUID.Zero; + //m_requestedSitTargetID = 0; + //m_requestedSitOffset = Vector3.Zero; + + SendSitResponse(ControllingClient, m_requestedSitTargetUUID, collisionPoint - m_requestedSitOffset, Quaternion.Identity); + } + */ public void HandleAgentRequestSit(IClientAPI remoteClient, UUID agentID, UUID targetID, Vector3 offset, string sitAnimation) { if (m_parentID != 0) @@ -1807,14 +2000,23 @@ namespace OpenSim.Region.Framework.Scenes if (part != null) { m_requestedSitTargetID = part.LocalId; - //m_requestedSitOffset = offset; + m_requestedSitOffset = offset; + m_requestedSitTargetUUID = targetID; + + m_log.DebugFormat("[SIT]: Client requested Sit Position: {0}", offset); + + if (m_scene.PhysicsScene.SupportsRayCast()) + { + //SitRayCastAvatarPosition(part); + //return; + } } else { m_log.Warn("Sit requested on unknown object: " + targetID); } - SendSitResponse(remoteClient, targetID, offset); + SendSitResponse(remoteClient, targetID, offset, Quaternion.Identity); } public void HandleAgentSit(IClientAPI remoteClient, UUID agentID) -- cgit v1.1