Example #1
0
 /// <summary>
 /// Called once per frame - If a straight path has been found, it draws a debug line detailing the path
 /// </summary>
 public void Update(float dt)
 {
     if (initializedCrowd)
     {
         CrowdAgentDebugInfo info = new CrowdAgentDebugInfo();
         Crowd.Update(dt, ref info);
     }
 }
Example #2
0
 /// <summary>
 /// Called once per frame - If a straight path has been found, it draws a debug line detailing the path
 /// </summary>
 public void Update()
 {
     if (initializedCrowd)
     {
         CrowdAgentDebugInfo info = new CrowdAgentDebugInfo();
         Crowd.Update(Time.deltaTime, ref info);
     }
 }
Example #3
0
 void Update()
 {
     crowd.Update(0.02f);
     foreach (var e in entities)
     {
         e.Value.Update();
         if (e.Value is Enemy)
         {
             var enemy = e.Value as Enemy;
             UpdateEnemyPosition(e.Key, crowd.GetAgent(enemy.agentID).Position);
         }
     }
 }
Example #4
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (!Focused)
            {
                return;
            }

            KeyboardState k = OpenTK.Input.Keyboard.GetState();
            MouseState    m = OpenTK.Input.Mouse.GetState();

            bool isShiftDown = false;

            if (k[Key.LShift] || k[Key.RShift])
            {
                isShiftDown = true;
            }

            //TODO make cam speed/shift speedup controllable from GUI
            float camSpeed  = 10f * (float)e.Time * (isShiftDown ? 3f : 1f);
            float zoomSpeed = (float)Math.PI * (float)e.Time * (isShiftDown ? 0.2f : 0.1f);

            if (k[Key.W])
            {
                cam.Move(-camSpeed);
            }
            if (k[Key.A])
            {
                cam.Strafe(-camSpeed);
            }
            if (k[Key.S])
            {
                cam.Move(camSpeed);
            }
            if (k[Key.D])
            {
                cam.Strafe(camSpeed);
            }
            if (k[Key.Q])
            {
                cam.Elevate(camSpeed);
            }
            if (k[Key.E])
            {
                cam.Elevate(-camSpeed);
            }
            if (k[Key.Z])
            {
                zoom += zoomSpeed;
                if (zoom > MathHelper.PiOver2)
                {
                    zoom = MathHelper.PiOver2;
                }
            }
            if (k[Key.C])
            {
                zoom -= zoomSpeed;
                if (zoom < 0.002f)
                {
                    zoom = 0.002f;
                }
            }

            if (m[MouseButton.Right])
            {
                cam.RotatePitch((m.X - prevM.X) * (float)e.Time * 2f);
                cam.RotateHeading((prevM.Y - m.Y) * (float)e.Time * 2f);
            }

            float   aspect = Width / (float)Height;
            Matrix4 persp  = Matrix4.CreatePerspectiveFieldOfView(zoom, aspect, 0.1f, 1000f);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref persp);
            GL.MatrixMode(MatrixMode.Modelview);
            cam.LoadView();
            if (crowd != null)
            {
                crowd.Update((float)e.Time);
            }

            prevK = k;
            prevM = m;

            if (gwenRenderer.TextCacheSize > 1000)
            {
                gwenRenderer.FlushTextCache();
            }
        }
