|
Post by mariog on Oct 10, 2019 13:45:02 GMT
Hi, I'm probably doing something obviously wrong but I don't seem to be able to translate a pattern. I was getting the same problem with a gradient pattern as another member posted to the forum and I saw Jamis's reply in which he recommended that you scale the pattern by 2 and then translate it in x by -1. I have done this. The scale works, but the pattern won't translate and the tests all check out okay. Here's my code for the abstract pattern class that handles the point transformations from world space to object space: public abstract class Pattern { Matrix transform;
public Pattern() { transform = new Matrix(4,4).identity(); } public Colour patternAtObject(Shape shape, Tuple worldPoint) { Tuple shapePoint = shape.transform.inverse().mult(worldPoint); Tuple patternPoint = transform.inverse().mult(shapePoint); return patternAt(patternPoint); }
public abstract Colour patternAt(Tuple point);
}
I've added the image I have rendered as an attachment. It has been correctly scaled by 2 in x, y and z:
Thanks for any help you can provide, --Mario
Attachments:
|
|
|
Post by mariog on Oct 10, 2019 15:16:16 GMT
Update: I have discovered that the pattern is actually translating, but the fix described by Jamis to correct the gradient across the sphere doesn't work. This bug is baffling!
|
|
|
Post by mariog on Oct 10, 2019 15:34:16 GMT
If I move the light source to the right by 10 units, I get this:
|
|
|
Post by gbordelon on Oct 13, 2019 21:00:02 GMT
Your patternAtObject method looks correct, assuming the Pattern.transform matrix is correctly initialized. I am concerned that the cause could be at least related to, if not caused by, your lerp function from one of your other posts. In the other post your lerp function interpolates over [-1, 1] instead of [0,1].
public static double lerp(double start, double end, double t) { return (1 - t) * start + t * end; } i'm only guessing because I stuck with the book's mathematical description on page 135:
color(p, ca, cb) = ca + (cb - ca) * (px - floor(px)) I hope that helps.
|
|