/// <summary>
        /// Initializes a new instance of the <see cref="SharpGLForm"/> class.
        /// </summary>
        public SharpGLForm()
        {
            InitializeComponent();

            int radius = 1;

            legacyModel.Build(
                new SharpGL.SceneGraph.Vertex(-radius, -0, -radius),
                new SharpGL.SceneGraph.Vertex(radius, 0, radius));

            vertexArrayModel.Build(
                new SharpGL.SceneGraph.Vertex(-radius, -radius, -radius),
                new SharpGL.SceneGraph.Vertex(radius, radius, radius));

            VBOModel.Build(
                new SharpGL.SceneGraph.Vertex(-radius, -radius, -radius),
                new SharpGL.SceneGraph.Vertex(radius, radius, radius));
            ScientificCamera camera = new ScientificCamera(CameraTypes.Perspecitive);

            camera.Target   = new SharpGL.SceneGraph.Vertex(0, 0, 0);
            camera.Position = new SharpGL.SceneGraph.Vertex(-2, 2, -2);
            camera.UpVector = new SharpGL.SceneGraph.Vertex(0, 1, 0);
            IPerspectiveViewCamera perspective = camera;

            perspective.AspectRatio = (double)Width / (double)Height;
            perspective.Far         = 100;
            perspective.Near        = 0.01;
            perspective.FieldOfView = 60;
            this.element            = new ScientificModelElement(VBOModel, camera);
        }
示例#2
0
        //Random random = new Random();

        /// <summary>
        /// Initializes a new instance of the <see cref="FormOpenGLControl"/> class.
        /// </summary>
        public FormSceneControl()
        {
            InitializeComponent();

            //for (int i = 0; i < verticesCount; i++)
            //{
            //    var position = new Vertex();
            //    position.X = (float)random.NextDouble() * 2 - 1;
            //    position.Y = (float)random.NextDouble() * 2 - 1;
            //    position.Z = (float)random.NextDouble() * 2 - 1;
            //    positions.Add(position);
            //    var color = new GLColor();
            //    color.R = (float)random.NextDouble();
            //    color.G = (float)random.NextDouble();
            //    color.B = (float)random.NextDouble();
            //    color.A = (float)random.NextDouble();
            //    colors.Add(color);
            //}

            IOrthoCamera orthoCamera = camera;

            orthoCamera.Left  = -10; orthoCamera.Bottom = -10; orthoCamera.Near = 0;
            orthoCamera.Right = 10; orthoCamera.Top = 10; orthoCamera.Far = 15;
            this.sceneControl.Scene.CurrentCamera = camera;
            this.cameraRotation.Camera            = this.camera;
            this.sceneControl.Scene.SceneContainer.Children.Clear();
            this.sceneControl.Scene.SceneContainer.Effects.Clear();
            //var model = new ModelDemo(
            //new Vertex(-1, -1, -1), new Vertex(1, 1, 1),
            //verticesCount, SharpGL.Enumerations.BeginMode.Points);
            //this.mySceneControl.Scene.SceneContainer.AddChild(model);
            {
                var model = new ScientificModel(verticesCount, SharpGL.Enumerations.BeginMode.Points);
                model.Build(new Vertex(-3, -3, -3), new Vertex(-1, -1, -1));
                var element = new ScientificModelElement(model, this.sceneControl.Scene.CurrentCamera as ScientificCamera);
                this.sceneControl.Scene.SceneContainer.AddChild(element);
            }
            {
                var model = new ScientificModel(verticesCount, SharpGL.Enumerations.BeginMode.Points);
                model.Build(new Vertex(-1, -1, -1), new Vertex(1, 1, 1));
                var element = new ScientificModelElement(model, this.sceneControl.Scene.CurrentCamera as ScientificCamera);
                this.sceneControl.Scene.SceneContainer.AddChild(element);
            }
            {
                var model = new ScientificModel(verticesCount, SharpGL.Enumerations.BeginMode.Points);
                model.Build(new Vertex(1, 1, 1), new Vertex(3, 3, 3));
                var element = new ScientificModelElement(model, this.sceneControl.Scene.CurrentCamera as ScientificCamera);
                this.sceneControl.Scene.SceneContainer.AddChild(element);
            }
            {
                var modelContainer = new ModelContainer();
                modelContainer.BoundingBox.Set(-3.1f, -3.1f, -3.1f, 3.1f, 3.1f, 3.1f);
                this.sceneControl.Scene.SceneContainer.AddChild(modelContainer);
            }

            this.sceneControl.MouseWheel += openGLControl_MouseWheel;
        }
