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()
constantAttenuation_ = 1;
linearAttenuation_ = 0;
quadraticAttenuation_ = 0;
radius_ = 0.1f;
}
void LightSource::position( Vec3d _pos){
......@@ -198,7 +200,8 @@ float LightSource::quadraticAttenuation() {
LightNode::LightNode( BaseNode* _parent,
const std::string& _name)
: BaseNode(_parent, _name),
lightId_(0) {
lightId_(0),
visualize_(false) {
if(lightSourceHandle == 0) {
lightSourceHandle = new LightSourceHandle();
......@@ -216,10 +219,47 @@ LightNode::~LightNode() {
//----------------------------------------------------------------------------
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 */ )
{
// 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_
getParameters(lightId_, lightSave_);
......@@ -237,8 +277,6 @@ void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ )
// std::cerr << "New Light pos :" << light_.position << std::endl;
}
glEnable(lightId_);
setParameters(lightId_, light_);
} else
......@@ -253,7 +291,7 @@ void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ )
void LightNode::leave(GLState& /* _state */ , DrawModes::DrawMode /* _drawmode*/ )
{
// 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
if(lightSave_.enabled_)
......
......@@ -189,6 +189,12 @@ public:
float quadraticAttenuation();
/// Get light source radius
float radius() { return radius_; }
/// Set light source radius
void radius(const float _radius) { radius_ = _radius; }
protected:
Vec4f position_;
......@@ -206,6 +212,11 @@ protected:
float constantAttenuation_;
float linearAttenuation_;
float quadraticAttenuation_;
/// When using ray tracing, light sources can have
/// extent. We simplify to spherical light sources with
/// radius radius_.
float radius_;
};
......@@ -226,11 +237,18 @@ public:
ACG_CLASSNAME(LightNode);
/// Get bounding box (for visualization purposes)
void boundingBox(ACG::Vec3d& /* _bbMin */, ACG::Vec3d& /*_bbMax*/ );
/// set current Light Sources
void enter(GLState& _state, DrawModes::DrawMode _drawmode);
/// restores original Light Sources
void leave(GLState& _state, DrawModes::DrawMode _drawmode);
/// Draw light source node
void draw(GLState& _state, DrawModes::DrawMode _drawMode);
/// Should node be visualized?
bool visualize() { return visualize_; }
......
......@@ -22,8 +22,9 @@
* You dont need to create an object of this type manually.
*/
LightObject::LightObject( ) :
BaseObjectData( ),
lightNode_(NULL)
BaseObjectData(),
lightNode_(0),
lightNodeVis_(0)
{
setDataType(DATA_LIGHT);
setTypeIcon(DATA_LIGHT,"LightType.png");
......@@ -99,15 +100,19 @@ BaseObject* LightObject::copy() {
/** 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
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.
PluginFunctions::addGlobalStatusNode(lightNode_);
/*
if (_plane){
......@@ -142,6 +147,10 @@ LightNode* LightObject::lightNode() {
return lightNode_;
}
LightNode* LightObject::lightNodeVis() {
return lightNodeVis_;
}
// ===============================================================================
// Object information
// ===============================================================================
......@@ -196,22 +205,22 @@ bool LightObject::pickingEnabled() {
void LightObject::show() {
if ( !visible_ ) {
BaseObjectData::show();
lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::ALLPASSES);
lightNode_->set_status( ACG::SceneGraph::BaseNode::Active );
visible_ = true;
lightNodeVis_->visualize(true);
emit visibilityChanged( id() );
PluginFunctions::viewAll();
}
}
void LightObject::hide() {
if ( visible_ ) {
BaseObjectData::hide();
lightNode_->setMultipassStatus(ACG::SceneGraph::BaseNode::NOPASS);
lightNode_->set_status( ACG::SceneGraph::BaseNode::HideNode );
visible_ = false;
emit visibilityChanged( id() );
PluginFunctions::viewAll();
}
}
......@@ -227,7 +236,17 @@ LightSource* LightObject::lightSource() {
}
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_);
lightNodeVis_->setLightSource(lightSource_);
}
......
......@@ -52,7 +52,7 @@ class DLLEXPORT LightObject : public BaseObjectData {
protected:
/// 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
......@@ -93,9 +93,16 @@ class DLLEXPORT LightObject : public BaseObjectData {
/// Get the scenegraph Node
LightNode* lightNode();
/// Get the scenegraph Node
LightNode* lightNodeVis();
private:
/// Light status node
LightNode* lightNode_;
/// Light rendering node (only for rendering purposes)
LightNode* lightNodeVis_;
/** @} */
//===========================================================================
......
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