Esempio n. 1
0
        public override void Draw(OpenGL gl)
        {
            //	Create the sphere if need be.
            if (sphere == null)
            {
                sphere = new Quadrics.Sphere();
            }

            //	Set the properties.
            sphere.Translate = position;

            sphere.Draw(gl);
        }
Esempio n. 2
0
        /// <summary>
        /// This function creates the internal scene and graphics object.
        /// </summary>
        /// <returns></returns>
        protected bool Create()
        {
            //	Create a scene from the offscreen graphics.
            previewScene.Initialise(previewWidth, previewHeight, SceneType.HighQuality);

            //	Create a sphere.
            Quadrics.Sphere sphere = new Quadrics.Sphere();
            sphere.TextureCoords = true;

            //	Set it as the preview object. Do this via the property, because it
            //	automatically updates the scene.
            PreviewObject = sphere;

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Draws the specified gl.
        /// </summary>
        /// <param name="gl">The gl.</param>
        public override void Draw(OpenGL gl)
        {
            //	Create the sphere if need be.
            if (sphere == null)
            {
                sphere = new Quadrics.Sphere();
            }

            //	Set the properties.
            sphere.Transformation.TranslateX = position.X;
            sphere.Transformation.TranslateY = position.Y;
            sphere.Transformation.TranslateZ = position.Z;

            sphere.Render(gl, Core.RenderMode.Design);
        }
Esempio n. 4
0
        public override SceneObject OnMouseDown(OpenGL gl, MouseEventArgs e)
        {
            base.OnMouseDown(gl, e);

            //	When the user presses the mouse down, we create the centre of the
            //	sphere.

            buildingObject = new Quadrics.Sphere();

            Vertex v = PointToVertexOnPlane(gl, Plane.xz,
                                            clicks[0].OpenGLx, clicks[0].OpenGLy);

            BuildingGrid grid = new BuildingGrid();

            grid.Clamp(v);

            if (v != null)
            {
                clicks[0].vertex         = v;
                buildingObject.Translate = v;
            }

            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// Casts a real time 3D shadow.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="lights">The lights.</param>
        private void CastShadow(OpenGL gl)
        {
            //    Set the connectivity, (calculate the neighbours of each face).
            SetConnectivity();

            //  Get the lights in the scene.
            var lights = TraverseToRootElement().Traverse <Light>(l => l.IsEnabled && l.On && l.CastShadow);

            //  Get some useful references.
            var faces = ParentPolygon.Faces;

            //    Go through every light in the scene.
            foreach (var light in lights)
            {
                //    Every face will have a visibility setting.
                bool[] facesVisible = new bool[faces.Count];

                //    Get the light position relative to the polygon.
                Vertex lightPos = light.Position;
                lightPos = lightPos - ParentPolygon.Transformation.TranslationVertex;

                //    Go through every face, finding out whether it's visible to the light.
                for (int nFace = 0; nFace < faces.Count; nFace++)
                {
                    //    Get a reference to the face.
                    Face face = faces[nFace];

                    //    Is this face facing the light?
                    float[] planeEquation = face.GetPlaneEquation(ParentPolygon);
                    float   side          = planeEquation[0] * lightPos.X +
                                            planeEquation[1] * lightPos.Y +
                                            planeEquation[2] * lightPos.Z + planeEquation[3];
                    facesVisible[nFace] = (side > 0) ? true : false;
                }

                //    Save all the attributes.
                gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);

                //    Turn off lighting.
                gl.Disable(OpenGL.GL_LIGHTING);

                //    Turn off writing to the depth mask.
                gl.DepthMask(0);
                gl.DepthFunc(OpenGL.GL_LEQUAL);

                //    Turn on stencil buffer testing.
                gl.Enable(OpenGL.GL_STENCIL_TEST);

                //    Translate our shadow volumes.
                ParentPolygon.PushObjectSpace(gl);

                //    Don't draw to the color buffer.
                gl.ColorMask(0, 0, 0, 0);
                gl.StencilFunc(OpenGL.GL_ALWAYS, 1, 0xFFFFFFFF);

                gl.Enable(OpenGL.GL_CULL_FACE);

                //    First Pass. Increase Stencil Value In The Shadow
                gl.FrontFace(OpenGL.GL_CCW);
                gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_INCR);
                DoShadowPass(gl, lightPos, facesVisible);

                //    Second Pass. Decrease Stencil Value In The Shadow
                gl.FrontFace(OpenGL.GL_CW);
                gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_DECR);
                DoShadowPass(gl, lightPos, facesVisible);

                gl.FrontFace(OpenGL.GL_CCW);

                ParentPolygon.PopObjectSpace(gl);

                //    Enable writing to the color buffer.
                gl.ColorMask(1, 1, 1, 1);

                // Draw A Shadowing Rectangle Covering The Entire Screen
                gl.Color(light.ShadowColor);
                gl.Enable(OpenGL.GL_BLEND);
                gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
                gl.StencilFunc(OpenGL.GL_NOTEQUAL, 0, 0xFFFFFFF);
                gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_KEEP);

                Quadrics.Sphere shadow = new Quadrics.Sphere();
                shadow.Transformation.ScaleX = shadowSize;
                shadow.Transformation.ScaleY = shadowSize;
                shadow.Transformation.ScaleZ = shadowSize;
                shadow.Render(gl, RenderMode.Design);

                gl.PopAttrib();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// This function creates the internal scene and graphics object.
        /// </summary>
        /// <returns></returns>
        protected bool Create()
        {
            //	Create a scene from the offscreen graphics.
            previewScene.Initialise(previewWidth, previewHeight, SceneType.HighQuality);

            //	Create a sphere.
            Quadrics.Sphere sphere = new Quadrics.Sphere();
            sphere.TextureCoords = true;

            //	Set it as the preview object. Do this via the property, because it
            //	automatically updates the scene.
            PreviewObject = sphere;

            return true;
        }
