Class GeneralLight
- ambient (SoftwareLightAmbient, AmbientLight) - directional (SoftwareLightDirectional, DirectionalLight) - point (SoftwareLightPoint, PointLight) - spot (SoftwareLightSpot, SpotLight)
An instance of this class can switch between any of these four types in which case a new pair of SoftwareLight and (Java) Light instances are now referenced. Any changes to light properties are set for both types of lights and any properties which are set which do not apply to a light of a particular type are maintained so that when the light type is switched, the properties can be applied to that light if applicable and any properties of the light being switched from are automatically set for the new type of light.
The following is a list of the properties which can be set:
- enable (on/off) - color (RGB) - intensity (scales color by factor in range [0,1]) - position (normalized to [-1,1] range) - direction (unit length) - target for direction (equal to position + direction) - type
Note that setting the direction or target causes subsequent updates to position to change the target or direction, or vice versa.
When an instance is created, a bit mask is specified which identifies which of the possible types of lights this instances can be switched to. The initial type of light is one of the types for which this instance is enabled starting with ambient, then directional, then point, and then spot.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanGeneral properties which can be shared by all lights types.private booleanProperties shared by directional and spot lights.private floatAttenuation factor red channel.private floatAttenuation factor green channel.private floatAttenuation factor blue channel.private floatLight intensity scale factor.private floatShinness factor, exponential power value for Phong type shading model.private final floatMaximum coordinate scale factor for real positions.private final floatScale factors for placing [-1,+1] normalized positions and targets into real world space with dimensions.private final floatfloat Y coordinate scale factor for real positions.private final floatfloat Y coordinate scale factor for real positions.private floatProperties for spot lights only.private floatSpot light exponential factor.private intType of light and limit for available light types which can be selected.private final intLight type mask.private StringDescription associated with this light.private javax.vecmath.Vector3fLight direction.private ColorLight color.private javax.vecmath.Point3fProperties shared by point and spot lights.private javax.vecmath.Point3fLight shooting target position.static final intAll light types maskstatic final intBit mask used to identify light types in combination.static final intDirectional light maskstatic final intPoint light mask.static final intSpot light mask.private static final String[]Light constant types array.private static final intAmbient light constant.private static final intDirectinal light constant.private static final intPoint light constant.private static final intSpot light constant. -
Constructor Summary
ConstructorsConstructorDescriptionGeneralLight(int iTypeMask, float fSizeX, float fSizeY, float fSizeZ) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanQuery if light can be set to the ambient type.final booleanQuery if light can be set to the directional type.final booleanQuery if light can be set to any non-ambient type.final booleanQuery if light can be set to the point type.final booleanQuery if light can be set to the spot type.javax.media.j3d.LightAccess Java3D light instance based on current type.final javax.vecmath.Vector3fCreate an instance which contains the normalized real space coordinates of the direction vector of the (Java3D) Light.final javax.vecmath.Point3fCreate an instance which contains the normalized real space coordinates for the position of the (Java3D) Light.private SoftwareLightcreateSoftwareLight(javax.vecmath.Point3f kPosition, javax.vecmath.Vector3f kDirection) Access software light instance based on current type.final SoftwareLightAccess current software light based on type.final SoftwareLightAccess current software light based on type.WildMagic.LibGraphics.Rendering.LightAccess Java3D light instance based on current type.final voidenable(boolean bEnable) Set whether light is enabled.final ColorgetColor()Query the current based color of the light.final StringGet description associated with this light.final javax.vecmath.Vector3fQuery the current direction of the light.final javax.vecmath.Color3fGet the light color scaled with the intensity factor.final floatQuery the current light intensity.final javax.vecmath.Point3fQuery the current position of the light.final javax.vecmath.Point3fQuery the current target of the light.final StringReturn a string which describes the type of light.final booleanQuery if updates to direction affect the target while keeping the direction fixed.final booleanQuery if light is currently enabled.final booleanQuery if updates to position affect direction while keeping the target fixed.booleanQuery if current light type is ambient.final booleanQuery if current light type is directional.final booleanQuery if current light type is point.final booleanQuery if current light type is spot.private floatnormalize(javax.vecmath.Vector3f kV) Replace a vector by a unit-length vector in the same direction.final voidSet the base color for the light.final voidsetDescription(String description) Set description associated with this light.final voidsetDirection(float fX, float fY, float fZ) Set the current direction of the light.final voidsetDirection(javax.vecmath.Vector3f kDir) Set the current direction of the light.final voidsetIntensity(float fIntensity) Set the intensity of the light which sets the actual color of the light to this factor times the base color of the light.final voidsetPosition(float fX, float fY, float fZ) Set the current position of the light.final voidsetPosition(javax.vecmath.Point3f kPosition) Set the current position of the light.final voidsetTarget(float fX, float fY, float fZ) Set the current target of the light.final voidsetTarget(javax.vecmath.Point3f kPosition) Set the current target of the light.final voidSet the current light type to ambient.final voidSet the current light type to directional.final voidSet the current light type to point.final voidSet the current light type to spot.private voidupdateDirection(float fX, float fY, float fZ) Set the current direction of the light.private voidupdateTarget(float fX, float fY, float fZ) Set the current target of the light.
-
Field Details
-
TYPE_AMBIENT
private static final int TYPE_AMBIENTAmbient light constant.- See Also:
-
TYPE_SPOT
private static final int TYPE_SPOTSpot light constant.- See Also:
-
TYPE_POINT
private static final int TYPE_POINTPoint light constant.- See Also:
-
TYPE_DIRECTIONAL
private static final int TYPE_DIRECTIONALDirectinal light constant.- See Also:
-
sakTypeName
Light constant types array. -
MASK_AMBIENT
public static final int MASK_AMBIENTBit mask used to identify light types in combination.- See Also:
-
MASK_SPOT
public static final int MASK_SPOTSpot light mask.- See Also:
-
MASK_POINT
public static final int MASK_POINTPoint light mask.- See Also:
-
MASK_DIRECTIONAL
public static final int MASK_DIRECTIONALDirectional light mask- See Also:
-
MASK_ALL
public static final int MASK_ALLAll light types mask- See Also:
-
m_bEnabled
private boolean m_bEnabledGeneral properties which can be shared by all lights types. -
m_bFixTarget
private boolean m_bFixTargetProperties shared by directional and spot lights. If this flag is true, then updates to position change the direction based on the current target. Otherwise, updates to position change the target based on the current direction. This flag is changed when the target or direction are explicitly set. -
m_fAttenuationC0
private float m_fAttenuationC0Attenuation factor red channel. -
m_fAttenuationC1
private float m_fAttenuationC1Attenuation factor green channel. -
m_fAttenuationC2
private float m_fAttenuationC2Attenuation factor blue channel. -
m_fIntensity
private float m_fIntensityLight intensity scale factor. -
m_fShininess
private float m_fShininessShinness factor, exponential power value for Phong type shading model. -
m_fSizeMax
private final float m_fSizeMaxMaximum coordinate scale factor for real positions. -
m_fSizeX
private final float m_fSizeXScale factors for placing [-1,+1] normalized positions and targets into real world space with dimensions. -
m_fSizeY
private final float m_fSizeYfloat Y coordinate scale factor for real positions. -
m_fSizeZ
private final float m_fSizeZfloat Y coordinate scale factor for real positions. -
m_fSpotAngle
private float m_fSpotAngleProperties for spot lights only. -
m_fSpotExponent
private float m_fSpotExponentSpot light exponential factor. -
m_iType
private int m_iTypeType of light and limit for available light types which can be selected. -
m_iTypeMask
private final int m_iTypeMaskLight type mask. -
m_kDescription
Description associated with this light. -
m_kDirection
private javax.vecmath.Vector3f m_kDirectionLight direction. -
m_kLightColor
Light color. -
m_kPosition
private javax.vecmath.Point3f m_kPositionProperties shared by point and spot lights. -
m_kTarget
private javax.vecmath.Point3f m_kTargetLight shooting target position.
-
-
Constructor Details
-
GeneralLight
public GeneralLight(int iTypeMask, float fSizeX, float fSizeY, float fSizeZ) Constructor. Note that the scale factors may be negative.- Parameters:
iTypeMask- int Bit mask which limits the types of lights which can be selected for this instance.fSizeX- float X coordinate scale factor for real positions.fSizeY- float Y coordinate scale factor for real positions.fSizeZ- float Z coordinate scale factor for real positions. after normalizations.
-
-
Method Details
-
canSetTypeAmbient
public final boolean canSetTypeAmbient()Query if light can be set to the ambient type.- Returns:
- boolean True if light type can be set to ambient.
-
canSetTypeDirectional
public final boolean canSetTypeDirectional()Query if light can be set to the directional type.- Returns:
- boolean True if light type can be set to directional.
-
canSetTypeNonAmbient
public final boolean canSetTypeNonAmbient()Query if light can be set to any non-ambient type.- Returns:
- boolean True if light type can be set to any non-ambient type.
-
canSetTypePoint
public final boolean canSetTypePoint()Query if light can be set to the point type.- Returns:
- boolean True if light type can be set to point.
-
canSetTypeSpot
public final boolean canSetTypeSpot()Query if light can be set to the spot type.- Returns:
- boolean True if light type can be set to spot.
-
createJava3dLight
public javax.media.j3d.Light createJava3dLight()Access Java3D light instance based on current type.- Returns:
- Light Java3D light instance based on current type.
-
createWMLight
public WildMagic.LibGraphics.Rendering.Light createWMLight()Access Java3D light instance based on current type.- Returns:
- Light Java3D light instance based on current type.
-
createJava3dLightDirection
public final javax.vecmath.Vector3f createJava3dLightDirection()Create an instance which contains the normalized real space coordinates of the direction vector of the (Java3D) Light.- Returns:
- Vector3f New instance created with direction vector.
-
createJava3dLightPosition
public final javax.vecmath.Point3f createJava3dLightPosition()Create an instance which contains the normalized real space coordinates for the position of the (Java3D) Light.- Returns:
- Point3f New instance created with the position.
-
createSoftwareLightModel
Access current software light based on type. Coordinates and direction are appropriate for software rendering for a light located in the "model" space of the objects being rendered.- Returns:
- SoftwareLight Software light instance based on current type.
-
createSoftwareLightWorld
Access current software light based on type. Coordinates and direction are appropriate for software rendering for a light located in the "world" relative to objects being rendered.- Returns:
- SoftwareLight Software light instance based on current type.
-
enable
public final void enable(boolean bEnable) Set whether light is enabled.- Parameters:
bEnable- boolean True if light is to be enabled.
-
getColor
Query the current based color of the light.- Returns:
- Color Base color of the light.
-
getDescription
Get description associated with this light.- Returns:
- String Text description for light.
-
getDirection
public final javax.vecmath.Vector3f getDirection()Query the current direction of the light.- Returns:
- Vector3f Normalized direction vector for the light.
-
getIntensifiedColor
public final javax.vecmath.Color3f getIntensifiedColor()Get the light color scaled with the intensity factor.- Returns:
- Light color!
-
getIntensity
public final float getIntensity()Query the current light intensity.- Returns:
- float Light color scale factor in range [0,1].
-
getPosition
public final javax.vecmath.Point3f getPosition()Query the current position of the light.- Returns:
- Point3f Position of the light where the coordinates are normalized to the [-1,+1] range.
-
getTarget
public final javax.vecmath.Point3f getTarget()Query the current target of the light.- Returns:
- Point3f Target position of the light where the coordinates are normalized to the [-1,+1] range.
-
getTypeString
Return a string which describes the type of light.- Returns:
- String
-
isDirectionFixed
public final boolean isDirectionFixed()Query if updates to direction affect the target while keeping the direction fixed.- Returns:
- boolean True if the direction is to remain fixed.
-
isEnabled
public final boolean isEnabled()Query if light is currently enabled.- Returns:
- boolean True if light is currently enabled.
-
isTargetFixed
public final boolean isTargetFixed()Query if updates to position affect direction while keeping the target fixed.- Returns:
- boolean True if the target is to remain fixed.
-
isTypeAmbient
public boolean isTypeAmbient()Query if current light type is ambient.- Returns:
- boolean True if current light type is ambient.
-
isTypeDirectional
public final boolean isTypeDirectional()Query if current light type is directional.- Returns:
- boolean True if current light type is directional.
-
isTypePoint
public final boolean isTypePoint()Query if current light type is point.- Returns:
- boolean True if current light type is point.
-
isTypeSpot
public final boolean isTypeSpot()Query if current light type is spot.- Returns:
- boolean True if current light type is spot.
-
setColor
Set the base color for the light. Actual color of light is the base color multiplied by the light intensity.- Parameters:
kColor- Color Base color for the light.
-
setDescription
Set description associated with this light.- Parameters:
description- String Text description for light.
-
setDirection
public final void setDirection(javax.vecmath.Vector3f kDir) Set the current direction of the light.- Parameters:
kDir- Vector3f Normalized direction vector for the light.
-
setDirection
public final void setDirection(float fX, float fY, float fZ) Set the current direction of the light.- Parameters:
fX- float X coordinate of light direction vector.fY- float Y coordinate of light direction vector.fZ- float Z coordinate of light direction vector.
-
setIntensity
public final void setIntensity(float fIntensity) Set the intensity of the light which sets the actual color of the light to this factor times the base color of the light.- Parameters:
fIntensity- float Normalized light color scale factor in range [0,1].
-
setPosition
public final void setPosition(javax.vecmath.Point3f kPosition) Set the current position of the light.- Parameters:
kPosition- Point3f Position of light where the coordinates are normalized to the [-1,+1] range.
-
setPosition
public final void setPosition(float fX, float fY, float fZ) Set the current position of the light.- Parameters:
fX- float X coordinate position of light in [-1,+1] range.fY- float Y coordinate position of light in [-1,+1] range.fZ- float Z coordinate position of light in [-1,+1] range.
-
setTarget
public final void setTarget(javax.vecmath.Point3f kPosition) Set the current target of the light.- Parameters:
kPosition- Point3f Target position of light where the coordinates are normalized to the [-1,+1] range.
-
setTarget
public final void setTarget(float fX, float fY, float fZ) Set the current target of the light.- Parameters:
fX- float X coordinate target position of light in [-1,+1] range.fY- float Y coordinate target position of light in [-1,+1] range.fZ- float Z coordinate target position of light in [-1,+1] range.
-
setTypeAmbient
public final void setTypeAmbient()Set the current light type to ambient. -
setTypeDirectional
public final void setTypeDirectional()Set the current light type to directional. -
setTypePoint
public final void setTypePoint()Set the current light type to point. -
setTypeSpot
public final void setTypeSpot()Set the current light type to spot. -
createSoftwareLight
private SoftwareLight createSoftwareLight(javax.vecmath.Point3f kPosition, javax.vecmath.Vector3f kDirection) Access software light instance based on current type.- Parameters:
kPosition- Point3f Input position of light.kDirection- Vector3f Input (normalized) direction vector of light.- Returns:
- SoftwareLight Software light instance based on current type.
-
normalize
private float normalize(javax.vecmath.Vector3f kV) Replace a vector by a unit-length vector in the same direction. If the input vector is (nearly) the zero vector, the replacement vector is the zero vector.- Parameters:
kV- the vector to be normalized- Returns:
- the length of the input vector
-
updateDirection
private void updateDirection(float fX, float fY, float fZ) Set the current direction of the light.- Parameters:
fX- float X coordinate of light direction vector.fY- float Y coordinate of light direction vector.fZ- float Z coordinate of light direction vector.
-
updateTarget
private void updateTarget(float fX, float fY, float fZ) Set the current target of the light.- Parameters:
fX- float X coordinate target position of light in [-1,+1] range.fY- float Y coordinate target position of light in [-1,+1] range.fZ- float Z coordinate target position of light in [-1,+1] range.
-