RayCastTest() { { Vertices vertices = new Vertices(3); vertices.Add(new Vector2(-0.5f, 0.0f)); vertices.Add(new Vector2(0.5f, 0.0f)); vertices.Add(new Vector2(0.0f, 1.5f)); _polygons[0] = new PolygonShape(vertices, 1); } { Vertices vertices2 = new Vertices(3); vertices2.Add(new Vector2(-0.1f, 0.0f)); vertices2.Add(new Vector2(0.1f, 0.0f)); vertices2.Add(new Vector2(0.0f, 1.5f)); _polygons[1] = new PolygonShape(vertices2, 1); } { const double w = 1.0f; double b = w / (2.0f + (double)Math.Sqrt(2.0)); double s = (double)Math.Sqrt(2.0) * b; Vertices vertices3 = new Vertices(8); vertices3.Add(new Vector2(0.5f * s, 0.0f)); vertices3.Add(new Vector2(0.5f * w, b)); vertices3.Add(new Vector2(0.5f * w, b + s)); vertices3.Add(new Vector2(0.5f * s, w)); vertices3.Add(new Vector2(-0.5f * s, w)); vertices3.Add(new Vector2(-0.5f * w, b + s)); vertices3.Add(new Vector2(-0.5f * w, b)); vertices3.Add(new Vector2(-0.5f * s, 0.0f)); _polygons[2] = new PolygonShape(vertices3, 1); } { _polygons[3] = new PolygonShape(1); _polygons[3].Vertices = PolygonTools.CreateRectangle(0.5f, 0.5f); } { _circle = new CircleShape(0.5f, 1); } _bodyIndex = 0; _angle = 0.0f; _mode = RayCastMode.Closest; }
private RayCastTest() { { Vertices vertices = new Vertices(3); vertices.Add(new Vector2(-0.5f, 0.0f)); vertices.Add(new Vector2(0.5f, 0.0f)); vertices.Add(new Vector2(0.0f, 1.5f)); _polygons[0] = new PolygonShape(vertices, 1); } { Vertices vertices2 = new Vertices(3); vertices2.Add(new Vector2(-0.1f, 0.0f)); vertices2.Add(new Vector2(0.1f, 0.0f)); vertices2.Add(new Vector2(0.0f, 1.5f)); _polygons[1] = new PolygonShape(vertices2, 1); } { const float w = 1.0f; float b = w / (2.0f + (float)Math.Sqrt(2.0)); float s = (float)Math.Sqrt(2.0) * b; Vertices vertices3 = new Vertices(8); vertices3.Add(new Vector2(0.5f * s, 0.0f)); vertices3.Add(new Vector2(0.5f * w, b)); vertices3.Add(new Vector2(0.5f * w, b + s)); vertices3.Add(new Vector2(0.5f * s, w)); vertices3.Add(new Vector2(-0.5f * s, w)); vertices3.Add(new Vector2(-0.5f * w, b + s)); vertices3.Add(new Vector2(-0.5f * w, b)); vertices3.Add(new Vector2(-0.5f * s, 0.0f)); _polygons[2] = new PolygonShape(vertices3, 1); } { _polygons[3] = new PolygonShape(1); _polygons[3].SetAsBox(0.5f, 0.5f); } { _circle = new CircleShape(0.5f, 1); } _bodyIndex = 0; _angle = 0.0f; _mode = RayCastMode.Closest; }
public override void Keyboard(KeyboardManager keyboardManager) { if (keyboardManager.IsNewKeyPress(Keys.D1)) { Create(0); } if (keyboardManager.IsNewKeyPress(Keys.D2)) { Create(1); } if (keyboardManager.IsNewKeyPress(Keys.D3)) { Create(2); } if (keyboardManager.IsNewKeyPress(Keys.D4)) { Create(3); } if (keyboardManager.IsNewKeyPress(Keys.D5)) { Create(4); } if (keyboardManager.IsNewKeyPress(Keys.D)) { DestroyBody(); } if (keyboardManager.IsNewKeyPress(Keys.M)) { switch (_mode) { case RayCastMode.Closest: _mode = RayCastMode.Any; break; case RayCastMode.Any: _mode = RayCastMode.Multiple; break; case RayCastMode.Multiple: _mode = RayCastMode.Closest; break; default: break; } } }
protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.D1) { Create(0); } if (e.KeyCode == Keys.D2) { Create(1); } if (e.KeyCode == Keys.D3) { Create(2); } if (e.KeyCode == Keys.D4) { Create(3); } if (e.KeyCode == Keys.D5) { Create(4); } if (e.KeyCode == Keys.D) { DestroyBody(); } if (e.KeyCode == Keys.M) { switch (_mode) { case RayCastMode.Closest: _mode = RayCastMode.Any; break; case RayCastMode.Any: _mode = RayCastMode.Multiple; break; case RayCastMode.Multiple: _mode = RayCastMode.Closest; break; default: break; } } }
public override void Keyboard(InputState input) { if (input.IsKeyPressed(Keys.D1)) { Create(0); } if (input.IsKeyPressed(Keys.D2)) { Create(1); } if (input.IsKeyPressed(Keys.D3)) { Create(2); } if (input.IsKeyPressed(Keys.D4)) { Create(3); } if (input.IsKeyPressed(Keys.D5)) { Create(4); } if (input.IsKeyPressed(Keys.D)) { DestroyBody(); } if (input.IsKeyPressed(Keys.M)) { switch (_mode) { case RayCastMode.Closest: _mode = RayCastMode.Any; break; case RayCastMode.Any: _mode = RayCastMode.Multiple; break; case RayCastMode.Multiple: _mode = RayCastMode.Closest; break; default: break; } } base.Keyboard(input); }
public RayCast() { // Ground body { BodyDef bd = new BodyDef(); Body ground = _world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f)); ground.CreateFixture(shape, 0.0f); } { var vertices = new Vector2[3]; vertices[0] = new Vector2(-0.5f, 0.0f); vertices[1] = new Vector2(0.5f, 0.0f); vertices[2] = new Vector2(0.0f, 1.5f); _polygons[0] = new PolygonShape(); _polygons[0].Set(vertices, 3); } { var vertices2 = new Vector2[3]; vertices2[0] = new Vector2(-0.1f, 0.0f); vertices2[1] = new Vector2(0.1f, 0.0f); vertices2[2] = new Vector2(0.0f, 1.5f); _polygons[1] = new PolygonShape(); _polygons[1].Set(vertices2, 3); } { float w = 1.0f; float b = w / (2.0f + (float)Math.Sqrt(2.0)); float s = (float)Math.Sqrt(2.0) * b; var vertices3 = new Vector2[8]; vertices3[0] = new Vector2(0.5f * s, 0.0f); vertices3[1] = new Vector2(0.5f * w, b); vertices3[2] = new Vector2(0.5f * w, b + s); vertices3[3] = new Vector2(0.5f * s, w); vertices3[4] = new Vector2(-0.5f * s, w); vertices3[5] = new Vector2(-0.5f * w, b + s); vertices3[6] = new Vector2(-0.5f * w, b); vertices3[7] = new Vector2(-0.5f * s, 0.0f); _polygons[2] = new PolygonShape(); _polygons[2].Set(vertices3, 8); } { _polygons[3] = new PolygonShape(); _polygons[3].SetAsBox(0.5f, 0.5f); } { _circle = new CircleShape(); _circle._radius = 0.5f; } _bodyIndex = 0; _angle = 0.0f; _mode = RayCastMode.Closest; }
public override void Keyboard(KeyboardState state, KeyboardState oldState) { if (state.IsKeyDown(Keys.D1) && oldState.IsKeyUp(Keys.D1)) { Create(0); } if (state.IsKeyDown(Keys.D2) && oldState.IsKeyUp(Keys.D2)) { Create(1); } if (state.IsKeyDown(Keys.D3) && oldState.IsKeyUp(Keys.D3)) { Create(2); } if (state.IsKeyDown(Keys.D4) && oldState.IsKeyUp(Keys.D4)) { Create(3); } if (state.IsKeyDown(Keys.D5) && oldState.IsKeyUp(Keys.D5)) { Create(4); } if (state.IsKeyDown(Keys.D) && oldState.IsKeyUp(Keys.D)) { DestroyBody(); } if (state.IsKeyDown(Keys.M) && oldState.IsKeyUp(Keys.M)) { switch (_mode) { case RayCastMode.Closest: _mode = RayCastMode.Any; break; case RayCastMode.Any: _mode = RayCastMode.Multiple; break; case RayCastMode.Multiple: _mode = RayCastMode.Closest; break; default: break; } } }
public RayCast() { // Ground body { BodyDef bd = new BodyDef(); Body ground = _world.CreateBody(bd); PolygonShape shape = new PolygonShape(); shape.SetAsEdge(new Vector2(-40.0, 0.0), new Vector2(40.0, 0.0)); ground.CreateFixture(shape, 0.0); } { var vertices = new Vector2[3]; vertices[0] = new Vector2(-0.5, 0.0); vertices[1] = new Vector2(0.5, 0.0); vertices[2] = new Vector2(0.0, 1.5); _polygons[0] = new PolygonShape(); _polygons[0].Set(vertices, 3); } { var vertices2 = new Vector2[3]; vertices2[0] = new Vector2(-0.1f, 0.0f); vertices2[1] = new Vector2(0.1f, 0.0f); vertices2[2] = new Vector2(0.0f, 1.5f); _polygons[1] = new PolygonShape(); _polygons[1].Set(vertices2, 3); } { double w = 1.0f; double b = w / (2.0f + (double)Math.Sqrt(2.0)); double s = (double)Math.Sqrt(2.0) * b; var vertices3 = new Vector2[8]; vertices3[0] = new Vector2(0.5f * s, 0.0f); vertices3[1] = new Vector2(0.5f * w, b); vertices3[2] = new Vector2(0.5f * w, b + s); vertices3[3] = new Vector2(0.5f * s, w); vertices3[4] = new Vector2(-0.5f * s, w); vertices3[5] = new Vector2(-0.5f * w, b + s); vertices3[6] = new Vector2(-0.5f * w, b); vertices3[7] = new Vector2(-0.5f * s, 0.0f); _polygons[2] = new PolygonShape(); _polygons[2].Set(vertices3, 8); } { _polygons[3] = new PolygonShape(); _polygons[3].SetAsBox(0.5f, 0.5f); } { _circle = new CircleShape(); _circle._radius = 0.5f; } _bodyIndex = 0; _angle = 0.0f; _mode = RayCastMode.Closest; }
private RayCastTest() { { Vertices vertices = new Vertices(3); vertices.Add(new Vector2(-0.5f, 0.0f)); vertices.Add(new Vector2(0.5f, 0.0f)); vertices.Add(new Vector2(0.0f, 1.5f)); _polygons[0] = new PolygonShape(vertices, 1); } { Vertices vertices2 = new Vertices(3); vertices2.Add(new Vector2(-0.1f, 0.0f)); vertices2.Add(new Vector2(0.1f, 0.0f)); vertices2.Add(new Vector2(0.0f, 1.5f)); _polygons[1] = new PolygonShape(vertices2, 1); } { const float w = 1.0f; float b = w / (2.0f + (float)Math.Sqrt(2.0)); float s = (float)Math.Sqrt(2.0) * b; Vertices vertices3 = new Vertices(8); vertices3.Add(new Vector2(0.5f * s, 0.0f)); vertices3.Add(new Vector2(0.5f * w, b)); vertices3.Add(new Vector2(0.5f * w, b + s)); vertices3.Add(new Vector2(0.5f * s, w)); vertices3.Add(new Vector2(-0.5f * s, w)); vertices3.Add(new Vector2(-0.5f * w, b + s)); vertices3.Add(new Vector2(-0.5f * w, b)); vertices3.Add(new Vector2(-0.5f * s, 0.0f)); _polygons[2] = new PolygonShape(vertices3, 1); } { _polygons[3] = new PolygonShape(1); _polygons[3].Vertices = PolygonTools.CreateRectangle(0.5f, 0.5f); } { _circle = new CircleShape(0.5f, 1); } _bodyIndex = 0; _angle = 0.0f; _mode = RayCastMode.Closest; }