public Vector3D ToAbsolute(Vector3D vector) { if (csystems.Count == 0) { return vector; } else { return csystems.Peek().ToAbsolute(vector); } }
public CoordinateSystem() { Position = new Vector3D(0, 0, 0); U = new Vector3D(1.0f, 0.0f, 0.0f); V = new Vector3D(0.0f, 1.0f, 0.0f); W = new Vector3D(0.0f, 0.0f, 1.0f); }
public CoordinateSystem Scale(float x, float y, float z) { U = U * x; V = V * y; W = W * z; return this; }
public void RotateW(float angle) { var sa = (float)System.Math.Sin(angle); var ca = (float)System.Math.Cos(angle); var nu = U * ca + V * sa; var nv = V * ca - U * sa; U = nu; V = nv; }
public CoordinateSystem RotateV(float angle) { var sa = (float)System.Math.Sin(angle); var ca = (float)System.Math.Cos(angle); var nw = W * ca + U * sa; var nu = U * ca - W * sa; W = nw; U = nu; return this; }
public CoordinateSystem RotateU(float angle) { var sa = (float)System.Math.Sin(angle); var ca = (float)System.Math.Cos(angle); var nv = V * ca + W * sa; var nw = W * ca - V * sa; V = nv; W = nw; return this; }
protected override void Render(REScene scene, Camera3D camera, Canvas canvas) { foreach (REBaseLight lightSource in scene.Lights) { var start = lightSource.Origin.CoordinateSystem.Position; var dir = new Vector3D( (float)(_rnd.NextDouble() * 2 - 1), (float)(_rnd.NextDouble() * 2 - 1), (float)(_rnd.NextDouble() * 2 - 1) ).Normalize(); var ray = new ColoredRay3D { Color = new PreciseColor(1, 1, 1), Start = start, End = start + dir }; ProcessRay(ray, scene, 0); } }
protected REFlatShape(Shape3D origin, Vector3D a, Vector3D ba, Vector3D ca) : base(origin) { _a = a; _ba = ba; _ca = ca; _b = ba + a; _c = ca + a; _w = Vector3D.Product(ba, ca); float det = Math3D.CalcDet(U.X, V.X, W.X, U.Y, V.Y, W.Y, U.Z, V.Z, W.Z); _tu = Vector3D.Product(V, W) / det; _tv = Vector3D.Product(W, U) / det; _tw = Vector3D.Product(U, V) / det; _normal = _w.Normalize(); }
public void DoubleConversionTest() { var cs = new CoordinateSystem { U = new Vector3D(1, 5, 2), V = new Vector3D(10, -2, 4), W = new Vector3D(3, 4, -2), Position = new Vector3D(100, 50, 20) }; var localPoint = new Vector3D(-1, 5, 7); var globalPoint = cs.ToAbsolute(localPoint); var csReversed = cs.ToReverse(); var local = csReversed.ToAbsolute(globalPoint); const double epsilon = 0.000001; Assert.AreEqual(localPoint.X, local.X, epsilon); Assert.AreEqual(localPoint.Y, local.Y, epsilon); Assert.AreEqual(localPoint.Z, local.Z, epsilon); }
public static Vector3D Product(Vector3D first, Vector3D second) { float x = first._y * second._z - first._z * second._y; float y = first._z * second._x - first._x * second._z; float z = first._x * second._y - first._y * second._x; return new Vector3D(x, y, z); }
public static float Scalar(Vector3D first, Vector3D second) { return first._x * second.X + first.Y * second.Y + first.Z * second.Z; }
public Sphere3D(Vector3D position) : this(position, 50) { }
public void AddTest() { var a = new Vector3D(1, 2, 3); var b = new Vector3D(-2, -4, -6); var c = a + b; Assert.AreEqual(new Vector3D(-1, -2, -3), c); }
public static Vector3D GetReflectedVector(Vector3D origin, Vector3D normal) { var cosa = -Vector3D.Scalar(origin.Normalize(), normal); var n = normal * (origin.Length * cosa); var a = origin + n; return n + a; }
protected Object3D(Vector3D position) { CoordinateSystem = new CoordinateSystem { Position = position }; }
public Vector3D ToRelative(Vector3D vector) { var rel = vector - Position; var det = CalcDet(); var detX = CalcDet(rel.X, V.X, W.X, rel.Y, V.Y, W.Y, rel.Z, V.Z, W.Z); var detY = CalcDet(U.X, rel.X, W.X, U.Y, rel.Y, W.Y, U.Z, rel.Z, W.Z); var detZ = CalcDet(U.X, V.X, rel.X, U.Y, V.Y, rel.Y, U.Z, V.Z, rel.Z); return new Vector3D(detX / det, detY / det, detZ / det); }
public GeneralCamera3D(Vector3D position) { Position = position; }
protected virtual void OptimizeComposite(REShapeComposite composite) { var points = new List<Vector3D>(); foreach (REBaseShape child in composite) { if (child is RETriangle) { RETriangle triangle = (RETriangle)child; points.Add(triangle.A); points.Add(triangle.B); points.Add(triangle.C); continue; } if (child is RERectangle) { var rectangle = (RERectangle)child; points.Add(rectangle.A); points.Add(rectangle.B); points.Add(rectangle.C); points.Add(rectangle.B + rectangle.C - rectangle.A); continue; } } List<Vector3D> prev = points; for (int i = 0; i < 0; i++) { List<Vector3D> additional = GetAdditionalPoints(prev, composite); points.AddRange(additional); prev = additional; } Vector3D a = new Vector3D(), b = new Vector3D(); float maxLength = float.MinValue; for (int i = 0; i < points.Count; i++) { for (int j = 0; j < points.Count; j++) { float length = (points[i] - points[j]).Length; if (length > maxLength) { a = points[i]; b = points[j]; maxLength = length; } } } if ((a - b).Length > 0.01) { Sphere3D holder = new Sphere3D(); Vector3D center = (a + b) * 0.5f; holder.CoordinateSystem.Position = center; holder.Radius = (a - b).Length / 2; composite.BoundingShape = new RESphere(holder); } }
public Sphere3D(Vector3D position, float radius) : base(position) { Radius = radius; }
public CoordinateSystem Translate(Vector3D delta) { Position += delta; return this; }
public void Shift(float x, float y, float z) { Position += new Vector3D(x, y, z); }
public Vector3D ToAbsolute(Vector3D vector) { return vector.X * U + vector.Y * V + vector.Z * W + Position; }
private Vector3D ToAbsolute(Vector3D source) { return _context.ToAbsolute(source); }
public REOmniLight(OmniLight3D origin, Vector3D position, REScene scene) : base(origin, scene) { omni = origin; this.position = position; }