// Author: Juan Carlos De Abreu (jcabreur@gmail.com)
//
// This file define a class inherent from SceneNode that allow put lights in 
// the scene and set it's properties.
//
// An use of this class can be;
// SmartPointer<ISceneNode> light_node = new LightNode();
// light_node->apply();
//
// BEGIN_LIGHT(light_node, 0);
// ... // render the objects that will be affected by the light.
// END_LIGHT(0);

#ifndef SCENE_LIGHT_NODE_H__
#define SCENE_LIGHT_NODE_H__

#include "../../global.h"
#include "scene_node.h"
#include "../../Math/Vector.h"

BEGIN_TEG_NAMESPACE();

#define BEGIN_LIGHT(pLight, lightNumber) \
    glEnable(GL_LIGHT0 + lightNumber); \
	pLight->render(lightNumber)

#define END_LIGHT(lightNumber) glDisable(GL_LIGHT0 + lightNumber)

class LightNode : public ISceneNode {
 public:
  // LightNode constructors and destructor.
  LightNode();
  LightNode(const Vec4f& ambient, const Vec4f& diffuse, const Vec4f& specular);
  ~LightNode();

  // Accessor and mutator methods to LightNode attributes.
  inline const Vec4f& ambient() const { return ambient_; }
  inline const Vec4f& diffuse() const { return diffuse_; }
  inline const Vec4f& specular() const { return specular_; }
  inline const Vec4f& position() const { return position_; }
  inline void set_ambient(const Vec4f& ambient) { ambient_ = ambient; }
  inline void set_diffuse(const Vec4f& diffuse) { diffuse_ = diffuse; }
  inline void set_specular(const Vec4f& specular) { specular_ = specular; }
  inline void set_position(const Vec4f& position) { position_ = position; }

  // Method to push the light in the list of lights in the scene.
  virtual void apply();

  // Method to set the light properties.
  void render(int lightNumber); 
  
  // Method to make a LightNode copy.
  virtual SmartPointer<ISceneNode> copy(); 
  AUTO_SIZE();

 private:
  // LightNode attributes.
  bool use_light_;     // To know if make the render with this light.
  Vec4f ambient_;     // Ambient component of the light.
  Vec4f diffuse_;     // Difusse component of the light.
  Vec4f specular_;    // Specular component of the light.
  Vec4f position_;    // Light position.
  Vec3f attenuation_; // Light Attenuation.
  DISALLOW_COPY_AND_ASSIGN(LightNode);
};

END_TEG_NAMESPACE();

#endif  // SCENE_LIGHT_NODE_H__
