public void RefractedColor() { Scene scene = new Scene(); RayObject a = scene.Objects[0]; a.material.Ambient = 1.0f; a.material.Pattern = new TestPattern(); RayObject b = scene.Objects[1]; b.material.Transparency = 1.0f; b.material.RefractIndex = 1.5f; Ray r = new Ray(new Point(0, 0, 0.1f), new Vector3(0, 1, 0)); Intersection i01 = new Intersection(-0.9899f, a); Intersection i02 = new Intersection(-0.4899f, b); Intersection i03 = new Intersection(0.4899f, b); Intersection i04 = new Intersection(0.9899f, a); List<Intersection> xs = new List<Intersection>() { i01, i02, i03, i04 }; Computation comps = new Computation(xs[2], r, xs); Color result = scene.RefractedColor(comps, 5); Color answer = new Color(0, 0.9963838f, 0.047175623f); // Answer doesn't match book exactly having small floating poitn difference Assert.True(answer == result); }
public void T14_FindRefractedColor() { if (Scene.current == null) { new Scene(); } Scene.current.Default(); RayObject a = Scene.current.root.GetChildren()[0]; a.material.Ambient = 1.0; a.material.pattern = new Patterns.TestPattern(); RayObject b = Scene.current.root.GetChildren()[1]; b.material.Transparency = 1.0; b.material.RefracIndex = 1.5; Ray ray = new Ray(new Point(0, 0, 0.1), new Vector(0, 1, 0)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(a, -0.9899)); xs.Add(new Intersection(b, -0.4899)); xs.Add(new Intersection(b, 0.4899)); xs.Add(new Intersection(a, 0.9899)); Computations c = Computations.Prepare(xs[2], ray, xs); Color color = Scene.current.RefractedColor(c, 5); Assert.AreEqual(new Color(0, 0.99888, 0.04725), color); }
public void T13_TotalInternalReflection() { if (Scene.current == null) { new Scene(); } Scene.current.Default(); RayObject ro1 = Scene.current.root.GetChildren()[0]; ro1.material.Transparency = 1.0; ro1.material.RefracIndex = 1.5; Ray r = new Ray(new Point(0, 0, Math.Sqrt(2) / 2), new Vector(0, 1, 0)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(ro1, Math.Sqrt(2) / -2)); xs.Add(new Intersection(ro1, Math.Sqrt(2) / 2)); Computations c = Computations.Prepare(xs[1], r, xs); Color color = Scene.current.RefractedColor(c, 5); Assert.AreEqual(Color.black, color); }
public void T12_RefractedColorAtMaxRecusionDepth() { if (Scene.current == null) { new Scene(); } Scene.current.Default(); RayObject ro1 = Scene.current.root.GetChildren()[0]; ro1.material.Transparency = 1; ro1.material.RefracIndex = 1.5; Ray r = new Ray(new Point(0, 0, -5), new Vector(0, 0, 1)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(ro1, 4)); xs.Add(new Intersection(ro1, 6)); Computations c = Computations.Prepare(xs[0], r, xs); Color color = Scene.current.RefractedColor(c, 0); Assert.AreEqual(Color.black, color); }
public void T11_RefractedColorOfOpaque() { if (Scene.current == null) { new Scene(); } Scene.current.Clear(); Scene.current.Default(); RayObject ro1 = Scene.current.root.GetChildren()[0]; Ray ray = new Ray(new Point(0, 0, -5), new Vector(0, 0, 1)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(ro1, 4)); xs.Add(new Intersection(ro1, 6)); Computations c = Computations.Prepare(xs[0], ray, xs); Color color = Scene.current.RefractedColor(c, 5); Assert.AreEqual(Color.black, color); }
public Color PatternAtObject(RayObject obj, Point p) { Point transPoint = obj.WorldToObject(p); transPoint = matrix.Inverse() * transPoint; //Move this into each pattern? return(this.PatternAt(transPoint)); }
public RayObject HexagonSide() { Group side = new Group(); RayObject hc = HexagonCorner(); RayObject he = HexagonEdge(); hc.SetParent(side); he.SetParent(side); return(side); }
public void ReflectColorNonReflectiveMaterial() { Scene scene = new Scene(); Ray r = new Ray(new Point(0, 0, 0), new Vector3(0, 0, 1)); RayObject s = scene.Objects[1]; s.material.Ambient = 1.0f; Intersection i = new Intersection(1, s); Computation comps = new Computation(i, r); Color result = scene.ReflectedColor(comps); Assert.True(result == Color.Black); }
public RayObject Hexagon() { //Group hexagon = new Group(); //hexagon.performAABBIntersectionTest = false; for (int i = 0; i < 6; i++) { RayObject side = HexagonSide(); side.SetMatrix(Mat4.RotateYMatrix(i * Constants.pi / 3)); //side.SetParent(hexagon); } return(null); }
public void ShadeIntersection() { Scene scene = new Scene(); Ray ray = new Ray(new Point(0, 0, -5), new Vector3(0, 0, 1)); RayObject shape = scene.Objects[0]; Intersection i = new Intersection(4, shape); Computation comp = new Computation(i, ray); Color color = scene.ShadeHit(comp); Color answer = new Color(0.38066f, 0.47583f, 0.2855f); Assert.True(answer == color); }
public void ShadeIntersectionInside() { Scene scene = new Scene(); scene.Lights[0] = new Light(new Color(1, 1, 1), new Point(0, 0.25f, 0)); Ray ray = new Ray(new Point(0, 0, 0), new Vector3(0, 0, 1)); RayObject shape = scene.Objects[1]; Intersection i = new Intersection(0.5f, shape); Computation comp = new Computation(i, ray); Color color = scene.ShadeHit(comp); Color answer = new Color(0.90417f, 0.90417f, 0.90417f); Assert.True(answer == color); }
public void BehindRayColor() { Scene scene = new Scene(); Material mat = new Material(Color.White, ambient: 1.0f); RayObject outer = scene.Objects[0]; RayObject inner = scene.Objects[1]; outer.material = mat; inner.material = mat; Ray r = new Ray(new Point(0, 0, 0.75f), new Vector3(0, 0, -1f)); Color color = scene.ColorAt(r); Assert.True(inner.material.mColor == color); }
public void OpaqueBlack() { Scene scene = new Scene(); RayObject s = scene.Objects[0]; s.material.Transparency = 0.0f; Ray r = new Ray(new Point(0, 0, -5), new Vector3(0, 0, 1)); Intersection i01 = new Intersection(4, s); Intersection i02 = new Intersection(6, s); List<Intersection> xs = new List<Intersection>() { i01, i02 }; Computation comps = new Computation(xs[0], r, xs); Color result = scene.RefractedColor(comps, 5); Assert.True(result == Color.Black); }
public void T13_PuttingItAllTogether() { if (Scene.current == null) { new Scene(); } Light light = new Light(new Point(0, 50, -25), Color.white); Camera camera = new Camera(600, 480, Constants.pi / 3.0); camera.ViewTransform(new Point(0, 2, -2), new Point(0, 0, 0), new Vector(0, 1, 0)); RayObject hexagon = Hexagon(); //Canvas canvas = Scene.current.Render(camera); Canvas canvas = Scene.current.Render(camera); Save.SaveCanvas(canvas, "Chapter14_Hexagon"); }
public void T03_NonReflectiveSurface() { if (Scene.current == null) { new Scene(); } Scene.current.Default(); Ray ray = new Ray(new Point(0, 0, 0), new Vector(0, 0, 1)); RayObject object2 = Scene.current.GetRayObjects()[1]; object2.material.Ambient = 1.0; Intersection i = new Intersection(object2, 1.0); Computations c = Computations.Prepare(i, ray, null); Color color = Scene.current.ReflectedColor(c); Assert.AreEqual(Color.black, color); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnCalculate() { int temp_signal_value = 0; double actualhigh = High[0]; double actuallow = Low[0]; if (this.Type == enum_swingray_type.open) { actualhigh = Open[0]; actuallow = Open[0]; } else if (this.Type == enum_swingray_type.close) { actualhigh = Close[0]; actuallow = Close[0]; } // build up cache of recent High and Low values // code devised from default Swing Indicator by marqui@BMT, 10-NOV-2010 lastHighCache.Add(actualhigh); if (lastHighCache.Count > (2 * strength) + 1) { lastHighCache.RemoveAt(0); // if cache is filled, drop the oldest value } lastLowCache.Add(actuallow); if (lastLowCache.Count > (2 * strength) + 1) { lastLowCache.RemoveAt(0); } // if (lastHighCache.Count == (2 * strength) + 1) // wait for cache of Highs to be filled { // test for swing high bool isSwingHigh = true; double swingHighCandidateValue = (double)lastHighCache[strength]; for (int i = 0; i < strength; i++) { if ((double)lastHighCache[i] >= swingHighCandidateValue - double.Epsilon) { isSwingHigh = false; // bar(s) to right of candidate were higher } } for (int i = strength + 1; i < lastHighCache.Count; i++) { if ((double)lastHighCache[i] > swingHighCandidateValue - double.Epsilon) { isSwingHigh = false; // bar(s) to left of candidate were higher } } // end of test if (isSwingHigh) { lastSwingHighValue = swingHighCandidateValue; } if (isSwingHigh) // if we have a new swing high then we draw a ray line on the chart { AddChartRay("highRay" + (ProcessingBarIndex - strength), false, strength, lastSwingHighValue, 0, lastSwingHighValue, swingHighColor, DashStyle.Solid, 1); RayObject newRayObject = new RayObject("highRay" + (ProcessingBarIndex - strength), strength, lastSwingHighValue, 0, lastSwingHighValue); swingHighRays.Push(newRayObject); // store a reference so we can remove it from the chart later } else if (actualhigh > lastSwingHighValue) // otherwise, we test to see if price has broken through prior swing high { if (swingHighRays.Count > 0) // just to be safe { //IRay currentRay = (IRay)swingHighRays.Pop(); // pull current ray from stack RayObject currentRay = (RayObject)swingHighRays.Pop(); // pull current ray from stack if (currentRay != null) { if (enableAlerts) { ShowAlert("Swing High at " + currentRay.Y1 + " broken", GlobalUtilities.GetSoundfile(this.Soundfile)); } temp_signal_value = 1; if (keepBrokenLines) // draw a line between swing point and break bar { int barsAgo = currentRay.BarsAgo1; ITrendLine newLine = AddChartLine("highLine" + (ProcessingBarIndex - barsAgo), false, barsAgo, currentRay.Y1, 0, currentRay.Y1, swingHighColor, DashStyle.Dot, 2); } RemoveChartDrawing(currentRay.Tag); if (swingHighRays.Count > 0) { //IRay priorRay = (IRay)swingHighRays.Peek(); RayObject priorRay = (RayObject)swingHighRays.Peek(); lastSwingHighValue = priorRay.Y1; // needed when testing the break of the next swing high } else { lastSwingHighValue = double.MaxValue; // there are no higher swings on the chart; reset to default } } } } } if (lastLowCache.Count == (2 * strength) + 1) // repeat the above for the swing lows { // test for swing low bool isSwingLow = true; double swingLowCandidateValue = (double)lastLowCache[strength]; for (int i = 0; i < strength; i++) { if ((double)lastLowCache[i] <= swingLowCandidateValue + double.Epsilon) { isSwingLow = false; // bar(s) to right of candidate were lower } } for (int i = strength + 1; i < lastLowCache.Count; i++) { if ((double)lastLowCache[i] < swingLowCandidateValue + double.Epsilon) { isSwingLow = false; // bar(s) to left of candidate were lower } } // end of test for low if (isSwingLow) { lastSwingLowValue = swingLowCandidateValue; } if (isSwingLow) // found a new swing low; draw it on the chart { AddChartRay("lowRay" + (ProcessingBarIndex - strength), false, strength, lastSwingLowValue, 0, lastSwingLowValue, swingLowColor, DashStyle.Solid, 1); RayObject newRayObject = new RayObject("lowRay" + (ProcessingBarIndex - strength), strength, lastSwingLowValue, 0, lastSwingLowValue); swingLowRays.Push(newRayObject); } else if (actuallow < lastSwingLowValue) // otherwise test to see if price has broken through prior swing low { if (swingLowRays.Count > 0) { //IRay currentRay = (IRay)swingLowRays.Pop(); RayObject currentRay = (RayObject)swingLowRays.Pop(); if (currentRay != null) { if (enableAlerts) { ShowAlert("Swing Low at " + currentRay.Y1 + " broken", GlobalUtilities.GetSoundfile(this.Soundfile)); } temp_signal_value = -1; if (keepBrokenLines) // draw a line between swing point and break bar { int barsAgo = currentRay.BarsAgo1; ITrendLine newLine = AddChartLine("highLine" + (ProcessingBarIndex - barsAgo), false, barsAgo, currentRay.Y1, 0, currentRay.Y1, swingLowColor, DashStyle.Dot, 2); } RemoveChartDrawing(currentRay.Tag); if (swingLowRays.Count > 0) { //IRay priorRay = (IRay)swingLowRays.Peek(); RayObject priorRay = (RayObject)swingLowRays.Peek(); lastSwingLowValue = priorRay.Y1; // price level of the prior swing low } else { lastSwingLowValue = double.MinValue; // no swing lows present; set this to default value } } } } } if (enablesignalline) { SignalLine.Set(temp_signal_value); } else { this.SwingHighs.Set(lastSwingHighValue); this.SwingLows.Set(lastSwingLowValue); this.PriceLines.Set(InSeries[0]); } //Set the color PlotColors[0][0] = this.Signal; OutputDescriptors[0].PenStyle = DashStyle.Solid; OutputDescriptors[0].Pen.Width = this.Plot0Width; PlotColors[1][0] = this.swingHighColor; OutputDescriptors[1].PenStyle = DashStyle.Solid; OutputDescriptors[1].Pen.Width = this.Plot0Width; PlotColors[2][0] = this.swingLowColor; OutputDescriptors[2].PenStyle = DashStyle.Solid; OutputDescriptors[2].Pen.Width = this.Plot0Width; PlotColors[3][0] = this.Signal; OutputDescriptors[3].PenStyle = DashStyle.Solid; OutputDescriptors[3].Pen.Width = this.Plot0Width; }