Exemple #1
0
 private void 球体ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     //SharpGL.SceneGraph.Quadrics.Sphere 球 = new SharpGL.SceneGraph.Quadrics.Sphere();
     SharpGL.SceneGraph.Quadrics.Sphere 球 = new SharpGL.SceneGraph.Quadrics.Sphere()
     {
         Name = "球"
     };
     球.Material      = new Material();
     球.TextureCoords = true;//允许纹理贴图
     球.AddEffect(objectArcBallEffect);
     sceneControl1.Scene.SceneContainer.AddChild(球);
     treeView1.Nodes.Clear();
     AddElementToTree(sceneControl1.Scene.SceneContainer, treeView1.Nodes);
 }
Exemple #2
0
        protected override void DrawPoint(OpenGL gl)
        {
            gl.Translate(0.0, 0.0, SizeX);

            SharpGL.SceneGraph.Quadrics.Sphere sphere = new SharpGL.SceneGraph.Quadrics.Sphere();
            sphere.Radius           = SizeX;
            sphere.Slices           = Slices;
            sphere.Stacks           = Stacks;
            sphere.QuadricDrawStyle = DrawStyle.Point;

            sphere.CreateInContext(gl);
            sphere.PushObjectSpace(gl);
            sphere.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            sphere.PopObjectSpace(gl);
            sphere.DestroyInContext(gl);
        }
Exemple #3
0
        public void draw_sphere(OpenGL gl, double agent)
        {
            Sphere sphere = new SharpGL.SceneGraph.Quadrics.Sphere();
            sphere.Radius = agent;
            GLColor glClr = new GLColor(0.0f, 0.0f, 1.0f, 0.5f);
            OpenGLAttributesEffect glEffect = new OpenGLAttributesEffect();
            glEffect.ColorBufferAttributes.ColorModeClearColor = glClr;
            glEffect.ColorBufferAttributes.ColorModeWriteMask = glClr;

            sphere.NormalGeneration = SharpGL.SceneGraph.Quadrics.Normals.Smooth;
            sphere.NormalOrientation = SharpGL.SceneGraph.Quadrics.Orientation.Outside;
            sphere.QuadricDrawStyle = SharpGL.SceneGraph.Quadrics.DrawStyle.Fill;
            sphere.AddEffect(glEffect);

            sphere.CreateInContext(gl);

            sphere.Slices = 100;
            sphere.Stacks = 100;
            sphere.TextureCoords = false;

            sphere.PushObjectSpace(gl);
            sphere.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
            sphere.PopObjectSpace(gl);
        }
Exemple #4
0
        /// <summary>
        /// Casts a real time 3D shadow.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="light">The source light.</param>
        public void CastShadow(OpenGL gl, Collections.LightCollection lights)
        {
            //	Set the connectivity, (calculate the neighbours of each face).
            SetConnectivity();

            //	Go through every light in the scene.
            foreach (Lights.Light light in lights)
            {
                //	Skip null lights.
                if (light == null)
                {
                    continue;
                }

                //	Skip turned off lights and non shadow lights.
                if (light.On == false || light.CastShadow == false)
                {
                    continue;
                }

                //	Every face will have a visibility setting.
                bool[] facesVisible = new bool[faces.Count];

                //	Get the light position relative to the polygon.
                Vertex lightPos = light.Translate;
                lightPos = lightPos - Translate;

                //	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(this);
                    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.ALL_ATTRIB_BITS);

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

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

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

                //	Translate our shadow volumes.
                gl.PushMatrix();
                Transform(gl);

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

                gl.Enable(OpenGL.CULL_FACE);

                //	First Pass. Increase Stencil Value In The Shadow
                gl.FrontFace(OpenGL.CCW);
                gl.StencilOp(OpenGL.KEEP, OpenGL.KEEP, OpenGL.INCR);
                DoShadowPass(gl, lightPos, facesVisible);

                //	Second Pass. Decrease Stencil Value In The Shadow
                gl.FrontFace(OpenGL.CW);
                gl.StencilOp(OpenGL.KEEP, OpenGL.KEEP, OpenGL.DECR);
                DoShadowPass(gl, lightPos, facesVisible);

                gl.FrontFace(OpenGL.CCW);

                gl.PopMatrix();

                //	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.BLEND);
                gl.BlendFunc(OpenGL.SRC_ALPHA, OpenGL.ONE_MINUS_SRC_ALPHA);
                gl.StencilFunc(OpenGL.NOTEQUAL, 0, 0xFFFFFFF);
                gl.StencilOp(OpenGL.KEEP, OpenGL.KEEP, OpenGL.KEEP);

                Quadrics.Sphere shadow = new Quadrics.Sphere();
                shadow.Scale.Set(shadowSize, shadowSize, shadowSize);
                shadow.Draw(gl);

                gl.PopAttrib();
            }
        }
Exemple #5
0
        /// <summary>
        /// Casts a real time 3D shadow.
        /// </summary>
        /// <param name="gl">The OpenGL object.</param>
        /// <param name="light">The source light.</param>
        public void CastShadow(OpenGL gl, Collections.LightCollection lights)
        {
            //	Set the connectivity, (calculate the neighbours of each face).
            SetConnectivity();

            //	Go through every light in the scene.
            foreach(Lights.Light light in lights)
            {
                //	Skip null lights.
                if(light == null)
                    continue;

                //	Skip turned off lights and non shadow lights.
                if(light.On == false || light.CastShadow == false)
                    continue;

                //	Every face will have a visibility setting.
                bool[] facesVisible = new bool[faces.Count];

                //	Get the light position relative to the polygon.
                Vertex lightPos = light.Translate;
                lightPos = lightPos - Translate;

                //	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(this);
                    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.ALL_ATTRIB_BITS);

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

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

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

                //	Translate our shadow volumes.
                gl.PushMatrix();
                Transform(gl);

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

                gl.Enable(OpenGL.CULL_FACE);

                //	First Pass. Increase Stencil Value In The Shadow
                gl.FrontFace(OpenGL.CCW);
                gl.StencilOp(OpenGL.KEEP, OpenGL.KEEP, OpenGL.INCR);
                DoShadowPass(gl, lightPos, facesVisible);

                //	Second Pass. Decrease Stencil Value In The Shadow
                gl.FrontFace(OpenGL.CW);
                gl.StencilOp(OpenGL.KEEP, OpenGL.KEEP, OpenGL.DECR);
                DoShadowPass(gl, lightPos, facesVisible);

                gl.FrontFace(OpenGL.CCW);

                gl.PopMatrix();

                //	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.BLEND);
                gl.BlendFunc(OpenGL.SRC_ALPHA, OpenGL.ONE_MINUS_SRC_ALPHA);
                gl.StencilFunc(OpenGL.NOTEQUAL, 0, 0xFFFFFFF);
                gl.StencilOp(OpenGL.KEEP, OpenGL.KEEP, OpenGL.KEEP);

                Quadrics.Sphere shadow = new Quadrics.Sphere();
                shadow.Scale.Set(shadowSize, shadowSize, shadowSize);
                shadow.Draw(gl);

                gl.PopAttrib();
            }
        }
Exemple #6
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;
        }
 internal static bool Equal(Sphere x, Sphere y)
 {
     if (x == null || y == null)
         return false;
     return TransformationEqual(x.Transformation, y.Transformation);
 }