Class GeneralLight
- java.lang.Object
-
- gov.nih.mipav.view.renderer.J3D.GeneralLight
-
public class GeneralLight extends java.lang.ObjectThis class maintains an instance of a SoftwareLight and a (Java3D) Light where these instances are of the same type:- 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
Fields Modifier and Type Field Description private booleanm_bEnabledGeneral properties which can be shared by all lights types.private booleanm_bFixTargetProperties shared by directional and spot lights.private floatm_fAttenuationC0Attenuation factor red channel.private floatm_fAttenuationC1Attenuation factor green channel.private floatm_fAttenuationC2Attenuation factor blue channel.private floatm_fIntensityLight intensity scale factor.private floatm_fShininessShinness factor, exponential power value for Phong type shading model.private floatm_fSizeMaxMaximum coordinate scale factor for real positions.private floatm_fSizeXScale factors for placing [-1,+1] normalized positions and targets into real world space with dimensions.private floatm_fSizeYfloat Y coordinate scale factor for real positions.private floatm_fSizeZfloat Y coordinate scale factor for real positions.private floatm_fSpotAngleProperties for spot lights only.private floatm_fSpotExponentSpot light exponential factor.private intm_iTypeType of light and limit for available light types which can be selected.private intm_iTypeMaskLight type mask.private java.lang.Stringm_kDescriptionDescription associated with this light.private javax.vecmath.Vector3fm_kDirectionLight direction.private java.awt.Colorm_kLightColorLight color.private javax.vecmath.Point3fm_kPositionProperties shared by point and spot lights.private javax.vecmath.Point3fm_kTargetLight shooting target position.static intMASK_ALLAll light types maskstatic intMASK_AMBIENTBit mask used to identify light types in combination.static intMASK_DIRECTIONALDirectional light maskstatic intMASK_POINTPoint light mask.static intMASK_SPOTSpot light mask.private static java.lang.String[]sakTypeNameLight constant types array.private static intTYPE_AMBIENTAmbient light constant.private static intTYPE_DIRECTIONALDirectinal light constant.private static intTYPE_POINTPoint light constant.private static intTYPE_SPOTSpot light constant.
-
Constructor Summary
Constructors Constructor Description GeneralLight(int iTypeMask, float fSizeX, float fSizeY, float fSizeZ)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanSetTypeAmbient()Query if light can be set to the ambient type.booleancanSetTypeDirectional()Query if light can be set to the directional type.booleancanSetTypeNonAmbient()Query if light can be set to any non-ambient type.booleancanSetTypePoint()Query if light can be set to the point type.booleancanSetTypeSpot()Query if light can be set to the spot type.javax.media.j3d.LightcreateJava3dLight()Access Java3D light instance based on current type.javax.vecmath.Vector3fcreateJava3dLightDirection()Create an instance which contains the normalized real space coordinates of the direction vector of the (Java3D) Light.javax.vecmath.Point3fcreateJava3dLightPosition()Create 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.SoftwareLightcreateSoftwareLightModel()Access current software light based on type.SoftwareLightcreateSoftwareLightWorld()Access current software light based on type.WildMagic.LibGraphics.Rendering.LightcreateWMLight()Access Java3D light instance based on current type.voidenable(boolean bEnable)Set whether light is enabled.java.awt.ColorgetColor()Query the current based color of the light.java.lang.StringgetDescription()Get description associated with this light.javax.vecmath.Vector3fgetDirection()Query the current direction of the light.javax.vecmath.Color3fgetIntensifiedColor()Get the light color scaled with the intensity factor.floatgetIntensity()Query the current light intensity.javax.vecmath.Point3fgetPosition()Query the current position of the light.javax.vecmath.Point3fgetTarget()Query the current target of the light.java.lang.StringgetTypeString()Return a string which describes the type of light.booleanisDirectionFixed()Query if updates to direction affect the target while keeping the direction fixed.booleanisEnabled()Query if light is currently enabled.booleanisTargetFixed()Query if updates to position affect direction while keeping the target fixed.booleanisTypeAmbient()Query if current light type is ambient.booleanisTypeDirectional()Query if current light type is directional.booleanisTypePoint()Query if current light type is point.booleanisTypeSpot()Query if current light type is spot.private floatnormalize(javax.vecmath.Vector3f kV)Replace a vector by a unit-length vector in the same direction.voidsetColor(java.awt.Color kColor)Set the base color for the light.voidsetDescription(java.lang.String description)Set description associated with this light.voidsetDirection(float fX, float fY, float fZ)Set the current direction of the light.voidsetDirection(javax.vecmath.Vector3f kDir)Set the current direction of the light.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.voidsetPosition(float fX, float fY, float fZ)Set the current position of the light.voidsetPosition(javax.vecmath.Point3f kPosition)Set the current position of the light.voidsetTarget(float fX, float fY, float fZ)Set the current target of the light.voidsetTarget(javax.vecmath.Point3f kPosition)Set the current target of the light.voidsetTypeAmbient()Set the current light type to ambient.voidsetTypeDirectional()Set the current light type to directional.voidsetTypePoint()Set the current light type to point.voidsetTypeSpot()Set 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 Detail
-
TYPE_AMBIENT
private static final int TYPE_AMBIENT
Ambient light constant.- See Also:
- Constant Field Values
-
TYPE_SPOT
private static final int TYPE_SPOT
Spot light constant.- See Also:
- Constant Field Values
-
TYPE_POINT
private static final int TYPE_POINT
Point light constant.- See Also:
- Constant Field Values
-
TYPE_DIRECTIONAL
private static final int TYPE_DIRECTIONAL
Directinal light constant.- See Also:
- Constant Field Values
-
sakTypeName
private static final java.lang.String[] sakTypeName
Light constant types array.
-
MASK_AMBIENT
public static final int MASK_AMBIENT
Bit mask used to identify light types in combination.- See Also:
- Constant Field Values
-
MASK_SPOT
public static final int MASK_SPOT
Spot light mask.- See Also:
- Constant Field Values
-
MASK_POINT
public static final int MASK_POINT
Point light mask.- See Also:
- Constant Field Values
-
MASK_DIRECTIONAL
public static final int MASK_DIRECTIONAL
Directional light mask- See Also:
- Constant Field Values
-
MASK_ALL
public static final int MASK_ALL
All light types mask- See Also:
- Constant Field Values
-
m_bEnabled
private boolean m_bEnabled
General properties which can be shared by all lights types.
-
m_bFixTarget
private boolean m_bFixTarget
Properties 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_fAttenuationC0
Attenuation factor red channel.
-
m_fAttenuationC1
private float m_fAttenuationC1
Attenuation factor green channel.
-
m_fAttenuationC2
private float m_fAttenuationC2
Attenuation factor blue channel.
-
m_fIntensity
private float m_fIntensity
Light intensity scale factor.
-
m_fShininess
private float m_fShininess
Shinness factor, exponential power value for Phong type shading model.
-
m_fSizeMax
private final float m_fSizeMax
Maximum coordinate scale factor for real positions.
-
m_fSizeX
private final float m_fSizeX
Scale factors for placing [-1,+1] normalized positions and targets into real world space with dimensions.
-
m_fSizeY
private final float m_fSizeY
float Y coordinate scale factor for real positions.
-
m_fSizeZ
private final float m_fSizeZ
float Y coordinate scale factor for real positions.
-
m_fSpotAngle
private float m_fSpotAngle
Properties for spot lights only.
-
m_fSpotExponent
private float m_fSpotExponent
Spot light exponential factor.
-
m_iType
private int m_iType
Type of light and limit for available light types which can be selected.
-
m_iTypeMask
private final int m_iTypeMask
Light type mask.
-
m_kDescription
private java.lang.String m_kDescription
Description associated with this light.
-
m_kDirection
private javax.vecmath.Vector3f m_kDirection
Light direction.
-
m_kLightColor
private java.awt.Color m_kLightColor
Light color.
-
m_kPosition
private javax.vecmath.Point3f m_kPosition
Properties shared by point and spot lights.
-
m_kTarget
private javax.vecmath.Point3f m_kTarget
Light shooting target position.
-
-
Constructor Detail
-
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 Detail
-
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
public final SoftwareLight 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
public final SoftwareLight 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
public final java.awt.Color getColor()
Query the current based color of the light.- Returns:
- Color Base color of the light.
-
getDescription
public final java.lang.String 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
public final java.lang.String 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
public final void setColor(java.awt.Color kColor)
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
public final void setDescription(java.lang.String description)
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.
-
-