public void checkAtTargets()
        {
            if (m_scriptListens_atTarget || m_scriptListens_notAtTarget)
            {
                if (m_targets.Count > 0)
                {
                    bool at_target = false;
                    //Vector3 targetPos;
                    //uint targetHandle;
                    Dictionary<uint, scriptPosTarget> atTargets = new Dictionary<uint, scriptPosTarget>();
                    lock (m_targets)
                    {
                        foreach (uint idx in m_targets.Keys)
                        {
                            scriptPosTarget target = m_targets[idx];
                            if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance)
                            {
                                // trigger at_target
                                if (m_scriptListens_atTarget)
                                {
                                    at_target = true;
                                    scriptPosTarget att = new scriptPosTarget();
                                    att.targetPos = target.targetPos;
                                    att.tolerance = target.tolerance;
                                    att.handle = target.handle;
                                    atTargets.Add(idx, att);
                                }
                            }
                        }
                    }
                    
                    if (atTargets.Count > 0)
                    {
                        uint[] localids = new uint[0];
                        lock (m_partsLock)
                        {
                            localids = new uint[m_parts.Count];
                            int cntr = 0;
                            foreach (SceneObjectPart part in m_partsList)
                            {
                                localids[cntr] = part.LocalId;
                                cntr++;
                            }
                        }
                        
                        for (int ctr = 0; ctr < localids.Length; ctr++)
                        {
                            foreach (uint target in atTargets.Keys)
                            {
                                scriptPosTarget att = atTargets[target];
                                m_scene.EventManager.TriggerAtTargetEvent(
                                    localids[ctr], att.handle, att.targetPos, m_rootPart.GroupPosition);
                            }
                        }
                        
                        return;
                    }
                    
                    if (m_scriptListens_notAtTarget && !at_target)
                    {
                        //trigger not_at_target
                        uint[] localids = new uint[0];
                        lock (m_partsLock)
                        {
                            localids = new uint[m_parts.Count];
                            int cntr = 0;
                            foreach (SceneObjectPart part in m_partsList)
                            {
                                localids[cntr] = part.LocalId;
                                cntr++;
                            }
                        }
                        
                        for (int ctr = 0; ctr < localids.Length; ctr++)
                        {
                            m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
                        }
                    }
                }
            }
            if (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget)
            {
                if (m_rotTargets.Count > 0)
                {
                    bool at_Rottarget = false;
                    Dictionary<uint, scriptRotTarget> atRotTargets = new Dictionary<uint, scriptRotTarget>();
                    lock (m_rotTargets)
                    {
                        foreach (uint idx in m_rotTargets.Keys)
                        {
                            scriptRotTarget target = m_rotTargets[idx];
                            double angle = Math.Acos(target.targetRot.X * m_rootPart.RotationOffset.X + target.targetRot.Y * m_rootPart.RotationOffset.Y + target.targetRot.Z * m_rootPart.RotationOffset.Z + target.targetRot.W * m_rootPart.RotationOffset.W) * 2;
                            if (angle < 0) angle = -angle;
                            if (angle > Math.PI) angle = (Math.PI * 2 - angle);
                            if (angle <= target.tolerance)
                            {
                                // trigger at_rot_target
                                if (m_scriptListens_atRotTarget)
                                {
                                    at_Rottarget = true;
                                    scriptRotTarget att = new scriptRotTarget();
                                    att.targetRot = target.targetRot;
                                    att.tolerance = target.tolerance;
                                    att.handle = target.handle;
                                    atRotTargets.Add(idx, att);
                                }
                            }
                        }
                    }

                    if (atRotTargets.Count > 0)
                    {
                        uint[] localids = new uint[0];
                        lock (m_partsLock)
                        {
                            localids = new uint[m_parts.Count];
                            int cntr = 0;
                            foreach (SceneObjectPart part in m_partsList)
                            {
                                localids[cntr] = part.LocalId;
                                cntr++;
                            }
                        }

                        for (int ctr = 0; ctr < localids.Length; ctr++)
                        {
                            foreach (uint target in atRotTargets.Keys)
                            {
                                scriptRotTarget att = atRotTargets[target];
                                m_scene.EventManager.TriggerAtRotTargetEvent(
                                    localids[ctr], att.handle, att.targetRot, m_rootPart.RotationOffset);
                            }
                        }

                        return;
                    }

                    if (m_scriptListens_notAtRotTarget && !at_Rottarget)
                    {
                        //trigger not_at_target
                        uint[] localids = new uint[0];
                        lock (m_partsLock)
                        {
                            localids = new uint[m_parts.Count];
                            int cntr = 0;
                            foreach (SceneObjectPart part in m_partsList)
                            {
                                localids[cntr] = part.LocalId;
                                cntr++;
                            }
                        }

                        for (int ctr = 0; ctr < localids.Length; ctr++)
                        {
                            m_scene.EventManager.TriggerNotAtRotTargetEvent(localids[ctr]);
                        }
                    }
                }
            }
        }
 public int registerTargetWaypoint(Vector3 target, float tolerance)
 {
     scriptPosTarget waypoint = new scriptPosTarget();
     waypoint.targetPos = target;
     waypoint.tolerance = tolerance;
     uint handle = m_scene.AllocateLocalId();
     waypoint.handle = handle;
     lock (m_targets)
     {
         if (m_targets.Count >= 8)
             m_targets.Remove(m_targets.ElementAt(0).Key);
         m_targets.Add(handle, waypoint);
     }
     m_scene.AddGroupTarget(this);
     return (int)handle;
 }
 public int registerTargetWaypoint(Vector3 target, float tolerance)
 {
     scriptPosTarget waypoint = new scriptPosTarget();
     waypoint.targetPos = target;
     waypoint.tolerance = tolerance;
     uint handle = m_scene.SceneGraph.AllocateLocalId();
     waypoint.handle = handle;
     lock (m_targets)
     {
         m_targets.Add(handle, waypoint);
     }
     AddGroupTarget(this);
     return (int)handle;
 }
