public LightXML(Light light) { Pos = light.Position; Intensity = light.Intensity; Range = light.Range; Col = light.Color; }
public Triangle(Point4 p1, Point4 p2, Point4 p3) { points[0] = p1; points[1] = p2; points[2] = p3; RecalculateNormal(); }
private void CalculateAndDrawAxes(Matrix PVM) { Vector4 tmp = PVM * OC.V; tmp = new Vector4(tmp.X / tmp.W, tmp.Y / tmp.W, tmp.Z / tmp.W, 1f); tmp = new Vector4((tmp.X + 1) * Canvas.Width / 2f, (tmp.Y + 1) * Canvas.Height / 2f, -(tmp.Z - 1f) / 2f, 1); Point4 PVMC = new Point4(tmp); tmp = PVM * OX.V; tmp = new Vector4(tmp.X / tmp.W, tmp.Y / tmp.W, tmp.Z / tmp.W, 1f); tmp = new Vector4((tmp.X + 1) * Canvas.Width / 2f, (tmp.Y + 1) * Canvas.Height / 2f, -(tmp.Z - 1f) / 2f, 1); Point4 PVMX = new Point4(tmp); tmp = PVM * OY.V; tmp = new Vector4(tmp.X / tmp.W, tmp.Y / tmp.W, tmp.Z / tmp.W, 1f); tmp = new Vector4((tmp.X + 1) * Canvas.Width / 2f, (tmp.Y + 1) * Canvas.Height / 2f, -(tmp.Z - 1f) / 2f, 1); Point4 PVMY = new Point4(tmp); tmp = PVM * OZ.V; tmp = new Vector4(tmp.X / tmp.W, tmp.Y / tmp.W, tmp.Z / tmp.W, 1f); tmp = new Vector4((tmp.X + 1) * Canvas.Width / 2f, (tmp.Y + 1) * Canvas.Height / 2f, -(tmp.Z - 1f) / 2f, 1); Point4 PVMZ = new Point4(tmp); Render.DrawAxes(bitmap, PVMC, PVMX, PVMY, PVMZ); }
public CameraXML(Camera camera) { Pos = camera.Position; Tar = camera.Target; FOV = camera.FOV; N = camera.N; F = camera.F; }
public void Reset() { Position = new Point4(defaultPosition); Target = new Point4(); FOV = 60; N = 0.1f; F = 100f; }
public Camera(CameraXML c) { Position = c.Pos; Target = c.Tar; FOV = c.FOV; N = c.N; F = c.F; }
public static void DrawAxes(Bitmap bitmap, Point4 center, Point4 OX, Point4 OY, Point4 OZ) { using (FastBitmap fast = bitmap.FastLock()) { DrawLine(fast, center, OX, Color.Red); DrawLine(fast, center, OY, Color.Green); DrawLine(fast, center, OZ, Color.Blue); } }
public Point4(Point4 A) { X = A.X; Y = A.Y; Z = A.Z; W = A.W; Normal = new Vector4(A.Normal.X, A.Normal.Y, A.Normal.Z, A.Normal.W); Binormal = new Vector4(A.Binormal.X, A.Binormal.Y, A.Binormal.Z, A.Binormal.W); Tangent = new Vector4(A.Tangent.X, A.Tangent.Y, A.Tangent.Z, A.Tangent.W); }
private static void FillFlatBottomTriangle(FastBitmap fast, Point4 v1, Point4 v2, Point4 v3, Color color) { float invslope1 = (v2.X - v1.X) / (v2.Y - v1.Y); float invslope2 = (v3.X - v1.X) / (v3.Y - v1.Y); float zslope1 = (v2.Z - v1.Z) / (v2.Y - v1.Y); float zslope2 = (v3.Z - v1.Z) / (v3.Y - v1.Y); if (v2.X > v3.X) { Swap(ref invslope1, ref invslope2); Swap(ref zslope1, ref zslope2); } float curX1 = v1.X; float curX2 = v1.X; float zL = v1.Z; float zR = v1.Z; for (int scanlineY = (int)v1.Y; scanlineY <= v2.Y; scanlineY++) { if (scanlineY > 0 && scanlineY < fast.Height) { float curZ = zL; float curQ = 1 / (float)((int)curX2 - (int)curX1); for (int i = (int)curX1; i < curX2; i++) { if (ZBuffering) { if (i > 0 && i < fast.Width) { if (curZ <= Depth[i][scanlineY]) { fast.SetPixel(i, scanlineY, color); Depth[i][scanlineY] = curZ; } } float q = curQ * (i - (int)curX1); curZ = zL * (1f - q) + zR * q; } else { if (i > 0 && i < fast.Width) { fast.SetPixel(i, scanlineY, color); } } } } zL += zslope1; zR += zslope2; curX1 += invslope1; curX2 += invslope2; } }
public static void FillScanline(FastBitmap fast, List <Point4> points, Color color) { points.Sort((p, r) => p.Y.CompareTo(r.Y)); Point4 v1 = points[0]; Point4 v2 = points[1]; Point4 v3 = points[2]; if (v2.Y == v3.Y) { FillFlatBottomTriangle(fast, v1, v2, v3, color); } else if (v1.Y == v2.Y) { FillFlatTopTriangle(fast, v1, v2, v3, color); } else { float z4 = v1.Z + (v2.Y - v1.Y) * (v3.Z - v1.Z) / (v3.Y - v1.Y); Point4 v4 = new Point4((int)(v1.X + ((float)(v2.Y - v1.Y) / (float)(v3.Y - v1.Y)) * (v3.X - v1.X)), (int)v2.Y, z4); FillFlatBottomTriangle(fast, v1, v2, v4, color); FillFlatTopTriangle(fast, v2, v4, v3, color); } //Outlines(fast, points, Color.Black); }
public Camera(Point4 pos, Point4 target) { Position = pos; Target = target; }
public Camera(Point4 pos) { Position = pos; }
public Camera() { Position = new Point4(defaultPosition); }
private static void DrawLine(FastBitmap fast, Point4 v0, Point4 v1, Color color) { int x0 = (int)v0.X; int y0 = (int)v0.Y; int x1 = (int)v1.X; int y1 = (int)v1.Y; float z0 = v0.Z; float z1 = v1.Z; float d = (v1.V - v0.V).Length(); float dz = (z1 - z0) / d; bool steep = Math.Abs(y1 - y0) > Math.Abs(x1 - x0); if (steep) { Swap(ref x0, ref y0); Swap(ref x1, ref y1); } if (x0 > x1) { Swap(ref x0, ref x1); Swap(ref y0, ref y1); Swap(ref z0, ref z1); } int dX = (x1 - x0); int dY = Math.Abs(y1 - y0); int err = (dX / 2); int ystep = (y0 < y1 ? 1 : -1); int y = y0; for (int x = x0; x <= x1; ++x) { if (steep) { if (y > 0 && y < fast.Width && x > 0 && x < fast.Height) { if (z1 <= Depth[y][x]) { fast.SetPixel(y, x, color); Depth[y][x] = z1; } } } else { if (y > 0 && y < fast.Height && x > 0 && x < fast.Width) { if (z1 <= Depth[x][y]) { fast.SetPixel(x, y, color); Depth[x][y] = z1; } } } err -= dY; if (err < 0) { y += ystep; err += dX; } z1 += dz; } }