| | |
| | | using DevExpress.Mvvm.Native; |
| | | using DevExpress.XtraCharts.GLGraphics; |
| | | using SharpGL; |
| | | |
| | | namespace Yw.WinFrmUI.HydroL3d |
| | |
| | | { |
| | | return; |
| | | } |
| | | SharpGL.OpenGL gl = this.openGLControl1.OpenGL; |
| | | OpenGL gl = openGLControl1.OpenGL; |
| | | gl.Enable(OpenGL.GL_DEPTH_TEST); |
| | | |
| | | //清除深度缓存 |
| | | gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); |
| | | |
| | | // 设置当前矩阵模式,对投影矩阵应用随后的矩阵操作 |
| | | gl.MatrixMode(OpenGL.GL_PROJECTION); |
| | | |
| | | // 重置当前指定的矩阵为单位矩阵,将当前的用户坐标系的原点移到了屏幕中心 |
| | | gl.LoadIdentity(); |
| | | |
| | | // 创建透视投影变换 |
| | | gl.Perspective(45f, openGLControl1.Width / openGLControl1.Height, 15696f, 38395f); |
| | | |
| | | |
| | | // 设置当前矩阵为模型视图矩阵 |
| | | gl.MatrixMode(OpenGL.GL_MODELVIEW); |
| | | |
| | | //重置当前指定的矩阵为单位矩阵,将当前的用户坐标系的原点移到了屏幕中心 |
| | | gl.LoadIdentity(); |
| | | |
| | | gl.Translate(_paras.Translation.X, _paras.Translation.Y, _paras.Translation.Z); |
| | | // gl.Translate(-_paras.Ceneter.X, -_paras.Ceneter.Y, -_paras.Ceneter.Z); |
| | | //gl.Translate(0, 0, -5f); |
| | | |
| | | gl.Rotate(_paras.Rotation.X, 1, 0, 0); |
| | | gl.Rotate(_paras.Rotation.Y, 0, 1, 0); |
| | | gl.Rotate(_paras.Rotation.Z, 0, 0, 1); |
| | | //gl.Rotate(_paras.Rotation.X, 1, 0, 0); |
| | | // gl.Rotate(_paras.Rotation.Y, 0, 1, 0); |
| | | //gl.Rotate(_paras.Rotation.Z, 0, 0, 1); |
| | | |
| | | gl.Color(1.0f, 1.0f, 1.0f); |
| | | foreach (var pipe in _network.Pipes) |
| | | { |
| | | var startPosition = pipe.StartPosition; |
| | | var endPosition = pipe.EndPosition; |
| | | gl.Begin(OpenGL.GL_LINES); |
| | | gl.Color(1.0f, 1.0f, 1.0f); |
| | | |
| | | gl.Vertex(startPosition.X, startPosition.Y, startPosition.Z);//左顶点 |
| | | gl.Vertex(endPosition.X, endPosition.Y, endPosition.Z);//右顶点 |
| | | gl.End(); |
| | | } |
| | | |
| | | gl.Begin(OpenGL.GL_LINES); |
| | | gl.Color(1.0f, 1.0f, 1.0f); |
| | | gl.Begin(OpenGL.GL_LINES); |
| | | |
| | | gl.Vertex(_paras.BoundingBox.Min.X, _paras.BoundingBox.Min.Y, _paras.BoundingBox.Min.Z);//左顶点 |
| | | gl.Vertex(_paras.BoundingBox.Max.X, _paras.BoundingBox.Max.Y, _paras.BoundingBox.Max.Z);//右顶点 |
| | | gl.End(); |
| | | |
| | | #region 点到线 |
| | | gl.Begin(OpenGL.GL_LINES); |
| | | gl.Color(1.0f, 1.0f, 1.0f); |
| | | gl.Vertex(-2.0f, 0.0f, 0.0f);//左顶点 |
| | | gl.Vertex(2.0f, 2.0f, 0.0f);//右顶点 |
| | | gl.End(); |
| | | #endregion |
| | | |
| | | var minX = _paras.BoundingBox.Min.X; |
| | | var maxX = _paras.BoundingBox.Max.X; |
| | | var minY = _paras.BoundingBox.Min.Y; |
| | | var maxY = _paras.BoundingBox.Max.Y; |
| | | var minZ = _paras.BoundingBox.Min.Z; |
| | | var maxZ = _paras.BoundingBox.Max.Z; |
| | | |
| | | float distance = Math.Max(maxX - minX, Math.Max(maxY - minY, maxZ - minZ)) * 1.5f; |
| | | |
| | | var centerX = (minX + maxX) / 2f; |
| | | var centerY = (minY + maxY) / 2f; |
| | | var centerZ = (minZ + maxZ) / 2f; |
| | | |
| | | var cameraX = centerX + distance; |
| | | var cameraY = centerY + distance; |
| | | var cameraZ = centerZ + distance; |
| | | |
| | | //gl.LookAt(cameraX, cameraY, cameraZ, centerX, centerY, centerZ, 0, 1, 0); |
| | | gl.LookAt(-27484f, -12576f, 8833f, 23675f, 23079f, -7200f, 0f, 0f, 1f); |
| | | gl.Flush(); //强制刷新 |
| | | |
| | | } |
| | |
| | | { |
| | | return; |
| | | } |
| | | _paras.Perspective.Aspect = this.openGLControl1.Width / (float)this.openGLControl1.Height; |
| | | Reset(); |
| | | // _paras.Perspective.Aspect = this.openGLControl1.Width / (float)this.openGLControl1.Height; |
| | | //Reset(); |
| | | } |
| | | |
| | | //重置 |
| | |
| | | gl.Perspective(_paras.Perspective.Fovy, _paras.Perspective.Aspect, _paras.Perspective.Near, _paras.Perspective.Far); |
| | | |
| | | // 视点变换 |
| | | gl.LookAt(_paras.LookAt.Eye.X, _paras.LookAt.Eye.Y, _paras.LookAt.Eye.Z, _paras.LookAt.Center.X, _paras.LookAt.Center.Y, _paras.LookAt.Center.Z, _paras.LookAt.Up.X, _paras.LookAt.Up.Y, _paras.LookAt.Up.Z); |
| | | // gl.LookAt(_paras.LookAt.Eye.X, _paras.LookAt.Eye.Y, _paras.LookAt.Eye.Z, _paras.LookAt.Center.X, _paras.LookAt.Center.Y, _paras.LookAt.Center.Z, _paras.LookAt.Up.X, _paras.LookAt.Up.Y, _paras.LookAt.Up.Z); |
| | | |
| | | // 设置当前矩阵为模型视图矩阵 |
| | | gl.MatrixMode(OpenGL.GL_MODELVIEW); |
| | |
| | | { |
| | | return; |
| | | } |
| | | Reset(); |
| | | //Reset(); |
| | | } |
| | | } |
| | | } |