private void DrawDisk() { for (int angle = 0; angle <= 360; angle += 72) { DrawingService.PickTexture(TextureNames.Metal); Gl.glBegin(Gl.GL_POLYGON); double x1 = Math.Cos(Angle3d.DegreeToRadian(angle)); double y1 = Math.Sin(Angle3d.DegreeToRadian(angle)); double x2 = Math.Cos(Angle3d.DegreeToRadian(angle - 35)); double y2 = Math.Sin(Angle3d.DegreeToRadian(angle - 35)); //Gl.glNormal3b(0, 0, 1); Gl.glTexCoord2d(1, 1); Gl.glVertex3d(x1, y1, 0); //Gl.glNormal3b(0, 0, 1); Gl.glTexCoord2d(0.7, 0.7); Gl.glVertex3d(x1 * 0.2, y1 * 0.2, 0); //Gl.glNormal3b(0, 0, 1); Gl.glTexCoord2d(0.35, 0.35); Gl.glVertex3d(x2, y2, 0); //Gl.glNormal3b(0, 0, 1); Gl.glTexCoord2d(0, 0); Gl.glVertex3d(x2 * 0.2, y2 * 0.2, 0); DrawingService.UnloadTexture(); Gl.glEnd(); } }
/// <summary> /// Передвигает объект с заданной скоростью. /// </summary> public void Move() { Angle3d angle = new Angle3d(this.Angle.X, this.Angle.Y, this.Angle.Z); Point3d vector = DataService.Rotate(new Point3d(0, 0, this.Speed), angle); this.Position += vector; }
public static void DrawCircle(double x, double y, double z) { Gl.glBegin(Gl.GL_POLYGON); for (int i = 360; i >= 1; i--) { double x1 = Math.Cos(Angle3d.DegreeToRadian(i)); double y1 = Math.Sin(Angle3d.DegreeToRadian(i)); Gl.glVertex3d(x + x1 / 2, y + y1 / 2, z); } Gl.glEnd(); }
public void Drive(MoveDirection direction) { if (driveAvailable) { double enlarger = direction == MoveDirection.Forward ? MaxSpeed / 4 : direction == MoveDirection.Backward ? -MaxSpeed / 4 : 0; this.Speed -= enlarger; double addAngle = driveWheels[0].Angle.Y; if (addAngle < -1 || addAngle > 1) { double enlargerAngle = addAngle / Math.Abs(addAngle); this.Angle.Y += enlarger * Math.Sin(Angle3d.DegreeToRadian(driveWheels[0].Angle.Y)) * 3; } } }
public override void Turn(Point3d axis, double angle, PositionType type = PositionType.Absolute) { base.Turn(axis, angle, type); Angle3d angle3d = new Angle3d(axis.X * angle, axis.Y * angle, axis.Z * angle); foreach (var obj in this.FixtureObjects) { Point3d result = DataService.Rotate(obj.Position, angle3d); if (obj is Fixture) { ((Fixture)obj).SetPosition(result); } else { obj.Position = result; } } }
public static void DrawRim(Point3d p1, Point3d p2, double size = 1, double radius = 1, string textureName = null) { for (int i = 360; i >= 1; i--) { if (textureName != null) { DrawingService.PickTexture(textureName); } Gl.glBegin(Gl.GL_POLYGON); double x1 = Math.Cos(Angle3d.DegreeToRadian(i)); double y1 = Math.Sin(Angle3d.DegreeToRadian(i)); double x2 = Math.Cos(Angle3d.DegreeToRadian(i - 3)); double y2 = Math.Sin(Angle3d.DegreeToRadian(i - 3)); Gl.glNormal3d(x1, y1, y1); Gl.glTexCoord3d(x2, 0, 0); //Gl.glNormal3b(0, 1, 0); Gl.glVertex3d(x2 * size + p2.X, y2 * radius + p2.Y, y2 * radius + p2.Z); Gl.glNormal3d(x1, y1, y1); Gl.glTexCoord3d(x2, 1, 0); //Gl.glNormal3b(0, 1, 0); Gl.glVertex3d(x2 * size + p1.X, y2 * radius + p1.Y, y2 * radius + p1.Z); Gl.glNormal3d(x1, y1, y1); Gl.glTexCoord3d(x1, 1, 0); //Gl.glNormal3b(0, 1, 0); Gl.glVertex3d(x1 * size + p1.X, y1 * radius + p1.Y, y1 * radius + p1.Z); Gl.glNormal3d(x1, y1, y1); Gl.glTexCoord3d(x1, 0, 0); //Gl.glNormal3b(0, 1, 0); Gl.glVertex3d(x1 * size + p2.X, y1 * radius + p2.Y, y1 * radius + p2.Z); Gl.glEnd(); DrawingService.UnloadTexture(); } }
/// <summary> /// Осуществляет поворот объекта вокруг оси на заданный угол. /// </summary> /// <param name="axis">Оси, вокруг которых осуществляется поворот.</param> /// <param name="angle">Угол, на который нужно повернуть объект.</param> /// <param name="type">Тип задания угла: абсолютно (перекрытие значений) или относительно (сложение значений).</param> public virtual void Turn(Point3d axis, Double angle, PositionType type = PositionType.Absolute) { Angle3d relative = new Angle3d(); if (type == PositionType.Relative) { relative = new Angle3d(this.Angle); } if (axis.X > 0) { this.Angle.X = angle + relative.X; } if (axis.Y > 0) { this.Angle.Y = angle + relative.Y; } if (axis.Z > 0) { this.Angle.Z = angle + relative.Z; } }
private void ResetWheels() { Angle3d angle = driveWheels[0].Angle; if (!turnFlag) { if (angle.Y < -1 || angle.Y > 1) { double angleEnlarger = angle.Y / Math.Abs(angle.Y); for (int i = 0; i <= driveWheels.Length - 1; i++) { driveWheels[i].Angle.Y -= angleEnlarger * 3; } } } else { if (frame++ == 5) { frame = 0; turnFlag = false; } } }
private void DrawRim(double depth = 1, double size = 1) { if (size == 0) { size = 1; } bool flag = depth == 1 && size == 1; for (int i = 360; i >= 0; i--) { if (flag) { DrawingService.PickTexture(TextureNames.Bus); } else { DrawingService.PickTexture(TextureNames.Body); } Gl.glBegin(Gl.GL_POLYGON); double x1 = Math.Cos(Angle3d.DegreeToRadian(i)); double y1 = Math.Sin(Angle3d.DegreeToRadian(i)); double x2 = Math.Cos(Angle3d.DegreeToRadian(i - 2)); double y2 = Math.Sin(Angle3d.DegreeToRadian(i - 2)); if (flag) { Gl.glTexCoord3d(x2, 0, 0); } else { Gl.glTexCoord3d(x2 - 0.5, y2 - 1, 0); } Gl.glNormal3d(x2, y2, 0); Gl.glVertex3d(x2, y2, 0); Gl.glNormal3d(0, 0, 1); if (flag) { Gl.glTexCoord3d(x2, 1, 0); } else { Gl.glTexCoord3d(x2 / size - 0.5, y2 / size - 1, 0); } Gl.glVertex3d(x2 / size, y2 / size, -depth); Gl.glNormal3d(0, 0, 1); if (flag) { Gl.glTexCoord3d(x1, 1, 0); } else { Gl.glTexCoord3d(x1 / size - 0.5, y1 / size - 1, 0); } Gl.glVertex3d(x1 / size, y1 / size, -depth); Gl.glNormal3d(0, 0, 1); if (flag) { Gl.glTexCoord3d(x1, 0, 0); } else { Gl.glTexCoord3d(x1 - 0.5, y1 - 1, 0); } Gl.glVertex3d(x1, y1, 0); DrawingService.UnloadTexture(); Gl.glEnd(); } }
public GraphObject() { this.Position = new Point3d(); this.Angle = new Angle3d(); }