Creating a Light Source

[ LiB ]

Creating a Light Source

The light source is the most important object in a 3D environment. If the light source were nonexistent, the world would be dark. The most common type of light source in most 3D applications is the point light. This point light source is like a light bulb that emits energy equally in all directions in a spherical pattern. The imaginary energy (in the form of photons ) that's emitted from the point light source is then spattered onto nearby objects such as planes, polygons, and spheres. The intensity of a point is relative to the angle and intensity of the light source. The farther away the object is from the light source, the weaker the overall intensity. This is known as the intensity falloff effect and can be applied to 3D renderers.

There are many types of light sources. The light that's emitted from a light source can be equal (point light), directional (spot lights), or area based (area lights). Let's define a light class (called cLight ) that encapsulates the basic attributes of the point light. The four major components you want to implement in the class are the light's position, its color , the power/wattage, and its active state. You'll have a few methods applied to the class for updating and changing data. Three constructors are to be defined in the class to accommodate the different types of parameters. One method is also required to assign the member data in the class at any time in the application.

NOTE

TIP

You can extend the light class to accommodate different types of lights such as spot lights and direc tional light.

 class cLight {    public:    cVector3 vPosition;    color3   Color;    float    fWattage;    bool     bActive;    cLight()    {    vPosition   = cVector3::vZero;    Color       = color3::White;    bActive     = true;    fWattage    = 1.0f;    };    cLight(float x, float y, float z, float wattage)    {    vPosition   = cVector3(-x,-y,z);    Color       = color3::White;    bActive     = true;    fWattage    = wattage;    };    cLight(float x, float y, float z, float wattage, color3 color)    {     vPosition   = cVector3(-x,-y,z);     bActive     = true;     fWattage    = wattage;     Color       = color;  };  void Setup(float x, float y, float z, float wattage,      color3 color = color3::White) {  vPosition   =  cVector3(-x,-y,z);  bActive     =  true;  fWattage    =  wattage;  Color       =  color;  }; }; 

[ LiB ]


Focus On Photon Mapping
Focus On Photon Mapping (Premier Press Game Development)
ISBN: 1592000088
EAN: 2147483647
Year: 2005
Pages: 128
Authors: Marlon John

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net