// Token: 0x06000138 RID: 312 RVA: 0x0001141C File Offset: 0x0000F61C public static void DrawCircle1(Color Col, Vector2 Center, float Radius) { GL.PushMatrix(); DrawMaterial.SetPass(0); GL.Begin(1); GL.Color(Col); for (float num = 0f; num < 6.28318548f; num += 0.05f) { GL.Vertex(new Vector3(Mathf.Cos(num) * Radius + Center.x, Mathf.Sin(num) * Radius + Center.y)); GL.Vertex(new Vector3(Mathf.Cos(num + 0.05f) * Radius + Center.x, Mathf.Sin(num + 0.05f) * Radius + Center.y)); } GL.End(); GL.PopMatrix(); }
private IModel CreateModel(float lenght, float width, float height, uint color) { IModel model = new ResourceFactory().CreateModel(); IDrawGroup group = new DrawGroup(); IDrawPrimitive primitive = new DrawPrimitive(); IFloatArray vertexArray = new FloatArray(); IFloatArray textureArray = new FloatArray(); IUInt32Array colorArray = new UInt32Array(); #region //顶点数组3个为一组(三角面1) vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f); //顶点数组3个为一组(三角面2) vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f); //顶点数组3个为一组(三角面3) vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); //顶点数组3个为一组(三角面4) vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); //顶点数组3个为一组(三角面5) vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght); //顶点数组3个为一组(三角面6) vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght); //顶点数组3个为一组(三角面7) vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); //顶点数组3个为一组(三角面8) vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); //顶点数组3个为一组(三角面9) vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); //顶点数组3个为一组(三角面10) vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(lenght); //顶点数组3个为一组(三角面11) vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); //顶点数组3个为一组(三角面12) vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(lenght); vertexArray.Append(0.0f); vertexArray.Append(0.0f); vertexArray.Append(lenght); #endregion #region //颜色数组1个为一组 colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); colorArray.Append(color); #endregion #region //纹理数组2个为一组 textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); textureArray.Append(1.0f); textureArray.Append(0.0f); textureArray.Append(1.0f); #endregion primitive.ColorArray = colorArray; primitive.TexcoordArray = textureArray; primitive.VertexArray = vertexArray; IDrawMaterial material = new DrawMaterial(); material.EnableLight = true; primitive.Material = material; group.AddPrimitive(primitive); //光照效果,跟法向有关 group.ComputeNormal(); model.AddGroup(group); return(model); }
/// <summary> /// 参数化建模 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDriveModel_Click(object sender, System.EventArgs e) { try { if (polyline != null) { center = polyline.Envelope.Center; IModelPoint mp = new GeometryFactory().CreateGeometry(gviGeometryType.gviGeometryModelPoint, gviVertexAttribute.gviVertexAttributeZ) as IModelPoint; mp.SpatialCRS = datasetCRS; mp.Position = center; IModel model = new ResourceFactory().CreateModel(); IDrawGroup group = new DrawGroup(); IDrawPrimitive primitive = new DrawPrimitive(); IDrawMaterial material = new DrawMaterial(); material.TextureName = (strMediaPath + @"\shp\road\textrure.jpg"); material.CullMode = gviCullFaceMode.gviCullNone; material.WrapModeS = gviTextureWrapMode.gviTextureWrapRepeat; material.WrapModeT = gviTextureWrapMode.gviTextureWrapRepeat; IFloatArray va = new FloatArray(); IFloatArray ta = new FloatArray(); // 逐点外扩 for (int i = 0; i < polyline.PointCount; i++) { #region 单独处理最后一个点 if (i == polyline.PointCount - 1) { curPoint = polyline.GetPoint(i); vecCurPos = curPoint.Position; // 最后一个点重用最后的方向向量 vecTarget = vecDirect.CrossProduct(vecZ); vecTarget.Normalize(); vecTarget.MultiplyByScalar(width / 2); vecP = vecCurPos.Add(vecTarget); vecTarget.MultiplyByScalar(-1); vecQ = vecCurPos.Add(vecTarget); // 设置外扩点 P = curPoint.Clone() as IPoint; P.Position = vecP; Q = curPoint.Clone() as IPoint; Q.Position = vecQ; // 把点坐标加进顶点数组 va.Append((float)(vecP.X - center.X)); va.Append((float)(vecP.Y - center.Y)); va.Append((float)(vecP.Z - center.Z)); va.Append((float)(vecQ.X - center.X)); va.Append((float)(vecQ.Y - center.Y)); va.Append((float)(vecQ.Z - center.Z)); // 加纹理坐标 ta.Append(0); //P点纹理 if (i == 0) { lastV = 0.0; } else { lastV = lastV + length / 10; //v方向上每隔10米重复一次 } ta.Append((float)lastV); ta.Append(1); //Q点纹理 ta.Append((float)lastV); { ISimplePointSymbol ps = new SimplePointSymbol(); ps.FillColor = System.Drawing.Color.Yellow; ps.Size = 5; rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(P, ps, rootId)); rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(Q, ps, rootId)); } break; } #endregion // 当不是最后一个点时: curPoint = polyline.GetPoint(i); nextPoint = polyline.GetPoint(i + 1); vecCurPos = curPoint.Position; vecNextPos = nextPoint.Position; // 运算 vecNextPos.MultiplyByScalar(-1); vecDirect = vecCurPos.Add(vecNextPos); //方向向量 vecZ.Set(0, 0, 1); vecTarget = vecDirect.CrossProduct(vecZ); vecTarget.Normalize(); vecTarget.MultiplyByScalar(width / 2); vecP = vecCurPos.Add(vecTarget); vecTarget.MultiplyByScalar(-1); vecQ = vecCurPos.Add(vecTarget); // 设置外扩点 P = curPoint.Clone() as IPoint; P.Position = vecP; Q = curPoint.Clone() as IPoint; Q.Position = vecQ; // 把点坐标加进顶点数组 va.Append((float)(vecP.X - center.X)); va.Append((float)(vecP.Y - center.Y)); va.Append((float)(vecP.Z - center.Z)); va.Append((float)(vecQ.X - center.X)); va.Append((float)(vecQ.Y - center.Y)); va.Append((float)(vecQ.Z - center.Z)); // 加纹理坐标 ta.Append(0); //P点纹理 if (i == 0) { lastV = 0.0; } else { lastV = lastV + length / 5; //v方向上每隔10米重复一次 } length = vecDirect.Length; //计算长度给奇数点用 ta.Append((float)lastV); ta.Append(1); //Q点纹理 ta.Append((float)lastV); { ISimplePointSymbol ps = new SimplePointSymbol(); ps.FillColor = System.Drawing.Color.Yellow; ps.Size = 5; rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(P, ps, rootId)); rPointToDelList.Add(this.axRenderControl1.ObjectManager.CreateRenderPoint(Q, ps, rootId)); } } // 计算索引坐标 IUInt16Array ia = new UInt16Array(); for (int i = 0; i < va.Length / 6 - 1; i++) { ia.Append((ushort)(2 * i)); ia.Append((ushort)(2 * i + 1)); ia.Append((ushort)(2 * i + 2)); ia.Append((ushort)(2 * i + 1)); ia.Append((ushort)(2 * i + 3)); ia.Append((ushort)(2 * i + 2)); } primitive.VertexArray = va; primitive.TexcoordArray = ta; primitive.IndexArray = ia; primitive.Material = material; group.AddPrimitive(primitive); model.AddGroup(group); // 在内存中临时存储模型 string modelName = fid.ToString(); this.axRenderControl1.ObjectManager.AddModel(modelName, model); mp.ModelName = modelName; mp.ModelEnvelope = model.Envelope; // 可视化临时模型 IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, null, rootId); rmp.MaxVisibleDistance = 100000; rmp.MouseSelectMask = gviViewportMask.gviViewNone; rModelpointToDelList.Add(rmp); } } catch (System.Exception ex) { if (ex.GetType().Name.Equals("UnauthorizedAccessException")) { MessageBox.Show("需要标准runtime授权"); } else { MessageBox.Show(ex.Message); } } }