public setTimeStep ( float timeStep ) : void | ||
timeStep | float | The time step of the simulation. Must be * positive. |
Результат | void |
void LateUpdate() { sim.setTimeStep(Time.deltaTime); //desired vels for (int i = 0; i < units.Count; i++) { Vector3 pos = units[i].GetFeetPosition(); var v = units[i].GetVelocity(); var vdes = units[i].DesiredVelocity; var rvoAgent = sim.agents_[i]; rvoAgent.position_ = new RVO.Vector2(pos.x, pos.z); rvoAgent.velocity_ = new RVO.Vector2(v.x, v.z); rvoAgent.prefVelocity_ = new RVO.Vector2(vdes.x, vdes.z); } //simulate sim.doStep(); //set new vels for (int i = 0; i < units.Count; i++) { var vnew = sim.agents_[i].velocity_; units[i].Move(new Vector3(vnew.x_, 0, vnew.y_)); } }
public void Step() { m_nextTimeStep = Mathf.Clamp(Time.deltaTime, 1.0f / 100.0f, 1.0f / 15.0f); ExecuteRemoves(); foreach (var i in m_agents) { i.PreUpdate(); } m_instance.setTimeStep(m_nextTimeStep); m_instance.doStepST(); foreach (var i in m_agents) { i.Sync(); } }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager) { base.LoadContent(GraphicInfo, factory, contentManager); { SimpleModel simpleModel = new SimpleModel(factory, "Model//block"); simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Red), TextureType.DIFFUSE); BoxObject tmesh = new BoxObject(new Vector3(0), 1, 1, 1, 10, new Vector3(1000, 1, 1000), Matrix.Identity, MaterialDescription.DefaultBepuMaterial()); tmesh.isMotionLess = true; ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); IObject obj = new IObject(fmaterial, simpleModel, tmesh); this.World.AddObject(obj); } Simulator = Simulator.Instance; Simulator.setTimeStep(0.25f); Simulator.setAgentDefaults(5.0f, 25, 10.0f, 25.0f, 2.0f, 4.0f,new Vector2(0)); for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { SimpleModel simpleModel = new SimpleModel(factory, "Model//block"); simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.White), TextureType.DIFFUSE); BoxObject tmesh = new BoxObject(new Vector3(100 + j*5, 5, i * 5), 1, 1, 1, 10, new Vector3(1, 1, 1), Matrix.Identity, MaterialDescription.DefaultBepuMaterial()); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); int id = Simulator.addAgent(tmesh.Position); RVOObject obj = new RVOObject(id, fmaterial, simpleModel, tmesh); obj.OnUpdate += new OnUpdate(obj_OnUpdate); /// dummy position update way =p this.World.AddObject(obj); } } ///counterclockwise vertices Simulator.addObstacle( new List<Vector2>() { new Vector2(20,20), new Vector2(40,20), new Vector2(40,40), new Vector2(40,40), new Vector2(20,40), new Vector2(20,20), } ); Simulator.processObstacles(); ///obstacle { SimpleModel simpleModel = new SimpleModel(factory, "Model//block"); simpleModel.SetTexture(factory.CreateTexture2DColor(1, 1, Color.Yellow), TextureType.DIFFUSE); GhostObject tmesh = new GhostObject(new Vector3(30,0,30),Matrix.Identity,new Vector3(10)); ForwardXNABasicShader shader = new ForwardXNABasicShader(ForwardXNABasicShaderDescription.Default()); ForwardMaterial fmaterial = new ForwardMaterial(shader); IObject obj = new IObject(fmaterial, simpleModel, tmesh); this.World.AddObject(obj); } this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo)); Picking p = new Picking(this, 1000); p.OnPickedLeftButton += new OnPicked(p_OnPickedLeftButton); }
/// <summary>Create a number of agents in circle and restart simulation</summary> public void CreateAgents(int num) { this.m_agentCount = num; goals = new Dictionary <int, Vector3>(); colors = new List <Color>(m_agentCount); m_agentIds = new List <int>(num); sim.Clear(); sim.setTimeStep(m_timeStep); sim.setAgentDefaults(neighborDist: m_neighbourDist, maxNeighbors: m_maxNeighbours, radius: m_radius, maxSpeed: m_maxSpeed, timeHorizon: 2, timeHorizonObst: 2, velocity: new RVO.Vector2(1, 1)); if (type == RVOExampleType.Circle) { float circleRad = Mathf.Sqrt(m_agentCount * m_radius * m_radius * 4 / Mathf.PI) * exampleScale * 0.05f; for (int i = 0; i < m_agentCount; i++) { Vector3 pos = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / m_agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / m_agentCount)) * circleRad * (1 + Random.value * 0.01f); var id = sim.addAgent(new RVO.Vector2(pos.x, pos.z)); m_agentIds.Add(id); goals.Add(id, -pos); colors.Add(ColorUtility.HSVToRGB(i * 360.0f / m_agentCount, 0.8f, 0.6f)); } } else if (type == RVOExampleType.Line) { for (int i = 0; i < m_agentCount; i++) { Vector3 pos = new Vector3((i % 2 == 0 ? 1 : -1) * exampleScale, 0, (i / 2) * m_radius * 2.5f); var id = sim.addAgent(new RVO.Vector2(pos.x, pos.z)); m_agentIds.Add(id); goals.Add(id, new Vector3(-pos.x, pos.y, pos.z)); colors.Add(i % 2 == 0 ? Color.red : Color.blue); } } else if (type == RVOExampleType.Point) { for (int i = 0; i < m_agentCount; i++) { Vector3 pos = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / m_agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / m_agentCount)) * m_radius; var id = sim.addAgent(new RVO.Vector2(pos.x, pos.z)); m_agentIds.Add(id); //sim.AddAgent(new Vector2(0, 0)); goals.Add(id, new Vector3(0, pos.y, 0)); colors.Add(ColorUtility.HSVToRGB(i * 360.0f / m_agentCount, 0.8f, 0.6f)); } } else if (type == RVOExampleType.RandomStreams) { float circleRad = Mathf.Sqrt(m_agentCount * m_radius * m_radius * 4 / Mathf.PI) * exampleScale * 0.05f; for (int i = 0; i < m_agentCount; i++) { float angle = Random.value * Mathf.PI * 2.0f; float targetAngle = Random.value * Mathf.PI * 2.0f; Vector3 pos = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * uniformDistance(circleRad); var id = sim.addAgent(new RVO.Vector2(pos.x, pos.z)); m_agentIds.Add(id); goals.Add(id, new Vector3(Mathf.Cos(targetAngle), 0, Mathf.Sin(targetAngle)) * uniformDistance(circleRad)); colors.Add(ColorUtility.HSVToRGB(targetAngle * Mathf.Rad2Deg, 0.8f, 0.6f)); } } else if (type == RVOExampleType.Crossing) { float distanceBetweenGroups = exampleScale * m_radius * 0.5f; int directions = (int)Mathf.Sqrt(m_agentCount / 25f); directions = Mathf.Max(directions, 2); const int AgentsPerDistance = 10; for (int i = 0; i < m_agentCount; i++) { float angle = ((i % directions) / (float)directions) * Mathf.PI * 2.0f; var dist = distanceBetweenGroups * ((i / (directions * AgentsPerDistance) + 1) + 0.3f * Random.value); Vector3 pos = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * dist; var id = sim.addAgent(new RVO.Vector2(pos.x, pos.z)); m_agentIds.Add(id); goals.Add(id, -pos.normalized * distanceBetweenGroups * 3); colors.Add(ColorUtility.HSVToRGB(angle * Mathf.Rad2Deg, 0.8f, 0.6f)); } } verts = new Vector3[4 * m_agentCount]; uv = new Vector2[verts.Length]; tris = new int[m_agentCount * 2 * 3]; meshColors = new Color[verts.Length]; }