예제 #1
0
        public override void Draw(SceneGraph.Cameras.Camera camera = null)
        {
            var gl = OpenGL;

            if (gl == null)
            {
                return;
            }

            //  TODO: we must decide what to do about drawing - are
            //  cameras completely outside of the responsibility of the scene?
            //  If no camera has been provided, use the current one.
            ScientificCamera currentCamera = this.CurrentCamera;

            currentCamera.Project(gl, ECameraType.Ortho);

            //gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);

            //  Render the root element, this will then render the whole
            //  of the scene tree.
            MyRenderElement(SceneContainer, gl, RenderMode.Design);

            //  TODO: Adding this code here re-enables textures- it should work without it but it
            //  doesn't, look into this.
            //gl.BindTexture(OpenGL.GL_TEXTURE_2D, 0);
            //gl.Enable(OpenGL.GL_TEXTURE_2D);

            gl.Flush();
        }
예제 #2
0
        void ScientificVisual3DControl_MouseWheel(object sender, MouseEventArgs e)
        {
            ScientificCamera camera = this.Scene.CurrentCamera;

            //if (camera == null) { return; }

            camera.Scale(e.Delta);

            ManualRender(this);
        }
        internal static void SetSceneCameraToUICamera(ScientificVisual3DControl scientificVisual3DControl)
        {
            ScientificCamera camera = scientificVisual3DControl.Scene.CurrentCamera;

            if (camera == null)
            {
                throw new Exception("this.Scene.CurrentCamera cannot be null.");
            }

            scientificVisual3DControl.UIScene.CurrentCamera = camera;
            scientificVisual3DControl.uiAxis.Camera         = camera;
            scientificVisual3DControl.CameraRotation.Camera = camera;
        }
예제 #4
0
        private void FormPointSpriteStringElement_Load(object sender, EventArgs e)
        {
            this.camera  = new ScientificCamera(CameraTypes.Perspecitive);
            this.rotator = new SatelliteRotation(this.camera);

            //this.fontElement = new PointSpriteStringElement(this.camera, "A", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            //this.fontElement = new PointSpriteStringElement(this.camera, "AA", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            //this.fontElement = new PointSpriteStringElement(this.camera, "AAA", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            //this.fontElement = new PointSpriteStringElement(this.camera, "AAAA", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            //this.fontElement = new PointSpriteStringElement(this.camera, "AAAAA", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            //this.fontElement = new PointSpriteStringElement(this.camera, "AAAAAA", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            //this.fontElement = new PointSpriteStringElement(this.camera, "AAAAAAA", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            //this.fontElement = new PointSpriteStringElement(this.camera, "AAAAAAAA", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            this.fontElement = new PointSpriteStringElement(
                this.camera, "AAAAAAAAAAAAAAAA", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            //this.fontElement = new PointSpriteStringElement(this.camera, "hi text!", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            //this.fontElement = new PointSpriteStringElement(this.camera, "qwertyuiop[]", new SharpGL.SceneGraph.Vertex(0, 0, 0));
            this.fontElement.Initialize(this.openGLControl.OpenGL);
        }
 public void Scale(int delta)
 {
     ScientificCamera camera = this;
     //if (camera.CameraType == CameraTypes.Perspecitive)
     {
         var target2Position = camera.Position - camera.Target;
         if (target2Position.Magnitude() < 0.01)
         {
             target2Position.Normalize();
             target2Position.X *= 0.01f;
             target2Position.Y *= 0.01f;
             target2Position.Z *= 0.01f;
         }
         var scaledTarget2Position = target2Position * (1 - delta * 0.001f);
         camera.Position = camera.Target + scaledTarget2Position;
         double lengthDiff = scaledTarget2Position.Magnitude() - target2Position.Magnitude();
         // Increase ortho camera's Near/Far property in case the camera's position changes too much.
         IPerspectiveCamera perspectiveCamera = camera;
         perspectiveCamera.Far += lengthDiff;
         //perspectiveCamera.Near += lengthDiff;
         IOrthoCamera orthoCamera = camera;
         orthoCamera.Far  += lengthDiff;
         orthoCamera.Near += lengthDiff;
     }
     //else if (camera.CameraType == CameraTypes.Ortho)
     {
         IOrthoCamera orthoCamera = camera;
         double       distanceX   = orthoCamera.Right - orthoCamera.Left;
         double       distanceY   = orthoCamera.Top - orthoCamera.Bottom;
         double       centerX     = (orthoCamera.Left + orthoCamera.Right) / 2;
         double       centerY     = (orthoCamera.Bottom + orthoCamera.Top) / 2;
         orthoCamera.Left   = centerX - distanceX * (1 - delta * 0.001) / 2;
         orthoCamera.Right  = centerX + distanceX * (1 - delta * 0.001) / 2;
         orthoCamera.Bottom = centerY - distanceY * (1 - delta * 0.001) / 2;
         orthoCamera.Top    = centerX + distanceY * (1 - delta * 0.001) / 2;
     }
 }
예제 #6
0
        /// <summary>
        /// Update camera when resized, model container's bounding box updated, etc.
        /// </summary>
        public void UpdateCamera()
        {
            ScientificCamera camera = this.Scene.CurrentCamera;

            //if (camera.CameraType == CameraTypes.Perspecitive)
            {
                IPerspectiveViewCamera perspecitive = camera;
                perspecitive.AdjustCamera(this.modelContainer.BoundingBox, this.OpenGL);
            }
            //else if (camera.CameraType == CameraTypes.Ortho)
            {
                IOrthoViewCamera orthoCamera = camera;
                orthoCamera.AdjustCamera(this.modelContainer.BoundingBox, this.OpenGL);
            }
            //else
            {
                //throw new NotImplementedException();
            }

            //camera.Scale(-camera.scaleFactor);
            //// force CameraRotation to udpate.
            //this.CameraRotation.Camera = this.Scene.CurrentCamera;
            ManualRender(this);
        }
예제 #7
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(ColorCodedPickingScene scene)
        {
            //  Create the 'Look At' camera
            var lookAtCamera = new ScientificCamera()
            {
                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);
        }