Esempio n. 7
0
        /// <summary>
        /// Casts a real time 3D shadow.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="lights">The lights.</param>
		private void CastShadow(OpenGL gl)
		{
			//	Set the connectivity, (calculate the neighbours of each face).
			SetConnectivity();

            //  Get the lights in the scene.
            var lights = TraverseToRootElement().Traverse<Light>(l => l.IsEnabled && l.On && l.CastShadow);

            //  Get some useful references.
            var faces = ParentPolygon.Faces;

			//	Go through every light in the scene.
			foreach(var light in lights)
			{
				//	Every face will have a visibility setting.
				bool[] facesVisible = new bool[faces.Count];

				//	Get the light position relative to the polygon.
				Vertex lightPos = light.Position;
				lightPos = lightPos - ParentPolygon.Transformation.TranslationVertex;

				//	Go through every face, finding out whether it's visible to the light.
				for(int nFace = 0; nFace < faces.Count; nFace++)
				{
					//	Get a reference to the face.
					Face face = faces[nFace];

					//	Is this face facing the light?
					float[] planeEquation = face.GetPlaneEquation(ParentPolygon);
					float side = planeEquation[0] * lightPos.X + 
						planeEquation[1] * lightPos.Y + 
						planeEquation[2] * lightPos.Z + planeEquation[3];
					facesVisible[nFace] = (side > 0) ? true : false;
				}

				//	Save all the attributes.
                gl.PushAttrib(OpenGL.GL_ALL_ATTRIB_BITS);
			
				//	Turn off lighting.
                gl.Disable(OpenGL.GL_LIGHTING);

				//	Turn off writing to the depth mask.
				gl.DepthMask(0);
                gl.DepthFunc(OpenGL.GL_LEQUAL);

				//	Turn on stencil buffer testing.
                gl.Enable(OpenGL.GL_STENCIL_TEST);

				//	Translate our shadow volumes.
				ParentPolygon.PushObjectSpace(gl);

				//	Don't draw to the color buffer.
				gl.ColorMask(0, 0, 0, 0);
                gl.StencilFunc(OpenGL.GL_ALWAYS, 1, 0xFFFFFFFF);

                gl.Enable(OpenGL.GL_CULL_FACE);
			
				//	First Pass. Increase Stencil Value In The Shadow
                gl.FrontFace(OpenGL.GL_CCW);
                gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_INCR);
				DoShadowPass(gl, lightPos, facesVisible);

				//	Second Pass. Decrease Stencil Value In The Shadow
                gl.FrontFace(OpenGL.GL_CW);
                gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_DECR);
				DoShadowPass(gl, lightPos, facesVisible);

                gl.FrontFace(OpenGL.GL_CCW);

				ParentPolygon.PopObjectSpace(gl);
			
				//	Enable writing to the color buffer.
				gl.ColorMask(1, 1, 1, 1); 
            
				// Draw A Shadowing Rectangle Covering The Entire Screen
				gl.Color(light.ShadowColor);
                gl.Enable(OpenGL.GL_BLEND);
                gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA);
                gl.StencilFunc(OpenGL.GL_NOTEQUAL, 0, 0xFFFFFFF);
                gl.StencilOp(OpenGL.GL_KEEP, OpenGL.GL_KEEP, OpenGL.GL_KEEP);
				
				Quadrics.Sphere shadow = new Quadrics.Sphere();
                shadow.Transformation.ScaleX = shadowSize;
                shadow.Transformation.ScaleY = shadowSize;
                shadow.Transformation.ScaleZ = shadowSize;
				shadow.Render(gl, RenderMode.Design);
	
				gl.PopAttrib();
			}
		}
Esempio n. 8
0
        public override void Draw(OpenGL gl)
        {
            //	Create the sphere if need be.
            if(sphere == null)
                sphere = new Quadrics.Sphere();

            //	Set the properties.
            sphere.Translate = position;

            sphere.Draw(gl);
        }
Esempio n. 9
0
        /// <summary>
        /// Draws the specified gl.
        /// </summary>
        /// <param name="gl">The gl.</param>
        public override void Draw(OpenGL gl)
        {
            //	Create the sphere if need be.
            if (sphere == null)
                sphere = new Quadrics.Sphere();

            //	Set the properties.
            sphere.Transformation.TranslateX = position.X;
            sphere.Transformation.TranslateY = position.Y;
            sphere.Transformation.TranslateZ = position.Z;

            sphere.Render(gl, Core.RenderMode.Design);
        }