Spotlight Project
The above video shows the project with the drawn 3D sphere after I finish compiling and rendering it (at which point, an image is generated based on what the chosen camera was able to render). You can see such image scrolling down on this page, in the slideshow. To build this project, I used openFrameworks, which is a C++ toolkit used for creative coding. It is written and built on top of OpenGL. The first step to make this project successful, was to setup a basic camera, a view plane, and a scene. Please note that because some essential parts of the source code were borrowed from Dr. Kevin Smith, I cannot share the entirety of the code (which is why I do not have this github project as public). I can, however, provide some pieces. The camera that is created for this project is stationary and along the Z axis.
The first step, was to create a light and spotlight class, both of which are children scene objects. To make it simple, scene objects are objects that can be pushed unto a scene and can be detected by a camera. The light and spot light classes have similar attributes (such as intensity), and both receive a glm vector that will serve as their location/position. Both call the draw function to draw their lights unto the scene. However, the spotlight class has additional features, such as conAngle, a direction vector, and bulb. Bulb, is simply a light object:
There is a class called "Sphere", that is able to create a Sphere primitive and push it unto the scene. One of the attributes in the class, is the diffuse color of the sphere.
Once I have the light, spotlight, and sphere classes, I initialize them and push them unto the scene. The following images show how I initialized and pushed the lights lightx, lighty, and lightz, as well as spotlight lighta:
Once the spotlight(s) and spheres are intialized and pushed unto the scene, I proceeded to create images featuring spotlights. I restricted the direction in which the light can be emitted from the bulb attribute, making the light emission restrictions look like a cone. These restrictions are controlled in a rayTracing function, by gathering the dot product of two vectors of the spotlight class: the direction and position vectors. There's a formula that I used to do this, and here's a section of that rayTracing function, restricting the light emissions:
After compiling and rendering, here are some of the images I generated:
Please note that most of the pictures shown above (from the 1st to the 18th), only have spotlights in the scene with no lights. From 19th onward, I start adding lights (the last one having three lights). The reason why the first 19 images only have one spotlight (which was the focus of the project), is to display how these spotlights look like when there are no regular lights around.
The project was awesome and I am satisfied with the imagery generated. This was a 2020 project, and I wish I could have had more time to play around with the lights. Perhaps one day, I will finish implementing Ambient and PointLights, which have slight differences from regular lights or spotlights: