OpenGL Lightsaber

Andrew Graham
CalPoly, CPE 471
Zoe Wood

 

Objective: To see what kind of lightsaber I could create using opengl.

 

Method:

The first part of the project was to make the hilt of the lightsaber. The hilt is made completely of glut primitives. The bottom in a cone, the middle is a cylinder and the top is another cone. There are also two cylinders on the side for activations buttons middle cylinders. The cylinders are arranged hierarchically to allow for the whole thing to be manipulated easily.


Figure 1. Lightsaber Hilt


Once the hilt was made I had to decide on how to make the blade. For the blade I used the idea of layered polygons. The white core is the front most layer with the colored layers getting farther back as color their colors get darker. Also as the layer get farther away from the white core they also get more transparent to give the effect of a glowing beam. Then to give the blade a non-shaded look the lights are disabled while the blade is rendered, thus preventing any shading. To create a lighting effect, a pointlight is placed above the lightsaber hilt. The light is the same color as the blade and can be turned on and off by turning the blade on and off. Later when the saber is animated the light moves with the saber.


Figure 2. Lightsaber Blade


Because the lightsaber blade is flat I used billboarding the make it always face the camera. To be more specific I used cylindrical billboarding, which restrains the rotation of the blade to be along the y axis. Therefore as the camera is rotated around the saber the the blade will face the camera.


Figure 3. Sideview with billboarding turned off


Figure 4. Blade Fanning


When the lightsaber is animated so it moves the bade will become wider at the top. This is called the fan of the lightsaber and is done to make the blade look like its moving. With the billbording turned on we get a weird effect. When the blade fans, it is only suppose to in the direction the lightsaber is moving, but with the billboading turned on the fan follows the camera, making the blade look like it is moving perpendicular to the actual direction of the lightsaber movement. To account for this I made a function that calculates the direction that the lightsaber is moving, and the direction that the camera is facing. By taking the dot product of these to vectors we can determine the angle between the lightsaber movement and the direction the camera is facing. Then I can scale the amount of fan that is shown based on where the camera is. If the camera is facing the direction the lightsaber is moving then the blade is not faned at all. If the Camera is facing perpendicular to the direction that the saber is moving then the full fan is shown.


Figure 5. Fanning the wrong way

 


Figure 6. Fanning the right way