public void DrawTriangle(Vector2Int[] points, Line.LineType lineType) { for (int i = 0; i < points.Length; i++) { Vector2Int v1 = points[i]; Vector2Int v2 = points[(i + 1) % 3]; DrawLine(v1, v2, lineType); } }
public void DrawPolygonWithTex(Polygon polygon, Line.LineType lineType) { Vector2Int[] points = new Vector2Int[3]; for (int i = 0; i < polygon.Vertices.Length; i++) { Vector3 v3 = _shader.OnVertex(polygon, i); v3 /= v3.Z; points[i] = new Vector2Int(Convert.ToInt32(v3.X), Convert.ToInt32(v3.Y)); } FillTriangleWithTex(points, polygon); }
public void DrawPolygon(Polygon polygon, float intensity, Line.LineType lineType) { byte gray = (byte)(intensity * 255); SetColor(Color.FromArgb(255, gray, gray, gray)); Vector2Int[] points = new Vector2Int[3]; for (int i = 0; i < polygon.Vertices.Length; i++) { Vector3 v3 = _shader.OnVertex(polygon, i); v3 /= v3.Z; points[i] = new Vector2Int(Convert.ToInt32(v3.X), Convert.ToInt32(v3.Y)); } //DrawTriangle(points, lineType); FillTriangle(points, polygon); //FillTriangle(points); //FillTriangle2(points); }
public void DrawMesh(Mesh mesh, Line.LineType lineType) { _depth = mesh.Polygons.Max(p => p.Vertices.Max(v => v.Z)) - mesh.Polygons.Min(p => p.Vertices.Min(v => v.Z)); _texture = new BitmapLock(mesh.Texture, ImageLockMode.ReadOnly); if (_cameraType == CameraType.Perspective) { _viewport = GetViewport(); _view = LookAt(new Vector3(-0.2f, 0.3f, 0), new Vector3(0.5f, 1, 0)); } _shader = new GouraudVertexShader(_lightDirection) { View = _view, Viewport = _viewport }; foreach (Polygon polygon in mesh.Polygons) { for (int i = 0; i < polygon.Vertices.Length; i++) { polygon.Vertices[i] = TransformVector(polygon.Vertices[i]); } float intensity = 0f; if (IsPolygonShouldBeDrawn(polygon, out intensity)) { if (polygon.UVs.Length == 0) { DrawPolygon(polygon, intensity, lineType); } else { DrawPolygonWithTex(polygon, lineType); } } } }
public void DrawLine(Vector2Int @from, Vector2Int to, Line.LineType type) { DrawLine(new Line(@from, to, type)); }