Commits

Anonymous committed 30794c3

cleanup

Comments (0)

Files changed (8)

SharpHammer/MathUtil.cs

+namespace SharpHammer
+{
+	public class MathUtil
+	{
+		public static float Clamp(float value, float min, float max)
+		{
+			if (value < min)
+				return min;
+			if (value > max)
+				return max;
+			return value;
+		}
+	}
+}

SharpHammer/Matrix4.cs

+using System;
+using System.Runtime.InteropServices;
+
+namespace SharpHammer
+{
+	[StructLayout(LayoutKind.Sequential)]
+	public struct Matrix4
+	{
+		public Matrix4(float m11, float m21, float m31, float m41,
+					   float m12, float m22, float m32, float m42,
+					   float m13, float m23, float m33, float m43,
+					   float m14, float m24, float m34, float m44)
+		{
+			Column1.X = m11;
+			Column2.X = m21;
+			Column3.X = m31;
+			Column4.X = m41;
+			Column1.Y = m12;
+			Column2.Y = m22;
+			Column3.Y = m32;
+			Column4.Y = m42;
+			Column1.Z = m13;
+			Column2.Z = m23;
+			Column3.Z = m33;
+			Column4.Z = m43;
+			Column1.W = m14;
+			Column2.W = m24;
+			Column3.W = m34;
+			Column4.W = m44;
+		}
+
+		public Matrix4(Vec4 column1, Vec4 column2, Vec4 column3, Vec4 column4)
+		{
+			this.Column1 = column1;
+			this.Column2 = column2;
+			this.Column3 = column3;
+			this.Column4 = column4;
+		}
+
+		public Matrix4(Matrix4 other)
+		{
+			this = other;
+		}
+
+		/// <summary>
+		/// Transpose this matrix.
+		/// </summary>
+		///
+		public void Transpose()
+		{
+			Matrix4 tmp = this;
+			Column1 = tmp.Row1;
+			Column2 = tmp.Row2;
+			Column3 = tmp.Row3;
+			Column4 = tmp.Row4;
+		}
+
+		/// <summary>
+		/// Invert this Matrix4.
+		/// </summary>
+		public void Invert()
+		{
+			this = Inverse;
+		}
+
+		public override string ToString()
+		{
+			return base.ToString();
+		}
+
+		/// <summary>
+		/// Multiply two matrices.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static Matrix4 Multiply(ref Matrix4 a, ref Matrix4 b)
+		{
+			Matrix4 r;
+			Multiply(ref a, ref b, out r);
+			return r;
+		}
+
+		/// <summary>
+		/// Multiply two matrices.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <param name="r"></param>
+		public static void Multiply(ref Matrix4 a, ref Matrix4 b, out Matrix4 r)
+		{
+			float
+				am11 = a.M11, am21 = a.M21, am31 = a.M31, am41 = a.M41,
+				am12 = a.M12, am22 = a.M22, am32 = a.M32, am42 = a.M42,
+				am13 = a.M13, am23 = a.M23, am33 = a.M33, am43 = a.M43,
+				am14 = a.M14, am24 = a.M24, am34 = a.M34, am44 = a.M44,
+
+				bm11 = b.M11, bm21 = b.M21, bm31 = b.M31, bm41 = b.M41,
+				bm12 = b.M12, bm22 = b.M22, bm32 = b.M32, bm42 = b.M42,
+				bm13 = b.M13, bm23 = b.M23, bm33 = b.M33, bm43 = b.M43,
+				bm14 = b.M14, bm24 = b.M24, bm34 = b.M34, bm44 = b.M44;
+
+			r.Column1.X = am11 * bm11 + am21 * bm12 + am31 * bm13 + am41 * bm14; // M11
+			r.Column2.X = am11 * bm21 + am21 * bm22 + am31 * bm23 + am41 * bm24; // M21
+			r.Column3.X = am11 * bm31 + am21 * bm32 + am31 * bm33 + am41 * bm34; // M31
+			r.Column4.X = am11 * bm41 + am21 * bm42 + am31 * bm43 + am41 * bm44; // M41
+
+			r.Column1.Y = am12 * bm11 + am22 * bm12 + am32 * bm13 + am42 * bm14; // M12
+			r.Column2.Y = am12 * bm21 + am22 * bm22 + am32 * bm23 + am42 * bm24; // M22
+			r.Column3.Y = am12 * bm31 + am22 * bm32 + am32 * bm33 + am42 * bm34; // M32
+			r.Column4.Y = am12 * bm41 + am22 * bm42 + am32 * bm43 + am42 * bm44; // M42
+
+			r.Column1.Z = am13 * bm11 + am23 * bm12 + am33 * bm13 + am43 * bm14; // M13
+			r.Column2.Z = am13 * bm21 + am23 * bm22 + am33 * bm23 + am43 * bm24; // M23
+			r.Column3.Z = am13 * bm31 + am23 * bm32 + am33 * bm33 + am43 * bm34; // M33
+			r.Column4.Z = am13 * bm41 + am23 * bm42 + am33 * bm43 + am43 * bm44; // M43
+
+			r.Column1.W = am14 * bm11 + am24 * bm12 + am34 * bm13 + am44 * bm14; // M14
+			r.Column2.W = am14 * bm21 + am24 * bm22 + am34 * bm23 + am44 * bm24; // M24
+			r.Column3.W = am14 * bm31 + am24 * bm32 + am34 * bm33 + am44 * bm34; // M34
+			r.Column4.W = am14 * bm41 + am24 * bm42 + am34 * bm43 + am44 * bm44;  // M44
+		}
+
+		/// <summary>
+		/// Multiply matrix by a scalar.
+		/// </summary>
+		/// <param name="mat"></param>
+		/// <param name="f"></param>
+		/// <param name="r"></param>
+		public static void Multiply(ref Matrix4 mat, float f, out Matrix4 r)
+		{
+			r.Column1.X = mat.Column1.X * f;
+			r.Column1.Y = mat.Column1.Y * f;
+			r.Column1.Z = mat.Column1.Z * f;
+			r.Column1.W = mat.Column1.W * f;
+			r.Column2.X = mat.Column2.X * f;
+			r.Column2.Y = mat.Column2.Y * f;
+			r.Column2.Z = mat.Column2.Z * f;
+			r.Column2.W = mat.Column2.W * f;
+			r.Column3.X = mat.Column3.X * f;
+			r.Column3.Y = mat.Column3.Y * f;
+			r.Column3.Z = mat.Column3.Z * f;
+			r.Column3.W = mat.Column3.W * f;
+			r.Column4.X = mat.Column4.X * f;
+			r.Column4.Y = mat.Column4.Y * f;
+			r.Column4.Z = mat.Column4.Z * f;
+			r.Column4.W = mat.Column4.W * f;
+		}
+
+		/// <summary>
+		/// Multiply matrix by a scalar.
+		/// </summary>
+		/// <param name="mat"></param>
+		/// <param name="f"></param>
+		/// <returns></returns>
+		public static Matrix4 Multiply(ref Matrix4 mat, float f)
+		{
+			Matrix4 r;
+			Multiply(ref mat, f, out r);
+			return r;
+		}
+
+		/// <summary>
+		/// Multiply two 4x3 matrices (assumes row 4 to be 0,0,0,1 ).
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static Matrix4 Multiply4x3(ref Matrix4 a, ref Matrix4 b)
+		{
+			Matrix4 r;
+			Multiply4x3(ref a, ref b, out r);
+			return r;
+		}
+
+		/// <summary>
+		/// Multiply two 4x3 matrices (assumes row 4 to be 0,0,0,1 ).
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <param name="r"></param>
+		public static void Multiply4x3(ref Matrix4 a, ref Matrix4 b, out Matrix4 r)
+		{
+			float
+				am11 = a.M11, am21 = a.M21, am31 = a.M31, am41 = a.M41,
+				am12 = a.M12, am22 = a.M22, am32 = a.M32, am42 = a.M42,
+				am13 = a.M13, am23 = a.M23, am33 = a.M33, am43 = a.M43,
+				am14 = a.M14, am24 = a.M24, am34 = a.M34, am44 = a.M44,
+
+				bm11 = b.M11, bm21 = b.M21, bm31 = b.M31, bm41 = b.M41,
+				bm12 = b.M12, bm22 = b.M22, bm32 = b.M32, bm42 = b.M42,
+				bm13 = b.M13, bm23 = b.M23, bm33 = b.M33, bm43 = b.M43;
+
+			r.Column1.X = am11 * bm11 + am21 * bm12 + am31 * bm13; // M11
+			r.Column2.X = am11 * bm21 + am21 * bm22 + am31 * bm23; // M21
+			r.Column3.X = am11 * bm31 + am21 * bm32 + am31 * bm33; // M31
+			r.Column4.X = am11 * bm41 + am21 * bm42 + am31 * bm43 + am41; // M41
+
+			r.Column1.Y = am12 * bm11 + am22 * bm12 + am32 * bm13; // M12
+			r.Column2.Y = am12 * bm21 + am22 * bm22 + am32 * bm23; // M22
+			r.Column3.Y = am12 * bm31 + am22 * bm32 + am32 * bm33; // M32
+			r.Column4.Y = am12 * bm41 + am22 * bm42 + am32 * bm43 + am42; // M42
+
+			r.Column1.Z = am13 * bm11 + am23 * bm12 + am33 * bm13; // M13
+			r.Column2.Z = am13 * bm21 + am23 * bm22 + am33 * bm23; // M23
+			r.Column3.Z = am13 * bm31 + am23 * bm32 + am33 * bm33; // M33
+			r.Column4.Z = am13 * bm41 + am23 * bm42 + am33 * bm43 + am43; // M43
+
+			r.Column1.W = 0; // M14
+			r.Column2.W = 0; // M24
+			r.Column3.W = 0; // M34
+			r.Column4.W = 1;  // M44
+		}
+
+		/// <summary>
+		/// Add two matrices.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <param name="r"></param>
+		public static void Add(ref Matrix4 a, ref Matrix4 b, out Matrix4 r)
+		{
+			r.Column1.X = a.Column1.X + b.Column1.X;
+			r.Column1.Y = a.Column1.Y + b.Column1.Y;
+			r.Column1.Z = a.Column1.Z + b.Column1.Z;
+			r.Column1.W = a.Column1.W + b.Column1.W;
+
+			r.Column2.X = a.Column2.X + b.Column2.X;
+			r.Column2.Y = a.Column2.Y + b.Column2.Y;
+			r.Column2.Z = a.Column2.Z + b.Column2.Z;
+			r.Column2.W = a.Column2.W + b.Column2.W;
+
+			r.Column3.X = a.Column3.X + b.Column3.X;
+			r.Column3.Y = a.Column3.Y + b.Column3.Y;
+			r.Column3.Z = a.Column3.Z + b.Column3.Z;
+			r.Column3.W = a.Column3.W + b.Column3.W;
+
+			r.Column4.X = a.Column4.X + b.Column4.X;
+			r.Column4.Y = a.Column4.Y + b.Column4.Y;
+			r.Column4.Z = a.Column4.Z + b.Column4.Z;
+			r.Column4.W = a.Column4.W + b.Column4.W;
+		}
+
+		/// <summary>
+		/// Add two matrices.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static Matrix4 Add(ref Matrix4 a, ref Matrix4 b)
+		{
+			Matrix4 r;
+			Add(ref a, ref b, out r);
+			return r;
+		}
+
+		/// <summary>
+		/// Subtract two matrices.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <param name="r"></param>
+		public static void Subtract(ref Matrix4 a, ref Matrix4 b, out Matrix4 r)
+		{
+			r.Column1.X = a.Column1.X - b.Column1.X;
+			r.Column1.Y = a.Column1.Y - b.Column1.Y;
+			r.Column1.Z = a.Column1.Z - b.Column1.Z;
+			r.Column1.W = a.Column1.W - b.Column1.W;
+
+			r.Column2.X = a.Column2.X - b.Column2.X;
+			r.Column2.Y = a.Column2.Y - b.Column2.Y;
+			r.Column2.Z = a.Column2.Z - b.Column2.Z;
+			r.Column2.W = a.Column2.W - b.Column2.W;
+
+			r.Column3.X = a.Column3.X - b.Column3.X;
+			r.Column3.Y = a.Column3.Y - b.Column3.Y;
+			r.Column3.Z = a.Column3.Z - b.Column3.Z;
+			r.Column3.W = a.Column3.W - b.Column3.W;
+
+			r.Column4.X = a.Column4.X - b.Column4.X;
+			r.Column4.Y = a.Column4.Y - b.Column4.Y;
+			r.Column4.Z = a.Column4.Z - b.Column4.Z;
+			r.Column4.W = a.Column4.W - b.Column4.W;
+		}
+
+		/// <summary>
+		/// Subtract two matrices.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static Matrix4 Subtract(ref Matrix4 a, ref Matrix4 b)
+		{
+			Matrix4 r;
+			Subtract(ref a, ref b, out r);
+			return r;
+		}
+
+		/// <summary>
+		/// Item at column 1 and row 1
+		/// </summary>
+		public float M11
+		{
+			get
+			{
+				return Column1.X;
+			}
+			set
+			{
+				Column1.X = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 1 and row 2
+		/// </summary>
+		public float M12
+		{
+			get
+			{
+				return Column1.Y;
+			}
+			set
+			{
+				Column1.Y = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 1 and row 3
+		/// </summary>
+		public float M13
+		{
+			get
+			{
+				return Column1.Z;
+			}
+			set
+			{
+				Column1.Z = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 1 and row 4
+		/// </summary>
+		public float M14
+		{
+			get
+			{
+				return Column1.W;
+			}
+			set
+			{
+				Column1.W = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 2 and row 1
+		/// </summary>
+		public float M21
+		{
+			get
+			{
+				return Column2.X;
+			}
+			set
+			{
+				Column2.X = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 2 and row 2
+		/// </summary>
+		public float M22
+		{
+			get
+			{
+				return Column2.Y;
+			}
+			set
+			{
+				Column2.Y = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 2 and row 3
+		/// </summary>
+		public float M23
+		{
+			get
+			{
+				return Column2.Z;
+			}
+			set
+			{
+				Column2.Z = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 2 and row 4
+		/// </summary>
+		public float M24
+		{
+			get
+			{
+				return Column2.W;
+			}
+			set
+			{
+				Column2.W = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 3 and row 1
+		/// </summary>
+		public float M31
+		{
+			get
+			{
+				return Column3.X;
+			}
+			set
+			{
+				Column3.X = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 3 and row 2
+		/// </summary>
+		public float M32
+		{
+			get
+			{
+				return Column3.Y;
+			}
+			set
+			{
+				Column3.Y = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 3 and row 3
+		/// </summary>
+		public float M33
+		{
+			get
+			{
+				return Column3.Z;
+			}
+			set
+			{
+				Column3.Z = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 3 and row 4
+		/// </summary>
+		public float M34
+		{
+			get
+			{
+				return Column3.W;
+			}
+			set
+			{
+				Column3.W = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 4 and row 1
+		/// </summary>
+		public float M41
+		{
+			get
+			{
+				return Column4.X;
+			}
+			set
+			{
+				Column4.X = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 4 and row 2
+		/// </summary>
+		public float M42
+		{
+			get
+			{
+				return Column4.Y;
+			}
+			set
+			{
+				Column4.Y = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 4 and row 3
+		/// </summary>
+		public float M43
+		{
+			get
+			{
+				return Column4.Z;
+			}
+			set
+			{
+				Column4.Z = value;
+			}
+		}
+
+		/// <summary>
+		/// Item at column 4 and row 4
+		/// </summary>
+		public float M44
+		{
+			get
+			{
+				return Column4.W;
+			}
+			set
+			{
+				Column4.W = value;
+			}
+		}
+
+		/// <summary>
+		/// Gets determinant of this matrix.
+		/// </summary>
+		public float Determinant
+		{
+			get
+			{
+				float m12 = M12, m22 = M22, m32 = M32, m42 = M42,
+					  m13 = M13, m23 = M23, m33 = M33, m43 = M43,
+					  m14 = M14, m24 = M24, m34 = M34, m44 = M44;
+
+				float a = m33 * m44 - m43 * m34;
+				float b = m13 * m44 - m43 * m14;
+				float c = m23 * m44 - m43 * m24;
+				float d = m13 * m24 - m23 * m14;
+				float e = m13 * m34 - m33 * m14;
+				float f = m23 * m34 - m33 * m24;
+
+				float ac = m22 * a - m32 * c + m42 * f;
+				float bc = m12 * a - m32 * b + m42 * e;
+				float cc = m12 * c - m22 * b + m42 * d;
+				float dc = m12 * f - m22 * e + m32 * d;
+
+				ac *= M11;
+				bc *= M21;
+				cc *= M31;
+				dc *= M41;
+
+				return ac - bc + cc - dc;
+			}
+		}
+
+		/// <summary>
+		/// Gets determinant of this matrix. (assumes row 4 to be 0,0,0,1 ).
+		/// </summary>
+		public float Determinant4x3
+		{
+			get
+			{
+				float m12 = M12, m13 = M13,
+					  m22 = M22, m23 = M23,
+					  m32 = M32, m33 = M33;
+
+				float ac = M11 * (m22 * m33 - m32 * m23);
+				float bc = M21 * (m12 * m33 - m32 * m13);
+				float cc = M31 * (m12 * m23 - m22 * m13);
+				return ac - bc + cc;
+			}
+		}
+
+		/// <summary>
+		/// Gets inverse of this Matrix4.
+		/// </summary>
+		public Matrix4 Inverse
+		{
+			get
+			{
+				float m11 = M11, m21 = M21, m31 = M31, m41 = M41,
+					  m12 = M12, m22 = M22, m32 = M32, m42 = M42,
+					  m13 = M13, m23 = M23, m33 = M33, m43 = M43,
+					  m14 = M14, m24 = M24, m34 = M34, m44 = M44;
+
+				float s0 = m11 * m22 - m12 * m21;
+				float s1 = m11 * m32 - m12 * m31;
+				float s2 = m11 * m42 - m12 * m41;
+				float s3 = m21 * m32 - m22 * m31;
+				float s4 = m21 * m42 - m22 * m41;
+				float s5 = m31 * m42 - m32 * m41;
+
+				float c5 = m33 * m44 - m34 * m43;
+				float c4 = m23 * m44 - m24 - m43;
+				float c3 = m23 * m34 - m24 * m33;
+				float c2 = m13 * m44 - m14 * m43;
+				float c1 = m13 * m34 - m14 * m33;
+				float c0 = m13 * m24 - m14 * m23;
+
+				float det = s0 * c5 - s1 * c4 + s2 * c3 + s3 * c2 - s4 * c1 + s5 * c0;
+
+				if ((float)Math.Abs(det) < .000000001f)
+					throw new InvalidOperationException("Matrix is not invertible.");
+
+				float invdet = 1 / det;
+
+				Matrix4 r;
+				r.Column1.X = (m22 * c5 - m32 * c4 + m42 * c3) * invdet;
+				r.Column2.X = (-m21 * c5 + m31 * c4 - m41 * c3) * invdet;
+				r.Column3.X = (m24 * s5 - m34 * s4 + m44 * s3) * invdet;
+				r.Column4.X = (-m23 * s5 + m33 * s4 - m43 * s3) * invdet;
+
+				r.Column1.Y = (-m12 * c5 + m32 * c2 - m42 * c1) * invdet;
+				r.Column2.Y = (m11 * c5 - m31 * c2 + m41 * c1) * invdet;
+				r.Column3.Y = (-m14 * s5 + m34 * s2 - m44 * s1) * invdet;
+				r.Column4.Y = (m13 * s5 - m33 * s2 + m43 * s1) * invdet;
+
+				r.Column1.Z = (m12 * c4 - m22 * c2 + m42 * c0) * invdet;
+				r.Column2.Z = (-m11 * c4 + m21 * c2 - m41 * c0) * invdet;
+				r.Column3.Z = (m14 * s4 - m24 * s2 + m44 * s0) * invdet;
+				r.Column4.Z = (-m13 * s4 + m23 * s2 - m43 * s0) * invdet;
+
+				r.Column1.W = (-m12 * c3 + m22 * c1 - m32 * c0) * invdet;
+				r.Column2.W = (m11 * c3 - m21 * c1 + m31 * c0) * invdet;
+				r.Column3.W = (-m14 * s3 + m24 * s1 - m34 * s0) * invdet;
+				r.Column4.W = (m13 * s3 - m23 * s1 + m33 * s0) * invdet;
+
+				return r;
+			}
+		}
+
+		public Vec4 Row1
+		{
+			get
+			{
+				return new Vec4(Column1.X, Column2.X, Column3.X, Column4.X);
+			}
+		}
+
+		public Vec4 Row2
+		{
+			get
+			{
+				return new Vec4(Column1.Y, Column2.Y, Column3.Y, Column4.Y);
+			}
+		}
+
+		public Vec4 Row3
+		{
+			get
+			{
+				return new Vec4(Column1.Z, Column2.Z, Column3.Z, Column4.Z);
+			}
+		}
+
+		public Vec4 Row4
+		{
+			get
+			{
+				return new Vec4(Column1.W, Column2.W, Column3.W, Column4.W);
+			}
+		}
+
+		public Vec4 Column1;
+		public Vec4 Column2;
+		public Vec4 Column3;
+		public Vec4 Column4;
+
+		/// <summary>
+		/// The identity matrix.
+		/// </summary>
+		public static readonly Matrix4 Identity = new Matrix4(1, 0, 0, 0,
+															  0, 1, 0, 0,
+															  0, 0, 1, 0,
+															  0, 0, 0, 1);
+	}
+}

SharpHammer/Quat.cs

+using System;
+using System.Runtime.InteropServices;
+
+namespace SharpHammer
+{
+	public struct Quat
+	{
+	}
+}

SharpHammer/Vec2.cs

+using System;
+using System.Runtime.InteropServices;
+
+namespace SharpHammer
+{
+	[StructLayout(LayoutKind.Sequential)]
+	public struct Vec2
+	{
+		public Vec2(float x, float y)
+		{
+			X = x;
+			Y = y;
+		}
+
+		/// <summary>
+		/// Normalize this Vec2.
+		/// </summary>
+		public void Normalize()
+		{
+			float invlength = 1.0f / Length;
+			X *= invlength;
+			Y *= invlength;
+		}
+
+		public System.Drawing.PointF ToPointF()
+		{
+			return new System.Drawing.PointF(X, Y);
+		}
+
+		public override string ToString()
+		{
+			return string.Format("X:{0} Y:{1}", X, Y);
+		}
+
+		/// <summary>
+		/// Returns dot product of this two Vec2.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static float Dot(Vec2 a, Vec2 b)
+		{
+			return a.X * b.X + a.Y * b.Y;
+		}
+
+		/// <summary>
+		/// Linearly interpolate from a to b.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <param name="t"></param>
+		/// <returns></returns>
+		public static Vec2 Lerp(Vec2 a, Vec2 b, float t)
+		{
+			return new Vec2((b.X - a.X) * t + a.X, (b.Y - a.Y) * t + a.Y);
+		}
+
+		/// <summary>
+		/// Returns distance between a to b.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static float Distance(Vec2 a, Vec2 b)
+		{
+			float dx = a.X - b.X;
+			float dy = a.Y - b.Y;
+			return (float)Math.Sqrt(dx * dx + dy * dy);
+		}
+
+		/// <summary>
+		/// Returns Squared distance between a to b.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static float SqrDistance(Vec2 a, Vec2 b)
+		{
+			float dx = a.X - b.X;
+			float dy = a.Y - b.Y;
+			return dx * dx + dy * dy;
+		}
+
+		/// <summary>
+		/// Returns Vec2 from system.drawing.PointF
+		/// </summary>
+		/// <param name="pnt"></param>
+		/// <returns></returns>
+		public static Vec2 FromPointF(System.Drawing.PointF pnt)
+		{
+			return new Vec2(pnt.X, pnt.Y);
+		}
+
+		public static Vec2 operator +(Vec2 a, Vec2 b)
+		{
+			a.X += b.X;
+			a.Y += b.Y;
+			return a;
+		}
+
+		public static Vec2 operator -(Vec2 a, Vec2 b)
+		{
+			a.X -= b.X;
+			a.Y -= b.Y;
+			return a;
+		}
+
+		public static Vec2 operator *(Vec2 a, Vec2 b)
+		{
+			a.X *= b.X;
+			a.Y *= b.Y;
+			return a;
+		}
+
+		public static Vec2 operator *(Vec2 a, float b)
+		{
+			a.X *= b;
+			a.Y *= b;
+			return a;
+		}
+
+		public static Vec2 operator *(float a, Vec2 b)
+		{
+			b.X *= a;
+			b.Y *= a;
+			return b;
+		}
+
+		public static Vec2 operator /(Vec2 a, Vec2 b)
+		{
+			a.X /= b.X;
+			a.Y /= b.Y;
+			return a;
+		}
+
+		public static Vec2 operator /(Vec2 a, float b)
+		{
+			float inv = 1.0f / b;
+			a.X *= inv;
+			a.Y *= inv;
+			return a;
+		}
+
+		/// <summary>
+		/// Gets the length of this Vec2.
+		/// </summary>
+		public float Length
+		{
+			get
+			{
+				return (float)Math.Sqrt(X * X + Y * Y);
+			}
+		}
+
+		/// <summary>
+		/// Gets the squared length of this Vec2.
+		/// </summary>
+		public float SqrLength
+		{
+			get
+			{
+				return X * X + Y * Y;
+			}
+		}
+
+		/// <summary>
+		/// Normalized version of this Vec2.
+		/// </summary>
+		public Vec2 Normalized
+		{
+			get
+			{
+				Vec2 tmp = this;
+				tmp.Normalize();
+				return tmp;
+			}
+		}
+
+		public float X;
+		public float Y;
+
+		public static readonly Vec2 Zero = new Vec2(0, 0);
+		public static readonly Vec2 One = new Vec2(1, 1);
+	}
+}

SharpHammer/Vec3.cs

+using System;
+using System.Runtime.InteropServices;
+
+namespace SharpHammer
+{
+	[StructLayout(LayoutKind.Sequential)]
+	public struct Vec3
+	{
+		public Vec3(float x, float y, float z)
+		{
+			X = x;
+			Y = y;
+			Z = z;
+		}
+
+		/// <summary>
+		/// Normalize this Vec3.
+		/// </summary>
+		public void Normalize()
+		{
+			float invlength = 1.0f / Length;
+			X *= invlength;
+			Y *= invlength;
+			Z *= invlength;
+		}
+
+		public override string ToString()
+		{
+			return string.Format("X:{0} Y:{1} Z:{2}", X, Y, Z);
+		}
+
+		/// <summary>
+		/// Returns dot product of this two Vec3.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static float Dot(Vec3 a, Vec3 b)
+		{
+			return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
+		}
+
+		/// <summary>
+		/// Returns cross product of this two Vec3.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static Vec3 Cross(Vec3 a, Vec3 b)
+		{
+			return new Vec3(a.Y * b.Z - a.Z * b.Y,
+							a.Z * b.X - a.X * b.Z,
+							a.X * b.Y - a.Y * b.X);
+		}
+
+		/// <summary>
+		/// Linearly interpolate from a to b.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <param name="t"></param>
+		/// <returns></returns>
+		public static Vec3 Lerp(Vec3 a, Vec3 b, float t)
+		{
+			return new Vec3((b.X - a.X) * t + a.X, (b.Y - a.Y) * t + a.Y, (b.Z - a.Z) * t + a.Z);
+		}
+
+		/// <summary>
+		/// Returns distance between a to b.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static float Distance(Vec3 a, Vec3 b)
+		{
+			float dx = a.X - b.X;
+			float dy = a.Y - b.Y;
+			float dz = a.Z - b.Z;
+			return (float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
+		}
+
+		/// <summary>
+		/// Returns Squared distance between a to b.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static float SqrDistance(Vec3 a, Vec3 b)
+		{
+			float dx = a.X - b.X;
+			float dy = a.Y - b.Y;
+			float dz = a.Z - b.Z;
+			return dx * dx + dy * dy + dz * dz;
+		}
+
+		/// <summary>
+		/// Transform a Vec3(position) by a matrix (assumes row 4 to be 0,0,0,1 ).
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <param name="r"></param>
+		public static void Transform(ref Matrix4 a, ref Vec3 b, out Vec3 r)
+		{
+			r.X = a.M11 * b.X + a.M21 * b.Y + a.M31 * b.Z + a.M41;
+			r.Y = a.M12 * b.X + a.M22 * b.Y + a.M32 * b.Z + a.M42;
+			r.Z = a.M13 * b.X + a.M23 * b.Y + a.M33 * b.Z + a.M43;
+		}
+
+		/// <summary>
+		/// Transform a Vec3(position) by a matrix (assumes row 4 to be 0,0,0,1 ).
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static Vec3 Transform(ref Matrix4 a, ref Vec3 b)
+		{
+			Vec3 r;
+			Transform(ref a, ref b, out r);
+			return r;
+		}
+
+		public static Vec3 operator +(Vec3 a, Vec3 b)
+		{
+			a.X += b.X;
+			a.Y += b.Y;
+			a.Z += b.Z;
+			return a;
+		}
+
+		public static Vec3 operator -(Vec3 a, Vec3 b)
+		{
+			a.X -= b.X;
+			a.Y -= b.Y;
+			a.Z -= b.Z;
+			return a;
+		}
+
+		public static Vec3 operator *(Vec3 a, Vec3 b)
+		{
+			a.X *= b.X;
+			a.Y *= b.Y;
+			a.Z *= b.Z;
+			return a;
+		}
+
+		public static Vec3 operator *(Vec3 a, float b)
+		{
+			a.X *= b;
+			a.Y *= b;
+			a.Z *= b;
+			return a;
+		}
+
+		public static Vec3 operator *(float a, Vec3 b)
+		{
+			b.X *= a;
+			b.Y *= a;
+			b.Z *= a;
+			return b;
+		}
+
+		public static Vec3 operator /(Vec3 a, Vec3 b)
+		{
+			a.X /= b.X;
+			a.Y /= b.Y;
+			a.Z /= b.Z;
+			return a;
+		}
+
+		public static Vec3 operator /(Vec3 a, float b)
+		{
+			float inv = 1.0f / b;
+			a.X *= inv;
+			a.Y *= inv;
+			a.Z *= inv;
+			return a;
+		}
+
+		/// <summary>
+		/// Gets the length of this Vec4.
+		/// </summary>
+		public float Length
+		{
+			get
+			{
+				return (float)Math.Sqrt(X * X + Y * Y + Z * Z);
+			}
+		}
+
+		/// <summary>
+		/// Gets the squared length of this Vec3.
+		/// </summary>
+		public float SqrLength
+		{
+			get
+			{
+				return X * X + Y * Y + Z * Z;
+			}
+		}
+
+		/// <summary>
+		/// Xy part of this Vec3.
+		/// </summary>
+		public Vec2 Xy
+		{
+			get
+			{
+				return new Vec2(X, Y);
+			}
+		}
+
+		/// <summary>
+		/// Normalized version of this Vec3.
+		/// </summary>
+		public Vec3 Normalized
+		{
+			get
+			{
+				Vec3 tmp = this;
+				tmp.Normalize();
+				return tmp;
+			}
+		}
+
+		public float X;
+		public float Y;
+		public float Z;
+
+		public static readonly Vec3 Up = new Vec3(0, 1, 0);
+		public static readonly Vec3 Down = new Vec3(0, -1, 0);
+		public static readonly Vec3 Right = new Vec3(1, 0, 0);
+		public static readonly Vec3 Left = new Vec3(-1, 0, 0);
+		public static readonly Vec3 Forward = new Vec3(0, 0, 1); // LH
+		public static readonly Vec3 Backward = new Vec3(0, 0, -1); // LH
+		public static readonly Vec3 Zero = new Vec3(0, 0, 0);
+		public static readonly Vec3 One = new Vec3(1, 1, 1);
+	}
+}

SharpHammer/Vec4.cs

+using System;
+using System.Runtime.InteropServices;
+
+namespace SharpHammer
+{
+	[StructLayout(LayoutKind.Sequential)]
+	public struct Vec4
+	{
+		public Vec4(float x, float y, float z, float w)
+		{
+			X = x;
+			Y = y;
+			Z = z;
+			W = w;
+		}
+
+		/// <summary>
+		/// Normalize this Vec4.
+		/// </summary>
+		public void Normalize()
+		{
+			float invlength = 1.0f / Length;
+			X *= invlength;
+			Y *= invlength;
+			Z *= invlength;
+			W *= invlength;
+		}
+
+		public override string ToString()
+		{
+			return string.Format("X:{0} Y:{1} Z:{2} W:", X, Y, Z) + W;
+		}
+
+		/// <summary>
+		/// Returns dot product of this two Vec4.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static float Dot(Vec4 a, Vec4 b)
+		{
+			return a.X * b.X + a.Y * b.Y + a.Z * b.Z + a.W * b.W;
+		}
+
+		/// <summary>
+		/// Linearly interpolate from a to b.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <param name="t"></param>
+		/// <returns></returns>
+		public static Vec4 Lerp(Vec4 a, Vec4 b, float t)
+		{
+			return new Vec4((b.X - a.X) * t + a.X, (b.Y - a.Y) * t + a.Y, (b.Z - a.Z) * t + a.Z, (b.W - a.W) * t + a.W);
+		}
+
+		/// <summary>
+		/// Returns distance between a to b.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static float Distance(Vec4 a, Vec4 b)
+		{
+			float dx = a.X - b.X;
+			float dy = a.Y - b.Y;
+			float dz = a.Z - b.Z;
+			float dw = a.W - b.W;
+			return (float)Math.Sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
+		}
+
+		/// <summary>
+		/// Returns Squared distance between a to b.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static float SqrDistance(Vec4 a, Vec4 b)
+		{
+			float dx = a.X - b.X;
+			float dy = a.Y - b.Y;
+			float dz = a.Z - b.Z;
+			float dw = a.W - b.W;
+			return dx * dx + dy * dy + dz * dz + dw * dw;
+		}
+
+		/// <summary>
+		/// Transform a Vec4 by a matrix.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <param name="r"></param>
+		public static void Transform(ref Matrix4 a, ref Vec4 b, out Vec4 r)
+		{
+			r.X = a.M11 * b.X + a.M21 * b.Y + a.M31 * b.Z + a.M41 * b.W;
+			r.Y = a.M12 * b.X + a.M22 * b.Y + a.M32 * b.Z + a.M42 * b.W;
+			r.Z = a.M13 * b.X + a.M23 * b.Y + a.M33 * b.Z + a.M43 * b.W;
+			r.W = a.M14 * b.X + a.M24 * b.Y + a.M34 * b.Z + a.M44 * b.W;
+		}
+
+		/// <summary>
+		/// Transform a Vec4 by a matrix.
+		/// </summary>
+		/// <param name="a"></param>
+		/// <param name="b"></param>
+		/// <returns></returns>
+		public static Vec4 Transform(ref Matrix4 a, ref Vec4 b)
+		{
+			Vec4 r;
+			Transform(ref a, ref b, out r);
+			return r;
+		}
+
+		public static Vec4 operator +(Vec4 a, Vec4 b)
+		{
+			a.X += b.X;
+			a.Y += b.Y;
+			a.Z += b.Z;
+			a.W += b.W;
+			return a;
+		}
+
+		public static Vec4 operator -(Vec4 a, Vec4 b)
+		{
+			a.X -= b.X;
+			a.Y -= b.Y;
+			a.Z -= b.Z;
+			a.W -= b.W;
+			return a;
+		}
+
+		public static Vec4 operator *(Vec4 a, Vec4 b)
+		{
+			a.X *= b.X;
+			a.Y *= b.Y;
+			a.Z *= b.Z;
+			a.W *= b.W;
+			return a;
+		}
+
+		public static Vec4 operator *(Vec4 a, float b)
+		{
+			a.X *= b;
+			a.Y *= b;
+			a.Z *= b;
+			a.W *= b;
+			return a;
+		}
+
+		public static Vec4 operator *(float a, Vec4 b)
+		{
+			b.X *= a;
+			b.Y *= a;
+			b.Z *= a;
+			b.W *= a;
+			return b;
+		}
+
+		public static Vec4 operator /(Vec4 a, Vec4 b)
+		{
+			a.X /= b.X;
+			a.Y /= b.Y;
+			a.Z /= b.Z;
+			a.W /= b.W;
+			return a;
+		}
+
+		public static Vec4 operator /(Vec4 a, float b)
+		{
+			float inv = 1.0f / b;
+			a.X *= inv;
+			a.Y *= inv;
+			a.Z *= inv;
+			a.W *= inv;
+			return a;
+		}
+
+		/// <summary>
+		/// Gets the length of this Vec4.
+		/// </summary>
+		public float Length
+		{
+			get
+			{
+				return (float)Math.Sqrt(X * X + Y * Y + Z * Z + W * W);
+			}
+		}
+
+		/// <summary>
+		/// Gets the squared length of this Vec4.
+		/// </summary>
+		public float SqrLength
+		{
+			get
+			{
+				return X * X + Y * Y + Z * Z + W * W;
+			}
+		}
+
+		/// <summary>
+		/// Xyz part of this Vec4.
+		/// </summary>
+		public Vec3 Xyz
+		{
+			get
+			{
+				return new Vec3(X, Y, Z);
+			}
+		}
+
+		/// <summary>
+		/// Normalized version of this Vec4.
+		/// </summary>
+		public Vec4 Normalized
+		{
+			get
+			{
+				Vec4 tmp = this;
+				tmp.Normalize();
+				return tmp;
+			}
+		}
+
+		public float X;
+		public float Y;
+		public float Z;
+		public float W;
+	}
+}

SharpHammer/core.cs

+using System;
+using System.Security;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace SharpHammer
+{
+	#region log
+
+	public enum log_type
+	{
+		Text = 0,
+		Error = 1,
+		Warning = 2,
+		Info = 3,
+		Load = 4
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	public struct log_stats
+	{
+		public UInt32 msgs_cnt;
+		public UInt32 errors_cnt;
+		public UInt32 warnings_cnt;
+	}
+
+	#endregion
+
+	#region error_codes
+	public enum result_t
+	{
+		RET_ABORT = 2,
+		RET_OK = 1,
+		RET_FAIL = 0,
+		RET_OUTOFMEMORY = -1,
+		RET_WARNING = -2,
+		RET_INVALIDARG = -3,
+		RET_FILE_ERROR = -4,
+		RET_NOT_IMPL = -5,
+		RET_NOT_SUPPORTED = -6,
+		RET_INVALIDCALL = -7
+	}
+	#endregion
+
+	[SuppressUnmanagedCodeSecurity]
+	public class core
+	{
+		public const string NativeDll = "dh_core.dll";
+
+		#region core
+		// core_init
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern result_t core_init(
+			[MarshalAs(UnmanagedType.Bool)] bool trace_mem);
+
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void core_release(
+			[MarshalAs(UnmanagedType.Bool)] bool report_leaks);
+
+		#endregion
+
+		#region log
+		// pfn_log_handler
+		public delegate void pfn_log_handler(log_type param0,
+			[In] [MarshalAs(UnmanagedType.LPStr)] string param1, IntPtr param2);
+
+		// log_outputconsole
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern result_t log_outputconsole(
+			[MarshalAs(UnmanagedType.Bool)]bool enable);
+		// log_outputfile
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern result_t log_outputfile(
+			[MarshalAs(UnmanagedType.Bool)]bool enable,
+			[In] [MarshalAs(UnmanagedType.LPStr)] string log_filepath);
+		// log_outputdebugger
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern result_t log_outputdebugger(
+			[MarshalAs(UnmanagedType.Bool)]bool enable);
+		// log_outputfunc
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern result_t log_outputfunc(uint enable,
+			pfn_log_handler log_fn, IntPtr param);
+		// log_isconsole
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		[return: MarshalAs(UnmanagedType.Bool)]
+		public static extern bool log_isconsole();
+		// log_isfile
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		[return: MarshalAs(UnmanagedType.Bool)]
+		public static extern bool log_isfile();
+		// log_isdebugger
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		[return: MarshalAs(UnmanagedType.Bool)]
+		public static extern bool log_isdebugger();
+		// log_isoutputfunc
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		[return: MarshalAs(UnmanagedType.Bool)]
+		public static extern bool log_isoutputfunc();
+		// log_print
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void log_print(log_type type,
+			[In] [MarshalAs(UnmanagedType.LPStr)] string text);
+		// log_getstats
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void log_getstats(ref log_stats stats);
+		// log_init
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern result_t log_init();
+		// log_release
+		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void Release();
+		#endregion
+
+	}
+}

SharpHammer/engine.cs

+using System;
+using System.Security;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace SharpHammer
+{
+
+	#region init_params
+	public enum eng_flags
+	{
+		ENG_FLAG_DEBUG = (1 << 0),
+		ENG_FLAG_DEV = (1 << 1),
+		ENG_FLAG_EDITOR = (1 << 2),
+		ENG_FLAG_CONSOLE = (1 << 3),
+		ENG_FLAG_DISABLEPHX = (1 << 4)
+	}
+
+	public enum gfx_flags
+	{
+		GFX_FLAG_FULLSCREEN = (1 << 0),
+		GFX_FLAG_VSYNC = (1 << 1),
+		GFX_FLAG_DEBUG = (1 << 2),
+		GFX_FLAG_FXAA = (1 << 3),
+		GFX_FLAG_REBUILDSHADERS = (1 << 4)
+	}
+
+	public enum msaa_mode
+	{
+		MSAA_NONE = 0,
+		MSAA_2X = 2,
+		MSAA_4X = 4,
+		MSAA_8X = 8,
+	}
+
+	public enum gfx_hwver
+	{
+		GFX_HWVER_UNKNOWN = 0,
+		GFX_HWVER_D3D11_0 = 3,
+		GFX_HWVER_D3D10_1 = 2,
+		GFX_HWVER_D3D10_0 = 1,
+		GFX_HWVER_GL4_3 = 10,
+		GFX_HWVER_GL4_2 = 9,
+		GFX_HWVER_GL4_0 = 8,
+		GFX_HWVER_GL3_3 = 7,
+		GFX_HWVER_GL3_2 = 6
+	}
+
+	public enum shading_quality
+	{
+		SHADING_QUALITY_LOW = 2,
+		SHADING_QUALITY_NORMAL = 1,
+		SHADING_QUALITY_HIGH = 0
+	}
+
+	public enum texture_filter
+	{
+		TEXTURE_FILTER_TRILINEAR = 0,
+		TEXTURE_FILTER_BILINEAR,
+		TEXTURE_FILTER_ANISO2X,
+		TEXTURE_FILTER_ANISO4X,
+		TEXTURE_FILTER_ANISO8X,
+		TEXTURE_FILTER_ANISO16X
+	}
+
+	public enum texture_quality
+	{
+		TEXTURE_QUALITY_HIGH = 1,
+		TEXTURE_QUALITY_NORMAL = 2,
+		TEXTURE_QUALITY_LOW = 3,
+		TEXTURE_QUALITY_HIGHEST = 0
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	public struct dev_params
+	{
+		public int fpsgraph_max;
+		public int ftgraph_max;
+		public int webserver_port;
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	public struct gfx_params
+	{
+		public uint flags;
+		public msaa_mode msaa;
+		public texture_quality tex_quality;
+		public texture_filter tex_filter;
+		public shading_quality shading_quality;
+		public gfx_hwver hwver;
+		public uint adapter_id;
+		public uint width;
+		public uint height;
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	public struct phx_params
+	{
+		UInt32 flags; 
+		UInt32 mem_sz;
+		UInt32 substeps_max;
+		UInt32 scratch_sz;
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	public struct sct_params
+	{
+		UInt32 mem_sz;
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	public struct init_params
+	{
+		public uint flags;
+		public uint console_lines_max;
+
+		public gfx_params gfx;
+		public dev_params dev;
+		public phx_params phx;
+		public sct_params sct;
+		[MarshalAs(UnmanagedType.LPStr)]
+		public string console_cmds;
+		UInt32 console_cmds_cnt;
+		[MarshalAs(UnmanagedType.LPStr)]
+		public string data_dir;
+	}
+	#endregion
+
+	#region engine
+	[StructLayout(LayoutKind.Sequential)]
+	public struct frame_stats
+	{
+		UInt64 start_tick;
+		UInt32 frame;
+		float ft;
+		UInt32 fps;
+	}
+
+	[StructLayout(LayoutKind.Sequential)]
+	public struct eng_mem_stats
+	{
+		uint data_max;
+		uint data_size;
+		uint lsr_max;
+		uint lsr_size;
+		uint tmp0_total;
+		uint tmp0_max;
+		UInt32 tmp0_max_frameid;
+	}
+	#endregion
+
+	#region app
+	// pfn_app_create
+	public delegate void pfn_app_create(
+	[In] [MarshalAs(UnmanagedType.LPStr)] string wnd_name);
+	// pfn_app_destroy
+	public delegate void pfn_app_destroy(
+	[In] [MarshalAs(UnmanagedType.LPStr)] string wnd_name);
+	// pfn_app_resize
+	public delegate void pfn_app_resize(
+	[In] [MarshalAs(UnmanagedType.LPStr)] string wnd_name, uint width, uint height);
+	// pfn_app_active
+	public delegate void pfn_app_active(
+	[In] [MarshalAs(UnmanagedType.LPStr)] string wnd_name, 
+	[MarshalAs(UnmanagedType.Bool)] bool active);
+	// pfn_app_keypress
+	public delegate void pfn_app_keypress(
+	[In] [MarshalAs(UnmanagedType.LPStr)] string wnd_name, byte charcode, uint vkeycode);
+	// pfn_app_update
+	public delegate void pfn_app_update();
+	#endregion
+
+	#region input
+	public enum input_mouse_key
+	{
+		INPUT_MOUSEKEY_NONE = 0,
+		INPUT_MOUSEKEY_LEFT = (1 << 0),
+		INPUT_MOUSEKEY_RIGHT = (1 << 1),
+		INPUT_MOUSEKEY_MIDDLE = (1 << 2),
+		INPUT_MOUSEKEY_WHEELUP = (1 << 3),
+		INPUT_MOUSEKEY_WHEELDWN = (1 << 4)
+	}
+	public enum input_key
+	{
+		INPUT_KEY_ESC = 0,
+		INPUT_KEY_F1,
+		INPUT_KEY_F2,
+		INPUT_KEY_F3,
+		INPUT_KEY_F4,
+		INPUT_KEY_F5,
+		INPUT_KEY_F6,
+		INPUT_KEY_F7,
+		INPUT_KEY_F8,
+		INPUT_KEY_F9,
+		INPUT_KEY_F10,
+		INPUT_KEY_F11,
+		INPUT_KEY_F12,
+		INPUT_KEY_PRINTSCREEN,
+		INPUT_KEY_BREAK,
+		INPUT_KEY_TILDE,
+		INPUT_KEY_1,
+		INPUT_KEY_2,
+		INPUT_KEY_3,
+		INPUT_KEY_4,
+		INPUT_KEY_5,
+		INPUT_KEY_6,
+		INPUT_KEY_7,
+		INPUT_KEY_8,
+		INPUT_KEY_9,
+		INPUT_KEY_0,
+		INPUT_KEY_DASH,
+		INPUT_KEY_EQUAL,
+		INPUT_KEY_BACKSPACE,
+		INPUT_KEY_TAB,
+		INPUT_KEY_Q,
+		INPUT_KEY_W,
+		INPUT_KEY_E,
+		INPUT_KEY_R,
+		INPUT_KEY_T,
+		INPUT_KEY_Y,
+		INPUT_KEY_U,
+		INPUT_KEY_I,
+		INPUT_KEY_O,
+		INPUT_KEY_P,
+		INPUT_KEY_BRACKET_OPEN,
+		INPUT_KEY_BEACKET_CLOSE,
+		INPUT_KEY_BACKSLASH,
+		INPUT_KEY_CAPS,
+		INPUT_KEY_A,
+		INPUT_KEY_S,
+		INPUT_KEY_D,
+		INPUT_KEY_F,
+		INPUT_KEY_G,
+		INPUT_KEY_H,
+		INPUT_KEY_J,
+		INPUT_KEY_K,
+		INPUT_KEY_L,
+		INPUT_KEY_SEMICOLON,
+		INPUT_KEY_QUOTE,
+		INPUT_KEY_ENTER,
+		INPUT_KEY_LSHIFT,
+		INPUT_KEY_Z,
+		INPUT_KEY_X,
+		INPUT_KEY_C,
+		INPUT_KEY_V,
+		INPUT_KEY_B,
+		INPUT_KEY_N,
+		INPUT_KEY_M,
+		INPUT_KEY_COMMA,
+		INPUT_KEY_DOT,
+		INPUT_KEY_SLASH,
+		INPUT_KEY_RSHIFT,
+		INPUT_KEY_LCTRL,
+		INPUT_KEY_LALT,
+		INPUT_KEY_SPACE,
+		INPUT_KEY_RALT,
+		INPUT_KEY_RCTRL,
+		INPUT_KEY_DELETE,
+		INPUT_KEY_INSERT,
+		INPUT_KEY_HOME,
+		INPUT_KEY_END,
+		INPUT_KEY_PGUP,
+		INPUT_KEY_PGDWN,
+		INPUT_KEY_UP,
+		INPUT_KEY_DOWN,
+		INPUT_KEY_LEFT,
+		INPUT_KEY_RIGHT,
+		INPUT_KEY_NUM_SLASH,
+		INPUT_KEY_NUM_MULTIPLY,
+		INPUT_KEY_NUM_MINUS,
+		INPUT_KEY_NUM_PLUS,
+		INPUT_KEY_NUM_ENTER,
+		INPUT_KEY_NUM_DOT,
+		INPUT_KEY_NUM_1,
+		INPUT_KEY_NUM_2,
+		INPUT_KEY_NUM_3,
+		INPUT_KEY_NUM_4,
+		INPUT_KEY_NUM_5,
+		INPUT_KEY_NUM_6,
+		INPUT_KEY_NUM_7,
+		INPUT_KEY_NUM_8,
+		INPUT_KEY_NUM_9,
+		INPUT_KEY_NUM_0,
+		INPUT_KEY_NUM_LOCK,
+		INPUT_KEY_CNT
+	}
+	#endregion
+
+	#region engine
+
+	#endregion
+
+	[SuppressUnmanagedCodeSecurity]
+	public class engine
+	{
+		public const string NativeDll = "dh_engine.dll";
+
+		#region engine
+		// eng_init
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern result_t eng_init(IntPtr @params);
+		// eng_release
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void eng_release();
+		// eng_update
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void eng_update();
+		// eng_get_framealloc
+		// eng_get_lsralloc
+		// eng_get_dataalloc
+		// eng_send_guimsgs
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void eng_send_guimsgs(byte c, UInt32 vkey);
+		// eng_pause
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void eng_pause();
+		// eng_resume
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void eng_resume();
+		#endregion
+
+		#region app
+		// app_load_config
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern IntPtr app_load_config(
+			[In] [MarshalAs(UnmanagedType.LPStr)] string cfg_jsonfile);
+		// app_defaultconfig
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern IntPtr app_defaultconfig();
+		// app_unload_config
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern IntPtr app_unload_config(IntPtr cfg);
+		// app_query_displaymodes
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern IntPtr app_query_displaymodes();
+		// app_free_displaymodes
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_free_displaymodes(IntPtr dispmodes);
+		// app_init
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern result_t app_init(
+			[In] [MarshalAs(UnmanagedType.LPStr)] string name, [In] IntPtr @params, 
+			IntPtr wnd_override);
+		// app_release
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_release();
+		// app_update
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_update();
+		// app_readejust
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_readjust(
+			UInt32 client_width, UInt32 client_height);
+		// app_set_alwaysactive
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_set_alwaysactive(
+			[MarshalAs(UnmanagedType.Bool)] bool active);
+		// app_set_rendertarget
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_set_rendertarget(
+			[In] [MarshalAs(UnmanagedType.LPStr)] string wnd_name);
+		// app_swapbuffers
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_swapbuffers();
+		// app_clear_rendertarget
+		// app_get_active
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		[return: MarshalAs(UnmanagedType.Bool)]
+		public static extern bool app_get_active();
+		// app_get_wndwidth
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern uint app_get_wndwidth();
+		// app_get_wndheight
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern uint app_get_wndheight();
+		// app_set_createfunc
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern bool app_set_createfunc(pfn_app_create fn);
+		// app_set_destroyfunc
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern bool app_set_destroyfunc(pfn_app_destroy fn);
+		// app_set_resizefunc
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern bool app_set_resizefunc(pfn_app_resize fn);
+		// app_set_activefunc
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern bool app_set_activefunc(pfn_app_active fn);
+		// app_set_keypressfunc
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern bool app_set_keypressfunc(pfn_app_keypress fn);
+		// app_set_updatefunc
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern bool app_set_updatefunc(pfn_app_update fn);
+		// app_get_gfxdriverstr
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern IntPtr app_get_gfxdriverstr();
+		// app_get_gfxinfo
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_get_gfxinfo(IntPtr info);
+		// app_get_gfxver
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern gfx_hwver app_get_gfxver();
+		// app_get_mainctx
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern IntPtr app_get_mainctx();
+		// app_show_window
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_show_window(
+			[In] [MarshalAs(UnmanagedType.LPStr)] string wnd_name);
+		// app_hide_window
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void app_hide_window(
+			[In] [MarshalAs(UnmanagedType.LPStr)] string wnd_name);
+		// app_get_name
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern IntPtr app_get_name();
+		// app_isactive
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		[return: MarshalAs(UnmanagedType.Bool)]
+		public static extern bool app_isactive();
+		// app_resize_window
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern result_t app_resize_window(
+			[In] [MarshalAs(UnmanagedType.LPStr)] string name, 
+			uint width , uint height);
+		#endregion
+
+		#region input
+		// input_update
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern void input_update();
+		// input_get_mouse
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		[return: MarshalAs(UnmanagedType.Bool)]
+		public static extern bool input_get_mouse(
+			ref int x, ref int y, ref uint mouse_keys);
+		// input_get_kbhit
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		[return: MarshalAs(UnmanagedType.Bool)]
+		public static extern bool input_get_kbhit(input_key key);
+		// input_translate_key
+		[DllImport(engine.NativeDll, CallingConvention = CallingConvention.Cdecl)]
+		public static extern input_key input_translate_key(uint vkey);
+		#endregion
+	}
+}