add the new properties to LightEntityItem class

This commit is contained in:
ZappoMan 2014-10-27 14:40:58 -07:00
parent 5d7a0c2934
commit c17ffe9433
3 changed files with 108 additions and 45 deletions

View file

@ -39,52 +39,44 @@ void RenderableLightEntityItem::render(RenderArgs* args) {
float largestDiameter = glm::max(dimensions.x, dimensions.y, dimensions.z);
const float MAX_COLOR = 255.0f;
float red = getColor()[RED_INDEX] / MAX_COLOR;
float green = getColor()[GREEN_INDEX] / MAX_COLOR;
float blue = getColor()[BLUE_INDEX] / MAX_COLOR;
float alpha = getLocalRenderAlpha();
/*
/// Adds a point light to render for the current frame.
void addPointLight(const glm::vec3& position, float radius, const glm::vec3& ambient = glm::vec3(0.0f, 0.0f, 0.0f),
const glm::vec3& diffuse = glm::vec3(1.0f, 1.0f, 1.0f), const glm::vec3& specular = glm::vec3(1.0f, 1.0f, 1.0f),
float constantAttenuation = 1.0f, float linearAttenuation = 0.0f, float quadraticAttenuation = 0.0f);
/// Adds a spot light to render for the current frame.
void addSpotLight(const glm::vec3& position, float radius, const glm::vec3& ambient = glm::vec3(0.0f, 0.0f, 0.0f),
const glm::vec3& diffuse = glm::vec3(1.0f, 1.0f, 1.0f), const glm::vec3& specular = glm::vec3(1.0f, 1.0f, 1.0f),
float constantAttenuation = 1.0f, float linearAttenuation = 0.0f, float quadraticAttenuation = 0.0f,
const glm::vec3& direction = glm::vec3(0.0f, 0.0f, -1.0f), float exponent = 0.0f, float cutoff = PI);
*/
glm::vec3 ambient = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 diffuse = glm::vec3(red, green, blue);
glm::vec3 specular = glm::vec3(red, green, blue);
float diffuseR = getDiffuseColor()[RED_INDEX] / MAX_COLOR;
float diffuseG = getDiffuseColor()[GREEN_INDEX] / MAX_COLOR;
float diffuseB = getDiffuseColor()[BLUE_INDEX] / MAX_COLOR;
float ambientR = getAmbientColor()[RED_INDEX] / MAX_COLOR;
float ambientG = getAmbientColor()[GREEN_INDEX] / MAX_COLOR;
float ambientB = getAmbientColor()[BLUE_INDEX] / MAX_COLOR;
float specularR = getSpecularColor()[RED_INDEX] / MAX_COLOR;
float specularG = getSpecularColor()[GREEN_INDEX] / MAX_COLOR;
float specularB = getSpecularColor()[BLUE_INDEX] / MAX_COLOR;
glm::vec3 ambient = glm::vec3(ambientR, ambientG, ambientB);
glm::vec3 diffuse = glm::vec3(diffuseR, diffuseG, diffuseB);
glm::vec3 specular = glm::vec3(specularR, specularG, specularB);
glm::vec3 direction = IDENTITY_FRONT * rotation;
float constantAttenuation = 1.0f;
float linearAttenuation = 0.0f;
float quadraticAttenuation = 0.0f;
float constantAttenuation = getConstantAttenuation();
float linearAttenuation = getLinearAttenuation();
float quadraticAttenuation = getQuadraticAttenuation();
float exponent = getExponent();
float cutoff = glm::radians(getCutoff());
if (_isSpotlight) {
Application::getInstance()->getDeferredLightingEffect()->addSpotLight(position, largestDiameter / 2.0f,
ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation,
direction);
direction, exponent, cutoff);
} else {
Application::getInstance()->getDeferredLightingEffect()->addPointLight(position, largestDiameter / 2.0f,
ambient, diffuse, specular, constantAttenuation, linearAttenuation, quadraticAttenuation);
}
bool wantDebug = false;
if (wantDebug) {
glColor4f(red, green, blue, alpha);
glColor4f(diffuseR, diffuseG, diffuseB, 1.0f);
glPushMatrix();
glTranslatef(position.x, position.y, position.z);
glm::vec3 axis = glm::axis(rotation);
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
glPushMatrix();
glm::vec3 positionToCenter = center - position;
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
@ -94,5 +86,4 @@ void RenderableLightEntityItem::render(RenderArgs* args) {
glPopMatrix();
glPopMatrix();
}
};

View file

@ -26,19 +26,33 @@ EntityItem* LightEntityItem::factory(const EntityItemID& entityID, const EntityI
// our non-pure virtual subclass for now...
LightEntityItem::LightEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) :
EntityItem(entityItemID, properties)
{
{
_type = EntityTypes::Light;
// default property values
const quint8 MAX_COLOR = 255;
_ambientColor[RED_INDEX] = _ambientColor[GREEN_INDEX] = _ambientColor[BLUE_INDEX] = 0;
_diffuseColor[RED_INDEX] = _diffuseColor[GREEN_INDEX] = _diffuseColor[BLUE_INDEX] = MAX_COLOR;
_specularColor[RED_INDEX] = _specularColor[GREEN_INDEX] = _specularColor[BLUE_INDEX] = MAX_COLOR;
_constantAttenuation = 1.0f;
_linearAttenuation = 0.0f;
_quadraticAttenuation = 0.0f;
_exponent = 0.0f;
_cutoff = PI;
setProperties(properties, true);
// a light is not collide-able so we make it's shape be a tiny sphere at origin
_emptyShape.setTranslation(glm::vec3(0.0f,0.0f,0.0f));
_emptyShape.setTranslation(glm::vec3(0.0f, 0.0f, 0.0f));
_emptyShape.setRadius(0.0f);
}
EntityItemProperties LightEntityItem::getProperties() const {
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
properties.setColor(getXColor());
properties.setDiffuseColor(getDiffuseXColor());
properties.setAmbientColor(getAmbientXColor());
properties.setSpecularColor(getSpecularXColor());
properties.setGlowLevel(getGlowLevel());
properties.setIsSpotlight(getIsSpotlight());
@ -48,7 +62,10 @@ EntityItemProperties LightEntityItem::getProperties() const {
bool LightEntityItem::setProperties(const EntityItemProperties& properties, bool forceCopy) {
bool somethingChanged = EntityItem::setProperties(properties, forceCopy); // set the properties in our base class
SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setDiffuseColor);
//SET_ENTITY_PROPERTY_FROM_PROPERTIES(diffuseColor, setDiffuseColor);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(ambientColor, setAmbientColor);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(specularColor, setSpecularColor);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(isSpotlight, setIsSpotlight);
if (somethingChanged) {
@ -71,8 +88,10 @@ int LightEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
int bytesRead = 0;
const unsigned char* dataAt = data;
READ_ENTITY_PROPERTY_COLOR(PROP_COLOR, _color);
READ_ENTITY_PROPERTY(PROP_IS_SPOTLIGHT, bool, _isSpotlight);
READ_ENTITY_PROPERTY_COLOR(PROP_DIFFUSE_COLOR, _diffuseColor);
READ_ENTITY_PROPERTY_COLOR(PROP_AMBIENT_COLOR, _ambientColor);
READ_ENTITY_PROPERTY_COLOR(PROP_SPECULAR_COLOR, _specularColor);
return bytesRead;
}
@ -95,6 +114,8 @@ void LightEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit
OctreeElement::AppendState& appendState) const {
bool successPropertyFits = true;
APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor());
APPEND_ENTITY_PROPERTY(PROP_IS_SPOTLIGHT, appendValue, getIsSpotlight());
APPEND_ENTITY_PROPERTY(PROP_DIFFUSE_COLOR, appendColor, getDiffuseColor());
APPEND_ENTITY_PROPERTY(PROP_AMBIENT_COLOR, appendColor, getAmbientColor());
APPEND_ENTITY_PROPERTY(PROP_SPECULAR_COLOR, appendColor, getSpecularColor());
}

View file

@ -41,26 +41,77 @@ public:
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData);
const rgbColor& getColor() const { return _color; }
xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; }
const rgbColor& getAmbientColor() const { return _ambientColor; }
xColor getAmbientXColor() const {
xColor color = { _ambientColor[RED_INDEX], _ambientColor[GREEN_INDEX], _ambientColor[BLUE_INDEX] }; return color;
}
void setColor(const rgbColor& value) { memcpy(_color, value, sizeof(_color)); }
void setColor(const xColor& value) {
_color[RED_INDEX] = value.red;
_color[GREEN_INDEX] = value.green;
_color[BLUE_INDEX] = value.blue;
void setAmbientColor(const rgbColor& value) { memcpy(_ambientColor, value, sizeof(_ambientColor)); }
void setAmbientColor(const xColor& value) {
_ambientColor[RED_INDEX] = value.red;
_ambientColor[GREEN_INDEX] = value.green;
_ambientColor[BLUE_INDEX] = value.blue;
}
const rgbColor& getDiffuseColor() const { return _diffuseColor; }
xColor getDiffuseXColor() const {
xColor color = { _diffuseColor[RED_INDEX], _diffuseColor[GREEN_INDEX], _diffuseColor[BLUE_INDEX] }; return color;
}
void setDiffuseColor(const rgbColor& value) { memcpy(_diffuseColor, value, sizeof(_diffuseColor)); }
void setDiffuseColor(const xColor& value) {
_diffuseColor[RED_INDEX] = value.red;
_diffuseColor[GREEN_INDEX] = value.green;
_diffuseColor[BLUE_INDEX] = value.blue;
}
const rgbColor& getSpecularColor() const { return _specularColor; }
xColor getSpecularXColor() const {
xColor color = { _specularColor[RED_INDEX], _specularColor[GREEN_INDEX], _specularColor[BLUE_INDEX] }; return color;
}
void setSpecularColor(const rgbColor& value) { memcpy(_specularColor, value, sizeof(_specularColor)); }
void setSpecularColor(const xColor& value) {
_specularColor[RED_INDEX] = value.red;
_specularColor[GREEN_INDEX] = value.green;
_specularColor[BLUE_INDEX] = value.blue;
}
bool getIsSpotlight() const { return _isSpotlight; }
void setIsSpotlight(bool value) { _isSpotlight = value; }
bool getConstantAttenuation() const { return _constantAttenuation; }
void setConstantAttenuation(float value) { _constantAttenuation = value; }
bool getLinearAttenuation() const { return _linearAttenuation; }
void setLinearAttenuation(float value) { _linearAttenuation = value; }
bool getQuadraticAttenuation() const { return _quadraticAttenuation; }
void setQuadraticAttenuation(float value) { _quadraticAttenuation = value; }
bool getExponent() const { return _exponent; }
void setExponent(bool value) { _exponent = value; }
bool getCutoff() const { return _cutoff; }
void setCutoff(bool value) { _cutoff = value; }
virtual const Shape& getCollisionShapeInMeters() const { return _emptyShape; }
protected:
virtual void recalculateCollisionShape() { /* nothing to do */ }
rgbColor _color;
// properties of a light
rgbColor _ambientColor;
rgbColor _diffuseColor;
rgbColor _specularColor;
bool _isSpotlight;
float _constantAttenuation;
float _linearAttenuation;
float _quadraticAttenuation;
float _exponent;
float _cutoff;
// used for collision detection
SphereShape _emptyShape;
};