Beispiel #4
0
 private void checkAtTargets()
 {
     if (m_scriptListens_atTarget || m_scriptListens_notAtTarget)
     {
         if (m_targets.Count > 0)
         {
             bool at_target = false;
             //Vector3 targetPos;
             //uint targetHandle;
             Dictionary<uint, scriptPosTarget> atTargets = new Dictionary<uint, scriptPosTarget>();
             lock (m_targets)
             {
                 foreach (uint idx in m_targets.Keys)
                 {
                     scriptPosTarget target = m_targets[idx];
                     if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance)
                     {
                         // trigger at_target
                         if (m_scriptListens_atTarget)
                         {
                             at_target = true;
                             scriptPosTarget att = new scriptPosTarget();
                             att.targetPos = target.targetPos;
                             att.tolerance = target.tolerance;
                             att.handle = target.handle;
                             atTargets.Add(idx, att);
                         }
                     }
                 }
             }
             
             if (atTargets.Count > 0)
             {
                 uint[] localids = new uint[0];
                 lock (m_parts)
                 {
                     localids = new uint[m_parts.Count];
                     int cntr = 0;
                     foreach (SceneObjectPart part in m_parts.Values)
                     {
                         localids[cntr] = part.LocalId;
                         cntr++;
                     }
                 }
                 
                 for (int ctr = 0; ctr < localids.Length; ctr++)
                 {
                     foreach (uint target in atTargets.Keys)
                     {
                         scriptPosTarget att = atTargets[target];
                         m_scene.EventManager.TriggerAtTargetEvent(
                             localids[ctr], att.handle, att.targetPos, m_rootPart.GroupPosition);
                     }
                 }
                 
                 return;
             }
             
             if (m_scriptListens_notAtTarget && !at_target)
             {
                 //trigger not_at_target
                 uint[] localids = new uint[0];
                 lock (m_parts)
                 {
                     localids = new uint[m_parts.Count];
                     int cntr = 0;
                     foreach (SceneObjectPart part in m_parts.Values)
                     {
                         localids[cntr] = part.LocalId;
                         cntr++;
                     }
                 }
                 
                 for (int ctr = 0; ctr < localids.Length; ctr++)
                 {
                     m_scene.EventManager.TriggerNotAtTargetEvent(localids[ctr]);
                 }
             }
         }
     }
 }