Post by kalldrexx on Dec 12, 2019 9:28:18 GMT
I"m near the end of chapter 10 and while all of my tests pass, I"m not getting the correct result.
There are multiple issues with this image:
- The middle sphere is supposed to be a red/green gradient pattern. Instead it's just solid (EDIT: fixed via adding a transform to the pattern)
- The obvious noise on the checkerboarding (Edit: fixed now)
The two items are defined as
var floor = new Plane
{
Material = new Material
{
Pattern = new CheckersPattern(Color.White, Color.Black),
Color = Color.White,
Specular = 0,
}
};
var middleSphere = new Sphere(Matrix4X4.CreateTranslation(-0.5, 1, 0.5))
{
Material = new Material
{
Pattern = new RingPattern(new Color(1, 0, 0), new Color(0, 1, 0)),
Diffuse = 0.7,
Specular = 0.3,
}
};
So there are no pattern transforms going on, only the one translation on the middle sphere.
My pattern base class contains
public Color ColorAt(Point point, RayTraceableObject objectBeingDrawn)
{
var transformedPoint = objectBeingDrawn.InverseTransform * point;
transformedPoint = _inverseTransform * transformedPoint;
return GetColorAtAdjustedPoint(transformedPoint);
}
protected abstract Color GetColorAtAdjustedPoint(Point point);
and my gradient and ring calculations are at
public class CheckersPattern : Pattern
{
private readonly Color _color1, _color2;
public CheckersPattern(Color color1, Color color2)
{
_color1 = color1;
_color2 = color2;
}
protected override Color GetColorAtAdjustedPoint(Point point)
=> (int) (Math.Floor(point.X) + Math.Floor(point.Y) + Math.Floor(point.Z)) % 2 == 0
? _color1
: _color2;
}
public class RingPattern : Pattern
{
private readonly Color _color1, _color2;
public RingPattern(Color color1, Color color2)
{
_color1 = color1;
_color2 = color2;
}
protected override Color GetColorAtAdjustedPoint(Point point)
{
var inner = Math.Pow(point.X, 2) + Math.Pow(point.Z, 2);
return (int)Math.Floor(Math.Sqrt(inner)) % 2 == 0
? _color1
: _color2;
}
}
Can anyone see what I'm doing wrong? I even looked up some others code on github and plugging that in didn't solve the issue .