Directional Light get/set
This commit is contained in:
parent
77981e45a8
commit
e5137c4c61
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under the terms of the GNU General Public License as published
|
under the terms of the GNU General Public License as published
|
||||||
by the Free Software Foundation; either version 3 of the License,
|
nnn by the Free Software Foundation; either version 3 of the License,
|
||||||
or (at your option) any later version.
|
or (at your option) any later version.
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
@ -92,6 +92,14 @@ DirectionalLight::DirectionalLight(Vector3 direction, Vector3 color, float ambie
|
|||||||
this->specular = specular;
|
this->specular = specular;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 DirectionalLight::GetDirection() {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectionalLight::SetDirection(Vector3 direction) {
|
||||||
|
this->direction = direction;
|
||||||
|
}
|
||||||
|
|
||||||
DirectionalLight *DirectionalLight::Create() {
|
DirectionalLight *DirectionalLight::Create() {
|
||||||
return new DirectionalLight;
|
return new DirectionalLight;
|
||||||
}
|
}
|
||||||
|
15
core/Light.h
15
core/Light.h
@ -95,13 +95,26 @@ protected:
|
|||||||
*/
|
*/
|
||||||
class DirectionalLight : public Light {
|
class DirectionalLight : public Light {
|
||||||
public:
|
public:
|
||||||
Vector3 direction;
|
|
||||||
DirectionalLight();
|
DirectionalLight();
|
||||||
DirectionalLight(Vector3 direction, Vector3 color, float ambient, float diffuse, float specular);
|
DirectionalLight(Vector3 direction, Vector3 color, float ambient, float diffuse, float specular);
|
||||||
|
|
||||||
|
/**
|
||||||
|
The direction from which this light is coming.
|
||||||
|
returns The direction of the light.
|
||||||
|
*/
|
||||||
|
Vector3 GetDirection();
|
||||||
|
/**
|
||||||
|
Set the direction from which the light is coming.
|
||||||
|
@param direction The desired light direction
|
||||||
|
*/
|
||||||
|
void SetDirection(Vector3 direction);
|
||||||
|
|
||||||
virtual Name GetType() const;
|
virtual Name GetType() const;
|
||||||
virtual DirectionalLight *Create();
|
virtual DirectionalLight *Create();
|
||||||
virtual DirectionalLight *Duplicate();
|
virtual DirectionalLight *Duplicate();
|
||||||
virtual DirectionalLight *Instance();
|
virtual DirectionalLight *Instance();
|
||||||
|
private:
|
||||||
|
Vector3 direction;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LIGHT_H */
|
#endif /* LIGHT_H */
|
||||||
|
@ -74,7 +74,7 @@ void Shader::UpdateMaterial(Material material) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Shader::UpdateDirectionalLight(DirectionalLight directionalLight) {
|
void Shader::UpdateDirectionalLight(DirectionalLight directionalLight) {
|
||||||
glUniform3fv(glGetUniformLocation(id, "directionalLight.direction"), 1, glm::value_ptr(directionalLight.direction));
|
glUniform3fv(glGetUniformLocation(id, "directionalLight.direction"), 1, glm::value_ptr(directionalLight.GetDirection()));
|
||||||
glUniform3fv(glGetUniformLocation(id, "directionalLight.color"), 1, glm::value_ptr(directionalLight.GetColor()));
|
glUniform3fv(glGetUniformLocation(id, "directionalLight.color"), 1, glm::value_ptr(directionalLight.GetColor()));
|
||||||
|
|
||||||
glUniform1f(glGetUniformLocation(id, "directionalLight.ambient"), directionalLight.GetAmbient());
|
glUniform1f(glGetUniformLocation(id, "directionalLight.ambient"), directionalLight.GetAmbient());
|
||||||
|
@ -37,7 +37,7 @@ function init()
|
|||||||
camera:Translate(couch.Vector3(0.0, 0.0, 10.0))
|
camera:Translate(couch.Vector3(0.0, 0.0, 10.0))
|
||||||
|
|
||||||
local light = couch.DirectionalLight()
|
local light = couch.DirectionalLight()
|
||||||
light.direction = couch.Vector3(0.0, -1.0, -1.0)
|
light:SetDirection(couch.Vector3(0.0, -1.0, -1.0))
|
||||||
light:SetColor(couch.Vector3(1.0, 1.0, 1.0))
|
light:SetColor(couch.Vector3(1.0, 1.0, 1.0))
|
||||||
light:SetAmbient(0.2)
|
light:SetAmbient(0.2)
|
||||||
light:SetDiffuse(1.0)
|
light:SetDiffuse(1.0)
|
||||||
|
Loading…
Reference in New Issue
Block a user