//绘制1坐标轴,含有箭头: private void DrawOLineInGL(double azimuth, double elevation, float length, float width, Color color, bool arrow) { float colorR, colorG, colorB; float x, y, z; colorR = color.R / 255.0f; colorG = color.G / 255.0f; colorB = color.B / 255.0f; x = length * (float)Math.Cos(elevation) * (float)Math.Cos(azimuth); y = length * (float)Math.Cos(elevation) * (float)Math.Sin(azimuth); z = length * (float)Math.Sin(elevation); GL.LineWidth(width); GL.Begin(BeginMode.Lines); GL.Color3(colorR, colorG, colorB); GL.Vertex3(0.0f, 0.0f, 0.0f); GL.Vertex3(x, y, z); //三轴末端位置 GL.End(); if (arrow) { float vx, vy, vz; vx = xMul(y, z, 0, 1); vy = xMul(z, x, 1, 0); vz = xMul(x, y, 0, 0); GL.LineWidth(1.0f); GL.PushMatrix(); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GL.Translate(x, y, z); //坐标轴箭头所在位置 if (isInLimits(elevation, Math.PI / 2, Math.PI / 2 * 3)) { GL.Rotate((float)(90 - elevation / Math.PI * 180), vx, vy, vz); //上半球? } else { GL.Rotate(-(float)(90 - elevation / Math.PI * 180), vx, vy, vz); //下半球? } Glu.Cylinder(Glu.NewQuadric(), 0.03, 0.0, 0.2, 20, 5); //圆锥形作箭头 //Glu.Sphere(Glu.NewQuadric(), 0.05, 12, 12);//球体作箭头 GL.PopMatrix(); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< } }
public Sphere(Vector3 pos, float radius, int slices, int stacks, int bodyIndex) { this.pos = pos; this.radius = radius; this.slices = slices; this.stacks = stacks; quad = Glu.NewQuadric(); this.bodyIndex = bodyIndex; this.cellPos = Vector3.Zero; cells = new List <Body>(8); cellArray = new uint[8]; /*for (int i = 0; i < 8; i++) * cellArray[i] |= (uint)bodyIndex << 5;*/ foreach (Body cell in cells) { checkCellType(cell.getPos().X, cell.getPos().Y, cell.getPos().Z, false); } }
//画多个内置立体件: private void DrawModels() { float width = 3; float height = 3; float length = 3; GL.LineWidth(4); GL.PointSize(8); var obj = Glu.NewQuadric(); //Glu.QuadricDrawStyle(obj, QuadricDrawStyle.Line); //Glu.QuadricDrawStyle(obj, QuadricDrawStyle.Silhouette); //Glu.QuadricDrawStyle(obj, QuadricDrawStyle.Point); //Glu.QuadricDrawStyle(obj, QuadricDrawStyle.Fill); Glu.QuadricDrawStyle(obj, QuadricDrawStyle.Line); ////画大正方形上可旋转各对象 Draw plane that the objects rest on //GL.PushMatrix(); //GL.Color4(0.5f,0.3f, 0.5f, 0.5f); // Blue //GL.Normal3(0.0f, 1.0f, 0.0f); //GL.Begin(BeginMode.Quads); //GL.Vertex3(-10.0f, -2.5f, -10.0f); //GL.Vertex3(-10.0f, -2.5f, 10.0f); //GL.Vertex3(10.0f, -2.5f, 10.0f); //GL.Vertex3(10.0f, -2.5f, -10.0f); //GL.End(); //GL.PopMatrix(); ////画网线空心球 //GL.PushMatrix(); //GL.Color3(0.6f, 0.6f, 0.8f); //GL.Translate(0.0f, -3.0f, 0.0f); //Glu.Sphere(obj, 2, 6, 4);//球体----------------- //GL.PopMatrix(); ////画立方体(6个正方形) Draw red cube //GL.PushMatrix(); //GL.Color3(0.5f, 0.75f, 0.5f); //GL.Translate(0.0f, 3.0f, 0.0f); //GL.Begin(BeginMode.Quads); //// //GL.Normal3(0.0f, 0.0f, -1.0f); //GL.Vertex3(-width, height, -length); //0 //GL.Vertex3(width, height, -length); //1 //GL.Vertex3(width, -height, -length);//2 //GL.Vertex3(-width, -height, -length); //3 //// //GL.Normal3(0.0f, 0.0f, 1.0f); //GL.Vertex3(-width, height, length); //4 //GL.Vertex3(-width, -height, length); //5 //GL.Vertex3(width, -height, length); //6 //GL.Vertex3(width, height, length); //7 //// //GL.Normal3(0.0f, 1.0f, 0.0f); //GL.Vertex3(-width, height, length); //8 (4) //GL.Vertex3(width, height, length); //9 (6) //GL.Vertex3(width, height, -length); //10 (0) //GL.Vertex3(-width, height, -length); //11 (1) //// //GL.Normal3(0.0f, -1.0f, 0.0f); //GL.Vertex3(-width, -height, length); //12 (5) //GL.Vertex3(-width, -height, -length);//13 (2) //GL.Vertex3(width, -height, -length); //14 (7) //GL.Vertex3(width, -height, length); //15 (3) //// //GL.Normal3(1.0f, 0.0f, 0.0f); //GL.Vertex3(width, height, -length); //16 (1) //GL.Vertex3(width, height, length); //17 (6) //GL.Vertex3(width, -height, length); //18 (3) //GL.Vertex3(width, -height, -length); //19 (7) //// //GL.Normal3(-1.0f, 0.0f, 0.0f); //GL.Vertex3(-width, height, -length); //20 (0) //GL.Vertex3(-width, -height, -length);//21 (2) //GL.Vertex3(-width, -height, length); //22 (4) //GL.Vertex3(-width, height, length); //23 (5) //// //GL.End(); //GL.PopMatrix(); //绿色球体 Draw green sphere GL.PushMatrix(); GL.Color3(0.0f, 1.0f, 0.0f); GL.Translate(-6.0f, 0.0f, 0.0f); Glu.Sphere(obj, 2.5f, 8, 12); GL.PopMatrix(); ////黄色锥体 Draw yellow cone //GL.PushMatrix(); //GL.Color3(1.0f, 1.0f, 0.0f); //GL.Rotate(-90.0f, 1.0f, 0.0f, 0.0f); //GL.Translate(6.0f, 0.0f, -2.4f); //Glu.Cylinder(obj, 2.5f, 1.0f, 5.0f, 8, 12); //GL.PopMatrix(); ////绘制实心圆环 Draw magenta torus //GL.PushMatrix(); //GL.Color3(1.0f, 0.0f, 1.0f); //GL.Translate(0.0f, 0.0f, 2.0f); //DrawTorus(5.0f, 1.0f, 20, 20);//绘制实心圆环 //GL.PopMatrix(); ////绘制八面体 Draw cyan octahedron //GL.PushMatrix(); //GL.Color3(0.0f, 1.0f, 1.0f); //GL.Translate(0.0f, -2.0f, 0f); //Glu.Sphere(obj, .5, 4, 2);//绘制八面体 //GL.PopMatrix(); }
public cGLShape() { quadObj = Glu.NewQuadric(); }