Example #5
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            base.OnUpdateFrame(e);

            if (!Focused)
            {
                return;
            }

            KeyboardState k = OpenTK.Input.Keyboard.GetState();
            MouseState    m = OpenTK.Input.Mouse.GetState();

            bool isShiftDown = false;

            if (k[Key.LShift] || k[Key.RShift])
            {
                isShiftDown = true;
            }

            //TODO make cam speed/shift speedup controllable from GUI
            float camSpeed  = 5f * (float)e.Time * (isShiftDown ? 3f : 1f);
            float zoomSpeed = (float)Math.PI * (float)e.Time * (isShiftDown ? 0.2f : 0.1f);

            if (k[Key.W])
            {
                cam.Move(-camSpeed);
            }
            if (k[Key.A])
            {
                cam.Strafe(-camSpeed);
            }
            if (k[Key.S])
            {
                cam.Move(camSpeed);
            }
            if (k[Key.D])
            {
                cam.Strafe(camSpeed);
            }
            if (k[Key.Q])
            {
                cam.Elevate(camSpeed);
            }
            if (k[Key.E])
            {
                cam.Elevate(-camSpeed);
            }
            if (k[Key.Z])
            {
                zoom += zoomSpeed;
                if (zoom > MathHelper.PiOver2)
                {
                    zoom = MathHelper.PiOver2;
                }
            }
            if (k[Key.C])
            {
                zoom -= zoomSpeed;
                if (zoom < 0.002f)
                {
                    zoom = 0.002f;
                }
            }

            if (m[MouseButton.Right])
            {
                cam.RotatePitch((m.X - prevM.X) * (float)e.Time * 2f);
                cam.RotateHeading((prevM.Y - m.Y) * (float)e.Time * 2f);
            }

            float   aspect = Width / (float)Height;
            Matrix4 persp  = Matrix4.CreatePerspectiveFieldOfView(zoom, aspect, 0.1f, 1000f);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref persp);
            GL.MatrixMode(MatrixMode.Modelview);
            cam.LoadView();

            if (hasGenerated && displayMode == DisplayMode.Crowd)
            {
                crowd.Update((float)e.Time);

                //Iterate through each crowd agent

                /*for (int j = 0; j < numActiveAgents; j++)
                 * {
                 *      Crowd.CrowdAgent ag = crowd.GetAgent(j);
                 *      if (!ag.Active)
                 *              continue;
                 *
                 *      //update agent movement trail
                 *      trails[j].HTrail = (trails[j].HTrail + 1) % AGENT_MAX_TRAIL;
                 *      trails[j].Trail[trails[j].HTrail] = ag.NPos;
                 * }*/
            }

            prevK = k;
            prevM = m;

            if (gwenRenderer.TextCacheSize > 1000)
            {
                gwenRenderer.FlushTextCache();
            }
        }
    // Update is called once per frame
    void Update()
    {
        if (transform.position != TargetPosition)
        {
            transform.position = Vector3.Lerp(transform.position, TargetPosition, Time.deltaTime * 50.0f);
        }
        else
        {
            if (CurrentNode < smoothPath.Count - 1)
            {
                ++CurrentNode;
                TargetPosition = ExportNavMeshToObj.ToUnityVector(smoothPath[CurrentNode]);
            }
        }

        if (crowd != null)
        {
            //Agent[] agents = new Agent[crowd.GetAgentCount()];
            for (int i = 0; i < crowd.GetAgentCount(); ++i)
            {
                lastPosition[i] = crowd.GetAgent(i).Position;
                //agents[i] = crowd.GetAgent(i);
            }

            //crowd.UpdateTopologyOptimization(agents, crowd.GetAgentCount(), Time.deltaTime);
            crowd.Update(Time.deltaTime);

            for (int i = 0; i < crowd.GetAgentCount(); ++i)
            {
                try
                {
                    //Debug.DrawLine(ExportNavMeshToObj.ToUnityVector(lastPosition[i]), ExportNavMeshToObj.ToUnityVector(crowd.GetAgent(i).Position), Color.green, 1);
                    mob[i].transform.position = ExportNavMeshToObj.ToUnityVector(crowd.GetAgent(i).Position);
                }
                catch
                {
                }
            }
        }

        if (Application.platform == RuntimePlatform.WindowsEditor)
        {   // 현재 플랫폼이 Window 에디터인지
            if (Input.GetMouseButtonDown(0))
            {
                Vector3 p = Input.mousePosition;

                Ray cast = Camera.main.ScreenPointToRay(Input.mousePosition);


                // Mouse의 포지션을 Ray cast 로 변환



                UnityEngine.RaycastHit hit;
                if (Physics.Raycast(cast, out hit))
                {
                    Debug.Log($"hit x {hit.point.x}, y {hit.point.y}, z {hit.point.z}");
                    var newPt = navMeshQuery.FindNearestPoly(ExportNavMeshToObj.ToSharpVector(hit.point), new SVector3 {
                        X = 10, Y = 10, Z = 10
                    });

                    for (int i = 0; i < crowd.GetAgentCount(); ++i)
                    {
                        NavPoint targetPt;
                        navMeshQuery.FindRandomPointAroundCircle(ref newPt, 3, out targetPt);

                        Debug.Log($"agent{i} : x {targetPt.Position.X}, y {targetPt.Position.Y}, z {targetPt.Position.Z}");

                        crowd.GetAgent(i).RequestMoveTarget(targetPt.Polygon, targetPt.Position);
                    }
                    crowd.UpdateMoveRequest();
                } // RayCast
            }     // Mouse Click
        }
    }