Marko Pintera 11 лет назад
Родитель
Сommit
9413cd61e8
2 измененных файлов с 95 добавлено и 0 удалено
  1. 46 0
      MBansheeEngine/Math/Ray.cs
  2. 49 0
      MBansheeEngine/Math/Rect2.cs

+ 46 - 0
MBansheeEngine/Math/Ray.cs

@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace BansheeEngine
+{
+    public class Ray
+    {
+		public Vector3 origin;
+		public Vector3 direction;
+
+        public Ray() {}
+
+        public Ray(Vector3 origin, Vector3 direction)
+        {
+            this.origin = origin;
+            this.direction = direction;
+        }
+
+		public static Vector3 operator*(Ray ray, float t) 
+		{
+            return ray.origin + ray.direction * t;
+		}
+
+        public void Transform(Matrix4 matrix)
+        {
+            Vector3 end = this * 1.0f;
+
+		    origin = matrix.Multiply(origin);
+		    end = matrix.Multiply(end);
+
+		    direction = Vector3.Normalize(end - origin);
+        }
+
+        public void TransformAffine(Matrix4 matrix)
+        {
+            Vector3 end = this * 1.0f;
+
+            origin = matrix.MultiplyAffine(origin);
+            end = matrix.MultiplyAffine(end);
+
+            direction = Vector3.Normalize(end - origin);
+        }
+    };
+}

+ 49 - 0
MBansheeEngine/Math/Rect2.cs

@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace BansheeEngine
+{
+    [StructLayout(LayoutKind.Sequential)]
+    public class Rect2
+    {
+        public Rect2(float x, float y, float width, float height)
+        {
+            this.x = x;
+            this.y = y;
+            this.width = width;
+            this.height = height;
+        }
+
+        public static bool operator ==(Rect2 lhs, Rect2 rhs)
+        {
+            return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height;
+        }
+
+        public static bool operator !=(Rect2 lhs, Rect2 rhs)
+        {
+            return !(lhs == rhs);
+        }
+
+        public override bool Equals(object other)
+        {
+            if (!(other is Rect2))
+                return false;
+
+            Rect2 rect = (Rect2)other;
+            if (x.Equals(rect.x) && y.Equals(rect.y) && width.Equals(rect.width) && height.Equals(rect.height))
+                return true;
+
+            return false;
+        }
+
+        public override int GetHashCode()
+        {
+            return base.GetHashCode();
+        }
+
+        public float x, y, width, height;
+    }
+}