// Draws the given model with texturing, shading and a normal map. void Rasterizer::DrawSolidTexturedNormalMapped(Model3D& model, std::vector<DirectionalLight*> directionalLights, std::vector<AmbientLight*> ambientLights, std::vector<PointLight*> pointLights) { std::vector<Polygon3D> _polygonList = model.GetPolygonList(); std::vector<Vertex> _vertexList = model.GetTransformedVertexList(); std::vector<UVCoordinate> _uvCoordList = model.GetUVCoordinateList(); for (unsigned int i = 0; i < _polygonList.size(); i++) { Polygon3D poly = _polygonList[i]; if (poly.GetBackfacing() == true) continue; Vertex v1 = _vertexList[poly.GetVertexIndex(0)]; Vertex v2 = _vertexList[poly.GetVertexIndex(1)]; Vertex v3 = _vertexList[poly.GetVertexIndex(2)]; // Set the uv coordinates of each vertex temporarily to the coordinates in the // uv coordinate list. v1.SetUVCoordinate(_uvCoordList[poly.GetUVIndex(0)]); v2.SetUVCoordinate(_uvCoordList[poly.GetUVIndex(1)]); v3.SetUVCoordinate(_uvCoordList[poly.GetUVIndex(2)]); // Fill the polygon using the models texture. if (model.GetNormalMapOn() == true) FillPolygonTexturedNormalMapped(v1, v2, v3, v1.GetColor(), model, directionalLights, ambientLights, pointLights); else FillPolygonTextured(v1, v2, v3, v1.GetColor(), model); } }
// Draws the given model with gouraud shading. void Rasterizer::DrawSolidShaded(Model3D& model) { std::vector<Polygon3D> _polygonList = model.GetPolygonList(); std::vector<Vertex> _vertexList = model.GetTransformedVertexList(); // Iterate over and render each of the polygons in the list. for (unsigned int i = 0; i < _polygonList.size(); i++) { Polygon3D poly = _polygonList[i]; if (poly.GetBackfacing() == true) continue; Vertex v1 = _vertexList[poly.GetVertexIndex(0)]; Vertex v2 = _vertexList[poly.GetVertexIndex(1)]; Vertex v3 = _vertexList[poly.GetVertexIndex(2)]; // Fill the polygon using the polygons colour. FillPolygonShaded(v1, v2, v3, poly.GetColor()); } }
// Draws the given model in wireframe mode. void Rasterizer::DrawWireFrame(Model3D& model) { std::vector<Polygon3D> _polygonList = model.GetPolygonList(); std::vector<Vertex> _vertexList = model.GetTransformedVertexList(); // Iterate over and render each of the polygons in the list. for (unsigned int i = 0; i < _polygonList.size(); i++) { Polygon3D poly = _polygonList[i]; if (poly.GetBackfacing() == true) continue; Vertex v1 = _vertexList[poly.GetVertexIndex(0)]; Vertex v2 = _vertexList[poly.GetVertexIndex(1)]; Vertex v3 = _vertexList[poly.GetVertexIndex(2)]; // Draw a line between each of the vertexs in the polygon. DrawLine(v1.GetX(), v1.GetY(), v2.GetX(), v2.GetY()); DrawLine(v2.GetX(), v2.GetY(), v3.GetX(), v3.GetY()); DrawLine(v1.GetX(), v1.GetY(), v3.GetX(), v3.GetY()); _polygonsRendered++; } }