com.threed.jpct.util
Class Light

java.lang.Object
  extended bycom.threed.jpct.util.Light
All Implemented Interfaces:
java.io.Serializable

public class Light
extends java.lang.Object
implements java.io.Serializable

Light is a helper class to ease the rather unintuitive handling of light sources in jPCT. Usually, lights are managed by the corresponding world instance and identified by a numerical ID. This is a fast way of doing it, but not very convenient nor OO. This little helper will improve this situation but it still sits on top of the "normal" implementation.

See Also:
Serialized Form

Constructor Summary
Light(World world)
          Creates a new light in the world.
 
Method Summary
 void disable()
          Disables a light.
 void dispose()
          Disposes the light.
 void enable()
          Enables a light.
 float getAttenuation()
          Returns the light's attenuation if it has been set before.
 float getDiscardDistance()
          Gets the discard distance of this light, if it has be set before.
 float getDistanceOverride()
          Returns the overriden distance.
 SimpleVector getIntensity()
          Sets the light's intensity.
 int getLightId()
          Returns the light's internal ID.
 SimpleVector getPosition()
          Returns the position of this light in world space.
 boolean isEnabled()
          Is the light enabled?
 void rotate(SimpleVector degrees, SimpleVector pivot)
          Rotates the light around a rotation pivot.
 void setAttenuation(float att)
          Sets the light's attenuation.
 void setDiscardDistance(float dist)
          Sets the light's discard distance.
 void setDistanceOverride(float distance)
          Overrides the distance that is usually calculated by taking the distance between the light source and an object.
 void setIntensity(float red, float green, float blue)
          Sets the light's intensity.
 void setIntensity(SimpleVector inty)
          Sets the light's intensity.
 void setPosition(SimpleVector pos)
          Sets the position of this light in world space.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Light

public Light(World world)
Creates a new light in the world. The light will be placed at (0,0,0) and with an intensity of (255,255,255).

Parameters:
world - the instance of world
Method Detail

enable

public void enable()
Enables a light. Each new light is enabled by default.


disable

public void disable()
Disables a light. The light is still part of the world, just not visible.


dispose

public void dispose()
Disposes the light. It has no influence on the scene anymore after calling this method. This can't be undone.


getLightId

public int getLightId()
Returns the light's internal ID.

Returns:

isEnabled

public boolean isEnabled()
Is the light enabled?

Returns:
boolean yes...or no?

setIntensity

public void setIntensity(SimpleVector inty)
Sets the light's intensity.

Parameters:
inty - a SimpleVector that contains the intensities of r,g,b in its x,y,z-components.

setIntensity

public void setIntensity(float red,
                         float green,
                         float blue)
Sets the light's intensity.

Parameters:
red - the red intensity
green - the green intensity
blue - the blue intensity

getIntensity

public SimpleVector getIntensity()
Sets the light's intensity.

Returns:
SimpleVector a SimpleVector that contains the intensities of r,g,b in its x,y,z-components.

setAttenuation

public void setAttenuation(float att)
Sets the light's attenuation. Overrides the setting from Config.linearDiv and Config.fadeoutLight for this light.

Parameters:
att - the attenuation. The lower the value, the faster the light will fade. -1 means no fading at all.

getAttenuation

public float getAttenuation()
Returns the light's attenuation if it has been set before. If it hasn't, the result will be below -1 but otherwise undefined.

Returns:
float the attenuation (if set)

setDiscardDistance

public void setDiscardDistance(float dist)
Sets the light's discard distance. Overrides the setting from Config.lightDiscardDistance for this light.

Parameters:
dist - the discard distance, i.e. the distance where the light will be "cut off" at latest. -1 means never.

getDiscardDistance

public float getDiscardDistance()
Gets the discard distance of this light, if it has be set before. If it hasn't, the result of this call in undefined (but lower than -1).

Returns:
float the discard distance (is previously set, otherwise something below -1)

setDistanceOverride

public void setDistanceOverride(float distance)
Overrides the distance that is usually calculated by taking the distance between the light source and an object. With this, it's possible to let a light source have an effect on an object even if it's very far away and many other lights are actually closer.

Parameters:
distance - the new distance

getDistanceOverride

public float getDistanceOverride()
Returns the overriden distance. If none is set, -1 will be returned.

Returns:
the overriden distance or -1

setPosition

public void setPosition(SimpleVector pos)
Sets the position of this light in world space.

Parameters:
pos - the position

getPosition

public SimpleVector getPosition()
Returns the position of this light in world space.

Returns:
SimpleVector the position

rotate

public void rotate(SimpleVector degrees,
                   SimpleVector pivot)
Rotates the light around a rotation pivot. Unlike the similar methods in World, this doesn't cause the light to execute this rotation every frame (which was stupid idea anyway...:-)). This is done, when you are calling the method. Not more, not less.

Parameters:
degrees - a SimpleVector that contains the rotation angles in its x,y,z-components
pivot - SimpleVector the rotation pivot