// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_sg_torche #define tools_sg_torche // directional light #include "node" #include "sf_vec3f" #include "render_action" #include "../colorfs" namespace tools { namespace sg { class torche : public node { TOOLS_NODE(torche,tools::sg::torche,node) public: sf_vec color; sf_vec ambient; sf_vec3f direction; sf on; public: virtual const desc_fields& node_desc_fields() const { TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::torche) static const desc_fields s_v(parent::node_desc_fields(),4, //WARNING : take care of count. TOOLS_ARG_FIELD_DESC(color), TOOLS_ARG_FIELD_DESC(ambient), TOOLS_ARG_FIELD_DESC(direction), TOOLS_ARG_FIELD_DESC(on) ); return s_v; } private: void add_fields(){ add_field(&color); add_field(&ambient); add_field(&direction); add_field(&on); } public: virtual void render(render_action& a_action) { if(!on.value()) return; state& state = a_action.state(); if((state.m_light+1)>=a_action.max_lights()) { a_action.out() << "GL_MAX_LIGHTS (" << a_action.max_lights() << ") reached." << std::endl; return; } state.m_GL_LIGHTING = true; a_action.enable_light(state.m_light,direction.value(),color.value(),ambient.value()); state.m_light++; } public: torche() :parent() ,color(colorf_white()) ,ambient(colorf_black()) ,direction(vec3f(0,0,-1)) ,on(true) { add_fields(); } virtual ~torche(){} public: torche(const torche& a_from) :parent(a_from) ,color(a_from.color) ,ambient(a_from.ambient) ,direction(a_from.direction) ,on(a_from.on) { add_fields(); } torche& operator=(const torche& a_from){ parent::operator=(a_from); color = a_from.color; ambient = a_from.ambient; direction = a_from.direction; on = a_from.on; return *this; } }; }} #endif