//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; }
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; }
/// <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; }
internal static ScientificModel GetModel(this GeometryModel.Gridder.HexahedronGridder gridder) { if (gridder == null) { return(null); } Random random = new Random(); const int factor = 14; ScientificModel model = new ScientificModel(gridder.Cells.Length * factor, SharpGL.Enumerations.BeginMode.TriangleString); // se binding box. Vertex min, max; GetMaxMinPosition(gridder, out min, out max); model.BoundingBox.Set(min.X, min.Y, min.Z, max.X, max.Y, max.Z); // set positions and colors. int modelIndex = 0; for (int index = 0; index < gridder.Cells.Length; index++) { GeometryModel.GLPrimitive.Hexahedron cell = gridder.Cells[index]; Vertex[] vertexes = new Vertex[factor] { cell.frt, cell.frb, cell.brt, cell.brb, cell.blb, cell.frb, cell.flb, cell.frt, cell.flt, cell.brt, cell.blt, cell.blb, cell.flt, cell.flb, }; foreach (Vertex vertex in vertexes) { model.Positions[modelIndex + 0] = vertex.X; model.Positions[modelIndex + 1] = vertex.Y; model.Positions[modelIndex + 2] = vertex.Z; model.Colors[modelIndex + 0] = cell.color.R; model.Colors[modelIndex + 1] = cell.color.G; model.Colors[modelIndex + 2] = cell.color.B; modelIndex += 3; } } // set first, count and primitive count for MultiDrawArrays() int[] first = new int[gridder.Cells.Length]; for (int i = 0; i < first.Length; i++) { first[i] = i * factor; } model.First = first; int[] count = new int[gridder.Cells.Length]; for (int i = 0; i < count.Length; i++) { count[i] = factor; } model.Count = count; model.PrimitiveCount = gridder.Cells.Length; //// set random color for now //for (int i = 0; i < model.Colors.Length; i++) //{ // model.Colors[i] = (float)random.NextDouble(); //} //for (int i = 0; i < gridder.Cells.Length; i++) //{ // model.Colors[i * 3 * factor] = gridder.Cells[i].color.R; // model.Colors[i * 3 * factor + 1] = gridder.Cells[i].color.G; // model.Colors[i * 3 * factor + 2] = gridder.Cells[i].color.B; //} return(model); //Random random = new Random(); //Vertex min = new Vertex(), max = new Vertex(); //bool isInit = false; //for (int i = 0; i < model.VertexCount; i++) //{ // var x = (float)((maxPosition.X - minPosition.X) * random.NextDouble() + minPosition.X); // var y = (float)((maxPosition.Y - minPosition.Y) * random.NextDouble() + minPosition.Y); // var z = (float)((maxPosition.Z - minPosition.Z) * random.NextDouble() + minPosition.Z); // if (!isInit) // { // min = new Vertex(x, y, z); // max = new Vertex(x, y, z); // isInit = true; // } // if (x < min.X) min.X = x; // if (x > max.X) max.X = x; // if (y < min.Y) min.Y = y; // if (y > max.Y) max.Y = y; // if (z < min.Z) min.Z = z; // if (z > max.Z) max.Z = z; // model.Positions[i * 3 + 0] = x; // model.Positions[i * 3 + 1] = y; // model.Positions[i * 3 + 2] = z; // model.Colors[i * 3 + 0] = (float)random.NextDouble(); // model.Colors[i * 3 + 1] = (float)random.NextDouble(); // model.Colors[i * 3 + 2] = (float)random.NextDouble(); //} //model.BoundingBox.Set(min.X, min.Y, min.Z, max.X, max.Y, max.Z); //throw new NotImplementedException(); }