public DrawMap(CoordPoint p0, CoordPoint p_x, CoordPoint p_y, CoordPoint p_z, CoordPoint p_camera) { origin_coordinates = p0; x_coordinates = p_x; y_coordinates = p_y; z_coordinates = p_z; camera_location = p_camera; }
public void SetCameraPosition(OpenGL gl, CoordPoint p_camera) { camera_location = p_camera; gl.MatrixMode(OpenGL.GL_MODELVIEW); gl.LoadIdentity(); gl.LookAt(camera_location.x, camera_location.y, camera_location.z, 0, 0, 0, 0, 1, 0); GLDrawCubeCoordinates(gl); }
private void glMap_MouseDown(object sender, MouseEventArgs e) { CoordPoint p = new CoordPoint(0, 50, 600); if (e.Button == System.Windows.Forms.MouseButtons.Left) { draw_t.SetCameraPosition(openGLControl1.OpenGL, p); } }
public void GLDrawGrid(OpenGL gl, CoordPoint pt1, CoordPoint pt2, int num) { double _xLen = (pt2.x - pt1.x) / num; double _yLen = (pt2.y - pt1.y) / num; double _zLen = (pt2.z - pt1.z) / num; gl.LineWidth(1.0f); gl.LineStipple(1, 0x0303);//线条样式 gl.Begin(OpenGL.GL_LINES); gl.Enable(OpenGL.GL_LINE_SMOOTH); //glColor3f(0.0f,0.0f, 1.0f); //白色线条 int xi = 0; int yi = 0; int zi = 0; //绘制平行于X的直线 for (zi = 0; zi <= num; zi++) { double z = _zLen * zi + pt1.z; for (yi = 0; yi <= num; yi++) { double y = _yLen * yi + pt1.y; gl.Vertex(pt1.x, y, z); gl.Vertex(pt2.x, y, z); } } //绘制平行于Y的直线 for (zi = 0; zi <= num; zi++) { double z = _zLen * zi + pt1.z; for (xi = 0; xi <= num; xi++) { double x = _xLen * xi + pt1.x; gl.Vertex(x, pt1.y, z); gl.Vertex(x, pt2.y, z); } } //绘制平行于Z的直线 for (yi = 0; yi <= num; yi++) { double y = _yLen * yi + pt1.y; for (xi = 0; xi <= num; xi++) { double x = _xLen * xi + pt1.x; gl.Vertex(x, y, pt1.z); gl.Vertex(x, y, pt2.z); } } gl.End(); }
public void GLDrawCubeCoordinates(OpenGL gl) { /*****网格绘制*****/ /*****使用颜色混合来消除一些锯齿, 主要针对点和线 * 以及不相互重叠的多边形的反锯齿。*****/ gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE_MINUS_SRC_ALPHA); gl.Enable(OpenGL.GL_BLEND); gl.Enable(OpenGL.GL_POINT_SMOOTH); //设置反走样 gl.Hint(OpenGL.GL_POINT_SMOOTH_HINT, OpenGL.GL_NICEST); //设置反走样 gl.Enable(OpenGL.GL_LINE_SMOOTH); gl.Hint(OpenGL.GL_LINE_SMOOTH_HINT, OpenGL.GL_NICEST); gl.Enable(OpenGL.GL_POLYGON_SMOOTH); gl.Hint(OpenGL.GL_POLYGON_SMOOTH_HINT, OpenGL.GL_NICEST); GLInitWindow(gl); //绘制立体坐标系 gl.Rotate(-45, 0.0, 1.0, 0.0); //确定坐标系原点 gl.PushMatrix(); gl.Color(1.0f, 1.0f, 1.0f); //gl.Translate(-5, 0, -5); gl.Sphere(gl.NewQuadric(), 0.2, 20, 20); gl.PopMatrix(); //画网格线,X-Z平面 CoordPoint cpoint1 = new CoordPoint(0, 0, 0); CoordPoint cpoint2 = new CoordPoint(x_coordinates.x, 0, z_coordinates.z); gl.Color(0.9f, 0.9f, 0.9f); GLDrawGrid(gl, cpoint1, cpoint2, 10); //画网格线, gl.PushMatrix(); gl.Rotate(90, 1.0, 0.0, 0.0); gl.Translate(0.0f, 0.0f, -z_coordinates.z); CoordPoint cpoint3 = new CoordPoint(0, 0, 0); CoordPoint cpoint4 = new CoordPoint(x_coordinates.x, 0, z_coordinates.z); gl.Color(0.9f, 0.9f, 0.0f); GLDrawGrid(gl, cpoint3, cpoint4, 10); gl.PopMatrix(); //画网格线 gl.PushMatrix(); gl.Rotate(90, 0.0, 0.0, 1.0); //gl.Translate(5, 5, -0); CoordPoint cpoint5 = new CoordPoint(0, 0, 0); CoordPoint cpoint6 = new CoordPoint(x_coordinates.x, 0, z_coordinates.z); gl.Color(0.0f, 0.9f, 0.0f); GLDrawGrid(gl, cpoint5, cpoint6, 10); gl.PopMatrix(); //画坐标轴 gl.PushMatrix(); gl.Color(0.0f, 1, 0.0f); gl.Cylinder(gl.NewQuadric(), 0.05, 0.05, z_coordinates.z, 10, 5); //Z gl.Translate(0, 0, z_coordinates.z); gl.Cylinder(gl.NewQuadric(), 0.2, 0.0, 0.5, 10, 5); //Z gl.PopMatrix(); gl.PushMatrix(); gl.Translate(0, 0.2, z_coordinates.z); GLPrint(gl, "Z"); // Print GL Text ToThe Screen gl.PopMatrix(); //画坐标轴 gl.PushMatrix(); gl.Color(1, 0, 0.0f); gl.Rotate(90, 0.0, 1.0, 0.0); gl.Cylinder(gl.NewQuadric(), 0.05, 0.05, x_coordinates.x, 10, 5); //X gl.Translate(0, 0, x_coordinates.x); gl.Cylinder(gl.NewQuadric(), 0.2, 0.0, 0.5, 10, 5); //X gl.PopMatrix(); gl.PushMatrix(); gl.Rotate(90, 0.0, 1.0, 0.0); gl.Translate(0, 0.2, x_coordinates.x); GLPrint(gl, "X"); // Print GL Text ToThe Screen gl.PopMatrix(); //画坐标轴 gl.PushMatrix(); gl.Color(1, 1, 0.0f); gl.Rotate(-90, 1.0, 0.0, 0.0); gl.Cylinder(gl.NewQuadric(), 0.05, 0.05, y_coordinates.y, 10, 5); //Y gl.Translate(0, 0, y_coordinates.y); gl.Cylinder(gl.NewQuadric(), 0.2, 0.0, 0.5, 10, 5); //Y gl.PopMatrix(); gl.PushMatrix(); gl.Rotate(-90, 1.0, 0.0, 0.0); gl.Translate(0.0, 0.6, y_coordinates.y); gl.Rotate(90, 1.0, 0.0, 0.0); GLPrint(gl, "Y"); // Print GL Text ToThe Screen gl.PopMatrix(); /*****取消反锯齿*****/ gl.Disable(OpenGL.GL_BLEND); gl.Disable(OpenGL.GL_LINE_SMOOTH); gl.Disable(OpenGL.GL_POINT_SMOOTH); gl.Disable(OpenGL.GL_POLYGON_SMOOTH); }