Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormSceneSample"/> class.
        /// </summary>
        public FormSceneSample()
        {
            InitializeComponent();

            sceneControl1.MouseDown += new MouseEventHandler(FormSceneSample_MouseDown);
            sceneControl1.MouseMove += new MouseEventHandler(FormSceneSample_MouseMove);
            sceneControl1.MouseUp += new MouseEventHandler(sceneControl1_MouseUp);

            //  Add some design-time primitives.
            sceneControl1.Scene.SceneContainer.AddChild(new
                SharpGL.SceneGraph.Primitives.Grid());
            sceneControl1.Scene.SceneContainer.AddChild(new 
                SharpGL.SceneGraph.Primitives.Axies());

            //  Create a light.
            Light light = new Light()
            {
                On = true,
                Position = new Vertex(3, 10, 3),
                GLCode = OpenGL.GL_LIGHT0
            };

            //  Add the light.
            sceneControl1.Scene.SceneContainer.AddChild(light);

            //  Create a sphere.
            Cube cube = new Cube();
            cube.AddEffect(arcBallEffect);
            
            //  Add it.
            sceneControl1.Scene.SceneContainer.AddChild(cube);

            //  Add the root element to the tree.
            AddElementToTree(sceneControl1.Scene.SceneContainer, treeView1.Nodes);
        }
Beispiel #2
0
        /// <summary>
        /// Calculates the lighting.
        /// </summary>
        /// <param name="light">The light.</param>
        /// <param name="angle">The angle.</param>
        /// <returns></returns>
		public GLColor CalculateLighting(Light light, float angle)
		{
			double angleRadians = angle * 3.14159 / 360.0;
			GLColor reflected = ambient * light.Ambient;
			reflected += diffuse * light.Diffuse * (float)Math.Cos(angleRadians);

			return reflected;
		}
Beispiel #3
0
 public Light()
     : base()
 {
     _light = new SharpGL.SceneGraph.Lighting.Light();
     SetTexture(ResourceManager.GetTexture("light"));
     SetStaticObject(true);
     EnableAirResistance(false);
     EnablePhysics(false);
     Z_Index = 100;
 }
Beispiel #4
0
 public Light()
     : base()
 {
     _light = new SharpGL.SceneGraph.Lighting.Light();
     SetTexture(ResourceManager.GetTexture("light"));
     SetStaticObject(true);
     EnableAirResistance(false);
     EnablePhysics(false);
     Z_Index = 100;
 }
Beispiel #5
0
 public Light(int r, int g, int b, int parentId)
     : base()
 {
     _light = new SharpGL.SceneGraph.Lighting.Light();
     _light.On = true;
     Color col = Color.FromArgb(255,r, g, b);
     _light.Ambient = col;
     _light.Diffuse = col;
     _light.Specular = col;
     SetTexture(ResourceManager.GetTexture("light"));
     SetStaticObject(true);
     EnableAirResistance(false);
     EnablePhysics(false);
     //_r = r;
     //_g = g;
     //_b = b;
     _parentId = parentId;
 }
Beispiel #6
0
        public Light(int r, int g, int b, int parentId)
            : base()
        {
            _light    = new SharpGL.SceneGraph.Lighting.Light();
            _light.On = true;
            Color col = Color.FromArgb(255, r, g, b);

            _light.Ambient  = col;
            _light.Diffuse  = col;
            _light.Specular = col;
            SetTexture(ResourceManager.GetTexture("light"));
            SetStaticObject(true);
            EnableAirResistance(false);
            EnablePhysics(false);
            //_r = r;
            //_g = g;
            //_b = b;
            _parentId = parentId;
        }
Beispiel #7
0
        public FormMain()
        {
            InitializeComponent();

            //  Create a light.
            Light light = new Light()
            {
                On = true,
                Position = new Vertex(30, 100, 30),
                GLCode = OpenGL.GL_LIGHT0
            };

            Cube cubeSmall = new Cube()
            {
                Position = new Vertex(0, 0, 1),
                Scale = new Vertex(1, 1, 1)
            };

            Cube cubeBig = new Cube
            {
                Position = new Vertex(-3, -3, 2),
                Scale = new Vertex(2, 2, 2)
            };

            //  Add some design-time primitives.
            sceneControl1.Scene.SceneContainer.AddChild(new Grid());
            sceneControl1.Scene.SceneContainer.AddChild(new Axies());
            //sceneControl1.Scene.CurrentCamera.Project();

            //  Add it.
            //  Add the light.
            sceneControl1.Scene.SceneContainer.AddChild(cubeSmall);
            sceneControl1.Scene.SceneContainer.AddChild(cubeBig);
            sceneControl1.Scene.SceneContainer.AddChild(light);

            Camera.Position = new Vertex(10, 10, 10);
            Camera.Target = new Vertex(0, 0, 0);
        }
Beispiel #8
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);
        }
Beispiel #9
0
 public Light(uint GLCode)
 {
     light = new Lighting.Light();
     light.On = true;
     light.GLCode = GLCode;
 }
Beispiel #10
0
 public Light(uint GLCode)
 {
     light        = new Lighting.Light();
     light.On     = true;
     light.GLCode = GLCode;
 }
 internal static bool Equal(Light x, Light y)
 {
     if (x == null || y == null)
         return false;
     return x.Position.Equals(y.Position) && x.CastShadow.Equals(y.CastShadow) && x.On.Equals(y.On)
          && ColorsEqual(x.Ambient, y.Ambient) && ColorsEqual(x.Diffuse, y.Diffuse) 
          && ColorsEqual(x.Specular, y.Specular) && GLColorsEqual(x.ShadowColor, y.ShadowColor)
          && x.GLCode.Equals(y.GLCode);
 }