Click here to Skip to main content
15,891,423 members
Articles / Multimedia / DirectX

Endogine sprite engine

Rate me:
Please Sign up or sign in to vote.
4.84/5 (53 votes)
17 Jul 200615 min read 716.8K   22.1K   216  
Sprite engine for D3D and GDI+ (with several game examples).
using System;

namespace Endogine
{
	/// <summary>
	/// Summary description for Vector3.
	/// </summary>
	public class Vector3
	{
		public float X, Y, Z;
		public Vector3(float x, float y, float z)
		{
			this.X = x;
			this.Y = y;
			this.Z = z;
		}
		public Vector3()
		{
		}

        public float this[int position]
        {
            get
            {
                switch (position)
                {
                    case 0:
                        return this.X;
                    case 1:
                        return this.Y;
                    case 2:
                        return this.Z;
                    default:
                        throw new Exception("Out of bounds in Vector3: " + position);
                }
            }
            set
            {
                switch (position)
                {
                    case 0:
                        this.X = value;
                        break;
                    case 1:
                        this.Y = value;
                        break;
                    case 2:
                        this.Z = value;
                        break;
                    default:
                        throw new Exception("Out of bounds in Vector3: " + position);
                }
            }
        }

    	public static Vector3 operator -(Vector3 v1, Vector3 v2)
		{
			return new Vector3(v1.X-v2.X, v1.Y-v2.Y, v1.Z-v2.Z);
		}
		public static Vector3 operator +(Vector3 v1, Vector3 v2)
		{
			return new Vector3(v1.X+v2.X, v1.Y+v2.Y, v1.Z+v2.Z);
		}
		public static Vector3 operator *(Vector3 v1, Vector3 v2)
		{
			return new Vector3(v1.X*v2.X, v1.Y*v2.Y, v1.Z*v2.Z);
		}
		public static Vector3 operator *(Vector3 v1, float f)
		{
			return new Vector3(v1.X*f, v1.Y*f, v1.Z*f);
		}
		public static Vector3 operator /(Vector3 v1, Vector3 v2)
		{
			return new Vector3(v1.X/v2.X, v1.Y/v2.Y, v1.Z/v2.Z);
		}
		public static Vector3 operator /(Vector3 v1, float f)
		{
			return new Vector3(v1.X/f, v1.Y/f, v1.Z/f);
		}

        public static Vector3 Cross(Vector3 v1, Vector3 v2)
        {
            return new Vector3(
                v1.Y * v2.Z - v2.Y * v1.Z,
                v1.Z * v2.X - v2.Z * v1.X,
                v1.X * v2.Y - v2.X * v1.Y);
        }

        public void Project(object viewport, Matrix4 projection, Matrix4 view, Matrix4 world)
        {
        }
        public void Unproject(object viewport, Matrix4 projection, Matrix4 view, Matrix4 world)
        {
        }

        public float Length
        {
            get { return (float)Math.Sqrt(X * X + Y * Y + Z * Z); }
        }
        public float LengthSquared
        {
            get { return (X * X + Y * Y + Z * Z); }
        }

        public void Normalize()
        {
            float len = this.Length;
            this.X /= len;
            this.Y /= len;
            this.Z /= len;
        }
        public float Dot(Vector3 v1)
        {
            return this.X*v1.X + this.Y*v1.Y + this.Z*v1.Z;
        }
        public Vector3 Cross(Vector3 v1)
        {
            return Vector3.Cross(this, v1);
        }

        public override string ToString()
        {
            return this.X.ToString() + ";" + this.Y + ";" + this.Z;
        }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions