Kemena3D
Loading...
Searching...
No Matches
kemena::kLight Class Reference

Scene-graph node that emits light. More...

#include <klight.h>

Inheritance diagram for kemena::kLight:
Collaboration diagram for kemena::kLight:

Public Member Functions

 kLight (kObject *parentNode=nullptr)
 Constructs a light node and optionally attaches it to a parent.
kVec3 getDiffuseColor ()
 Returns the diffuse colour component.
void setDiffuseColor (kVec3 newColor)
 Sets the diffuse colour component.
kVec3 getSpecularColor ()
 Returns the specular colour component.
void setSpecularColor (kVec3 newColor)
 Sets the specular colour component.
float getPower ()
 Returns the light power (intensity multiplier).
void setPower (float newValue)
 Sets the light power (intensity multiplier).
float getConstant ()
 Returns the constant attenuation term.
float getLinear ()
 Returns the linear attenuation term.
float getQuadratic ()
 Returns the quadratic attenuation term.
void setConstant (float newValue)
 Sets the constant attenuation term.
void setLinear (float newValue)
 Sets the linear attenuation term.
void setQuadratic (float newValue)
 Sets the quadratic attenuation term.
kVec3 getDirection ()
 Returns the light direction (sun and spotlight only).
void setDirection (kVec3 newValue)
 Sets the light direction (sun and spotlight only).
float getCutOff ()
 Returns the inner cut-off cosine (spotlight only).
void setCutOff (float newValue)
 Sets the inner cut-off angle (spotlight only).
float getOuterCutOff ()
 Returns the outer cut-off cosine (spotlight only).
void setOuterCutOff (float newValue)
 Sets the outer cut-off angle (spotlight only).
kLightType getLightType ()
 Returns the light type.
void setLightType (kLightType newType)
 Sets the light type.
json serialize () override
 Serialises this light node to JSON.
Public Member Functions inherited from kemena::kObject
 kObject (kObject *parentNode=nullptr)
 Constructs a kObject and optionally attaches it to a parent.
virtual ~kObject ()
 Destroys the object.
kObjectgetParent ()
 Returns the parent node.
void setParent (kObject *newParent)
 Reparents this object under newParent.
void detachFromParent ()
 Removes this object from its parent's children list.
void setParentKeepTransform (kObject *newParent)
 Reparents this object while keeping its world transform.
std::vector< kObject * > getChildren ()
 Returns the list of direct children.
std::vector< kScript > & getScripts ()
 Returns a mutable reference to the list of attached scripts.
void addScript (const kScript &script)
 Appends a script descriptor to this object.
void removeScript (const kString &uuid)
 Removes the script with the given UUID from this object.
std::vector< kParticle > & getParticles ()
 Returns a mutable reference to the list of attached particle systems.
void addParticle (const kParticle &particle)
 Appends a particle system descriptor to this object.
void removeParticle (const kString &uuid)
 Removes the particle system with the given UUID from this object.
std::vector< kAudioSource > & getAudioSources ()
 Returns a mutable reference to the list of attached audio sources.
void addAudioSource (const kAudioSource &source)
 Appends an audio source descriptor to this object.
void removeAudioSource (const kString &uuid)
 Removes the audio source with the given UUID from this object.
std::vector< kAudioListener > & getAudioListeners ()
 Returns a mutable reference to the list of audio listener components (0 or 1).
void addAudioListener (const kAudioListener &listener)
 Attaches an audio listener descriptor to this object.
void removeAudioListener (const kString &uuid)
 Removes the audio listener with the given UUID from this object.
bool getHasPhysicsDesc () const
 Returns true if this object has a physics body descriptor configured.
void setHasPhysicsDesc (bool val)
 Sets whether this object has a physics body descriptor.
kPhysicsObjectDescgetPhysicsDesc ()
 Returns a mutable reference to the physics body descriptor.
bool getHasCharacterDesc () const
 Returns true if this object has a character controller configured.
void setHasCharacterDesc (bool val)
 Sets whether this object has a character controller descriptor.
kCharacterControllerDescgetCharacterDesc ()
 Returns a mutable reference to the character controller descriptor.
bool getHasNavMeshDesc () const
 Returns true if this object carries a navigation surface.
void setHasNavMeshDesc (bool val)
 Sets whether this object carries a navigation surface.
kNavMeshDescgetNavMeshDesc ()
 Returns a mutable reference to the navigation surface descriptor.
kNodeType getType ()
 Returns the scene-graph node type tag.
void setType (kNodeType newType)
 Sets the node type tag.
bool getActive ()
 Returns whether this object is active (visible/processed).
void setActive (bool newActive)
 Activates or deactivates the object.
bool getStatic ()
 Returns whether this object is marked as static (immobile geometry).
void setStatic (bool newStatic)
 Marks the object as static or dynamic.
bool getDebugMode ()
 Returns whether editor debug visualization is enabled.
void setDebugMode (bool newMode)
 Enables or disables editor debug visualization for this object.
unsigned int getId ()
 Returns the numeric identifier of this object.
void setId (unsigned int newId)
 Sets the numeric identifier.
kString getUuid ()
 Returns the UUID kString of this object.
void setUuid (kString newUuid)
 Sets the UUID kString.
kString getName ()
 Returns the display name of this object.
void setName (kString newName)
 Sets the display name.
kString getPrefabRef () const
 Returns the prefab asset UUID this object is an instance of, or empty.
void setPrefabRef (const kString &ref)
 Sets the prefab asset UUID this object is an instance of.
kString getTemplateUuid () const
 Returns the UUID of the corresponding node in the prefab template.
void setTemplateUuid (const kString &uuid)
 Sets the corresponding template UUID for this prefab instance node.
kVec3 getPosition ()
 Returns the local position.
virtual void setPosition (kVec3 newPosition)
 Sets the local position.
kQuat getRotation ()
 Returns the local rotation as a quaternion.
kVec3 getRotationEuler ()
 Returns the local rotation as Euler angles in degrees.
virtual void setRotation (kQuat newRotation)
 Sets the local rotation from a quaternion.
kVec3 getScale ()
 Returns the local scale.
virtual void setScale (kVec3 newScale)
 Sets the local scale.
kVec3 calculateRight ()
 Computes the local right (+X) direction in world space.
kVec3 calculateForward ()
 Computes the local forward (-Z) direction in world space.
kVec3 calculateUp ()
 Computes the local up (+Y) direction in world space.
void rotate (kVec3 rotationAxis, float angularSpeed)
 Rotates the object around an axis by a given angular speed.
kVec3 getGlobalPosition ()
 Returns the world-space position derived from the world transform.
kQuat getGlobalRotation ()
 Returns the world-space rotation derived from the world transform.
kVec3 getGlobalScale ()
 Returns the world-space scale derived from the world transform.
void setMaterial (kMaterial *newMaterial, bool setChildren=true)
 Assigns a material to this object and optionally its children.
kMaterialgetMaterial ()
 Returns the assigned material.
void setMaterialUuid (const kString &uuid)
 Sets the source asset UUID of the assigned material.
kString getMaterialUuid () const
 Returns the source asset UUID of the assigned material.
void setImportChild (bool v)
 Marks this node as an import-derived sub-mesh.
bool getImportChild () const
 Whether this node is an import-derived sub-mesh (see setImportChild).
void calculateModelMatrix ()
 Recomputes the local and world-space model matrices.
kMat4 getModelMatrixWorld ()
 Returns the world-space model matrix.
kMat4 getModelMatrixLocal ()
 Returns the local model matrix (relative to the parent).
virtual void draw ()
 Draws the object.
virtual void deserialize (json data)
 Restores the object state from a JSON value.
void attachPhysics (kPhysicsObject *physicsObj)
 Attaches a physics body to this object.
void detachPhysics ()
 Detaches the physics body without destroying it.
kPhysicsObjectgetPhysicsObject ()
 Returns the attached physics body, or nullptr if none is attached.
void syncFromPhysics ()
 Copies the physics body's current position and rotation into this object's local transform.
void attachCharacter (kCharacterController *character)
 Attaches a runtime character controller to this object.
void detachCharacter ()
 Detaches the character controller without destroying it.
kCharacterControllergetCharacterController ()
 Returns the attached character controller, or nullptr.
void syncFromCharacter ()
 Copies the character controller's position into this object's local transform. Call once per frame after the physics update.

Detailed Description

Scene-graph node that emits light.

Supports three light types controlled by setLightType():

  • LIGHT_TYPE_POINT — omnidirectional, attenuated by distance.
  • LIGHT_TYPE_SUN — parallel rays (directional), no attenuation.
  • LIGHT_TYPE_SPOTLIGHT — cone-shaped, inner/outer cut-off angles.

Phong colour components (diffuse, specular) apply to all types. Attenuation coefficients apply to point and spot lights only. Ambient lighting is handled at the scene level via kScene::setAmbientLightColor().

Constructor & Destructor Documentation

◆ kLight()

kemena::kLight::kLight ( kObject * parentNode = nullptr)

Constructs a light node and optionally attaches it to a parent.

Parameters
parentNodeParent scene-graph node, or nullptr.
Here is the call graph for this function:

Member Function Documentation

◆ getConstant()

float kemena::kLight::getConstant ( )

Returns the constant attenuation term.

Returns
Constant term used in the attenuation formula.

◆ getCutOff()

float kemena::kLight::getCutOff ( )

Returns the inner cut-off cosine (spotlight only).

Returns
cos(inner half-angle).

◆ getDiffuseColor()

kVec3 kemena::kLight::getDiffuseColor ( )

Returns the diffuse colour component.

Returns
RGB diffuse colour (0..1 per channel).

◆ getDirection()

kVec3 kemena::kLight::getDirection ( )

Returns the light direction (sun and spotlight only).

Returns
Normalised direction vector in world space.

◆ getLightType()

kLightType kemena::kLight::getLightType ( )

Returns the light type.

Returns
One of the kLightType enum values.

◆ getLinear()

float kemena::kLight::getLinear ( )

Returns the linear attenuation term.

Returns
Linear term used in the attenuation formula.

◆ getOuterCutOff()

float kemena::kLight::getOuterCutOff ( )

Returns the outer cut-off cosine (spotlight only).

Returns
cos(outer half-angle).

◆ getPower()

float kemena::kLight::getPower ( )

Returns the light power (intensity multiplier).

Returns
Power value (default 10.0).

◆ getQuadratic()

float kemena::kLight::getQuadratic ( )

Returns the quadratic attenuation term.

Returns
Quadratic term used in the attenuation formula.

◆ getSpecularColor()

kVec3 kemena::kLight::getSpecularColor ( )

Returns the specular colour component.

Returns
RGB specular colour (0..1 per channel).

◆ serialize()

json kemena::kLight::serialize ( )
overridevirtual

Serialises this light node to JSON.

Overrides kObject::serialize() to include the light-specific properties (type, colours, power, attenuation, direction and spotlight cut-off angles) in addition to the base node data.

Returns
JSON object describing the light.

Reimplemented from kemena::kObject.

◆ setConstant()

void kemena::kLight::setConstant ( float newValue)

Sets the constant attenuation term.

Parameters
newValueNew constant attenuation value.

◆ setCutOff()

void kemena::kLight::setCutOff ( float newValue)

Sets the inner cut-off angle (spotlight only).

Parameters
newValuecos(inner half-angle).

◆ setDiffuseColor()

void kemena::kLight::setDiffuseColor ( kVec3 newColor)

Sets the diffuse colour component.

Parameters
newColorRGB diffuse colour.

◆ setDirection()

void kemena::kLight::setDirection ( kVec3 newValue)

Sets the light direction (sun and spotlight only).

Parameters
newValueNormalised direction vector in world space.

◆ setLightType()

void kemena::kLight::setLightType ( kLightType newType)

Sets the light type.

Parameters
newTypeNew light type.

◆ setLinear()

void kemena::kLight::setLinear ( float newValue)

Sets the linear attenuation term.

Parameters
newValueNew linear attenuation value.

◆ setOuterCutOff()

void kemena::kLight::setOuterCutOff ( float newValue)

Sets the outer cut-off angle (spotlight only).

Parameters
newValuecos(outer half-angle).

◆ setPower()

void kemena::kLight::setPower ( float newValue)

Sets the light power (intensity multiplier).

Parameters
newValueNew power value.

◆ setQuadratic()

void kemena::kLight::setQuadratic ( float newValue)

Sets the quadratic attenuation term.

Parameters
newValueNew quadratic attenuation value.

◆ setSpecularColor()

void kemena::kLight::setSpecularColor ( kVec3 newColor)

Sets the specular colour component.

Parameters
newColorRGB specular colour.

The documentation for this class was generated from the following file: