The Light component
A light source in our scene is a type of Component
with a color and a float array that is used to represent the calculated location in eye space. Let's create the Light
class now.
Create a new Light
Java class in the renderbox/components
folder. Define it as follows:
public class Light extends Component { private static final String TAG = "RenderBox.Light"; public final float[] lightPosInEyeSpace = new float[4]; public float[] color = new float[]{1,1,1,1}; public void onDraw(float[] view){ Matrix.multiplyMV(lightPosInEyeSpace, 0, view, 0, transform.getPosition().toFloat4(), 0); } }
Our default light is white (color 1,1,1).
The onDraw
method calculates the actual light position in eye space based on the position of Transform
multiplied by the current view matrix.
It's possible to extend RenderBox
to support multiple light sources and other fancy rendering, such as shadows and so on. However, we will limit the scene to a single light source. Thus...