dimanche 22 avril 2012

Components part 1



As I said in my previous post, I wanted to model the components. This is still a work in progress but I proudly present you the *new* lens and detector design. To construct them I wrote a class which take advantage of the pyglet batch system. God I love those batches... The two models are in fact made out of three new primitive forms (plus my old cube) which are cylinder, disk and hollow disk. I simply create them with appropriate dimensions and position and add them to the component's batch. That allows me to render the component in a single call !

This is especially interesting as I can therefore use the batch position when building the vertices, allowing me simple and fast manipulation of objects from my scene. This works by building the model each time that a position is altered, either by a call from the GUI or by user manipulation (through picking), the others batches aren't altered.
There is no lighting here it is just different coloring of the primitives. I will soon implement a GLSL lighting, I am currently testing it.
I also have a little color picking script that kinda work but that will wait a bit as I am not really happy with this solution. I think I will look more deeply into the ray picking technique maybe with bounding boxes to speed it up.

If I don't have too much work this week I will also design the source and I would like to include a mirror component into my project (I still have to figure out how to cut one end of the beam according to the angle of the mirror). Also still a long way to go...   

vendredi 20 avril 2012

Virtual Optics

Yesterday I put my hands again on the Virtual Optics project that I was telling about. I hadn't touched it in a month or so as I was busy with other things and I learned the hard way a very basic lesson of programming: cleaning and commenting the code is essential !!! Anyway I spent the last two days repairing my laziness and now it is a brand new project that I can work on, I reorganized all of my scripts and commented half of it, you can see the result in the video below:

 

It is not much, it is basically an ABCD matrix [1] program for a two lenses system. It allows to calculate the shape of a laser beam in such a system. The main goal of this project is at the end to be a possibility to quickly and interactively evaluate the feasibility and also some characteristics of an optical setup.

It is entirely written in python with pyglet and glydget libraries as only dependencies, the GUI window can be reduced to only display "Menu" and can be moved around. The frame rate displayed at the bottom left corner is only there for debug. To model the beam I used a parametric surface (altered function from the torus example of  pyglet).

That's it for the introduction, I spend approximatively a month coding it as a hobby but now I have a solid base to build on. In the near future I will redesign the components and implement others, I also want to make them pickable and It will be also great to be able to add or remove optical components on the fly.

More on this coming later... 
If interested I will happily give the code, it will be great for me to have feedbacks, just write me an email at: simulationplayground@gmail.com