/// <summary> /// Adds a new set of primitives to the batch /// </summary> /// <param name="renderMode">type of primitive to render</param> /// <param name="vertices">buffer containing the vertices to add</param> /// <param name="numVertices">number of vertices to add</param> /// <param name="color">color of the batched primitives</param> public void AddPrimitive(Mathbox.RenderMode renderMode, Vector3[] vertices, int numVertices, Color color) { if (renderMode == Mathbox.RenderMode.Dot || numVertices == 1) { AddDotPrimitive(vertices, numVertices, color); } else if (renderMode == Mathbox.RenderMode.Vector || numVertices == 2) { AddVectorPrimitive(vertices, numVertices, color); } else if (numVertices >= 3) { AddPolygonPrimitive(vertices, numVertices, color); } }
void BuildPrimitive(UInt16 address, Color color, Mathbox.RenderMode renderMode) { // add points to buffer for (int numVertices = 0; ;) { VertexInstruction vertex = Memory[++address]; Vertices[numVertices++] = Vector3.Transform(GetVertexFromTable(vertex), Parent.D3DTS_WORLD); // is this the last point of the plygon? if (vertex.IsLastVertex) { #if DEBUG if (MaxVertices < numVertices) { MaxVertices = numVertices; Debug.WriteLine($"Max Vertices = {MaxVertices}"); } #endif DisplayListManager.AddPrimitive(renderMode, Vertices, numVertices, color); return; } } }
public void AddPrimitive(Mathbox.RenderMode renderMode, Vector3[] vertices, int numVertices, Color color) { Primitives.AddPrimitive(renderMode, vertices, numVertices, color); }
public void Rasterize() { // locate the tile table in memory System.Diagnostics.Debug.Assert(Memory[TERRAIN_BASE_ADDRESS] == 0xE00); TileTableBaseAddress = Memory[TERRAIN_BASE_ADDRESS]; // always 0x0E00 Parent.StartRender(); Parent.LoadLightVector(); Parent.LoadViewPosition(); Parent.LoadViewMatrix(0x15); Rotation = Parent.ViewRotation; Parent.SetWorldMatrix(ref Parent.Terrain.Rotation); // determine rendering method (dot/vector/polygon) switch (Memory[TERRAIN_RENDERING_MODE]) { case 0x0000: renderMode = Mathbox.RenderMode.Polygon; break; case 0x0100: renderMode = Mathbox.RenderMode.Vector; break; default: renderMode = Mathbox.RenderMode.Dot; break; } // get address of terrain object buffer ObjectList = Memory[TERRAIN_OBJECT_LIST_ADDRESS]; Int16 z_max = (Int16)Memory[TERRAIN_Z_MAX]; Int16 z_min = (Int16)Memory[TERRAIN_Z_MIN]; Int16 x = (Int16)Memory[TERRAIN_X]; Int16 z_frac = (Int16)Memory[TERRAIN_Z_FRAC]; Int16 x_offset = (Int16)Memory[TERRAIN_X_OFFSET]; Int16 z_offset = (Int16)Memory[TERRAIN_Z_OFFSET]; // locate left front tile corner (x1,y1,z1) // +-------+ // / /| // / / | x2 = x1 + Mathbox.Tile.SIZE_X // y1-- +-------+ | y2 = y1 + Mathbox.Tile.SIZE_Y // | | + --z2 z2 = z1 + Mathbox.Tile.SIZE_Z // | | / // | |/ // y2-- +-------+ --z1 // | | // x1 x2 Vector3 corner = new Vector3( Tile.WIDTH_X - x_offset * 128 - x, -Parent.ViewPosition.Y, z_max * 128 - z_frac); // render each row in the terrain int row = z_offset / 16 + z_max; // first absolute row to be rendered Row.Count = z_max - z_min + 1; // number of rows to display while (Row.Count-- > 0) { DrawTerrainRow(row-- & 31, corner); corner.Z -= Tile.DEPTH_Z; // move to next row along the Z axis } Parent.EndRender(); }