示例#3
0
        private void Create3DObject(object sender, EventArgs e)
        {
            try
            {
                int   nx       = System.Convert.ToInt32(tbNX.Text);
                int   ny       = System.Convert.ToInt32(tbNY.Text);
                int   nz       = System.Convert.ToInt32(tbNZ.Text);
                float step     = System.Convert.ToSingle(tbColorIndicatorStep.Text);
                float radius   = System.Convert.ToSingle(this.tbRadius.Text);
                float minValue = System.Convert.ToSingle(this.tbRangeMin.Text);
                float maxValue = System.Convert.ToSingle(this.tbRangeMax.Text);
                if (minValue >= maxValue)
                {
                    throw new ArgumentException("min value equal or equal to maxValue");
                }

                int    vertexCount = nx * ny * nz;
                Vertex min         = new Vertex(minValue, minValue, minValue);
                Vertex max         = new Vertex(maxValue, maxValue, maxValue);

                ScientificModel model = new ScientificModel(vertexCount, BeginMode.Points);
                model.Build(min, max);

                //this.sceneControl.AddScientificModel(model);// This is replaced by codes below.
                ScientificModelElement element = new ScientificModelElement(
                    model, this.scientificVisual3DControl.Scene.CurrentCamera);
                element.Name = string.Format("element {0}", elementCounter++);
                this.scientificVisual3DControl.AddModelElement(element);
                // update ModelContainer's BoundingBox.
                BoundingBox  boundingBox      = this.scientificVisual3DControl.ModelContainer.BoundingBox;
                IBoundingBox modelBoundingBox = model.BoundingBox;
                if (this.scientificVisual3DControl.ModelContainer.Children.Count > 1)
                {
                    boundingBox.Extend(modelBoundingBox.MinPosition);
                    boundingBox.Extend(modelBoundingBox.MaxPosition);
                }
                else
                {
                    boundingBox.Set(modelBoundingBox.MinPosition.X,
                                    modelBoundingBox.MinPosition.Y,
                                    modelBoundingBox.MinPosition.Z,
                                    modelBoundingBox.MaxPosition.X,
                                    modelBoundingBox.MaxPosition.Y,
                                    modelBoundingBox.MaxPosition.Z);
                }
                boundingBox.Expand();

                // update ViewType to UserView.
                this.scientificVisual3DControl.ViewType = ViewTypes.UserView;

                this.scientificVisual3DControl.SetColorIndicator(minValue, maxValue, step);
            }
            catch (Exception error)
            {
                MessageBox.Show(error.ToString());
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormOpenGLControl"/> class.
        /// </summary>
        public FormScientificVisual3DControl()
        {
            InitializeComponent();

            // Create model and add it to model container.
            //{
            //    var model = new ModelDemo(
            //        new Vertex(-3, -3, -3), new Vertex(-1, -1, -1),
            //        verticesCount, SharpGL.Enumerations.BeginMode.Points);
            //    this.scientificControl.AddModelElement(model);
            //}
            //{
            //    var model = new ModelDemo(
            //        new Vertex(-1, -1, -1), new Vertex(1, 1, 1),
            //        verticesCount, SharpGL.Enumerations.BeginMode.Points);
            //    this.scientificControl.AddModelElement(model);
            //}
            //{
            //    var model = new ModelDemo(
            //        new Vertex(1, 1, 1), new Vertex(3, 3, 3),
            //        verticesCount, SharpGL.Enumerations.BeginMode.Points);
            //    this.scientificControl.AddModelElement(model);
            //}
            {
                var model = new ScientificModel(verticesCount, SharpGL.Enumerations.BeginMode.Points);
                model.Build(new Vertex(-3, -3, -3), new Vertex(-1, -1, -1));
                var element = new ScientificModelElement(model, this.scientificControl.Scene.CurrentCamera);
                this.scientificControl.AddModelElement(element);
            }
            {
                var model = new ScientificModel(verticesCount, SharpGL.Enumerations.BeginMode.Points);
                model.Build(new Vertex(-1, -1, -1), new Vertex(1, 1, 1));
                var element = new ScientificModelElement(model, this.scientificControl.Scene.CurrentCamera);
                this.scientificControl.AddModelElement(element);
            }
            {
                var model = new ScientificModel(verticesCount, SharpGL.Enumerations.BeginMode.Points);
                model.Build(new Vertex(1, 1, 1), new Vertex(3, 3, 3));
                var element = new ScientificModelElement(model, this.scientificControl.Scene.CurrentCamera);
                this.scientificControl.AddModelElement(element);
            }

            // Update model container's bounding box.
            var boundingBox = this.scientificControl.ModelContainer.BoundingBox;

            boundingBox.Set(-3.1f, -3.1f, -3.1f, 3.1f, 3.1f, 3.1f);
            // Update camera
            this.scientificControl.UpdateCamera();
        }
        private void InitializeSceneControl()
        {
            var root = this.mySceneControl.Scene.SceneContainer;

            root.Children.Clear();
            root.Effects.Clear();
            //InitializeSceneAttributes(root);
            this.modelContainer = new ModelContainer();
            this.modelContainer.RenderBoundingBox = false;
            root.AddChild(this.modelContainer);

            {
                var model = new ScientificModel(100 * 100 * 100, BeginMode.Points);
                model.Build(new Vertex(-5, -5, -5), new Vertex(5, 5, 5));
                ScientificModelElement element = new ScientificModelElement(
                    model, this.mySceneControl.Scene.CurrentCamera);
                this.modelContainer.AddChild(element);
                this.modelContainer.BoundingBox.Extend(model.BoundingBox.MaxPosition);
                this.modelContainer.BoundingBox.Extend(model.BoundingBox.MinPosition);
            }

            // Diff: MySceneControl don't need this.
            //var camera = new ScientificCamera()
            //{
            //    Position = new Vertex(-10f, -10f, 10f),
            //    Target = new Vertex(0f, 0f, 0f),
            //    UpVector = new Vertex(0f, 0f, 1f)
            //};
            //this.sceneControl.Scene.CurrentCamera = camera;

            this.cameraRotation        = new SatelliteRotation();
            this.cameraRotation.Camera = this.mySceneControl.Scene.CurrentCamera as ScientificCamera;

            this.mySceneControl.MouseDown  += ScientificVisual3DControl_MouseDown;
            this.mySceneControl.MouseMove  += ScientificVisual3DControl_MouseMove;
            this.mySceneControl.MouseUp    += ScientificVisual3DControl_MouseUp;
            this.mySceneControl.MouseWheel += ScientificVisual3DControl_MouseWheel;
            this.mySceneControl.Resized    += ScientificVisual3DControl_Resized;
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormOpenGLControl"/> class.
        /// </summary>
        public FormOpenGLControl()
        {
            InitializeComponent();

            {
                var model = new ScientificModel(verticesCount, SharpGL.Enumerations.BeginMode.Points);
                model.Build(new Vertex(-3, -3, -3), new Vertex(-1, -1, -1));

                var element = new ScientificModelElement(model, this.camera);
                elements.Add(element);
            }
            {
                var model = new ScientificModel(verticesCount, SharpGL.Enumerations.BeginMode.Points);
                model.Build(new Vertex(-1, -1, -1), new Vertex(1, 1, 1));
                var element = new ScientificModelElement(model, this.camera);
                elements.Add(element);
            }
            {
                var model = new ScientificModel(verticesCount, SharpGL.Enumerations.BeginMode.Points);
                model.Build(new Vertex(1, 1, 1), new Vertex(3, 3, 3));
                var element = new ScientificModelElement(model, this.camera);
                elements.Add(element);
            }
            {
                var modelContainer = new ModelContainer();
                modelContainer.BoundingBox.Set(-3.1f, -3.1f, -3.1f, 3.1f, 3.1f, 3.1f);
                elements.Add(modelContainer);
            }

            IOrthoCamera orthoCamera = camera;

            orthoCamera.Left               = -10; orthoCamera.Bottom = -10; orthoCamera.Near = 0;
            orthoCamera.Right              = 10; orthoCamera.Top = 10; orthoCamera.Far = 15;
            this.cameraRotation.Camera     = this.camera;
            this.openGLControl.MouseWheel += openGLControl_MouseWheel;
        }