|
Post by Rod on Jan 4, 2023 14:30:40 GMT
This is my current project, some of it works, lots more to do. It simulates a science class light table and allows lenses and mirrors and such to be placed on the table and then to shine a light through and follow the path. Future functions include optical instrument simulation, telescope binoculars c etc. The mirror will hang the code if you go beyond a simple reflection. Drag lamps and lenses and mirrors onto the screen from the resource tray at the bottom. Left click to highlight and (Delete) to delete an item. They can be moved about. Some items can be rotated by right clicking. Press (L) to light the lamps on the table. The prism bends light correctly but does not as yet pull out the RGB rainbow difference. EDIT updated to lightLens7 it now has a black background and the mirror works, right click to rotate it. It also runs full screen. EDIT updated to lightLens8 lenses, filters and mirror works. Prism sort of works so too the parabolic mirror. Slit and interference pattern needs work. The eye will eventually issue rays same as the lamp. So still lots to do. It runs full screen, you may not see all of the optical components on a small screen. Thats still to fix! Edit updated to lightLens9 Now has a clear screen button though you can delete individual objects by highlighting and pressing delete. New color catchers added, in combination with the color filters you can now filter and mix colored light rays. There are three lamps with various sized beams. I have taken out the snap to grid and just left the placement free. If objects are too close together it can confuse the ray tracking. Still lots to do but a little rest from it now. This is the .zip fileHere is how it looks
|
|
|
Post by marshawn on Jan 5, 2023 8:35:29 GMT
now that's a mod, very beautiful. I wanted to do a similar thing some time ago with prisms but never got around to finishing it
|
|
|
Post by marshawn on Jan 6, 2023 0:26:23 GMT
B+ also has a nice mod that is a mouse controlled laser shining through a bunch of circular mirrors
|
|
|
Post by Rod on Jan 19, 2023 15:20:12 GMT
Ok, version6 is now linked at the head of the thread. Mirrors are working, prism sort of works as do the lenses. The convex mirror does not work yet. I am in a quandary now. To make the best of this I really need to move every collision to a vector collision. Just now I fudge the lenses but the mirror collision is fully vector and can happen at any angle. To improve the lenses and make them rotatable I need to put in sphere type vector collision but not as a reflected ray, it needs refracted. Something I have not researched yet. So too the convex mirror and indeed the prism collisions all need to move to vector collisions and I need to find how to work out the refraction. Fun so far but beginning to look like too big a challenge. How to collide with a triangle!?
|
|
|
Post by plus on Jan 19, 2023 18:24:14 GMT
B+ also has a nice mod that is a mouse controlled laser shining through a bunch of circular mirrors Alas, bplus avoids vectors like the plague and attempts everything with Trig including ATan2 which Rod does not want. The code you are talking about was just a simple mod of your ( marshawn 's) spectacular code of same from single location if I recall. I don't think vectors were used there ( and then) either. JB might be fast enough that that graphic might work specially if you can blank out lines without blinking screen. Colliding with triangle? Wouldn't the ray lines run perpendicular to the side hit? Well maybe if made of polarized glass, otherwise some will act like mirror and others will be absorbed in material and heat the triangle? That's just my layman's science intuition...
|
|
|
Post by Rod on Jan 19, 2023 18:46:03 GMT
Well vectors really are trig simplified. That’s why I like them. Everything is triangulated. So a sphere collision just gets the norm of the Ray, the norm of the sphere, which is the sphere centre to the intersect point normalised. Thus the reflection can be calculated as per the mirror by getting the dot product of the two norms.
A lens is just a segment of a sphere, so focal point to intersect gets the vector. A mirror is just a line intersect with the norm st 90o. However a prism is three lines, not sure about that yet.
The biggest stumbling block for me is how to calculate an intersects refraction rather than its reflection. So instead of bouncing at 90o to the collision norm it needs to keep going moved by a much reduced angle of refraction.
You can see the power of vector maths in my new code to manage the mirror. I just need more of the same.
Brain works a bit slower these days but it’s holding my attention.
|
|
|
Post by honkytonk on Jan 21, 2023 17:51:35 GMT
Hello, How it works ? For me, it opens a black window and nothing happens. it's normal ?
|
|
|
Post by tsh73 on Jan 21, 2023 19:54:37 GMT
Honkytonk, v6 looks like screenshot in the first post, but with black BG Also, click in window refreshes (redraws) window.
It says
WindowWidth = 1240 WindowHeight = 800
What your screen size? May be you are seeing just top left part, and toolbar left below desktop bottom? What's your windows version? I am seeing in in Win XP 1280x1024 desktop.
EDIT just set desktop to 1280x768 I have no idea how but window positions itself so that top seems to be negative (titlebar is off screen) I Pretty that was impossible (that is, setting top negative did not worked for me before But may be this is because window is too big for screen size) Anyway black work field and toolbar below are both visible and working OK.
|
|
|
Post by Rod on Jan 21, 2023 21:17:38 GMT
If you can see the bottom of the screen with the optical objects then left click on one and drag it onto the top screen. Drag a lamp on to the screen. Then press L the lamp will cast its rays. I first saw a light table in my school physics class. Thought it was really cool and we were just told to play with it for a while.
If the screen size is too big I need to change that but it needs a lot of pixel space.
|
|
|
Post by honkytonk on Jan 22, 2023 12:11:25 GMT
My screen is 1024 x 600 (XP) I have a big screen but it's on Win 10, it's too slow and I don't like Win 10. By putting the buttons and accessories at the top, it allows smaller screens to use the software, resizing the bottom as needed.
I'm reworking your code to fit my screen, but it seems to me that your bmp loading/processing procedure is unconventional !!
|
|
|
Post by Rod on Jan 24, 2023 13:11:51 GMT
I have updated the link in the original post with a version that will run full screen. I don't normally like full screen apps but in this case it probably needs it to make the most of small screens.
|
|
|
Post by Rod on Feb 3, 2023 12:47:28 GMT
I have posted version 8, it has more robust component selection, placement and rotation. The lenses and mirror and color filters work. The prism, parabolic mirror and slit need work. I need to improve the tray display as you may not see all components on a smaller screen.
So the idea is you drag components from the bottom tray onto the table. Left click and drag to move them, right click and drag to rotate them. Now press L or click the lamp button and the rays will be traced. Kinda fun, lots more to do. The eye for example needs to issue rays as if it is looking. I also need to create a component to show color merging and the prism rainbow as graduations not single lines.
Eventually you will be able to click a button and have telescopes and microscopes and binoculars and periscopes appear on screen in component form.
|
|
|
Post by tsh73 on Feb 3, 2023 13:16:55 GMT
Finally I saw a visible a switch to turn light on/off! Like, you have all these cool gadgets placed by mouse - and then suddenly you need to press sertain key for the thing to start working :(
>>I need to improve the tray display as you may not see all components on a smaller screen. I see, it needs screen width just to put them all. Well, what about displaying them at 50% on a toolbar, may be only for smaller screen sizes?
|
|
|
Post by Rod on Feb 6, 2023 18:35:44 GMT
I have added three types of lamp, ray, beam and point. But more interestingly I have a new orb that absorbs light it receives. So now those color filters can issue light that gets absorbed and reflected in a new optical component. So we can mix light!
Also added. Light bulb and a 35mm slide but need to think through how they are presented.
If anyone has ideas just shout. For example fibre optic tube?
|
|
|
Post by Rod on Feb 9, 2023 13:46:52 GMT
Posted latest version, link is in first post. color catchers are good fun.
|
|