Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing a Circle with a forward vector and Moving both along with Rotation
    primarykey
    data
    text
    <p>Been rather busy posting today and creating an AI program to simulate Boids. Right now I am just working on getting a single "boids" drawing a moving around. The "boid" is just a circle(ellipsis) with a line draw to symbolize its "Forward Vector".</p> <pre><code>class SwarmCir { public float _pointX; public float _pointY; public float _height; public float _width; Pen _pen = new Pen(Color.Black); PointF _ForwardPoint = new PointF(0, 0); float rotAng = 0.0f; public SwarmCir() { _pointX = 1.0f; _pointY = 1.0f; _height = 5.0f; _width = 5.0f; _ForwardPoint.X = 7.0f; _ForwardPoint.Y = 7.0f; } public SwarmCir(Point XY) { _pointX = XY.X; _pointY = XY.Y; _height = 5.0f; _width = 5.0f; } public SwarmCir( Point XY, float Height, float Width ) { _pointX = XY.X; _pointY = XY.Y; _height = Height; _width = Width; } public void SetPen(Pen p) { _pen = p; } public void Draw(Graphics g) { g.DrawEllipse(_pen, _pointX, _pointY, _width, _height); g.DrawLine(_pen, new PointF(_pointX, _pointY), _ForwardPoint); } public void Rotate(PaintEventArgs e) { e.Graphics.TranslateTransform(_pointX, _pointY); e.Graphics.RotateTransform(rotAng); e.Graphics.TranslateTransform(-_pointX, -_pointY); } public PointF ForwardVec() { PointF temp = new PointF(); temp.X = _pointX - _ForwardPoint.X; temp.Y = _pointY - _ForwardPoint.Y; return Normalize(temp); } public PointF Normalize(PointF p) { PointF temp = new PointF(); if (p.X &gt; p.Y) { temp.X = 1; temp.Y = p.Y / p.X; } else if (p.Y &gt; p.X) { temp.Y = 1; temp.X = p.X / p.Y; } else { return new PointF(1, 1); } return temp; } public void MoveForward() { _pointX += ForwardVec().X; _pointY += ForwardVec().Y; } public void MoveBackwards() { _pointX -= ForwardVec().X; _pointY -= ForwardVec().Y; } public void TurnLeft() { rotAng += 10.0f; } public void TurnRight() { rotAng -= 10.0f; } } </code></pre> <p>Currently when running a program implementing this class, instantiate a default SwarmCir() and just calling the moving functions at the bottom I get really weird results. Essentially I want 'W' to move the circle along the "forward vector" which ever way the line is pointing. Obviously for 'S' is just reverse. Then when turning I would like the shape and line to turn properly. If more information is needed Please ask. Working towards a complete AI workbench.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload