|
Post by Richard Moss on Jul 24, 2019 18:52:16 GMT
Hello, I feel this is a slightly off-topic question, but I suppose it doesn't hurt to ask. I've been having a blast with this book and I've just finished Chapter 12. For the end of chapter challenge, I am supposed to create a room containing a table. Except I'll be darned if I can position the legs properly - I thought I mostly had it until I rendered at a slightly higher resolution and then noticed one of my legs is way out. I also noticed the mirror I added as a test if hovering in front of the wall (sigh!). I'm a 2D guy used to having to explicitly say "plot at x,y" and being absolute with everything; evidently I'm not grokking the 3D co-ordinate space effectively. I assumed that if I simply added or subtracted the same sets of numbers I'd get four related positions - but it isn't working out great. top: translate(-1, 1, 1) * rotatey(pi / 4) * scale(2, 0.1, 2) back left: translate(-1, 0.5, 1) * rotatey(pi / 4) * scale(0.1, 0.5, 0.1) back right: translate(1.5, 0.5, 1.5) * rotatey(pi / 4) * scale(0.1, 0.5, 0.1) front left: translate(-3, 0.5, 0) * rotatey(pi / 4) * scale(0.1, 0.5, 0.1) font right: translate(-1, 0.5, -1.5) * rotatey(pi / 4) * scale(0.1, 0.5, 0.1) Is there something really obvious that I'm missing or is it just another case of me being dense with maths? Thanks; Richard Moss
|
|
|
Post by ascotti on Jul 24, 2019 19:19:13 GMT
These matrix compositions can be really confusing!
Couple of tips.
Using the origin (0,0,0) as a reference can be useful. Try to build your table so that it's symmetrical around the origin, then put all objects into a group and move the group.
Check your camera. Sometimes the camera placement and especially the "up" vector can mess with our perception of the scene, e.g. we think the floor is the (x,z) plane but it has become say the (z,y) plane because of the camera orientation.
|
|
|
Post by Richard Moss on Jul 25, 2019 16:58:24 GMT
Hello,
Thanks for responding. I think I'll take your advice - grouping is only a couple of chapters ahead so I think I'll shelve trying to make the table until I've implemented groups then revisit it and try your suggestion.
Thanks again!
Regards; Richard Moss
|
|
|
Post by chrisd on Jul 26, 2019 4:49:25 GMT
I'm one chapter behind you, but here are my thoughts ...
I'm not sure why you are rotating by pi/4 in the Y axis. Do you have the camera pointing straight ahead, and you've rotated every object in the scene? Maybe you would be better off having the items in the scene not be rotated, and only have the camera be looking at the scene at a 45 degree angle. Probably much easier to create the scene that way.
P.S. It looks like you are making a really nice user interface to your ray tracer!
|
|
|
Post by Richard Moss on Jul 27, 2019 12:59:41 GMT
chrisd , Thanks for the reply. I have no idea why I put the rotation in either As far as the camera goes, I'm using a "default" camera from much earlier in the book, with the FOV tweaked slightly as otherwise the end of the table was offscreen. I followed the next chapter and added cones, unfortunately there's a strange glitch where the outline of a black circle is rendered in front of the cones and I couldn't find a fault in the code. I pushed on and implemented groups and then tried to do the "putting it together" hexagon. The first piece of that rendered fine, the other pieces are an utter mess - right place, but rendered completely incorrectly. Evidently I have nasty bug somewhere that is causing this, but not triggering any test failures. If I can't figure that out I'll probably have to make another post However, I did take the grouping functionality and create my table using it. ascotti was correct, it was much easier to base my table of the 0 origin and then translate the group, instead of trying to position and rotate each piece in turn (not that rotation was needed for the legs of course). I thought it was still broken as all the shadows were wrong until I rendered at a higher resolution then finally realized my table was floating two feet off the ground I haven't wrote a YAML parser yet, but I did copy the light, camera, ceiling, walls and table materials to set up the scene better for my home grown table, it looked quite good. It is strange the table works fine when the hexagon is a hideous mess though. Thanks for the compliment in regards to the user interface! For the first couple of chapters I just had a basic form which lots and lots of controls on them for entering various X, Y's and Z's. I quickly got fed up of that though so started building something a little more complex, creating custom UIEditors and TypeConverters so I could build everything from a PropertyGrid. It works quite nicely (especially for chaining matrices) and means I can test things out at runtime instead of laboriously editing the code, running, blah blah. It also makes it easy for me to flip between different (code base) worlds and world presets, at least until I write the YAML parser. I've been committing everything to a Git repository, my intention is to push it all to GitHub when I'm done. Edit: Turns out when I went back to fix the hexagon it was rendering perfectly. I'd introduced a bug where sometimes the parent wouldn't get set, I found and fixed this when wondering why material inheritance wasn't working on the table legs. Appears this is the cause for the broken hex too.
|
|
|
Post by chrisd on Aug 3, 2019 2:10:09 GMT
Hey, Richard,
I'm glad you were able to get decent results. I thought of another idea for how you could have solved it - using two separate translations. For each part of the table: scale to the right size translate (to the position relative to the table "object") rotate (the same rotation for every piece of the table "object") translate (the same translation for every piece of the table "object") This is effectively treating the object as a group. But if you've added the grouping functionality, that's a far superior way of doing the same thing.
- Chris
|
|