Exemple #1
0
        private void InitLight(SceneElement parent)
        {
            Light light1 = new Light()
            {
                Name     = "Light 1",
                On       = true,
                Position = new Vertex(-9, -9, 11),
                GLCode   = OpenGL.GL_LIGHT0
            };
            Light light2 = new Light()
            {
                Name     = "Light 2",
                On       = true,
                Position = new Vertex(9, -9, 11),
                GLCode   = OpenGL.GL_LIGHT1
            };
            Light light3 = new Light()
            {
                Name     = "Light 3",
                On       = true,
                Position = new Vertex(0, 15, 15),
                GLCode   = OpenGL.GL_LIGHT2
            };
            var folder = new SharpGL.SceneGraph.Primitives.Folder()
            {
                Name = "光照"
            };

            parent.AddChild(folder);
            folder.AddChild(light1);
            folder.AddChild(light2);
            folder.AddChild(light3);
        }
Exemple #2
0
        /// <summary>
        /// 设置轴线
        /// </summary>
        public void Axiesline(float interval)
        {
            ///x轴
            ///y轴
            var folder = new SharpGL.SceneGraph.Primitives.Folder()
            {
                Name = "Axis"
            };

            Material red = new Material();

            red.Emission = Color.Red;
            red.Diffuse  = Color.Red;

            Cylinder x1 = new Cylinder()
            {
                Name = "X1"
            };

            x1.BaseRadius             = 0.05;
            x1.TopRadius              = 0.05;
            x1.Height                 = 1.5;
            x1.Transformation.RotateY = 90f;
            x1.Material               = red;
            folder.AddChild(x1);


            Cylinder x2 = new Cylinder()
            {
                Name = "X2"
            };

            x2.BaseRadius = 0.1;
            x2.TopRadius  = 0;
            x2.Height     = 0.2;
            x2.Transformation.TranslateX = 1.5f;
            x2.Transformation.RotateY    = 90f;
            x2.Material = red;
            folder.AddChild(x2);

            // Y轴
            Material green = new Material();

            green.Emission = Color.Green;
            green.Diffuse  = Color.Green;

            Cylinder y1 = new Cylinder()
            {
                Name = "Y1"
            };

            y1.BaseRadius             = 0.05;
            y1.TopRadius              = 0.05;
            y1.Height                 = 1.5;
            y1.Transformation.RotateX = -90f;
            y1.Material               = green;
            folder.AddChild(y1);

            Cylinder y2 = new Cylinder()
            {
                Name = "Y2"
            };

            y2.BaseRadius = 0.1;
            y2.TopRadius  = 0;
            y2.Height     = 0.2;
            y2.Transformation.TranslateY = 1.5f;
            y2.Transformation.RotateX    = -90f;
            y2.Material = green;
            folder.AddChild(y2);

            // Z轴
            Material blue = new Material();

            blue.Emission = Color.Blue;
            blue.Diffuse  = Color.Blue;

            Cylinder z1 = new Cylinder()
            {
                Name = "Z1"
            };

            z1.BaseRadius = 0.05;
            z1.TopRadius  = 0.05;
            z1.Height     = 1.5;
            z1.Material   = blue;
            folder.AddChild(z1);

            Cylinder z2 = new Cylinder()
            {
                Name = "Z2"
            };

            z2.BaseRadius = 0.1;
            z2.TopRadius  = 0;
            z2.Height     = 0.2;
            z2.Transformation.TranslateZ = 1.5f;
            z2.Material = blue;
            folder.AddChild(z2);
        }
Exemple #3
0
        /// <summary>
        /// Initialises a modeling scene. A modeling scene has:
        ///  - A 'Look At' camera targetting the centre of the scene
        ///  - Three gentle omnidirectional lights
        ///  - A design time grid and axis.
        /// </summary>
        /// <param name="scene">The scene.</param>
        public static void InitialiseModelingScene(Scene scene)
        {
            //  Create the 'Look At' camera
            var lookAtCamera = new LookAtCamera()
            {
                Position = new Vertex(-10f, -10f, 10f),
                Target = new Vertex(0f, 0f, 0f),
                UpVector = new Vertex(0f, 0f, 1f)
            };

            //  Set the look at camera as the current camera.
            scene.CurrentCamera = lookAtCamera;

            //  Add some design-time primitives.
            var folder = new Folder() { Name = "Design Primitives" };
            folder.AddChild(new Grid());
            folder.AddChild(new Axies());
            scene.SceneContainer.AddChild(folder);

            //  Create some lights.
            Light light1 = new Light()
            {
                Name="Light 1",
                On = true,
                Position = new Vertex(-9, -9, 11),
                GLCode = OpenGL.GL_LIGHT0
            };
            Light light2 = new Light()
            {
                Name = "Light 2",
                On = true,
                Position = new Vertex(9, -9, 11),
                GLCode = OpenGL.GL_LIGHT1
            };
            Light light3 = new Light()
            {
                Name = "Light 3",
                On = true,
                Position = new Vertex(0, 15, 15),
                GLCode = OpenGL.GL_LIGHT2
            };
            //  Add the lights.
            folder = new Folder() { Name = "Lights" };
            folder.AddChild(light1);
            folder.AddChild(light2);
            folder.AddChild(light3);
            scene.SceneContainer.AddChild(folder);

            //  Create a set of scene attributes.
            OpenGLAttributesEffect sceneAttributes = new OpenGLAttributesEffect()
            {
                Name = "Scene Attributes"
            };

            //  Specify the scene attributes.
            sceneAttributes.EnableAttributes.EnableDepthTest = true;
            sceneAttributes.EnableAttributes.EnableNormalize = true;
            sceneAttributes.EnableAttributes.EnableLighting = true;
            sceneAttributes.EnableAttributes.EnableTexture2D = true;
            sceneAttributes.EnableAttributes.EnableBlend = true;
            sceneAttributes.ColorBufferAttributes.BlendingSourceFactor = BlendingSourceFactor.SourceAlpha;
            sceneAttributes.ColorBufferAttributes.BlendingDestinationFactor = BlendingDestinationFactor.OneMinusSourceAlpha;
            sceneAttributes.LightingAttributes.TwoSided = true;
            scene.SceneContainer.AddEffect(sceneAttributes);
        }