I am having trouble incorporating transformations. For whatever reasons, everything is not going as I think it should, but to be honest - all the transformations back and forth make me quite dizzy.
As I have read everywhere (although explicit explanations are rare, imho), the principle algorithm for transformations is as follows:
- transform the Ray (Origin and Direction) with the inverse of the transformation matrix
- transform the resulting Intersection-Point with the transformation matrix
- transform the object's normal at the Intersection-Point with the transposed of the inverse
From what I understood, that should do the trick. I'm pretty sure that my problem lies when I try to calculate the lighting, since both the initial intersection and the lighting algorithm use the same function (obj.getIntersection()
). But then again, I have no idea. :(
You can read parts of my code here:
main.cpp, scene.cpp, sphere.cpp, sdf-loader.cpp
Please let me know if you need more info to help me - and please help me! ;)
EDIT:
I made some results, maybe someone "sees" (by the results) where I may be wrong:
untransformed scene:
sphere scaled (2,4,2):
box translated (0,-200,0):
sphere translated (-300,0,0):
sphere x-rotated (45°):