/// <summary> /// Expand the internal list of billboards /// </summary> private void Expand() { fMaxObjects = fMaxObjects * 2; VertexBillboardParticle[] vertices = new VertexBillboardParticle[fMaxObjects * 4]; short[] indices = new short[fMaxObjects * 6]; for (int i = 0; i < fVertices.Length; i++) { vertices[i] = fVertices[i]; } for (int i = 0; i < fIndices.Length; i++) { indices[i] = fIndices[i]; } fIndices = indices; fVertices = vertices; }
/// <summary> /// Add a new object /// </summary> public bool AddObject(Vector3 position, Color color, float size) { if (fObjects > MAX_OBJECTS) { return(false); } if (fObjects >= fMaxObjects) { Expand(); } int verticeNumberBase = fIndexVertice; if (fMode == BillboardMode.PointList) { fVertices[fIndexVertice++] = new VertexBillboardParticle(position, Vector2.Zero, size, color); fVertices[fIndexVertice++] = new VertexBillboardParticle(position, new Vector2(1, 0), size, color); fVertices[fIndexVertice++] = new VertexBillboardParticle(position, Vector2.One, size, color); fVertices[fIndexVertice++] = new VertexBillboardParticle(position, new Vector2(0, 1), size, color); } else { float size2 = size * 0.5f; fVertices[fIndexVertice++] = new VertexBillboardParticle(new Vector3(position.X - size2, position.Y - size2, position.Z), new Vector2(0, 1), size, color); fVertices[fIndexVertice++] = new VertexBillboardParticle(new Vector3(position.X + size2, position.Y - size2, position.Z), new Vector2(1, 1), size, color); fVertices[fIndexVertice++] = new VertexBillboardParticle(new Vector3(position.X + size2, position.Y + size2, position.Z), new Vector2(1, 0), size, color); fVertices[fIndexVertice++] = new VertexBillboardParticle(new Vector3(position.X - size2, position.Y + size2, position.Z), new Vector2(0, 0), size, color); } fIndices[fIndexIndice++] = (short)(0 + verticeNumberBase); fIndices[fIndexIndice++] = (short)(1 + verticeNumberBase); fIndices[fIndexIndice++] = (short)(2 + verticeNumberBase); fIndices[fIndexIndice++] = (short)(0 + verticeNumberBase); fIndices[fIndexIndice++] = (short)(2 + verticeNumberBase); fIndices[fIndexIndice++] = (short)(3 + verticeNumberBase); fObjects++; fVertexBufferLoaded = false; return(true); }