Commit 422544ea authored by Mike Kremer's avatar Mike Kremer
Browse files

Light sources can now be visualized and turned on/off (independently from each...

Light sources can now be visualized and turned on/off (independently from each other) via data control plugin.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9019 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 961094c7
...@@ -86,6 +86,8 @@ LightSource::LightSource() ...@@ -86,6 +86,8 @@ LightSource::LightSource()
constantAttenuation_ = 1; constantAttenuation_ = 1;
linearAttenuation_ = 0; linearAttenuation_ = 0;
quadraticAttenuation_ = 0; quadraticAttenuation_ = 0;
radius_ = 0.1f;
} }
void LightSource::position( Vec3d _pos){ void LightSource::position( Vec3d _pos){
...@@ -198,7 +200,8 @@ float LightSource::quadraticAttenuation() { ...@@ -198,7 +200,8 @@ float LightSource::quadraticAttenuation() {
LightNode::LightNode( BaseNode* _parent, LightNode::LightNode( BaseNode* _parent,
const std::string& _name) const std::string& _name)
: BaseNode(_parent, _name), : BaseNode(_parent, _name),
lightId_(0) { lightId_(0),
visualize_(false) {
if(lightSourceHandle == 0) { if(lightSourceHandle == 0) {
lightSourceHandle = new LightSourceHandle(); lightSourceHandle = new LightSourceHandle();
...@@ -211,16 +214,53 @@ LightNode::LightNode( BaseNode* _parent, ...@@ -211,16 +214,53 @@ LightNode::LightNode( BaseNode* _parent,
LightNode::~LightNode() { LightNode::~LightNode() {
lightSourceHandle->removeLight(this); lightSourceHandle->removeLight(this);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void LightNode::boundingBox(ACG::Vec3d& _bbMin, ACG::Vec3d& _bbMax) {
if( visualize_ && !light_.directional() ) {
_bbMin.minimize( light_.position() - Vec3d(light_.radius()) );
_bbMax.maximize( light_.position() + Vec3d(light_.radius()) );
}
}
//----------------------------------------------------------------------------
void LightNode::draw(GLState& _state, DrawModes::DrawMode /*_drawMode*/) {
// Visualize light node
if(visualize_ && !light_.directional()) {
ACG::Vec3d p = light_.position();
ACG::Vec4f c = light_.ambientColor();
// Origin
_state.push_modelview_matrix ();
//_state.reset_modelview();
_state.translate(p[0], p[1], p[2]);
GLUquadricObj* quadric = gluNewQuadric();
glColor3f(c[0], c[1], c[2]);
gluSphere( quadric, light_.radius(), 10, 10 );
// TODO: Visualize vieweing direction
gluDeleteQuadric(quadric);
_state.pop_modelview_matrix();
}
}
void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ ) void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ )
{ {
// Return if we don't have a valid light source // Return if we don't have a valid light source
if(lightId_ == GL_INVALID_ENUM) return; if(lightId_ == GL_INVALID_ENUM || !light_.enabled()) return;
/// transfer GL-preferences to lightSave_ /// transfer GL-preferences to lightSave_
getParameters(lightId_, lightSave_); getParameters(lightId_, lightSave_);
...@@ -237,8 +277,6 @@ void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ ) ...@@ -237,8 +277,6 @@ void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ )
// std::cerr << "New Light pos :" << light_.position << std::endl; // std::cerr << "New Light pos :" << light_.position << std::endl;
} }
glEnable(lightId_); glEnable(lightId_);
setParameters(lightId_, light_); setParameters(lightId_, light_);
} else } else
...@@ -253,7 +291,7 @@ void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ ) ...@@ -253,7 +291,7 @@ void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ )
void LightNode::leave(GLState& /* _state */ , DrawModes::DrawMode /* _drawmode*/ ) void LightNode::leave(GLState& /* _state */ , DrawModes::DrawMode /* _drawmode*/ )
{ {
// Return if we don't have a valid light source // Return if we don't have a valid light source
if(lightId_ == GL_INVALID_ENUM) return; if(lightId_ == GL_INVALID_ENUM || !light_.enabled()) return;
// restore old enabled light // restore old enabled light
if(lightSave_.enabled_) if(lightSave_.enabled_)
......
...@@ -189,6 +189,12 @@ public: ...@@ -189,6 +189,12 @@ public:
float quadraticAttenuation(); float quadraticAttenuation();
/// Get light source radius
float radius() { return radius_; }
/// Set light source radius
void radius(const float _radius) { radius_ = _radius; }
protected: protected:
Vec4f position_; Vec4f position_;
...@@ -206,6 +212,11 @@ protected: ...@@ -206,6 +212,11 @@ protected:
float constantAttenuation_; float constantAttenuation_;
float linearAttenuation_; float linearAttenuation_;
float quadraticAttenuation_; float quadraticAttenuation_;
/// When using ray tracing, light sources can have
/// extent. We simplify to spherical light sources with
/// radius radius_.
float radius_;
}; };
...@@ -226,10 +237,17 @@ public: ...@@ -226,10 +237,17 @@ public:
ACG_CLASSNAME(LightNode); ACG_CLASSNAME(LightNode);
/// Get bounding box (for visualization purposes)
void boundingBox(ACG::Vec3d& /* _bbMin */, ACG::Vec3d& /*_bbMax*/ );
/// set current Light Sources /// set current Light Sources
void enter(GLState& _state, DrawModes::DrawMode _drawmode); void enter(GLState& _state, DrawModes::DrawMode _drawmode);
/// restores original Light Sources /// restores original Light Sources
void leave(GLState& _state, DrawModes::DrawMode _drawmode); void leave(GLState& _state, DrawModes::DrawMode _drawmode);
/// Draw light source node
void draw(GLState& _state, DrawModes::DrawMode _drawMode);
/// Should node be visualized? /// Should node be visualized?
bool visualize() { return visualize_; } bool visualize() { return visualize_; }
......
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
* You dont need to create an object of this type manually. * You dont need to create an object of this type manually.
*/ */
LightObject::LightObject( ) : LightObject::LightObject( ) :
BaseObjectData( ), BaseObjectData(),
lightNode_(NULL) lightNode_(0),
lightNodeVis_(0)
{ {
setDataType(DATA_LIGHT); setDataType(DATA_LIGHT);
setTypeIcon(DATA_LIGHT,"LightType.png"); setTypeIcon(DATA_LIGHT,"LightType.png");
...@@ -99,15 +100,19 @@ BaseObject* LightObject::copy() { ...@@ -99,15 +100,19 @@ BaseObject* LightObject::copy() {
/** This function initalizes the light object. It creates the scenegraph nodes. /** This function initalizes the light object. It creates the scenegraph nodes.
*/ */
void LightObject::init(LightNode* _light) { void LightObject::init(LightNode* _light, LightNode* _lightVis) {
///\TODO Add Light Node here ///\TODO Add Light Node here
lightNode_ = new LightNode( 0 , "NEW LightNode"); lightNode_ = new LightNode( 0 , "LightNode");
lightNodeVis_ = new LightNode( manipulatorNode() , "LightNode Visualization");
lightNodeVis_->show();
lightNode_->visualize(false);
lightNodeVis_->visualize(true);
// Light nodes have to be on top of all other nodes. // Light nodes have to be on top of all other nodes.
PluginFunctions::addGlobalStatusNode(lightNode_); PluginFunctions::addGlobalStatusNode(lightNode_);
/* /*
if (_plane){ if (_plane){
...@@ -142,6 +147,10 @@ LightNode* LightObject::lightNode() { ...@@ -142,6 +147,10 @@ LightNode* LightObject::lightNode() {
return lightNode_; return lightNode_;
} }
LightNode* LightObject::lightNodeVis() {
return lightNodeVis_;
}
// =============================================================================== // ===============================================================================
// Object information // Object information
// =============================================================================== // ===============================================================================
...@@ -196,22 +205,22 @@ bool LightObject::pickingEnabled() { ...@@ -196,22 +205,22 @@ bool LightObject::pickingEnabled() {
void LightObject::show() { void LightObject::show() {
if ( !visible_ ) { if ( !visible_ ) {
BaseObjectData::show(); BaseObjectData::show();
lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::ALLPASSES);
lightNode_->set_status( ACG::SceneGraph::BaseNode::Active );
visible_ = true; visible_ = true;
lightNodeVis_->visualize(true);
emit visibilityChanged( id() ); emit visibilityChanged( id() );
PluginFunctions::viewAll();
} }
} }
void LightObject::hide() { void LightObject::hide() {
if ( visible_ ) { if ( visible_ ) {
BaseObjectData::hide(); BaseObjectData::hide();
lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::NOPASS);
lightNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
visible_ = false; visible_ = false;
emit visibilityChanged( id() ); emit visibilityChanged( id() );
PluginFunctions::viewAll();
} }
} }
...@@ -227,7 +236,17 @@ LightSource* LightObject::lightSource() { ...@@ -227,7 +236,17 @@ LightSource* LightObject::lightSource() {
} }
void LightObject::update(UpdateType _type) { void LightObject::update(UpdateType _type) {
if(lightSource_.enabled()) {
lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::ALLPASSES);
lightNode_->set_status( ACG::SceneGraph::BaseNode::Active );
} else {
lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::NOPASS);
lightNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
}
lightNode_->setLightSource(lightSource_); lightNode_->setLightSource(lightSource_);
lightNodeVis_->setLightSource(lightSource_);
} }
......
...@@ -52,7 +52,7 @@ class DLLEXPORT LightObject : public BaseObjectData { ...@@ -52,7 +52,7 @@ class DLLEXPORT LightObject : public BaseObjectData {
protected: protected:
/// Initialise current object, including all related nodes. /// Initialise current object, including all related nodes.
virtual void init(LightNode* _light = 0); virtual void init(LightNode* _light = 0, LightNode* _lightVis = 0);
//=========================================================================== //===========================================================================
/** @name Name and Path handling /** @name Name and Path handling
...@@ -93,8 +93,15 @@ class DLLEXPORT LightObject : public BaseObjectData { ...@@ -93,8 +93,15 @@ class DLLEXPORT LightObject : public BaseObjectData {
/// Get the scenegraph Node /// Get the scenegraph Node
LightNode* lightNode(); LightNode* lightNode();
/// Get the scenegraph Node
LightNode* lightNodeVis();
private: private:
/// Light status node
LightNode* lightNode_; LightNode* lightNode_;
/// Light rendering node (only for rendering purposes)
LightNode* lightNodeVis_;
/** @} */ /** @} */
......
...@@ -549,7 +549,7 @@ void DataControlPlugin::slotSwitchLight() { ...@@ -549,7 +549,7 @@ void DataControlPlugin::slotSwitchLight() {
light->lightSource()->disable() : light->lightSource()->disable() :
light->lightSource()->enable(); light->lightSource()->enable();
emit updatedObject(id); emit updatedObject(id);
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment