public Grid(MeshCreatorControl control) { this.control = control; //El bounding box del piso es bien grande para hacer colisiones boundingBox = new TgcBoundingBox(new Vector3(-BIG_VAL, -SMALL_VAL, -BIG_VAL), new Vector3(BIG_VAL, 0, BIG_VAL)); //Planos para colision de picking pickingXZAabb = new TgcBoundingBox(new Vector3(-BIG_VAL, -SMALL_VAL, -BIG_VAL), new Vector3(BIG_VAL, 0, BIG_VAL)); pickingXYAabb = new TgcBoundingBox(new Vector3(-BIG_VAL, -BIG_VAL, -SMALL_VAL), new Vector3(BIG_VAL, BIG_VAL, 0)); pickingYZAabb = new TgcBoundingBox(new Vector3(-SMALL_VAL, -BIG_VAL, -BIG_VAL), new Vector3(0, BIG_VAL, BIG_VAL)); vertices = new CustomVertex.PositionColored[12 * 2 * 2]; int color = Color.FromArgb(76, 76, 76).ToArgb(); //10 lineas horizontales en X for (int i = 0; i < 11; i++) { vertices[i * 2] = new CustomVertex.PositionColored(-GRID_RADIUS, 0, -GRID_RADIUS + LINE_SEPARATION * i, color); vertices[i * 2 + 1] = new CustomVertex.PositionColored(GRID_RADIUS, 0, -GRID_RADIUS + LINE_SEPARATION * i, color); } //10 lineas horizontales en Z for (int i = 11; i < 22; i++) { vertices[i * 2] = new CustomVertex.PositionColored(-GRID_RADIUS * 3 + LINE_SEPARATION * i - LINE_SEPARATION, 0, -GRID_RADIUS, color); vertices[i * 2 + 1] = new CustomVertex.PositionColored(-GRID_RADIUS * 3 + LINE_SEPARATION * i - LINE_SEPARATION, 0, GRID_RADIUS, color); } }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; //Crear vertexBuffer vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default); //Cargar informacion de vertices: (X,Y,Z) + Color CustomVertex.PositionColored[] data = new CustomVertex.PositionColored[3]; data[0] = new CustomVertex.PositionColored(-1, 0, 0, Color.Red.ToArgb()); data[1] = new CustomVertex.PositionColored(1, 0, 0, Color.Green.ToArgb()); data[2] = new CustomVertex.PositionColored(0, 1, 0, Color.Blue.ToArgb()); //Almacenar información en VertexBuffer vertexBuffer.SetData(data, 0, LockFlags.None); //Configurar camara en rotacion GuiController.Instance.RotCamera.setCamera(new Vector3(0, 0.5f, 0), 3f); //User Vars GuiController.Instance.UserVars.addVar("Vertices"); GuiController.Instance.UserVars.setValue("Vertices", data.Length); }
//////////////////////////////////////////////////////////////////////////////////// private void GenerateAllPartitionLines(Polygon[] p) { int total = 0; //所有边总和(此处没有重复!) for (int i = 0; i < p.Length; i++) { total += p[i].vertex.Length; } pvexs = new CustomVertex.PositionColored[total * 2]; int pos = 0; for (int i = 0; i < p.Length; i++) { Polygon pi = p[i]; for (int j = 0; j < pi.vertex.Length; j++) { CustomVertex.PositionNormalColored from = pi.vertex[j]; CustomVertex.PositionNormalColored to = pi.vertex[(j + 1) % pi.vertex.Length]; pvexs[pos++] = new CustomVertex.PositionColored(from.X, from.Y, from.Z, color.ToArgb()); pvexs[pos++] = new CustomVertex.PositionColored(to.X, to.Y, to.Z, color.ToArgb()); } } }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; //Crear VertexBuffer vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default); //Cargar informacion de vertices: (X,Y,Z) + Color data = new CustomVertex.PositionColored[3]; data[0] = new CustomVertex.PositionColored(-1, 0, 0, Color.Red.ToArgb()); data[1] = new CustomVertex.PositionColored(1, 0, 0, Color.Green.ToArgb()); data[2] = new CustomVertex.PositionColored(0, 1, 0, Color.Blue.ToArgb()); //FPS Camara GuiController.Instance.FpsCamera.Enable = false; GuiController.Instance.FpsCamera.setCamera(new Vector3(0.5f, 0, -3), new Vector3(0, 0, 0)); //User Vars GuiController.Instance.UserVars.addVar("Vertices", 0); GuiController.Instance.UserVars.addVar("Triangles", 0); GuiController.Instance.Modifiers.addFloat("translateX", -5, 5f, 0f); GuiController.Instance.Modifiers.addFloat("rotationZ", 0, (float)(2.0f * Math.PI), 0f); GuiController.Instance.Modifiers.addFloat("ScaleXYZ", 0, 3, 1f); }
/// <summary> /// Actualizar parámetros de la caja en base a los valores configurados /// </summary> public void updateValues() { var vertices = new CustomVertex.PositionColored[VERTICES_COUNT]; int idx; var c = color.ToArgb(); //Botton Face idx = 0; createLineZ(vertices, idx, c, PMin, new Vector3(PMin.X, PMin.Y, PMax.Z)); idx += LINE_VERTICES_COUNT; createLineX(vertices, idx, c, new Vector3(PMin.X, PMin.Y, PMax.Z), new Vector3(PMax.X, PMin.Y, PMax.Z)); idx += LINE_VERTICES_COUNT; createLineZ(vertices, idx, c, new Vector3(PMax.X, PMin.Y, PMax.Z), new Vector3(PMax.X, PMin.Y, PMin.Z)); idx += LINE_VERTICES_COUNT; createLineX(vertices, idx, c, new Vector3(PMax.X, PMin.Y, PMin.Z), PMin); //Top Face idx += LINE_VERTICES_COUNT; createLineZ(vertices, idx, c, new Vector3(PMin.X, PMax.Y, PMin.Z), new Vector3(PMin.X, PMax.Y, PMax.Z)); idx += LINE_VERTICES_COUNT; createLineX(vertices, idx, c, new Vector3(PMin.X, PMax.Y, PMax.Z), PMax); idx += LINE_VERTICES_COUNT; createLineZ(vertices, idx, c, PMax, new Vector3(PMax.X, PMax.Y, PMin.Z)); idx += LINE_VERTICES_COUNT; createLineX(vertices, idx, c, new Vector3(PMax.X, PMax.Y, PMin.Z), new Vector3(PMin.X, PMax.Y, PMin.Z)); //Conexión Bottom-Top idx += LINE_VERTICES_COUNT; createLineY(vertices, idx, c, PMin, new Vector3(PMin.X, PMax.Y, PMin.Z)); idx += LINE_VERTICES_COUNT; createLineY(vertices, idx, c, new Vector3(PMin.X, PMin.Y, PMax.Z), new Vector3(PMin.X, PMax.Y, PMax.Z)); idx += LINE_VERTICES_COUNT; createLineY(vertices, idx, c, new Vector3(PMax.X, PMin.Y, PMax.Z), PMax); idx += LINE_VERTICES_COUNT; createLineY(vertices, idx, c, new Vector3(PMax.X, PMin.Y, PMin.Z), new Vector3(PMax.X, PMax.Y, PMin.Z)); //Cargar VertexBuffer vertexBuffer.SetData(vertices, 0, LockFlags.None); }
public void VertexContainer( object sender, EventArgs e ) { Device dev = (Device)sender ; // Set culling so we're not rendering the back of our triangle dev.RenderState.CullMode = Cull.CounterClockwise ; // Turn off D3D lighting, since we are providing our own vertex colors dev.RenderState.Lighting = false ; // Create an instance of ready-made DirectX VertexBuffer vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, dev, 0, CustomVertex.PositionColored.Format, Pool.Default); // Lock our buffer so nothing gets changed while we are reading the data GraphicsStream GraphixStream = vertexBuffer.Lock( 0, 0, 0 ); CustomVertex.PositionColored[] VerticeArray = new CustomVertex.PositionColored[3]; VerticeArray[0].Position = new Vector3( -0.5f, 0.5f, 0 ); // top right Vertice VerticeArray[0].Color = System.Drawing.Color.Yellow.ToArgb(); VerticeArray[1].Position = new Vector3( 0.5f, -0.5f, 0 ); // bottom right VerticeArray[1].Color = System.Drawing.Color.Orange.ToArgb(); VerticeArray[2].Position = new Vector3( -0.5f, -0.5f, 0 ); // bottom left VerticeArray[2].Color = System.Drawing.Color.Red.ToArgb(); GraphixStream.Write(VerticeArray); vertexBuffer.Unlock(); }
/// <summary> /// Actualizar parámetros del plano en base a los valores configurados /// </summary> public void updateValues() { var vertices = new CustomVertex.PositionColored[6]; //Crear un Quad con dos triángulos sobre XZ con normal default (0, 1, 0) var min = new Vector3(-Size.X / 2, 0, -Size.Y / 2); var max = new Vector3(Size.X / 2, 0, Size.Y / 2); var c = color.ToArgb(); vertices[0] = new CustomVertex.PositionColored(min, c); vertices[1] = new CustomVertex.PositionColored(min.X, 0, max.Z, c); vertices[2] = new CustomVertex.PositionColored(max, c); vertices[3] = new CustomVertex.PositionColored(min, c); vertices[4] = new CustomVertex.PositionColored(max, c); vertices[5] = new CustomVertex.PositionColored(max.X, 0, min.Z, c); //Obtener matriz de rotacion respecto de la normal del plano normal.Normalize(); var angle = FastMath.Acos(Vector3.Dot(ORIGINAL_DIR, normal)); var axisRotation = Vector3.Cross(ORIGINAL_DIR, normal); axisRotation.Normalize(); var t = Matrix.RotationAxis(axisRotation, angle) * Matrix.Translation(Center); //Transformar todos los puntos for (var i = 0; i < vertices.Length; i++) { vertices[i].Position = Vector3.TransformCoordinate(vertices[i].Position, t); } //Cargar vertexBuffer vertexBuffer.SetData(vertices, 0, LockFlags.None); }
////////////////////////////////////////////////////////////////////////////////////////////////////// public void CreateAllBuffer(Device device, Matrix trans) { if (vexbuf == null) { CustomVertex.PositionColored[] v = new CustomVertex.PositionColored[5]; for (int i = 0; i < 5; i++) { v[i] = vex[i]; v[i].Position = Vector3.TransformCoordinate(vex[i].Position, trans); } //由于是一次性创建,并不是每一帧都修改,因此使用静态顶点缓冲 vexbuf = new VertexBuffer( typeof(CustomVertex.PositionColored), //顶点类型 vex.Length, //顶点个数 device, Usage.WriteOnly, CustomVertex.PositionColored.Format, //顶点格式 Pool.Default); vexbuf.SetData(v, 0, LockFlags.None); } if (idxbuf == null) { //由于是一次性创建,并不是每一帧都修改,因此使用静态索引缓冲 idxbuf = new IndexBuffer(typeof(short), idx.Length, device, Usage.WriteOnly, Pool.Default); idxbuf.SetData(idx, 0, LockFlags.None); } }
/// <summary> /// 选中输入的范围框 /// </summary> /// <param name="rects">要选中的范围框列表</param> /// <param name="selectLineColor">选中范围框的颜色</param> public void SelectExtents(List <RectangleF> rects, Color selectLineColor) { m_selectExtentsPCs = new List <CustomVertex.PositionColored[]>(); foreach (RectangleF rf in rects) { Point3d pt0 = createPoint3dByLatLon(rf.Y, rf.X); Point3d pt1 = createPoint3dByLatLon(rf.Y, rf.Right); Point3d pt2 = createPoint3dByLatLon(rf.Bottom, rf.Right); Point3d pt3 = createPoint3dByLatLon(rf.Bottom, rf.X); List <CustomVertex.PositionColored> curve1 = getCurveFromPoints(pt0, pt1, selectLineColor); List <CustomVertex.PositionColored> curve2 = getCurveFromPoints(pt1, pt2, selectLineColor); List <CustomVertex.PositionColored> curve3 = getCurveFromPoints(pt2, pt3, selectLineColor); List <CustomVertex.PositionColored> curve4 = getCurveFromPoints(pt3, pt0, selectLineColor); List <CustomVertex.PositionColored> curve5 = getCurveFromPoints(pt0, pt2, selectLineColor); List <CustomVertex.PositionColored> curve6 = getCurveFromPoints(pt2, pt1, selectLineColor); List <CustomVertex.PositionColored> curve7 = getCurveFromPoints(pt1, pt3, selectLineColor); CustomVertex.PositionColored[] ppcs = new CustomVertex.PositionColored[curve1.Count + curve2.Count + curve3.Count + curve4.Count + curve5.Count + curve6.Count + curve7.Count - 6]; curve1.CopyTo(ppcs); curve2.CopyTo(1, ppcs, curve1.Count, curve2.Count - 1); curve3.CopyTo(1, ppcs, curve1.Count + curve2.Count - 1, curve3.Count - 1); curve4.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count - 2, curve4.Count - 1); curve5.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count + curve4.Count - 3, curve5.Count - 1); curve6.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count + curve4.Count + curve5.Count - 4, curve6.Count - 1); curve7.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count + curve4.Count + curve5.Count + curve6.Count - 5, curve7.Count - 1); m_selectExtentsPCs.Add(ppcs); } }
/// <summary> /// Actualizar valores de renderizado. /// Hay que llamarlo al menos una vez para poder hacer Render() /// </summary> public void updateValues() { //Crear VertexBuffer on demand if (vertexBuffer == null || vertexBuffer.Disposed) { vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), BoundingVertices.Length, D3DDevice.Instance.Device, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default); //Shader Effect = TgcShaders.Instance.VariosShader; Technique = TgcShaders.T_POSITION_COLORED; } //Crear como TriangleFan var c = Color.ToArgb(); var vertices = new CustomVertex.PositionColored[BoundingVertices.Length]; for (var i = 0; i < BoundingVertices.Length; i++) { vertices[i] = new CustomVertex.PositionColored(BoundingVertices[i], c); } //Cargar vertexBuffer vertexBuffer.SetData(vertices, 0, LockFlags.None); }
// Default 값 public void setCollisionBox() { if (null != m_CollisionBox) { m_CollisionBox.Dispose(); } m_CollisionBox = new VertexBuffer(typeof(CustomVertex.PositionColored), 8, m_device, 0, CustomVertex.PositionColored.Format, Pool.Default); CustomVertex.PositionColored[] posColoredVerts = new CustomVertex.PositionColored[8]; for (int i = 0; i < posColoredVerts.Length; ++i ) { posColoredVerts[i].Position = new Vector3(0, 0, 0); posColoredVerts[i].Color = System.Drawing.Color.Black.ToArgb(); } GraphicsStream gstm = m_CollisionBox.Lock(0, 0, LockFlags.None); gstm.Write(posColoredVerts); m_CollisionBox.Unlock(); // indexedBuffer m_IndexBuffer = new IndexBuffer(m_device, 12 * 2 * 2, Usage.WriteOnly, Pool.Managed, true); GraphicsStream idstm = m_IndexBuffer.Lock(0, 0, LockFlags.None); idstm.Write(m_IndexedBufferOrder); m_IndexBuffer.Unlock(); }
/// <summary> /// 选中输入的范围框 /// </summary> /// <param name="rects">要选中的范围框列表</param> /// <param name="selectLineColor">选中范围框的颜色</param> public void SelectExtents1(List <List <float> > rects, Color selectLineColor) { m_selectExtentsPCs = new List <CustomVertex.PositionColored[]>(); foreach (List <float> rf in rects) { Point3d pt0 = createPoint3dByLatLon(rf[1], rf[0]); Point3d pt1 = createPoint3dByLatLon(rf[3], rf[2]); Point3d pt2 = createPoint3dByLatLon(rf[5], rf[4]); Point3d pt3 = createPoint3dByLatLon(rf[7], rf[6]); List <CustomVertex.PositionColored> curve1 = getCurveFromPoints(pt0, pt1, selectLineColor); List <CustomVertex.PositionColored> curve2 = getCurveFromPoints(pt1, pt2, selectLineColor); List <CustomVertex.PositionColored> curve3 = getCurveFromPoints(pt2, pt3, selectLineColor); List <CustomVertex.PositionColored> curve4 = getCurveFromPoints(pt3, pt0, selectLineColor); List <CustomVertex.PositionColored> curve5 = getCurveFromPoints(pt0, pt2, selectLineColor); List <CustomVertex.PositionColored> curve6 = getCurveFromPoints(pt2, pt1, selectLineColor); List <CustomVertex.PositionColored> curve7 = getCurveFromPoints(pt1, pt3, selectLineColor); CustomVertex.PositionColored[] ppcs = new CustomVertex.PositionColored[curve1.Count + curve2.Count + curve3.Count + curve4.Count + curve5.Count + curve6.Count + curve7.Count - 6]; curve1.CopyTo(ppcs); curve2.CopyTo(1, ppcs, curve1.Count, curve2.Count - 1); curve3.CopyTo(1, ppcs, curve1.Count + curve2.Count - 1, curve3.Count - 1); curve4.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count - 2, curve4.Count - 1); curve5.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count + curve4.Count - 3, curve5.Count - 1); curve6.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count + curve4.Count + curve5.Count - 4, curve6.Count - 1); curve7.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count + curve4.Count + curve5.Count + curve6.Count - 5, curve7.Count - 1); m_selectExtentsPCs.Add(ppcs); } }
public void VertexContainer(object sender, EventArgs e) { Device dev = (Device)sender; // Set culling so we're not rendering the back of our triangle dev.RenderState.CullMode = Cull.CounterClockwise; // Turn off D3D lighting, since we are providing our own vertex colors dev.RenderState.Lighting = false; // Create an instance of ready-made DirectX VertexBuffer vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, dev, 0, CustomVertex.PositionColored.Format, Pool.Default); // Lock our buffer so nothing gets changed while we are reading the data GraphicsStream GraphixStream = vertexBuffer.Lock(0, 0, 0); CustomVertex.PositionColored[] VerticeArray = new CustomVertex.PositionColored[3]; VerticeArray[0].Position = new Vector3(-0.5f, 0.5f, 0); // top right Vertice VerticeArray[0].Color = System.Drawing.Color.Yellow.ToArgb(); VerticeArray[1].Position = new Vector3(0.5f, -0.5f, 0); // bottom right VerticeArray[1].Color = System.Drawing.Color.Orange.ToArgb(); VerticeArray[2].Position = new Vector3(-0.5f, -0.5f, 0); // bottom left VerticeArray[2].Color = System.Drawing.Color.Red.ToArgb(); GraphixStream.Write(VerticeArray); vertexBuffer.Unlock(); }
// override // 자 이 함수가 뭐냐면 오브젝트의 로컬 좌표계 기준으로 오브젝트 중심이 (0, 0, 0)일 때 // 축 길이를 조절할 수 있는 함수입니다 public void setCollisionBox(float axisLenX, float axisLenY, float axisLenZ) { if (null != m_CollisionBox) { m_CollisionBox.Dispose(); } m_CollisionBox = new VertexBuffer(typeof(CustomVertex.PositionColored), 8, m_device, 0, CustomVertex.PositionColored.Format, Pool.Default); CustomVertex.PositionColored[] posColoredVerts = new CustomVertex.PositionColored[8]; posColoredVerts[0].Position = new Vector3(-axisLenX, axisLenY, -axisLenZ); posColoredVerts[0].Color = System.Drawing.Color.Black.ToArgb(); posColoredVerts[1].Position = new Vector3(axisLenX, axisLenY, -axisLenZ); posColoredVerts[1].Color = System.Drawing.Color.Black.ToArgb(); posColoredVerts[2].Position = new Vector3(axisLenX, axisLenY, axisLenZ); posColoredVerts[2].Color = System.Drawing.Color.Black.ToArgb(); posColoredVerts[3].Position = new Vector3(-axisLenX, axisLenY, axisLenZ); posColoredVerts[3].Color = System.Drawing.Color.Black.ToArgb(); posColoredVerts[4].Position = new Vector3(-axisLenX, -axisLenY, -axisLenZ); posColoredVerts[4].Color = System.Drawing.Color.Black.ToArgb(); posColoredVerts[5].Position = new Vector3(axisLenX, -axisLenY, -axisLenZ); posColoredVerts[5].Color = System.Drawing.Color.Crimson.ToArgb(); posColoredVerts[6].Position = new Vector3(axisLenX, -axisLenY, axisLenZ); posColoredVerts[6].Color = System.Drawing.Color.Crimson.ToArgb(); posColoredVerts[7].Position = new Vector3(-axisLenX, -axisLenY, axisLenZ); posColoredVerts[7].Color = System.Drawing.Color.Crimson.ToArgb(); GraphicsStream gstm = m_CollisionBox.Lock(0, 0, LockFlags.None); gstm.Write(posColoredVerts); m_CollisionBox.Unlock(); }
// Default 값 public void setCollisionBox() { if (null != m_CollisionBox) { m_CollisionBox.Dispose(); } m_CollisionBox = new VertexBuffer(typeof(CustomVertex.PositionColored), 8, m_device, 0, CustomVertex.PositionColored.Format, Pool.Default); CustomVertex.PositionColored[] posColoredVerts = new CustomVertex.PositionColored[8]; for (int i = 0; i < posColoredVerts.Length; ++i) { posColoredVerts[i].Position = new Vector3(0, 0, 0); posColoredVerts[i].Color = System.Drawing.Color.Black.ToArgb(); } GraphicsStream gstm = m_CollisionBox.Lock(0, 0, LockFlags.None); gstm.Write(posColoredVerts); m_CollisionBox.Unlock(); // indexedBuffer m_IndexBuffer = new IndexBuffer(m_device, 12 * 2 * 2, Usage.WriteOnly, Pool.Managed, true); GraphicsStream idstm = m_IndexBuffer.Lock(0, 0, LockFlags.None); idstm.Write(m_IndexedBufferOrder); m_IndexBuffer.Unlock(); }
protected void UpdateTrackVertexList() { if (State == DrawState.Drawing && !movingPt.IsNaN && PointList.Count > 0) { Point3d[] Pts = new Point3d[4]; Pts[0] = PointList[0]; Pts[1] = new Point3d(Pts[0].X, movingPt.Y, Pts[0].Z); Pts[2] = movingPt; Pts[3] = new Point3d(movingPt.X, Pts[0].Y, Pts[0].Z); if (movingFill) { CreatePolygon(Pts); } else { List <CustomVertex.PositionColored> movingPcs1 = getCurveFromPoints(Pts[0], Pts[1], lineColor); List <CustomVertex.PositionColored> movingPcs2 = getCurveFromPoints(Pts[1], Pts[2], lineColor); List <CustomVertex.PositionColored> movingPcs3 = getCurveFromPoints(Pts[2], Pts[3], lineColor); List <CustomVertex.PositionColored> movingPcs4 = getCurveFromPoints(Pts[3], Pts[0], lineColor); pcs = null; pcs = new CustomVertex.PositionColored[movingPcs1.Count + movingPcs2.Count + movingPcs3.Count + movingPcs4.Count - 3]; movingPcs1.CopyTo(pcs); movingPcs2.CopyTo(1, pcs, movingPcs1.Count, movingPcs2.Count - 1); movingPcs3.CopyTo(1, pcs, movingPcs1.Count + movingPcs2.Count - 1, movingPcs3.Count - 1); movingPcs4.CopyTo(1, pcs, movingPcs1.Count + movingPcs2.Count + movingPcs3.Count - 2, movingPcs4.Count - 1); } } }
//画多边形 public void UpdateExtents(List <List <float> > rects) { m_listpcs.Clear(); foreach (List <float> rect in rects) { Point3d pt0 = createPoint3dByLatLon(rect[1], rect[0]); Point3d pt1 = createPoint3dByLatLon(rect[3], rect[2]); Point3d pt2 = createPoint3dByLatLon(rect[5], rect[4]); Point3d pt3 = createPoint3dByLatLon(rect[7], rect[6]); List <CustomVertex.PositionColored> curve1 = getCurveFromPoints(pt0, pt1, lineColor); List <CustomVertex.PositionColored> curve2 = getCurveFromPoints(pt1, pt2, lineColor); List <CustomVertex.PositionColored> curve3 = getCurveFromPoints(pt2, pt3, lineColor); List <CustomVertex.PositionColored> curve4 = getCurveFromPoints(pt3, pt0, lineColor); CustomVertex.PositionColored[] ppcs = new CustomVertex.PositionColored[curve1.Count + curve2.Count + curve3.Count + curve4.Count - 3]; curve1.CopyTo(ppcs); curve2.CopyTo(1, ppcs, curve1.Count, curve2.Count - 1); curve3.CopyTo(1, ppcs, curve1.Count + curve2.Count - 1, curve3.Count - 1); curve4.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count - 2, curve4.Count - 1); m_listpcs.Add(ppcs); } this.Render(this.drawArgs);//20130926 DLF 解决切片查询不重绘问题 }
/// <summary> Create the Vertex Array. </summary> /// <remarks>Where our Vertice Points are initially stored with each of /// their positions in 3D space in X, Y, and Z coordinates. /// Also any color or texture information.</remarks> public void CreateVertexArray(object sender, EventArgs e) { CustomVertex.PositionColored[] VerticeArray = // Declare a new Array called VerticeArray new CustomVertex.PositionColored[NumberOfVertices]; // Type of Vertices and number of Points // Draw TriangleFan from Vertice Points in a clockwise direction VerticeArray[0].Position = new Vector3(0.0f, 0.32f, 0.0f); // Top Center VerticeArray[0].Color = System.Drawing.Color.Yellow.ToArgb(); VerticeArray[1].Position = new Vector3(-0.32f, -0.32f, 0.32f); // Left Bottom Rear VerticeArray[1].Color = System.Drawing.Color.Yellow.ToArgb(); VerticeArray[2].Position = new Vector3(0.32f, -0.32f, 0.32f); // Right Bottom Rear VerticeArray[2].Color = System.Drawing.Color.Orange.ToArgb(); VerticeArray[3].Position = new Vector3(0.32f, -0.32f, -0.32f); // Right Bottom Front VerticeArray[3].Color = System.Drawing.Color.Red.ToArgb(); VerticeArray[4].Position = new Vector3(-0.32f, -0.32f, -0.32f); // Bottom Front Left VerticeArray[4].Color = System.Drawing.Color.Orange.ToArgb(); VerticeArray[5].Position = new Vector3(-0.32f, -0.32f, 0.32f); // Left Bottom Rear VerticeArray[5].Color = System.Drawing.Color.Yellow.ToArgb(); vertexBuffer.SetData(VerticeArray, 0, LockFlags.None); }
public override void init() { Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice; //Cuerpo principal que se controla con el teclado box = TgcBox.fromSize(new Vector3(0, 10, 0), new Vector3(10, 10, 10), Color.Blue); //triangulo triangle = new CustomVertex.PositionColored[3]; triangle[0] = new CustomVertex.PositionColored(-100, 0, 0, Color.Red.ToArgb()); triangle[1] = new CustomVertex.PositionColored(0, 0, 50, Color.Green.ToArgb()); triangle[2] = new CustomVertex.PositionColored(0, 100, 0, Color.Blue.ToArgb()); triagleAABB = TgcBoundingBox.computeFromPoints(new Vector3[] { triangle[0].Position, triangle[1].Position, triangle[2].Position }); //box2 box2 = TgcBox.fromSize(new Vector3(-50, 10, -20), new Vector3(15, 15, 15), Color.Violet); //sphere sphere = new TgcBoundingSphere(new Vector3(30, 20, -20), 15); //OBB: computar OBB a partir del AABB del mesh. TgcSceneLoader loader = new TgcSceneLoader(); TgcMesh meshObb = loader.loadSceneFromFile(GuiController.Instance.ExamplesMediaDir + "MeshCreator\\Meshes\\Vehiculos\\StarWars-ATST\\StarWars-ATST-TgcScene.xml").Meshes[0]; obb = TgcObb.computeFromAABB(meshObb.BoundingBox); meshObb.dispose(); obb.move(new Vector3(100, 0, 30)); obb.setRotation(new Vector3(0, FastMath.PI / 4, 0)); //Configurar camara en Tercer Persona GuiController.Instance.ThirdPersonCamera.Enable = true; GuiController.Instance.ThirdPersonCamera.setCamera(box.Position, 30, -75); }
/// <summary> /// Renders the flattened path to the device using the specified color. /// </summary> /// <param name="device">The device to use for rendering the path.</param> /// <param name="color">The color to use for the vertices.</param> /// <param name="flattenedPath">The path to render.</param> protected virtual void Render(Device device, int color, GraphicsPath flattenedPath) { PointF[] points = flattenedPath.PathPoints; device.VertexFormat = CustomVertex.PositionColored.Format; bool isClosed; GraphicsPathIterator pi = new GraphicsPathIterator(flattenedPath); while (pi.NextSubpath(flattenedPath, out isClosed) != 0) { byte type; int start, end; while (pi.NextPathType(out type, out start, out end) != 0) { int numDistinctPoints = end - start + 1; int totNumPoints = numDistinctPoints; if (isClosed) { totNumPoints++; } CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[totNumPoints]; P3Util.CreateColoredVertexList(colVerts, points, start, 0, numDistinctPoints, color); if (isClosed) { colVerts[numDistinctPoints] = colVerts[0]; } device.DrawUserPrimitives(PrimitiveType.LineStrip, totNumPoints - 1, colVerts); } } }
private void drawFrame() { CustomVertex.PositionColored[] frameVertices = new CustomVertex.PositionColored[8]; frameVertices[0].X = minX - (dx * 0.5f); frameVertices[0].Y = minY - (dy * 0.5f); frameVertices[0].Z = maxZ; frameVertices[0].Color = Color.Black.ToArgb(); frameVertices[1].X = minX - (dx * 0.5f); frameVertices[1].Y = maxY + (dy * 0.5f); frameVertices[1].Z = maxZ; frameVertices[1].Color = Color.Black.ToArgb(); frameVertices[2].X = minX - (dx * 0.5f); frameVertices[2].Y = maxY + (dy * 0.5f); frameVertices[2].Z = maxZ; frameVertices[2].Color = Color.Navy.ToArgb(); frameVertices[3].X = maxX + (dx * 0.5f); frameVertices[3].Y = maxY + (dy * 0.5f); frameVertices[3].Z = maxZ; frameVertices[3].Color = Color.Navy.ToArgb(); frameVertices[4].X = maxX + (dx * 0.5f); frameVertices[4].Y = maxY + (dy * 0.5f); frameVertices[4].Z = maxZ; frameVertices[4].Color = Color.Black.ToArgb(); frameVertices[5].X = maxX + (dx * 0.5f); frameVertices[5].Y = minY - (dy * 0.5f); frameVertices[5].Z = maxZ; frameVertices[5].Color = Color.Black.ToArgb(); frameVertices[6].X = maxX + (dx * 0.5f); frameVertices[6].Y = minY - (dy * 0.5f); frameVertices[6].Z = maxZ; frameVertices[6].Color = Color.Red.ToArgb(); frameVertices[7].X = minX - (dx * 0.5f); frameVertices[7].Y = minY - (dy * 0.5f); frameVertices[7].Z = maxZ; frameVertices[7].Color = Color.Red.ToArgb(); // Create a vertex buffer to hold vertices VertexBuffer frameVertBuffer = new VertexBuffer( typeof(CustomVertex.PositionColored), // type of the buffer frameVertices.Length * CustomVertex.PositionColored.StrideSize, //size map.device, // device Usage.WriteOnly, // write only CustomVertex.PositionColored.Format, // format required Pool.SystemMemory); // Set the data in the vertex buffer to our triangles frameVertBuffer.SetData(frameVertices, 0, LockFlags.None); map.device.SetStreamSource(0, frameVertBuffer, 0); map.device.DrawPrimitives(PrimitiveType.LineList, 0, 4); }
/// <summary> /// Actualizar parámetros de la línea en base a los valores configurados /// </summary> public void updateValues() { var c = color.ToArgb(); vertices[0] = new CustomVertex.PositionColored(PStart, c); vertices[1] = new CustomVertex.PositionColored(PEnd, c); }
public void Poke( DateTime timestamp, Device world ) { var vb = new VertexBuffer( typeof( CustomVertex.PositionColored ), 6, world, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default ); var vertices = new CustomVertex.PositionColored[6]; int i = 0; vertices[i].Color = System.Drawing.Color.Gray.ToArgb(); vertices[i++].Position = new Vector3( 100, 200, 1 ); vertices[i].Color = System.Drawing.Color.Gray.ToArgb(); vertices[i++].Position = new Vector3( 0, 100, 1 ); vertices[i].Color = System.Drawing.Color.Gray.ToArgb(); vertices[i++].Position = new Vector3( 200, 100, 1 ); vertices[i].Color = System.Drawing.Color.Gray.ToArgb(); vertices[i++].Position = new Vector3( 200, 300, 1 ); vertices[i].Color = System.Drawing.Color.Gray.ToArgb(); vertices[i++].Position = new Vector3( 0, 300, 1 ); vertices[i].Color = System.Drawing.Color.Gray.ToArgb(); vertices[i++].Position = new Vector3( 0, 100, 1 ); vb.SetData( vertices, 0, LockFlags.None ); world.SetStreamSource( 1, vb, 0 ); world.DrawPrimitives( PrimitiveType.TriangleFan, 0, 6 ); }
public void Init(Device device) { this.device = device; ray = new CustomVertex.PositionColored[2]; ray[0] = new CustomVertex.PositionColored(start, Color.Red.ToArgb()); ray[1] = new CustomVertex.PositionColored(end, Color.Red.ToArgb()); }
/// <summary> /// Renders the list of primitives to the device. /// </summary> /// <param name="device">The device to use for rendering the primitives.</param> /// <param name="renderList">The list of primitives to render.</param> protected virtual void Render(Device device, ArrayList renderList) { PointF[] points = (PointF[])renderList.ToArray(typeof(PointF)); device.VertexFormat = CustomVertex.PositionColored.Format; for (int i = 0; i < renderListTypes.Count; i++) { PrimitiveTypeInfo pti = (PrimitiveTypeInfo)renderListTypes[i]; int numVerts = (pti.End - pti.Start + 1); CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[numVerts]; P3Util.CreateColoredVertexList(colVerts, points, pti.Start, 0, numVerts, pti.Color); switch (pti.Type) { case PrimitiveType.TriangleFan: device.DrawUserPrimitives(PrimitiveType.TriangleFan, colVerts.Length - 2, colVerts); break; case PrimitiveType.TriangleList: device.DrawUserPrimitives(PrimitiveType.TriangleList, colVerts.Length / 3, colVerts); break; case PrimitiveType.TriangleStrip: device.DrawUserPrimitives(PrimitiveType.TriangleStrip, colVerts.Length - 2, colVerts); break; } } }
void DrawBackground() { render.Transform.Ortho(); render.State.DepthTest(false); CustomVertex.PositionColored[] backgr = new CustomVertex.PositionColored[6]; backgr[0].Color = System.Drawing.Color.FromArgb(1, 0, 0, 0).ToArgb(); backgr[1].Color = backgr[0].Color; backgr[2].Color = System.Drawing.Color.FromArgb(1, 200, 200, 150).ToArgb(); backgr[3].Color = backgr[2].Color; backgr[4].Color = backgr[2].Color; backgr[5].Color = backgr[0].Color; backgr[0].Position = new Vector3(-1, -1, 0); backgr[1].Position = new Vector3(1, -1, 1); backgr[2].Position = new Vector3(1, 1, 1); backgr[3].Position = new Vector3(1, 1, 0); backgr[4].Position = new Vector3(-1, 1, 0); backgr[5].Position = new Vector3(-1, -1, 0); render.Draw.Triangles(backgr); render.State.DepthTest(true); render.Transform.Projection(); render.Transform.ViewByCam(cam); }
public void UpdateExtents(List <RectangleF> rects) { listpcs.Clear(); foreach (RectangleF rect in rects) { Point3d pt0 = CreatePoint3dByLatLon(rect.Y, rect.X); Point3d pt1 = CreatePoint3dByLatLon(rect.Y, rect.Right); Point3d pt2 = CreatePoint3dByLatLon(rect.Bottom, rect.Right); Point3d pt3 = CreatePoint3dByLatLon(rect.Bottom, rect.X); List <CustomVertex.PositionColored> curve1 = getCurveFromPoints(pt0, pt1, m_LineColorAtImageMode); List <CustomVertex.PositionColored> curve2 = getCurveFromPoints(pt1, pt2, m_LineColorAtImageMode); List <CustomVertex.PositionColored> curve3 = getCurveFromPoints(pt2, pt3, m_LineColorAtImageMode); List <CustomVertex.PositionColored> curve4 = getCurveFromPoints(pt3, pt0, m_LineColorAtImageMode); CustomVertex.PositionColored[] ppcs = new CustomVertex.PositionColored[curve1.Count + curve2.Count + curve3.Count + curve4.Count - 3]; curve1.CopyTo(ppcs); curve2.CopyTo(1, ppcs, curve1.Count, curve2.Count - 1); curve3.CopyTo(1, ppcs, curve1.Count + curve2.Count - 1, curve3.Count - 1); curve4.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count - 2, curve4.Count - 1); listpcs.Add(ppcs); } }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { try { device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1.0f, 0); SetupCamera(); device.BeginScene(); for (int i = 0; i < matrMin.GetLength(0); i++) { DrawCube((float)matrMin[i, 0], (float)matrMax[i, 0], (float)matrMin[i, 1], (float)matrMax[i, 1], (float)matrMin[i, 2], (float)matrMax[i, 2], arrTexture[i]); } int lc2 = Color.Black.ToArgb(); CustomVertex.PositionColored[] arrVL2 = new CustomVertex.PositionColored[] { new CustomVertex.PositionColored(0, 0, 0, lc2), new CustomVertex.PositionColored(1.2f, 0, 0, lc2), new CustomVertex.PositionColored(0, 0, 0, lc2), new CustomVertex.PositionColored(0, 1.2f, 0, lc2), new CustomVertex.PositionColored(0, 0, 0, lc2), new CustomVertex.PositionColored(0, 0, 1.2f, lc2) }; device.DrawUserPrimitives(PrimitiveType.LineList, 3, arrVL2); device.EndScene(); device.Present(); } catch { } }
public override List <RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform) { List <RenderInfo> result = new List <RenderInfo>(); transform.Push(); transform.NJTranslate(item.Position); int x = item.Rotation.X; int y = item.Rotation.Y; if (!item.Scale.IsEmpty) { (item.Position - item.Scale).GetRotation(out x, out y); } transform.NJRotateX(x); transform.NJRotateY(y); transform.NJRotateZ(item.Rotation.Z); result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), meshes)); if (item.Selected) { result.AddRange(model.DrawModelTreeInvert(transform, meshes)); } transform.Pop(); if (item.Selected) { CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[2]; verts[0] = new CustomVertex.PositionColored(item.Position.ToVector3(), System.Drawing.Color.Yellow.ToArgb()); verts[1] = new CustomVertex.PositionColored(item.Scale.ToVector3(), System.Drawing.Color.Yellow.ToArgb()); dev.VertexFormat = VertexFormats.Position | VertexFormats.Diffuse; dev.DrawUserPrimitives(PrimitiveType.LineList, 1, verts); } return(result); }
static public void DrawRotationMatrix(Matrix mat) { float scale = 2.0f; CustomVertex.PositionColored[] vertices = new CustomVertex.PositionColored[6]; //x-axis vertices[0].Position = new Vector3(0, 0, 0); vertices[0].Color = Color.Red.ToArgb(); vertices[1].Position = new Vector3(mat.M11 * scale, mat.M21 * scale, mat.M31 * scale); vertices[1].Color = Color.Red.ToArgb(); //y-axis vertices[2].Position = new Vector3(0, 0, 0); vertices[2].Color = Color.Blue.ToArgb(); vertices[3].Position = new Vector3(mat.M12 * scale, mat.M22 * scale, mat.M32 * scale); vertices[3].Color = Color.Blue.ToArgb(); //z-axis vertices[4].Position = new Vector3(0, 0, 0); vertices[4].Color = Color.Green.ToArgb(); vertices[5].Position = new Vector3(mat.M13 * scale, mat.M23 * scale, mat.M33 * scale); vertices[5].Color = Color.Green.ToArgb(); MdxRender.Dev.VertexFormat = CustomVertex.PositionColored.Format; MdxRender.Dev.DrawUserPrimitives(PrimitiveType.LineList, 3, vertices); }
public static void DrawColoredRectangle(Device dev,RectangleF rect,Color color) { VertexBuffer vb=null; IndexBuffer ib=null; try{ int colorArgb=color.ToArgb(); CustomVertex.PositionColored[] quadVerts=new CustomVertex.PositionColored[] { new CustomVertex.PositionColored(rect.Left,rect.Bottom,0,colorArgb), new CustomVertex.PositionColored(rect.Left,rect.Top,0,colorArgb), new CustomVertex.PositionColored(rect.Right,rect.Top,0,colorArgb), new CustomVertex.PositionColored(rect.Right,rect.Bottom,0,colorArgb), }; vb=new VertexBuffer(typeof(CustomVertex.PositionColored), CustomVertex.PositionColored.StrideSize*quadVerts.Length, dev,Usage.WriteOnly,CustomVertex.PositionColored.Format,Pool.Managed); vb.SetData(quadVerts,0,LockFlags.None); int[] indicies=new int[] { 0,1,2,0,2,3 }; ib=new IndexBuffer(typeof(int),indicies.Length,dev,Usage.None,Pool.Managed); ib.SetData(indicies,0,LockFlags.None); dev.VertexFormat=CustomVertex.PositionColored.Format; dev.SetStreamSource(0,vb,0); dev.Indices=ib; dev.DrawIndexedPrimitives(PrimitiveType.TriangleList,0,0,quadVerts.Length,0,indicies.Length/3); }finally{ if(vb!=null){ vb.Dispose(); vb=null; } if(ib!=null){ ib.Dispose(); ib=null; } } }
//test public void DrawVertical() { CustomVertex.PositionColored[] pcList = new CustomVertex.PositionColored[(PointList.Count + 1) * 2]; int j = 0; for (int i = 0; i < PointList.Count + 1; i++) { Point3d curPoint = (i == PointList.Count) ? PointList[0] : PointList[i]; Point3d verticalPt = new Point3d(curPoint.X, curPoint.Y, curPoint.Z + DistanceAboveSurface); CustomVertex.PositionColored newPc = Point3d2PositionColored(verticalPt, Color.FromArgb(128, fillColor)); pcList[j] = newPc; j++; Point3d groundPt = new Point3d(curPoint.X, curPoint.Y, 0); CustomVertex.PositionColored newPc2 = Point3d2PositionColored(groundPt, Color.FromArgb(128, fillColor)); pcList[j] = newPc2; j++; } Vector3 rc = new Vector3( (float)drawArgs.WorldCamera.ReferenceCenter.X, (float)drawArgs.WorldCamera.ReferenceCenter.Y, (float)drawArgs.WorldCamera.ReferenceCenter.Z ); drawArgs.device.Transform.World = Matrix.Translation(-rc); //float oldWidth = drawArgs.device.RenderState.PointSize; //drawArgs.device.RenderState.PointSize = 3.5f; drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleStrip, pcList.Length - 2, pcList); //drawArgs.device.RenderState.PointSize = oldWidth; drawArgs.device.Transform.World = drawArgs.WorldCamera.WorldMatrix; }
public void UpdateExtents(List <RectangleF> rects) { listpcs.Clear(); foreach (RectangleF rect in rects) { Point3d pt0 = CreatePoint3dByLatLon(rect.Y, rect.X); Point3d pt1 = CreatePoint3dByLatLon(rect.Y, rect.Right); Point3d pt2 = CreatePoint3dByLatLon(rect.Bottom, rect.Right); Point3d pt3 = CreatePoint3dByLatLon(rect.Bottom, rect.X); List <CustomVertex.PositionColored> curve1 = getCurveFromPoints(pt0, pt1, lineColor); List <CustomVertex.PositionColored> curve2 = getCurveFromPoints(pt1, pt2, lineColor); List <CustomVertex.PositionColored> curve3 = getCurveFromPoints(pt2, pt3, lineColor); List <CustomVertex.PositionColored> curve4 = getCurveFromPoints(pt3, pt0, lineColor); CustomVertex.PositionColored[] ppcs = new CustomVertex.PositionColored[curve1.Count + curve2.Count + curve3.Count + curve4.Count - 3]; curve1.CopyTo(ppcs); curve2.CopyTo(1, ppcs, curve1.Count, curve2.Count - 1); curve3.CopyTo(1, ppcs, curve1.Count + curve2.Count - 1, curve3.Count - 1); curve4.CopyTo(1, ppcs, curve1.Count + curve2.Count + curve3.Count - 2, curve4.Count - 1); listpcs.Add(ppcs); } this.Render(this.drawArgs);//20130926 DLF 解决切片查询不重绘问题 }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; //Crear VertexBuffer vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, d3dDevice, Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default); //Cargar informacion de vertices: (X,Y,Z) + Color data = new CustomVertex.PositionColored[3]; data[0] = new CustomVertex.PositionColored(-1, 0, 0, Color.Red.ToArgb()); data[1] = new CustomVertex.PositionColored(1, 0, 0, Color.Green.ToArgb()); data[2] = new CustomVertex.PositionColored(0, 1, 0, Color.Blue.ToArgb()); //FPS Camara GuiController.Instance.FpsCamera.Enable = false; GuiController.Instance.FpsCamera.setCamera(new Vector3(0.5f, 0,-3), new Vector3(0, 0, 0)); //User Vars GuiController.Instance.UserVars.addVar("Vertices", 0); GuiController.Instance.UserVars.addVar("Triangles", 0); GuiController.Instance.Modifiers.addFloat("translateX", -5, 5f, 0f); GuiController.Instance.Modifiers.addFloat("rotationZ", 0, (float)(2.0f * Math.PI), 0f); GuiController.Instance.Modifiers.addFloat("ScaleXYZ", 0, 3, 1f); }
private void InitVertexBuffer() { vertexBuffer[0] = new CustomVertex.PositionColored(-0.25f, -triangleHeight / 2f, 0f, 0xFF0000); vertexBuffer[1] = new CustomVertex.PositionColored(0.25f, -triangleHeight / 2f, 0f, 0x00FF00); vertexBuffer[2] = new CustomVertex.PositionColored(0f, triangleHeight / 2f, 0f, 0x0000FF); vertexBuffer[3] = new CustomVertex.PositionColored(-0.25f, -triangleHeight / 2f, 0.1f, 0xFF0000); vertexBuffer[4] = new CustomVertex.PositionColored(0.25f, -triangleHeight / 2f, 0.1f, 0x00FF00); vertexBuffer[5] = new CustomVertex.PositionColored(0f, triangleHeight / 2f, 0f, 0x0000FF); vertexBuffer[6] = new CustomVertex.PositionColored(-0.25f, -triangleHeight / 2f, 0f, 0xFF0000); vertexBuffer[7] = new CustomVertex.PositionColored(-0.25f, -triangleHeight / 2f, 0.1f, 0x00FF00); vertexBuffer[8] = new CustomVertex.PositionColored(0f, triangleHeight / 2f, 0f, 0x0000FF); vertexBuffer[9] = new CustomVertex.PositionColored(0.25f, -triangleHeight / 2f, 0f, 0xFF0000); vertexBuffer[10] = new CustomVertex.PositionColored(0.25f, -triangleHeight / 2f, 0.1f, 0x00FF00); vertexBuffer[11] = new CustomVertex.PositionColored(0f, triangleHeight / 2f, 0f, 0x0000FF); vertexBuffer[12] = new CustomVertex.PositionColored(-0.25f, -triangleHeight / 2f, 0f, 0xFF0000); vertexBuffer[13] = new CustomVertex.PositionColored(-0.25f, -triangleHeight / 2f, 0.1f, 0xFFFF00); vertexBuffer[14] = new CustomVertex.PositionColored(0.25f, -triangleHeight / 2f, 0f, 0xFF00FF); vertexBuffer[15] = new CustomVertex.PositionColored(0.25f, -triangleHeight / 2f, 0f, 0xFFFF00); vertexBuffer[16] = new CustomVertex.PositionColored(0.25f, -triangleHeight / 2f, 0.1f, 0x00FF00); vertexBuffer[17] = new CustomVertex.PositionColored(-0.25f, -triangleHeight / 2f, 0.1f, 0x00FFFF); }
/// <summary> /// Construye el mesh del Elipsoid /// </summary> private void updateValues() { if (vertices == null) { int verticesCount = (ELIPSOID_MESH_RESOLUTION * 2 + 2) * 3; this.vertices = new CustomVertex.PositionColored[verticesCount]; } int index = 0; float step = FastMath.TWO_PI / (float)ELIPSOID_MESH_RESOLUTION; // Plano XY for (float a = 0f; a <= FastMath.TWO_PI; a += step) { vertices[index++] = new CustomVertex.PositionColored(new Vector3(FastMath.Cos(a) * radius.X, FastMath.Sin(a) * radius.Y, 0f) + center, renderColor); vertices[index++] = new CustomVertex.PositionColored(new Vector3(FastMath.Cos(a + step) * radius.X, FastMath.Sin(a + step) * radius.Y, 0f) + center, renderColor); } // Plano XZ for (float a = 0f; a <= FastMath.TWO_PI; a += step) { vertices[index++] = new CustomVertex.PositionColored(new Vector3(FastMath.Cos(a) * radius.X, 0f, FastMath.Sin(a) * radius.Z) + center, renderColor); vertices[index++] = new CustomVertex.PositionColored(new Vector3(FastMath.Cos(a + step) * radius.X, 0f, FastMath.Sin(a + step) * radius.Z) + center, renderColor); } // Plano YZ for (float a = 0f; a <= FastMath.TWO_PI; a += step) { vertices[index++] = new CustomVertex.PositionColored(new Vector3(0f, FastMath.Cos(a) * radius.Y, FastMath.Sin(a) * radius.Z) + center, renderColor); vertices[index++] = new CustomVertex.PositionColored(new Vector3(0f, FastMath.Cos(a + step) * radius.Y, FastMath.Sin(a + step) * radius.Z) + center, renderColor); } }
public static void CreateCoordLines() { lines = new CustomVertex.PositionColored[6]; lines[1] = lines[3] = lines[5] = new CustomVertex.PositionColored(new Vector3(0, 0, 0), 0); lines[0] = new CustomVertex.PositionColored(new Vector3(1, 0, 0), 0); lines[2] = new CustomVertex.PositionColored(new Vector3(0, 1, 0), 0); lines[4] = new CustomVertex.PositionColored(new Vector3(0, 0, 1), 0); }
private static void BuildRingOnZ(CustomVertex.PositionColored[] verts, int index, int clr, Vector2[] points) { int pIdx = 0; for (int i = index; i < index + points.Length; i++) { verts[i] = new CustomVertex.PositionColored(points[pIdx].X, points[pIdx].Y, 0, clr); pIdx++; } verts[index + points.Length] = new CustomVertex.PositionColored(points[0].X, points[0].Y, 0, clr); }
private void BuildGeometry() { geom = GpuDemGeometry.CreateGeometry(rDb, gDevice, out maxDataValue, reader); clipBottomSideQuad = new CustomVertex.PositionColored[4]; int clr = Color.DarkGray.ToArgb(); clipBottomSideQuad[1] = new CustomVertex.PositionColored(0, -0.5f, 0, clr); clipBottomSideQuad[0] = new CustomVertex.PositionColored(0, -0.5f, 5, clr); clipBottomSideQuad[3] = new CustomVertex.PositionColored(5, -0.5f, 0, clr); clipBottomSideQuad[2] = new CustomVertex.PositionColored(5, -0.5f, 5, clr); }
public Line(float x1, float y1, float x2, float y2) { Vertices = new CustomVertex.PositionColored[4]; Vertices[0] = new CustomVertex.PositionColored( new Vector3(x1, y2, 0.0f), Color.White.ToArgb()); Vertices[1] = new CustomVertex.PositionColored( new Vector3(x1, y1, 0.0f), Color.White.ToArgb()); Vertices[2] = new CustomVertex.PositionColored( new Vector3(x2, y2, 0.0f), Color.White.ToArgb()); Vertices[3] = new CustomVertex.PositionColored( new Vector3(x2, y1, 0.0f), Color.White.ToArgb()); }
public override void init() { Device d3dDevice = GuiController.Instance.D3dDevice; //Definir array de vertices para el triangulo, del tipo Coordendas (X,Y,Z) + Color data = new CustomVertex.PositionColored[3]; //Cargar información de vertices. Nesitamos 3 vertices para crear un triángulo data[0] = new CustomVertex.PositionColored(-1, 0, 0, Color.Red.ToArgb()); data[1] = new CustomVertex.PositionColored(1, 0, 0, Color.Green.ToArgb()); data[2] = new CustomVertex.PositionColored(0, 1, 0, Color.Blue.ToArgb()); //Configurar camara en rotacion GuiController.Instance.RotCamera.setCamera(new Vector3(0, 0.5f, 0), 3f); //Cargar variables de usuario con alguna informacion util para ver en pantalla GuiController.Instance.UserVars.addVar("Cantida de Vertices", data.Length); }
public ColorCube(Device i_dev, float i_size) { //立方体(頂点数8)の準備 this._vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 8, i_dev, Usage.None, CustomVertex.PositionColored.Format, _pool_mode); //8点の情報を格納するためのメモリを確保 CustomVertex.PositionColored[] vertices = new CustomVertex.PositionColored[8]; float size = i_size / 2; //頂点を設定 vertices[0] = new CustomVertex.PositionColored(-size, size, size, Color.Yellow.ToArgb()); vertices[1] = new CustomVertex.PositionColored(size, size, size, Color.Gray.ToArgb()); vertices[2] = new CustomVertex.PositionColored(-size, size, -size, Color.Purple.ToArgb()); vertices[3] = new CustomVertex.PositionColored(size, size, -size, Color.Red.ToArgb()); vertices[4] = new CustomVertex.PositionColored(-size, -size, size, Color.SkyBlue.ToArgb()); vertices[5] = new CustomVertex.PositionColored(size, -size, size, Color.Orange.ToArgb()); vertices[6] = new CustomVertex.PositionColored(-size, -size, -size, Color.Green.ToArgb()); vertices[7] = new CustomVertex.PositionColored(size, -size, -size, Color.Blue.ToArgb()); //頂点バッファをロックする using (GraphicsStream data = this._vertexBuffer.Lock(0, 0, LockFlags.None)) { // 頂点データを頂点バッファにコピーします data.Write(vertices); // 頂点バッファのロックを解除します this._vertexBuffer.Unlock(); } // インデックスバッファの作成 // 第2引数の数値は(三角ポリゴンの数)*(ひとつの三角ポリゴンの頂点数)* // (16 ビットのインデックスサイズ(2byte)) this._indexBuffer = new IndexBuffer(i_dev, 12 * 3 * 2, Usage.WriteOnly, _pool_mode, true); // インデックスバッファをロックする using (GraphicsStream data = this._indexBuffer.Lock(0, 0, LockFlags.None)) { // インデックスデータをインデックスバッファにコピーします data.Write(_vertexIndices); // インデックスバッファのロックを解除します this._indexBuffer.Unlock(); } return; }
public LineGrid(float w, float h, int rows, int cols) { Vertices = new CustomVertex.PositionColored[(rows + cols + 2) * 2]; for (int i = 0; i < rows + 1; i++) { Vertices[i * 2] = new CustomVertex.PositionColored( new Vector3(i * (w / rows), 0, 0.0f), ColorPicker.ColorFromRGB(255,255,255).ToArgb()); Vertices[i * 2 + 1] = new CustomVertex.PositionColored( new Vector3(i * (w / rows), h, 0.0f), ColorPicker.ColorFromRGB(255, 255, 255).ToArgb()); } for (int i = rows + 1; i < rows + cols + 2; i++) { Vertices[i * 2] = new CustomVertex.PositionColored( new Vector3(0, (i - rows - 1) * (h / cols), 0.0f), ColorPicker.ColorFromRGB(255, 255, 255).ToArgb()); Vertices[i * 2 + 1] = new CustomVertex.PositionColored( new Vector3(w, (i - rows - 1) * (h / cols), 0.0f), ColorPicker.ColorFromRGB(255, 255, 255).ToArgb()); } }
/// <summary> Create the Vertex Array. </summary> /// <remarks>Where our Vertice Points are initially stored with each of /// their positions in 3D space in X, Y, and Z coordinates. /// Also any color or texture information.</remarks> public void CreateVertexArray(object sender, EventArgs e) { CustomVertex.PositionColored[] VerticeArray = // Declare a new Array called VerticeArray new CustomVertex.PositionColored[4]; // Type of Vertices and number of Points // Draw Polygon from Vertice Points in a clockwise direction VerticeArray[0].Position = new Vector3(-0.25f, 0.32f, 0.5f); // Top Left Vertice VerticeArray[0].Color = System.Drawing.Color.Red.ToArgb(); VerticeArray[1].Position = new Vector3(0.25f, 0.32f, 0.5f); // Top Right VerticeArray[1].Color = System.Drawing.Color.Yellow.ToArgb(); VerticeArray[2].Position = new Vector3(0.25f, -0.32f, 0.5f); // Bottom Right VerticeArray[2].Color = System.Drawing.Color.Blue.ToArgb(); VerticeArray[3].Position = new Vector3(-0.25f, -0.32f, 0.5f); // Bottom Left VerticeArray[3].Color = System.Drawing.Color.Purple.ToArgb(); vertexBuffer.SetData(VerticeArray, 0, LockFlags.None); }
public static void DrawWireframe(Device device, BoundingBox box, int clr) { CustomVertex.PositionColored[] lines = new CustomVertex.PositionColored[24]; // bottom lines[0] = new CustomVertex.PositionColored(/*box.position*/new Vector3(), clr); lines[1] = new CustomVertex.PositionColored(/*box.position.X +*/ box.dimensions.X, /*box.position.Y*/0, /*box.position.Z*/0, clr); lines[2] = lines[1]; lines[3] = new CustomVertex.PositionColored(lines[2].X, /*box.position.Y*/0, /*box.position.Z +*/ box.dimensions.Z, clr); lines[4] = lines[3]; lines[5] = new CustomVertex.PositionColored(/*box.position.X*/0, /*box.position.Y*/0, /*box.position.Z +*/ box.dimensions.Z, clr); lines[6] = lines[5]; lines[7] = lines[0]; // top for (int i = 8; i < 16; i++) { lines[i] = lines[i - 8]; lines[i].Y = /*box.position.Y +*/ box.dimensions.Y; } // connectors lines[16] = lines[0]; lines[17] = lines[8]; lines[18] = lines[2]; lines[19] = lines[10]; lines[20] = lines[4]; lines[21] = lines[12]; lines[22] = lines[6]; lines[23] = lines[14]; // render lines device.VertexFormat = CustomVertex.PositionColored.Format; device.Indices = null; device.DrawUserPrimitives(PrimitiveType.LineList, 12, lines); }
public void OnCreateVertexBuffer(object sender, EventArgs e) { VertexBuffer buffer = (VertexBuffer)sender; CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[BufferSize]; verts[0].Position = new Vector3( 0.32f, 0, 0.5f ) ; // Top Right verts[0].Color = System.Drawing.Color.AntiqueWhite.ToArgb(); verts[1].Position = new Vector3( 0.32f, -0.32f, 0.5f ); // Bottom Right verts[1].Color = System.Drawing.Color.Black.ToArgb(); verts[2].Position = new Vector3( 0, -0.32f, 0.5f ); // Bottom Left verts[2].Color = System.Drawing.Color.Purple.ToArgb(); verts[3].Position = new Vector3( 0, 0, 0.5f ); // Top Left verts[3].Color = System.Drawing.Color.Purple.ToArgb(); buffer.SetData(verts, 0, LockFlags.None); }
public void SetAxisLine(Device d3dDevice) { m_CoordinateAxis = new VertexBuffer(typeof(CustomVertex.PositionColored), 6, d3dDevice, 0, CustomVertex.PositionColored.Format, Pool.Managed); CustomVertex.PositionColored[] posColoredVerts = new CustomVertex.PositionColored[6]; posColoredVerts[0].Position = new Microsoft.DirectX.Vector3(0, 0, 0); posColoredVerts[0].Color = System.Drawing.Color.Red.ToArgb(); posColoredVerts[1].Position = new Microsoft.DirectX.Vector3(10, 0, 0); posColoredVerts[1].Color = System.Drawing.Color.Red.ToArgb(); posColoredVerts[2].Position = new Microsoft.DirectX.Vector3(0, 0, 0); posColoredVerts[2].Color = System.Drawing.Color.Green.ToArgb(); posColoredVerts[3].Position = new Microsoft.DirectX.Vector3(0, 10, 0); posColoredVerts[3].Color = System.Drawing.Color.Green.ToArgb(); posColoredVerts[4].Position = new Microsoft.DirectX.Vector3(0, 0, 10); posColoredVerts[4].Color = System.Drawing.Color.Blue.ToArgb(); posColoredVerts[5].Position = new Microsoft.DirectX.Vector3(0, 0, 0); posColoredVerts[5].Color = System.Drawing.Color.Blue.ToArgb(); Microsoft.DirectX.GraphicsStream gstm = m_CoordinateAxis.Lock(0, 0, LockFlags.None); gstm.Write(posColoredVerts); m_CoordinateAxis.Unlock(); }
public Obj_Polygon2D(Vector3[] points, Color fill) { Centroid = new Vector2(); diffuse = new Material(); diffuse.Diffuse = fill; ColorValue c = ColorValue.FromArgb(fill.ToArgb()); c.Alpha = 255 / 2; CalculateProperties(points); Console.WriteLine("Area = {0}", Area); Console.WriteLine("Centroid = {0}, {1}", Centroid.X, Centroid.Y); polygon = new CustomVertex.PositionColored[points.Length+1]; polygon[0] = new CustomVertex.PositionColored(new Vector3(Centroid.X, Centroid.Y, 0), c.ToArgb()); for (int i = 0; i < points.Length; i++) { Console.WriteLine("{0} = {1}", i, points[i].ToString()); polygon[i+1] = new CustomVertex.PositionColored(points[i], c.ToArgb()); } }
/// <summary> /// Builds an array of PositionColored vertices that form a /// nX by nY tesselation of a quad given by it's 2 corners /// </summary> /// <param name="bottomLeft">Bottom left corner of the quad</param> /// <param name="topRight">Top right corner of the quad</param> /// <param name="nX">amount of X tesselation</param> /// <param name="nY">amount of Y tesselation</param> /// <param name="bRight">The color of bottom right corner</param> /// <param name="bLeft">The color of bottom left corner</param> /// <param name="tRight">The color of top right corner</param> /// <param name="tLeft">The color of top left corner</param> /// <returns>An array of PositionColored vertices</returns> public static CustomVertex.PositionColored[] BuildPositionSmoothColored(PointF bottomLeft, PointF topRight, int nX, int nY, Color bRight, Color bLeft, Color tRight, Color tLeft) { if (nX < 2 || nY < 2) { throw new Exception("Cannot tesselate with nX or nY below 2"); } float deltaX = (topRight.X - bottomLeft.X) / (float)(nX - 1); float deltaY = (topRight.Y - bottomLeft.Y) / (float)(nY - 1); float fx, fy; CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[nX * nY]; for (int y = 0; y < nY; y++) { if (y == nY - 1) fy = topRight.Y; else fy = bottomLeft.Y + (float)y * deltaY; for (int x = 0; x < nX; x++) { if (x == nX - 1) fx = topRight.X; else fx = bottomLeft.X + (float)x * deltaX; float tX = (fx - bottomLeft.X) / (topRight.X - bottomLeft.X); float tY = (fy - bottomLeft.Y) / (topRight.Y - bottomLeft.Y); verts[y * nY + x].X = fx; verts[y * nY + x].Y = fy; verts[y * nY + x].Z = 0; float col1r = (1f - tY) * (float)bLeft.R + tY * (float)tLeft.R; float col2r = (1f - tY) * (float)bRight.R + tY * (float)tRight.R; int col3r = (int)((1f - tX) * col1r + tX * col2r); float col1g = (1f - tY) * (float)bLeft.G + tY * (float)tLeft.G; float col2g = (1f - tY) * (float)bRight.G + tY * (float)tRight.G; int col3g = (int)((1f - tX) * col1g + tX * col2g); float col1b = (1f - tY) * (float)bLeft.B + tY * (float)tLeft.B; float col2b = (1f - tY) * (float)bRight.B + tY * (float)tRight.B; int col3b = (int)((1f - tX) * col1b + tX * col2b); float col1a = (1f - tY) * (float)bLeft.A + tY * (float)tLeft.A; float col2a = (1f - tY) * (float)bRight.A + tY * (float)tRight.A; int col3a = (int)((1f - tX) * col1a + tX * col2a); verts[y * nY + x].Color = (Color.FromArgb(col3a, col3r, col3g, col3b)).ToArgb(); } } return verts; }
/// <summary> /// Builds an array of PositionColored vertices that form a /// nX by nY tesselation of a quad given by it's 2 corners /// </summary> /// <param name="bottomLeft">Bottom left corner of the quad</param> /// <param name="topRight">Top right corner of the quad</param> /// <param name="nX">amount of X tesselation</param> /// <param name="nY">amount of Y tesselation</param> /// /// <param name="color">The color of the quad</param> /// <returns>An array of PositionColored vertices</returns> public static CustomVertex.PositionColored[] BuildPositionSingleColored(PointF bottomLeft, PointF topRight, int nX, int nY, Color color) { if (nX < 2 || nY < 2) { throw new Exception("Cannot tesselate with nX or nY below 2"); } float deltaX = (topRight.X - bottomLeft.X) / (float)(nX - 1); float deltaY = (topRight.Y - bottomLeft.Y) / (float)(nY - 1); float fx, fy; CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[nX * nY]; for (int y = 0; y < nY; y++) { if (y == nY - 1) fy = topRight.Y; else fy = bottomLeft.Y + (float)y * deltaY; for (int x = 0; x < nX; x++) { if (x == nX - 1) fx = topRight.X; else fx = bottomLeft.X + (float)x * deltaX; verts[y * nY + x].X = fx; verts[y * nY + x].Y = fy; verts[y * nY + x].Z = 0; verts[y * nY + x].Color = color.ToArgb(); } } return verts; }
/// <summary> /// Overridden. See <see cref="PCamera.PaintDebugFullBounds">PaintDebugFullBounds</see>. /// </summary> protected override void PaintDebugFullBounds(PPaintContext paintContext, Brush fullBoundsBrush, RectangleF nodeBounds) { Device device = (paintContext as P3PaintContext).Device; CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[VERTEX_COUNT]; P3Util.CreateColoredRectangle(colVerts, 0, nodeBounds, (fullBoundsBrush as SolidBrush).Color.ToArgb()); device.VertexFormat = CustomVertex.PositionColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, colVerts); }
/// <summary> /// Overridden. See <see cref="PCamera.PaintDebugBounds">PCamera.PaintDebugBounds</see>. /// </summary> protected override void PaintDebugBounds(PPaintContext paintContext, Pen boundsPen, RectangleF nodeBounds) { Device device = (paintContext as P3PaintContext).Device; CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[VERTEX_COUNT]; P3Util.CreateColoredRectangleOutline(colVerts, 0, nodeBounds, boundsPen.Color.ToArgb()); device.VertexFormat = CustomVertex.PositionColored.Format; device.DrawUserPrimitives(PrimitiveType.LineStrip, 4, colVerts); }
/// <summary> /// Override this method to fill the vertex buffer with the appropriate data. Most nodes /// that extend P3Node will need to override this method since their number and type of /// vertices will vary. /// </summary> /// <remarks> /// It is not safe to call GetValidVertexBuffer() here, since that method may call /// FillVertexBuffer(). /// </remarks> /// <param name="vb">The vertex buffer to fill.</param> protected virtual void FillVertexBuffer(VertexBuffer vb) { if (Brush != null) { GraphicsStream stm = vb.Lock(0, 0, 0); CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[VERTEX_COUNT]; P3Util.CreateColoredRectangle(colVerts, 0, Bounds, (Brush as SolidBrush).Color.ToArgb()); stm.Write(colVerts); vb.Unlock(); } }
/// <summary> /// Creates a PositionColored sphere centered on zero /// modified to provide a sky/atmosphere gradient dome /// </summary> /// <param name="device">The current direct3D drawing device.</param> /// <param name="radius">The sphere's radius</param> /// <param name="slices">Number of slices (Horizontal resolution).</param> /// <param name="stacks">Number of stacks. (Vertical resolution)</param> /// <returns></returns> /// <remarks> /// Number of vertices in the sphere will be (slices+1)*(stacks+1)<br/> /// Number of faces :slices*stacks*2 /// Number of Indexes : Number of faces * 3; /// </remarks> private Mesh ColoredSphere(Microsoft.DirectX.Direct3D.Device device, float radius, double startLat, double endLat, int slices, int stacks) { int numVertices = (slices+1)*(stacks+1); int numFaces = slices*stacks*2; int indexCount = numFaces * 3; Mesh mesh = new Mesh(numFaces,numVertices,MeshFlags.Managed,CustomVertex.PositionColored.Format,device); // Get the original sphere's vertex buffer. int [] ranks = new int[1]; ranks[0] = mesh.NumberVertices; System.Array arr = mesh.VertexBuffer.Lock(0,typeof(CustomVertex.PositionColored),LockFlags.None,ranks); // Set the vertex buffer int vertIndex=0; CustomVertex.PositionColored pnt; Vector3 v; // bottom fade double latitude = startLat - ((endLat - startLat) / 4); if(latitude < startLat - 1) latitude = startLat - 1; for(int slice = 0; slice <= slices; slice++) { pnt = new CustomVertex.PositionColored(); double longitude = 180 - ((float)slice/slices*(float)360); v = MathEngine.SphericalToCartesian( latitude, longitude, radius); pnt.X = v.X; pnt.Y = v.Y; pnt.Z = v.Z; pnt.Color = Color.FromArgb(255, horizonColor.R, horizonColor.G, horizonColor.B).ToArgb(); arr.SetValue(pnt,vertIndex++); } // stacks and slices for(int stack = 1; stack < stacks; stack++) { //latitude = startLat + ((float)(stack-1)/(stacks-1f)*(float)(endLat - startLat)); double linear = (float)(stack-1)/(stacks-1f); double k = 1 - Math.Cos(linear * Math.PI/2); latitude = startLat + (k*(float)(endLat - startLat)); //double colorFactorZ = (float)(stack-1)/(stacks-1f); // coef zenith color double colorFactorZ = linear; // coef zenith color double colorFactorH = 1 - colorFactorZ; // coef horizon color double alphaFactor = 1 - (linear * linear * linear); // coef alpha transparency if(alphaFactor > 1) alphaFactor = 1f; for(int slice = 0; slice <= slices; slice++) { pnt = new CustomVertex.PositionColored(); double longitude = 180 - ((float)slice/slices*(float)360); v = MathEngine.SphericalToCartesian( latitude, longitude, radius); pnt.X = v.X; pnt.Y = v.Y; pnt.Z = v.Z; pnt.Color = Color.FromArgb( (int)(255f * alphaFactor), (int)(horizonColor.R * colorFactorH + zenithColor.R * colorFactorZ), (int)(horizonColor.G * colorFactorH + zenithColor.G * colorFactorZ), (int)(horizonColor.B * colorFactorH + zenithColor.B * colorFactorZ)).ToArgb(); arr.SetValue(pnt,vertIndex++); } } // top fade latitude = endLat + ((endLat - startLat) / 10); for(int slice = 0; slice <= slices; slice++) { pnt = new CustomVertex.PositionColored(); double longitude = 180 - ((float)slice/slices*(float)360); v = MathEngine.SphericalToCartesian( latitude, longitude, radius); pnt.X = v.X; pnt.Y = v.Y; pnt.Z = v.Z; pnt.Color = Color.FromArgb(0, zenithColor.R, zenithColor.G, zenithColor.B).ToArgb(); arr.SetValue(pnt,vertIndex++); } mesh.VertexBuffer.Unlock(); ranks[0]=indexCount; arr = mesh.LockIndexBuffer(typeof(short),LockFlags.None,ranks); int i=0; short bottomVertex = 0; short topVertex = 0; // stacks and slices for(short x = 0; x < stacks; x++) { bottomVertex = (short)((slices+1) * x); topVertex = (short)(bottomVertex + slices + 1); for(int y = 0; y < slices; y++) { arr.SetValue(bottomVertex,i++); arr.SetValue((short)(topVertex+1),i++); arr.SetValue(topVertex,i++); arr.SetValue(bottomVertex,i++); arr.SetValue((short)(bottomVertex+1),i++); arr.SetValue((short)(topVertex+1),i++); bottomVertex++; topVertex++; } } mesh.IndexBuffer.SetData(arr,0,LockFlags.None); //mesh.ComputeNormals(); return mesh; }
public Triangle() { Vertices = new CustomVertex.PositionColored[4]; Vertices[0].Position = new Vector3(5f, 0f, 5f); Vertices[0].Color = Color.Red.ToArgb(); Vertices[1].Position = new Vector3(5f, 15f, 5f); //Vertices[1].Color = Color.Green.ToArgb(); Vertices[2].Position = new Vector3(10f, 0f, -5f); //Vertices[2].Color = Color.Yellow.ToArgb(); Vertices[3].Position = new Vector3(10f, 15f, -5f); Vertices[3].Color = Color.Blue.ToArgb(); }
public Quad(double x, double y, double w, double h) { this.x = x; this.y = y; this.w = w; this.h = h; Vertices = new CustomVertex.PositionColored[4]; Vertices[0] = new CustomVertex.PositionColored( new Vector3((float)x, (float)y, 0.0f), Color.White.ToArgb()); Vertices[1] = new CustomVertex.PositionColored( new Vector3((float)x, (float)(y + h), 0.0f), Color.White.ToArgb()); Vertices[2] = new CustomVertex.PositionColored( new Vector3((float)(x + w), (float)y, 0.0f), Color.White.ToArgb()); Vertices[3] = new CustomVertex.PositionColored( new Vector3((float)(x + w), (float)(y + h), 0.0f), Color.White.ToArgb()); }