/// <summary> /// Builds cube sides into this VertexStructure (these sides are built up of 16 vertices, so texture coordinates and normals are set) /// </summary> /// <param name="start">Start poiint of the cube</param> /// <param name="size">Size of the cube</param> /// <param name="color">Color of the cube</param> public BuiltVerticesRange BuildCubeSides16V(Vector3 start, Vector3 size, Color4 color) { BuiltVerticesRange result = new BuiltVerticesRange(m_owner); result.StartVertex = m_owner.CountVertices; Vector3 dest = start + size; float texX = 1f; float texY = 1f; float texZ = 1f; if (m_tileSize != Vector2.Zero) { texX = size.X / m_tileSize.X; texY = size.Y / m_tileSize.Y; texZ = size.Z / m_tileSize.X; } //Front side Vertex vertex = new Vertex(start, color, new Vector2(0f, texY), new Vector3(0f, 0f, -1f)); int a = m_owner.AddVertex(vertex); int b = m_owner.AddVertex(vertex.Copy(new Vector3(dest.X, start.Y, start.Z), new Vector2(texX, texY))); int c = m_owner.AddVertex(vertex.Copy(new Vector3(dest.X, dest.Y, start.Z), new Vector2(texX, 0f))); int d = m_owner.AddVertex(vertex.Copy(new Vector3(start.X, dest.Y, start.Z), new Vector2(0f, 0f))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); //Right side a = m_owner.AddVertex(vertex.Copy(new Vector3(dest.X, start.Y, start.Z), new Vector3(1f, 0f, 0f), new Vector2(0f, texY))); b = m_owner.AddVertex(vertex.Copy(new Vector3(dest.X, start.Y, dest.Z), new Vector3(1f, 0f, 0f), new Vector2(texZ, texY))); c = m_owner.AddVertex(vertex.Copy(new Vector3(dest.X, dest.Y, dest.Z), new Vector3(1f, 0f, 0f), new Vector2(texZ, 0f))); d = m_owner.AddVertex(vertex.Copy(new Vector3(dest.X, dest.Y, start.Z), new Vector3(1f, 0f, 0f), new Vector2(0f, 0f))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); //Back side a = m_owner.AddVertex(vertex.Copy(new Vector3(dest.X, start.Y, dest.Z), new Vector3(0f, 0f, 1f), new Vector2(0f, texY))); b = m_owner.AddVertex(vertex.Copy(new Vector3(start.X, start.Y, dest.Z), new Vector3(0f, 0f, 1f), new Vector2(texX, texY))); c = m_owner.AddVertex(vertex.Copy(new Vector3(start.X, dest.Y, dest.Z), new Vector3(0f, 0f, 1f), new Vector2(texX, 0f))); d = m_owner.AddVertex(vertex.Copy(new Vector3(dest.X, dest.Y, dest.Z), new Vector3(0f, 0f, 1f), new Vector2(0f, 0f))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); //Left side a = m_owner.AddVertex(vertex.Copy(new Vector3(start.X, start.Y, dest.Z), new Vector3(-1f, 0f, 0f), new Vector2(0f, texY))); b = m_owner.AddVertex(vertex.Copy(new Vector3(start.X, start.Y, start.Z), new Vector3(-1f, 0f, 0f), new Vector2(texZ, texY))); c = m_owner.AddVertex(vertex.Copy(new Vector3(start.X, dest.Y, start.Z), new Vector3(-1f, 0f, 0f), new Vector2(texZ, 0f))); d = m_owner.AddVertex(vertex.Copy(new Vector3(start.X, dest.Y, dest.Z), new Vector3(-1f, 0f, 0f), new Vector2(0f, 0f))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); result.VertexCount = (int)(m_owner.CountVertices - result.StartVertex); return(result); }
/// <summary> /// Builds a cube into this VertexStructure (this cube is built up of 24 vertices, so texture coordinates and normals are set) /// </summary> /// <param name="start">Start point of the cube</param> /// <param name="size">Size of the cube</param> /// <param name="color">Color of the cube</param> public BuiltVerticesRange BuildCube24V(Vector3 start, Vector3 size, Color4 color) { BuiltVerticesRange result = new BuiltVerticesRange(m_owner); result.Merge(this.BuildCubeSides16V(start, size, color)); result.Merge(this.BuildCubeTop4V(start, size, color)); result.Merge(this.BuildCubeBottom4V(start, size, color)); return(result); }
/// <summary> /// Merges this structure with the given one. /// This method does only work if the given structure does begin after the end of the current one. /// </summary> /// <param name="otherRange">The other range to merge with.</param> public void Merge(BuiltVerticesRange otherRange) { if (VertexCount <= 0) { StartVertex = otherRange.StartVertex; VertexCount = otherRange.VertexCount; } else { if (StartVertex + VertexCount != otherRange.StartVertex) { throw new SeeingSharpGraphicsException("Unable to merge given vertex ranges!"); } VertexCount = (int)(VertexCount + otherRange.VertexCount); } }
/// <summary> /// Builds a cube of 4 vertices and a defined hight. /// </summary> /// <param name="topA"></param> /// <param name="topB"></param> /// <param name="topC"></param> /// <param name="topD"></param> /// <param name="heigh"></param> /// <param name="color"></param> public BuiltVerticesRange BuildCube24V(Vector3 topA, Vector3 topB, Vector3 topC, Vector3 topD, float heigh, Color4 color) { BuiltVerticesRange result = new BuiltVerticesRange(m_owner); result.StartVertex = m_owner.CountVertices; int startTriangleIndex = this.CountTriangles; // Calculate texture coordinates Vector3 size = new Vector3( (topB - topA).Length(), Math.Abs(heigh), (topC - topB).Length()); float texX = 1f; float texY = 1f; float texZ = 1f; if (m_tileSize != Vector2.Zero) { texX = size.X / m_tileSize.X; texY = size.Y / m_tileSize.Y; texZ = size.Z / m_tileSize.X; } // Calculate bottom vectors Vector3 bottomA = new Vector3(topA.X, topA.Y - heigh, topA.Z); Vector3 bottomB = new Vector3(topB.X, topB.Y - heigh, topB.Z); Vector3 bottomC = new Vector3(topC.X, topC.Y - heigh, topC.Z); Vector3 bottomD = new Vector3(topD.X, topD.Y - heigh, topD.Z); // Build Top side Vertex vertex = new Vertex(topA, color, new Vector2(texX, 0f), new Vector3(0f, 1f, 0f)); int a = m_owner.AddVertex(vertex); int b = m_owner.AddVertex(vertex.Copy(topB, new Vector2(texX, texY))); int c = m_owner.AddVertex(vertex.Copy(topC, new Vector2(0f, texY))); int d = m_owner.AddVertex(vertex.Copy(topD, new Vector2(0f, 0f))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); // Build Bottom side vertex = new Vertex(topA, color, new Vector2(0f, 0f), new Vector3(0f, -1f, 0f)); a = m_owner.AddVertex(vertex); b = m_owner.AddVertex(vertex.Copy(topD, new Vector2(texX, 0f))); c = m_owner.AddVertex(vertex.Copy(topC, new Vector2(texX, texY))); d = m_owner.AddVertex(vertex.Copy(topB, new Vector2(0f, texY))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); // Build Front side vertex = new Vertex(topA, color, new Vector2(0f, texY), new Vector3(0f, 0f, -1f)); a = m_owner.AddVertex(vertex); b = m_owner.AddVertex(vertex.Copy(topB, new Vector2(texX, texY))); c = m_owner.AddVertex(vertex.Copy(bottomB, new Vector2(texX, 0f))); d = m_owner.AddVertex(vertex.Copy(bottomA, new Vector2(0f, 0f))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); // Build Right side a = m_owner.AddVertex(vertex.Copy(topB, new Vector3(1f, 0f, 0f), new Vector2(0f, texY))); b = m_owner.AddVertex(vertex.Copy(topC, new Vector3(1f, 0f, 0f), new Vector2(texZ, texY))); c = m_owner.AddVertex(vertex.Copy(bottomC, new Vector3(1f, 0f, 0f), new Vector2(texZ, 0f))); d = m_owner.AddVertex(vertex.Copy(bottomB, new Vector3(1f, 0f, 0f), new Vector2(0f, 0f))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); // Build Back side a = m_owner.AddVertex(vertex.Copy(topC, new Vector3(0f, 0f, 1f), new Vector2(0f, texY))); b = m_owner.AddVertex(vertex.Copy(topD, new Vector3(0f, 0f, 1f), new Vector2(texX, texY))); c = m_owner.AddVertex(vertex.Copy(bottomD, new Vector3(0f, 0f, 1f), new Vector2(texX, 0f))); d = m_owner.AddVertex(vertex.Copy(bottomC, new Vector3(0f, 0f, 1f), new Vector2(0f, 0f))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); // Build Left side a = m_owner.AddVertex(vertex.Copy(topD, new Vector3(-1f, 0f, 0f), new Vector2(0f, texY))); b = m_owner.AddVertex(vertex.Copy(topA, new Vector3(-1f, 0f, 0f), new Vector2(texZ, texY))); c = m_owner.AddVertex(vertex.Copy(bottomA, new Vector3(-1f, 0f, 0f), new Vector2(texZ, 0f))); d = m_owner.AddVertex(vertex.Copy(bottomD, new Vector3(-1f, 0f, 0f), new Vector2(0f, 0f))); this.AddTriangle(a, c, b); this.AddTriangle(a, d, c); // Calculate normals finally this.CalculateNormalsFlat(startTriangleIndex, this.CountTriangles - startTriangleIndex); result.VertexCount = (int)(m_owner.CountVertices - result.StartVertex); return(result); }