diff options
author | UbitUmarov | 2018-01-04 23:59:47 +0000 |
---|---|---|
committer | UbitUmarov | 2018-01-04 23:59:47 +0000 |
commit | ce0aa53cc43a99ee9bb82cd912758629d278d46e (patch) | |
tree | 07b2af5c589f6346d7b688eaedc67b06ed66b30e /OpenSim | |
parent | disable some XmlResolver (diff) | |
download | opensim-SC-ce0aa53cc43a99ee9bb82cd912758629d278d46e.zip opensim-SC-ce0aa53cc43a99ee9bb82cd912758629d278d46e.tar.gz opensim-SC-ce0aa53cc43a99ee9bb82cd912758629d278d46e.tar.bz2 opensim-SC-ce0aa53cc43a99ee9bb82cd912758629d278d46e.tar.xz |
let tau do something in avatar MoveToTarget
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 296 |
1 files changed, 163 insertions, 133 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 6bce406..e10e787 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -101,7 +101,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
101 | public bool IsGod { get; set; } | 101 | public bool IsGod { get; set; } |
102 | 102 | ||
103 | private PresenceType m_presenceType; | 103 | private PresenceType m_presenceType; |
104 | public PresenceType PresenceType { | 104 | public PresenceType PresenceType |
105 | { | ||
105 | get {return m_presenceType;} | 106 | get {return m_presenceType;} |
106 | private set | 107 | private set |
107 | { | 108 | { |
@@ -368,8 +369,28 @@ namespace OpenSim.Region.Framework.Scenes | |||
368 | private Quaternion m_headrotation = Quaternion.Identity; | 369 | private Quaternion m_headrotation = Quaternion.Identity; |
369 | 370 | ||
370 | //PauPaw:Proper PID Controler for autopilot************ | 371 | //PauPaw:Proper PID Controler for autopilot************ |
371 | public bool MovingToTarget { get; private set; } | 372 | |
372 | public Vector3 MoveToPositionTarget { get; private set; } | 373 | private bool m_movingToTarget; |
374 | public bool MovingToTarget | ||
375 | { | ||
376 | get {return m_movingToTarget;} | ||
377 | private set {m_movingToTarget = value; } | ||
378 | } | ||
379 | |||
380 | private Vector3 m_moveToPositionTarget; | ||
381 | public Vector3 MoveToPositionTarget | ||
382 | { | ||
383 | get {return m_moveToPositionTarget;} | ||
384 | private set {m_moveToPositionTarget = value; } | ||
385 | } | ||
386 | |||
387 | private float m_moveToSpeed; | ||
388 | public float MoveToSpeed | ||
389 | { | ||
390 | get {return m_moveToSpeed;} | ||
391 | private set {m_moveToSpeed = value; } | ||
392 | } | ||
393 | |||
373 | private double m_delayedStop = -1.0; | 394 | private double m_delayedStop = -1.0; |
374 | 395 | ||
375 | /// <summary> | 396 | /// <summary> |
@@ -1160,7 +1181,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1160 | ControllingClient.OnStopAnim += HandleStopAnim; | 1181 | ControllingClient.OnStopAnim += HandleStopAnim; |
1161 | ControllingClient.OnChangeAnim += avnHandleChangeAnim; | 1182 | ControllingClient.OnChangeAnim += avnHandleChangeAnim; |
1162 | ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; | 1183 | ControllingClient.OnForceReleaseControls += HandleForceReleaseControls; |
1163 | ControllingClient.OnAutoPilotGo += MoveToTarget; | 1184 | ControllingClient.OnAutoPilotGo += MoveToTargetHandle; |
1164 | ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles; | 1185 | ControllingClient.OnUpdateThrottles += RaiseUpdateThrottles; |
1165 | // ControllingClient.OnAgentFOV += HandleAgentFOV; | 1186 | // ControllingClient.OnAgentFOV += HandleAgentFOV; |
1166 | 1187 | ||
@@ -1180,7 +1201,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1180 | ControllingClient.OnStopAnim -= HandleStopAnim; | 1201 | ControllingClient.OnStopAnim -= HandleStopAnim; |
1181 | ControllingClient.OnChangeAnim -= avnHandleChangeAnim; | 1202 | ControllingClient.OnChangeAnim -= avnHandleChangeAnim; |
1182 | ControllingClient.OnForceReleaseControls -= HandleForceReleaseControls; | 1203 | ControllingClient.OnForceReleaseControls -= HandleForceReleaseControls; |
1183 | ControllingClient.OnAutoPilotGo -= MoveToTarget; | 1204 | ControllingClient.OnAutoPilotGo -= MoveToTargetHandle; |
1184 | ControllingClient.OnUpdateThrottles -= RaiseUpdateThrottles; | 1205 | ControllingClient.OnUpdateThrottles -= RaiseUpdateThrottles; |
1185 | // ControllingClient.OnAgentFOV += HandleAgentFOV; | 1206 | // ControllingClient.OnAgentFOV += HandleAgentFOV; |
1186 | } | 1207 | } |
@@ -2587,11 +2608,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
2587 | } | 2608 | } |
2588 | 2609 | ||
2589 | bool update_movementflag = false; | 2610 | bool update_movementflag = false; |
2590 | bool mvToTarget = MovingToTarget; | 2611 | bool mvToTarget = m_movingToTarget; |
2591 | if (agentData.UseClientAgentPosition) | 2612 | if (agentData.UseClientAgentPosition) |
2592 | { | 2613 | { |
2593 | MovingToTarget = (agentData.ClientAgentPosition - AbsolutePosition).LengthSquared() > 0.04f; | 2614 | m_movingToTarget = (agentData.ClientAgentPosition - AbsolutePosition).LengthSquared() > 0.04f; |
2594 | MoveToPositionTarget = agentData.ClientAgentPosition; | 2615 | m_moveToPositionTarget = agentData.ClientAgentPosition; |
2616 | m_moveToSpeed = -1f; | ||
2595 | } | 2617 | } |
2596 | 2618 | ||
2597 | int i = 0; | 2619 | int i = 0; |
@@ -2686,7 +2708,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2686 | update_movementflag = true; | 2708 | update_movementflag = true; |
2687 | } | 2709 | } |
2688 | 2710 | ||
2689 | if (MovingToTarget) | 2711 | if (m_movingToTarget) |
2690 | { | 2712 | { |
2691 | // If the user has pressed a key then we want to cancel any move to target. | 2713 | // If the user has pressed a key then we want to cancel any move to target. |
2692 | if (DCFlagKeyPressed) | 2714 | if (DCFlagKeyPressed) |
@@ -2787,7 +2809,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2787 | } | 2809 | } |
2788 | else | 2810 | else |
2789 | { | 2811 | { |
2790 | if(MovingToTarget || | 2812 | if(m_movingToTarget || |
2791 | (Animator.currentControlState != ScenePresenceAnimator.motionControlStates.flying && | 2813 | (Animator.currentControlState != ScenePresenceAnimator.motionControlStates.flying && |
2792 | Animator.currentControlState != ScenePresenceAnimator.motionControlStates.onsurface) | 2814 | Animator.currentControlState != ScenePresenceAnimator.motionControlStates.onsurface) |
2793 | ) | 2815 | ) |
@@ -2878,7 +2900,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2878 | 2900 | ||
2879 | bool updated = false; | 2901 | bool updated = false; |
2880 | 2902 | ||
2881 | Vector3 LocalVectorToTarget3D = MoveToPositionTarget - AbsolutePosition; | 2903 | Vector3 LocalVectorToTarget3D = m_moveToPositionTarget - AbsolutePosition; |
2882 | 2904 | ||
2883 | // m_log.DebugFormat( | 2905 | // m_log.DebugFormat( |
2884 | // "[SCENE PRESENCE]: bAllowUpdateMoveToPosition {0}, m_moveToPositionInProgress {1}, m_autopilotMoving {2}", | 2906 | // "[SCENE PRESENCE]: bAllowUpdateMoveToPosition {0}, m_moveToPositionInProgress {1}, m_autopilotMoving {2}", |
@@ -2891,9 +2913,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
2891 | } | 2913 | } |
2892 | else | 2914 | else |
2893 | { | 2915 | { |
2894 | Vector3 hdist = LocalVectorToTarget3D; | 2916 | distanceToTarget = (float)Math.Sqrt(LocalVectorToTarget3D.X * LocalVectorToTarget3D.X + |
2895 | hdist.Z = 0; | 2917 | LocalVectorToTarget3D.Y * LocalVectorToTarget3D.Y); |
2896 | distanceToTarget = hdist.Length(); | ||
2897 | } | 2918 | } |
2898 | 2919 | ||
2899 | // m_log.DebugFormat( | 2920 | // m_log.DebugFormat( |
@@ -2905,128 +2926,126 @@ namespace OpenSim.Region.Framework.Scenes | |||
2905 | { | 2926 | { |
2906 | // We are close enough to the target | 2927 | // We are close enough to the target |
2907 | Velocity = Vector3.Zero; | 2928 | Velocity = Vector3.Zero; |
2908 | AbsolutePosition = MoveToPositionTarget; | 2929 | AbsolutePosition = m_moveToPositionTarget; |
2909 | if (Flying) | 2930 | if (Flying) |
2910 | { | 2931 | { |
2911 | if (LandAtTarget) | 2932 | if (LandAtTarget) |
2912 | Flying = false; | 2933 | Flying = false; |
2913 | 2934 | ||
2914 | // A horrible hack to stop the avatar dead in its tracks rather than having them overshoot | 2935 | // A horrible hack to stop the avatar dead in its tracks rather than having them overshoot |
2915 | // the target if flying. | 2936 | // the target if flying. |
2916 | // We really need to be more subtle (slow the avatar as it approaches the target) or at | 2937 | // We really need to be more subtle (slow the avatar as it approaches the target) or at |
2917 | // least be able to set collision status once, rather than 5 times to give it enough | 2938 | // least be able to set collision status once, rather than 5 times to give it enough |
2918 | // weighting so that that PhysicsActor thinks it really is colliding. | 2939 | // weighting so that that PhysicsActor thinks it really is colliding. |
2919 | for (int i = 0; i < 5; i++) | 2940 | for (int i = 0; i < 5; i++) |
2920 | IsColliding = true; | 2941 | IsColliding = true; |
2921 | } | 2942 | } |
2922 | ResetMoveToTarget(); | 2943 | ResetMoveToTarget(); |
2923 | return false; | 2944 | return false; |
2924 | } | 2945 | } |
2925 | else | ||
2926 | { | ||
2927 | try | ||
2928 | { | ||
2929 | // move avatar in 3D at one meter/second towards target, in avatar coordinate frame. | ||
2930 | // This movement vector gets added to the velocity through AddNewMovement(). | ||
2931 | // Theoretically we might need a more complex PID approach here if other | ||
2932 | // unknown forces are acting on the avatar and we need to adaptively respond | ||
2933 | // to such forces, but the following simple approach seems to works fine. | ||
2934 | |||
2935 | LocalVectorToTarget3D = LocalVectorToTarget3D * Quaternion.Inverse(Rotation); // change to avatar coords | ||
2936 | 2946 | ||
2937 | LocalVectorToTarget3D.Normalize(); | 2947 | if(m_moveToSpeed > 0 && distanceToTarget <= m_moveToSpeed * Scene.FrameTime) |
2938 | 2948 | m_moveToSpeed = distanceToTarget / Scene.FrameTime; | |
2939 | // update avatar movement flags. the avatar coordinate system is as follows: | ||
2940 | // | ||
2941 | // +X (forward) | ||
2942 | // | ||
2943 | // ^ | ||
2944 | // | | ||
2945 | // | | ||
2946 | // | | ||
2947 | // | | ||
2948 | // (left) +Y <--------o--------> -Y | ||
2949 | // avatar | ||
2950 | // | | ||
2951 | // | | ||
2952 | // | | ||
2953 | // | | ||
2954 | // v | ||
2955 | // -X | ||
2956 | // | ||
2957 | |||
2958 | // based on the above avatar coordinate system, classify the movement into | ||
2959 | // one of left/right/back/forward. | ||
2960 | |||
2961 | const uint noMovFlagsMask = (uint)(~(Dir_ControlFlags.DIR_CONTROL_FLAG_BACK | | ||
2962 | Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD | Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT | | ||
2963 | Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT | Dir_ControlFlags.DIR_CONTROL_FLAG_UP | | ||
2964 | Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN)); | ||
2965 | |||
2966 | MovementFlag &= noMovFlagsMask; | ||
2967 | uint tmpAgentControlFlags = (uint)m_AgentControlFlags; | ||
2968 | tmpAgentControlFlags &= noMovFlagsMask; | ||
2969 | |||
2970 | if (LocalVectorToTarget3D.X < 0) //MoveBack | ||
2971 | { | ||
2972 | MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; | ||
2973 | tmpAgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; | ||
2974 | updated = true; | ||
2975 | } | ||
2976 | else if (LocalVectorToTarget3D.X > 0) //Move Forward | ||
2977 | { | ||
2978 | MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; | ||
2979 | tmpAgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; | ||
2980 | updated = true; | ||
2981 | } | ||
2982 | |||
2983 | if (LocalVectorToTarget3D.Y > 0) //MoveLeft | ||
2984 | { | ||
2985 | MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; | ||
2986 | tmpAgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; | ||
2987 | updated = true; | ||
2988 | } | ||
2989 | else if (LocalVectorToTarget3D.Y < 0) //MoveRight | ||
2990 | { | ||
2991 | MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; | ||
2992 | tmpAgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; | ||
2993 | updated = true; | ||
2994 | } | ||
2995 | |||
2996 | if (LocalVectorToTarget3D.Z > 0) //Up | ||
2997 | { | ||
2998 | // Don't set these flags for up or down - doing so will make the avatar crouch or | ||
2999 | // keep trying to jump even if walking along level ground | ||
3000 | //MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP; | ||
3001 | //AgentControlFlags | ||
3002 | //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_UP; | ||
3003 | updated = true; | ||
3004 | } | ||
3005 | else if (LocalVectorToTarget3D.Z < 0) //Down | ||
3006 | { | ||
3007 | //MovementFlag += (byte)(uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN; | ||
3008 | //AgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN; | ||
3009 | updated = true; | ||
3010 | } | ||
3011 | 2949 | ||
2950 | try | ||
2951 | { | ||
2952 | // move avatar in 3D towards target, in avatar coordinate frame. | ||
2953 | // This movement vector gets added to the velocity through AddNewMovement(). | ||
2954 | // Theoretically we might need a more complex PID approach here if other | ||
2955 | // unknown forces are acting on the avatar and we need to adaptively respond | ||
2956 | // to such forces, but the following simple approach seems to works fine. | ||
2957 | |||
2958 | float angle = 0.5f * (float)Math.Atan2(LocalVectorToTarget3D.Y, LocalVectorToTarget3D.X); | ||
2959 | Quaternion rot = new Quaternion(0,0, (float)Math.Sin(angle),(float)Math.Cos(angle)); | ||
2960 | Rotation = rot; | ||
2961 | LocalVectorToTarget3D = LocalVectorToTarget3D * Quaternion.Inverse(rot); // change to avatar coords | ||
2962 | LocalVectorToTarget3D.Normalize(); | ||
2963 | |||
2964 | // update avatar movement flags. the avatar coordinate system is as follows: | ||
2965 | // | ||
2966 | // +X (forward) | ||
2967 | // | ||
2968 | // ^ | ||
2969 | // | | ||
2970 | // | | ||
2971 | // | | ||
2972 | // | | ||
2973 | // (left) +Y <--------o--------> -Y | ||
2974 | // avatar | ||
2975 | // | | ||
2976 | // | | ||
2977 | // | | ||
2978 | // | | ||
2979 | // v | ||
2980 | // -X | ||
2981 | // | ||
2982 | |||
2983 | // based on the above avatar coordinate system, classify the movement into | ||
2984 | // one of left/right/back/forward. | ||
2985 | |||
2986 | const uint noMovFlagsMask = (uint)(~(Dir_ControlFlags.DIR_CONTROL_FLAG_BACK | | ||
2987 | Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD | Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT | | ||
2988 | Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT | Dir_ControlFlags.DIR_CONTROL_FLAG_UP | | ||
2989 | Dir_ControlFlags.DIR_CONTROL_FLAG_DOWN)); | ||
2990 | |||
2991 | MovementFlag &= noMovFlagsMask; | ||
2992 | uint tmpAgentControlFlags = (uint)m_AgentControlFlags; | ||
2993 | tmpAgentControlFlags &= noMovFlagsMask; | ||
2994 | |||
2995 | if (LocalVectorToTarget3D.X < 0) //MoveBack | ||
2996 | { | ||
2997 | MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; | ||
2998 | tmpAgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_BACK; | ||
2999 | updated = true; | ||
3000 | } | ||
3001 | else if (LocalVectorToTarget3D.X > 0) //Move Forward | ||
3002 | { | ||
3003 | MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; | ||
3004 | tmpAgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD; | ||
3005 | updated = true; | ||
3006 | } | ||
3007 | |||
3008 | if (LocalVectorToTarget3D.Y > 0) //MoveLeft | ||
3009 | { | ||
3010 | MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; | ||
3011 | tmpAgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_LEFT; | ||
3012 | updated = true; | ||
3013 | } | ||
3014 | else if (LocalVectorToTarget3D.Y < 0) //MoveRight | ||
3015 | { | ||
3016 | MovementFlag |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; | ||
3017 | tmpAgentControlFlags |= (uint)Dir_ControlFlags.DIR_CONTROL_FLAG_RIGHT; | ||
3018 | updated = true; | ||
3019 | } | ||
3020 | |||
3021 | if (LocalVectorToTarget3D.Z > 0) //Up | ||
3022 | updated = true; | ||
3023 | |||
3024 | else if (LocalVectorToTarget3D.Z < 0) //Down | ||
3025 | updated = true; | ||
3026 | |||
3012 | // m_log.DebugFormat( | 3027 | // m_log.DebugFormat( |
3013 | // "[SCENE PRESENCE]: HandleMoveToTargetUpdate adding {0} to move vector {1} for {2}", | 3028 | // "[SCENE PRESENCE]: HandleMoveToTargetUpdate adding {0} to move vector {1} for {2}", |
3014 | // LocalVectorToTarget3D, agent_control_v3, Name); | 3029 | // LocalVectorToTarget3D, agent_control_v3, Name); |
3015 | 3030 | ||
3016 | m_AgentControlFlags = (AgentManager.ControlFlags) tmpAgentControlFlags; | 3031 | m_AgentControlFlags = (AgentManager.ControlFlags) tmpAgentControlFlags; |
3032 | if(updated) | ||
3017 | agent_control_v3 += LocalVectorToTarget3D; | 3033 | agent_control_v3 += LocalVectorToTarget3D; |
3018 | } | 3034 | } |
3019 | catch (Exception e) | 3035 | catch (Exception e) |
3020 | { | 3036 | { |
3021 | //Avoid system crash, can be slower but... | 3037 | //Avoid system crash, can be slower but... |
3022 | m_log.DebugFormat("Crash! {0}", e.ToString()); | 3038 | m_log.DebugFormat("Crash! {0}", e.ToString()); |
3023 | } | ||
3024 | } | 3039 | } |
3025 | 3040 | ||
3026 | return updated; | 3041 | return updated; |
3027 | // AddNewMovement(agent_control_v3); | 3042 | // AddNewMovement(agent_control_v3); |
3028 | } | 3043 | } |
3029 | 3044 | ||
3045 | public void MoveToTargetHandle(Vector3 pos, bool noFly, bool landAtTarget) | ||
3046 | { | ||
3047 | MoveToTarget(pos, noFly, landAtTarget); | ||
3048 | } | ||
3030 | /// <summary> | 3049 | /// <summary> |
3031 | /// Move to the given target over time. | 3050 | /// Move to the given target over time. |
3032 | /// </summary> | 3051 | /// </summary> |
@@ -3039,8 +3058,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3039 | /// <param name="landAtTarget"> | 3058 | /// <param name="landAtTarget"> |
3040 | /// If true and the avatar starts flying during the move then land at the target. | 3059 | /// If true and the avatar starts flying during the move then land at the target. |
3041 | /// </param> | 3060 | /// </param> |
3042 | public void MoveToTarget(Vector3 pos, bool noFly, bool landAtTarget) | 3061 | public void MoveToTarget(Vector3 pos, bool noFly, bool landAtTarget, float tau = -1f) |
3043 | { | 3062 | { |
3044 | m_delayedStop = -1; | 3063 | m_delayedStop = -1; |
3045 | 3064 | ||
3046 | if (SitGround) | 3065 | if (SitGround) |
@@ -3073,30 +3092,36 @@ namespace OpenSim.Region.Framework.Scenes | |||
3073 | // "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}", | 3092 | // "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}", |
3074 | // Name, pos, terrainHeight, m_scene.RegionInfo.RegionName); | 3093 | // Name, pos, terrainHeight, m_scene.RegionInfo.RegionName); |
3075 | 3094 | ||
3095 | terrainHeight += Appearance.AvatarHeight; // so 1.5 * AvatarHeight above ground at target | ||
3076 | bool shouldfly = Flying; | 3096 | bool shouldfly = Flying; |
3077 | if (noFly) | 3097 | if (noFly) |
3078 | shouldfly = false; | 3098 | shouldfly = false; |
3079 | else if (pos.Z > terrainHeight || Flying) | 3099 | else if (pos.Z > terrainHeight || Flying) |
3080 | shouldfly = true; | 3100 | shouldfly = true; |
3081 | 3101 | ||
3082 | LandAtTarget = landAtTarget; | ||
3083 | MovingToTarget = true; | ||
3084 | MoveToPositionTarget = pos; | ||
3085 | Flying = shouldfly; | ||
3086 | |||
3087 | // Rotate presence around the z-axis to point in same direction as movement. | ||
3088 | // Ignore z component of vector | ||
3089 | Vector3 localVectorToTarget3D = pos - AbsolutePosition; | 3102 | Vector3 localVectorToTarget3D = pos - AbsolutePosition; |
3090 | 3103 | ||
3091 | // m_log.DebugFormat("[SCENE PRESENCE]: Local vector to target is {0},[1}", localVectorToTarget3D.X,localVectorToTarget3D.Y); | 3104 | // m_log.DebugFormat("[SCENE PRESENCE]: Local vector to target is {0},[1}", localVectorToTarget3D.X,localVectorToTarget3D.Y); |
3105 | |||
3106 | m_movingToTarget = true; | ||
3107 | LandAtTarget = landAtTarget; | ||
3108 | m_moveToPositionTarget = pos; | ||
3109 | if(tau > 0) | ||
3110 | { | ||
3111 | if(tau < Scene.FrameTime) | ||
3112 | tau = Scene.FrameTime; | ||
3113 | m_moveToSpeed = localVectorToTarget3D.Length() / tau; | ||
3114 | if(m_moveToSpeed < 0.5f) //to tune | ||
3115 | m_moveToSpeed = 0.5f; | ||
3116 | else if(m_moveToSpeed > 50f) | ||
3117 | m_moveToSpeed = 50f; | ||
3092 | 3118 | ||
3093 | // Calculate the yaw. | 3119 | SetAlwaysRun = false; |
3094 | Vector3 angle = new Vector3(0, 0, (float)(Math.Atan2(localVectorToTarget3D.Y, localVectorToTarget3D.X))); | 3120 | } |
3095 | 3121 | else | |
3096 | // m_log.DebugFormat("[SCENE PRESENCE]: Angle is {0}", angle); | 3122 | m_moveToSpeed = 4.096f * m_speedModifier; |
3097 | 3123 | ||
3098 | Rotation = Quaternion.CreateFromEulers(angle); | 3124 | Flying = shouldfly; |
3099 | // m_log.DebugFormat("[SCENE PRESENCE]: Body rot for {0} set to {1}", Name, Rotation); | ||
3100 | 3125 | ||
3101 | Vector3 control = Vector3.Zero; | 3126 | Vector3 control = Vector3.Zero; |
3102 | if(HandleMoveToTargetUpdate(1f, ref control)) | 3127 | if(HandleMoveToTargetUpdate(1f, ref control)) |
@@ -3110,7 +3135,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3110 | { | 3135 | { |
3111 | // m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name); | 3136 | // m_log.DebugFormat("[SCENE PRESENCE]: Resetting move to target for {0}", Name); |
3112 | 3137 | ||
3113 | MovingToTarget = false; | 3138 | m_movingToTarget = false; |
3139 | m_moveToSpeed = -1f; | ||
3114 | // MoveToPositionTarget = Vector3.Zero; | 3140 | // MoveToPositionTarget = Vector3.Zero; |
3115 | // lock(m_forceToApplyLock) | 3141 | // lock(m_forceToApplyLock) |
3116 | // m_forceToApplyValid = false; // cancel possible last action | 3142 | // m_forceToApplyValid = false; // cancel possible last action |
@@ -3294,7 +3320,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3294 | RemoveFromPhysicalScene(); | 3320 | RemoveFromPhysicalScene(); |
3295 | } | 3321 | } |
3296 | 3322 | ||
3297 | if (MovingToTarget) | 3323 | if (m_movingToTarget) |
3298 | ResetMoveToTarget(); | 3324 | ResetMoveToTarget(); |
3299 | 3325 | ||
3300 | Velocity = Vector3.Zero; | 3326 | Velocity = Vector3.Zero; |
@@ -3436,7 +3462,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3436 | 3462 | ||
3437 | RemoveFromPhysicalScene(); | 3463 | RemoveFromPhysicalScene(); |
3438 | 3464 | ||
3439 | if (MovingToTarget) | 3465 | if (m_movingToTarget) |
3440 | ResetMoveToTarget(); | 3466 | ResetMoveToTarget(); |
3441 | 3467 | ||
3442 | Velocity = Vector3.Zero; | 3468 | Velocity = Vector3.Zero; |
@@ -3716,8 +3742,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
3716 | if ((vec.Z == 0f) && !Flying) | 3742 | if ((vec.Z == 0f) && !Flying) |
3717 | direc.Z = 0f; // Prevent camera WASD up. | 3743 | direc.Z = 0f; // Prevent camera WASD up. |
3718 | 3744 | ||
3745 | bool notmvtrgt = !m_movingToTarget || m_moveToSpeed <= 0; | ||
3719 | // odd rescalings | 3746 | // odd rescalings |
3720 | direc *= 0.032f * 128f * SpeedModifier * thisAddSpeedModifier; | 3747 | if(notmvtrgt) |
3748 | direc *= 4.096f * SpeedModifier * thisAddSpeedModifier; | ||
3749 | else | ||
3750 | direc *= m_moveToSpeed; | ||
3721 | 3751 | ||
3722 | // m_log.DebugFormat("[SCENE PRESENCE]: Force to apply before modification was {0} for {1}", direc, Name); | 3752 | // m_log.DebugFormat("[SCENE PRESENCE]: Force to apply before modification was {0} for {1}", direc, Name); |
3723 | 3753 | ||
@@ -3735,12 +3765,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
3735 | // landing situation, prevent avatar moving or it may fail to land | 3765 | // landing situation, prevent avatar moving or it may fail to land |
3736 | // animator will handle this condition and do the land | 3766 | // animator will handle this condition and do the land |
3737 | direc = Vector3.Zero; | 3767 | direc = Vector3.Zero; |
3738 | else | 3768 | else if(notmvtrgt) |
3739 | direc *= 4.0f; | 3769 | direc *= 4.0f; |
3740 | } | 3770 | } |
3741 | else if (IsColliding) | 3771 | else if (IsColliding) |
3742 | { | 3772 | { |
3743 | if (direc.Z > 2.0f) // reinforce jumps | 3773 | if (direc.Z > 2.0f && notmvtrgt) // reinforce jumps |
3744 | { | 3774 | { |
3745 | direc.Z *= 2.6f; | 3775 | direc.Z *= 2.6f; |
3746 | } | 3776 | } |
@@ -3780,7 +3810,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3780 | if (IsInTransit || IsLoggingIn) | 3810 | if (IsInTransit || IsLoggingIn) |
3781 | return; | 3811 | return; |
3782 | 3812 | ||
3783 | if(MovingToTarget) | 3813 | if(m_movingToTarget) |
3784 | { | 3814 | { |
3785 | m_delayedStop = -1; | 3815 | m_delayedStop = -1; |
3786 | Vector3 control = Vector3.Zero; | 3816 | Vector3 control = Vector3.Zero; |