示例#1
0
        /// <summary>
        /// Constructor or added a new light to the scene
        /// </summary>
        /// <param name="type">the light type you wish to have or default of point</param>
        public LightClass(string type = "Point")
        {
            if (type == LightType.Point.ToString())
            {
                light.Type = LightType.Point;
                light.Diffuse = Color.White;
                light.Ambient = Color.White;
                light.Specular = Color.White;
                light.Position = Vector3.Zero;
                light.Range = 100.0f;
            }
            else if (type == LightType.Directional.ToString())
            {
                light.Type = LightType.Directional;
                light.Direction = Vector3.Zero;
                light.Ambient = Color.White;
                light.Diffuse = Color.White;
                light.Specular = Color.White;
                light.Range = 100.0f;
            }

            isLightEnabled = false;
            Type = type.ToString();
            Name = Type;
            Position = Vector3.Zero;
            Direction = Vector3.Zero;
            world = Matrix.Identity;
            //mesh = Mesh.CreateSphere(Engine.GameEngine.LocalDevice.LocalDevice, .1f, 10, 10);
            MeshObject = new MeshClass(MeshType.Sphere);

            material.Diffuse = Color.White;
            material.Ambient = Color.White;

            Engine.GameEngine.LocalDevice.ThisDevice.Material = material;
        }
示例#2
0
        public GameObject(string type = "Cube")
        {
            if (type.ToLower().Equals("triangle"))
            {
                MeshObject = new MeshClass(MeshType.Triangle);
            }
            else
            {
                MeshObject = new MeshClass(MeshType.Cube);
            }

            Name = type;
        }
示例#3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="mousePosition"></param>
        /// <param name="mesh"></param>
        /// <returns></returns>
        public bool RayIntersection(Vector2 mousePosition, MeshClass mesh)
        {
            Vector3 mouse = new Vector3();

            mouse.X = (((2.0f * mousePosition.X) / Engine.GameEngine.LocalDevice.ThisDevice.Viewport.Width) - 1) / projection.M11;
            mouse.Y = -(((2.0f * mousePosition.Y) / Engine.GameEngine.LocalDevice.ThisDevice.Viewport.Height) - 1) / projection.M22;
            mouse.Z = 1.0f;

            Matrix worldView = View * Engine.GameEngine.LocalDevice.ThisDevice.GetTransform(TransformState.World);

            Matrix m = new Matrix();

            m = Matrix.Invert(worldView);

            Vector3 direction = new Vector3();

            direction.X = mouse.X * m.M11 + mouse.Y * m.M21 + mouse.Z * m.M31;
            direction.Y = mouse.X * m.M12 + mouse.Y * m.M22 + mouse.Z * m.M32;
            direction.Z = mouse.X * m.M13 + mouse.Y * m.M23 + mouse.Z * m.M33;

            mouse.X = m.M41;
            mouse.Y = m.M42;
            mouse.Z = m.M43;

            Ray selectionRay = new Ray(mouse, direction);

            if (mesh != null)
            {
                return mesh.ObjectMesh.Intersects(selectionRay);
            }

            return false;
        }
示例#4
0
 /// <summary>
 /// Constructor for building a .x object
 /// </summary>
 /// <param name="fileName">The file name of the object</param>
 /// <param name="path">The path of the object</param>
 public GameObject(string fileName = "", string path = "")
 {
     MeshObject = new MeshClass(path, fileName);
     FileName = fileName;
     FilePath = path;
 }