Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Microsoft.Xna.Framework;
- namespace BackBlast
- {
- public class Plane : GameObject
- {
- List<GameObject> Contents = new List<GameObject>();
- List<Matrix> Positions = new List<Matrix>();
- List<Matrix> Angles = new List<Matrix>();
- Matrix Rotation;
- float AngleX, AngleY;
- public Plane(float x, float y) : base(x, y, "")
- {
- Rotation = Matrix.CreateTranslation(0f, 0f, 0f);
- SetLayer(Layer.Objects0);
- }
- public void SetAngle(float angleX, float angleY, float angleZ)
- {
- AngleX = Mathx.FixAngle(angleX);
- AngleY = Mathx.FixAngle(angleY);
- Angle = Mathx.FixAngle(angleZ);
- UpdateRotation();
- }
- public void SetAngleX(float angleX)
- {
- AngleX = Mathx.FixAngle(angleX);
- UpdateRotation();
- }
- public void SetAngleY(float angleY)
- {
- AngleY = Mathx.FixAngle(angleY);
- UpdateRotation();
- }
- new public void SetAngle(float angleZ)
- {
- Angle = Mathx.FixAngle(angleZ);
- UpdateRotation();
- }
- public void SetAngleZ(float angleZ)
- {
- Angle = Mathx.FixAngle(angleZ);
- UpdateRotation();
- }
- public void RotateX(float degrees)
- {
- AngleX = Mathx.FixAngle(AngleX + degrees);
- UpdateRotation();
- }
- public void RotateY(float degrees)
- {
- AngleY = Mathx.FixAngle(AngleY + degrees);
- UpdateRotation();
- }
- public void RotateZ(float degrees)
- {
- Angle = Mathx.FixAngle(Angle + degrees);
- UpdateRotation();
- }
- public void Rotate(float x, float y, float z)
- {
- AngleX = Mathx.FixAngle(AngleX + x);
- AngleY = Mathx.FixAngle(AngleY + y);
- Angle = Mathx.FixAngle(Angle + z);
- UpdateRotation();
- }
- private void UpdateRotation()
- {
- Rotation = Matrix.CreateRotationZ(Angle * 0.0174533f) * Matrix.CreateRotationY(AngleY * 0.0174533f) * Matrix.CreateRotationX(AngleX * 0.0174533f);
- }
- public void Add(GameObject obj)
- {
- Contents.Add(obj);
- Positions.Add(Matrix.CreateTranslation(obj.X - X, obj.Y - Y, 0f));
- float angle = obj.GetAngle();
- Angles.Add(Matrix.CreateTranslation(Mathx.DCos(angle), Mathx.DSin(angle), 0f));
- }
- public void Clear()
- {
- Contents.Clear();
- Positions.Clear();
- Angles.Clear();
- }
- public void Remove(GameObject obj)
- {
- int index = Contents.IndexOf(obj);
- Contents.RemoveAt(index);
- Positions.RemoveAt(index);
- Angles.RemoveAt(index);
- }
- public void SetPosition(GameObject obj, float x, float y)
- {
- int index = Contents.IndexOf(obj);
- Positions[index] = Matrix.CreateTranslation(obj.X - X, obj.Y - Y, 0f);
- }
- public void SetAngle(GameObject obj, float angle)
- {
- int index = Contents.IndexOf(obj);
- Angles[index] = Matrix.CreateTranslation(Mathx.DCos(angle), Mathx.DSin(angle), 0f);
- }
- public override bool Update()
- {
- base.Update();
- Matrix transformation = Matrix.CreateScale(ScaleX, ScaleY, 1f) * Rotation * Matrix.CreateTranslation(X, Y, 0f);
- for (int i = 0; i < Contents.Count; i++)
- {
- GameObject obj = Contents[i];
- if (obj.Exists())
- {
- Matrix transformedTranslation = Positions[i] * transformation;
- Vector3 newTranslation = transformedTranslation.Translation;
- obj.X = newTranslation.X;
- obj.Y = newTranslation.Y;
- Matrix transformedRotation = Angles[i] * Rotation;
- Vector3 newRotation = transformedRotation.Translation;
- obj.SetAngle(Mathx.DAtan2(newRotation.Y, newRotation.X));
- }
- else
- {
- Contents.RemoveAt(i);
- Positions.RemoveAt(i);
- Angles.RemoveAt(i);
- i--;
- }
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement