Commit 6c4c9378 authored by Isaak Lim's avatar Isaak Lim
Browse files

LightNode conversion to GLPrimitives

refs #285

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13490 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 16c3177d
......@@ -231,11 +231,19 @@ LightNode::LightNode( BaseNode* _parent,
if(lightSourceHandle == 0) {
lightSourceHandle = new LightSourceHandle();
}
sphere_ = new ACG::GLSphere(10, 10);
cone_ = new ACG::GLCone(10, 10, 1.0f, 1.0f, false, true);
}
//----------------------------------------------------------------------------
LightNode::~LightNode() {
if (sphere_)
delete sphere_;
if (cone_)
delete cone_;
}
//----------------------------------------------------------------------------
......@@ -314,8 +322,6 @@ void LightNode::draw(GLState& _state, const DrawModes::DrawMode& /*_drawMode*/)
// Backup variables
GLboolean lighting_backup;
GLUquadricObj* quadric = gluNewQuadric();
// Origin
_state.push_modelview_matrix();
// Transform to light origin and direction
......@@ -339,8 +345,6 @@ void LightNode::draw(GLState& _state, const DrawModes::DrawMode& /*_drawMode*/)
// Reset all stored attributes before returning
if(!lighting_backup) ACG::GLState::disable(GL_LIGHTING);
gluDeleteQuadric(quadric);
_state.pop_modelview_matrix();
return;
......@@ -360,8 +364,7 @@ void LightNode::draw(GLState& _state, const DrawModes::DrawMode& /*_drawMode*/)
ACG::GLState::enable(lightId_);
gluQuadricOrientation(quadric, GLU_OUTSIDE);
gluSphere( quadric, light_.radius(), 10, 10 );
sphere_->draw(_state, light_.radius());
// Visualize spot cone (or direction)
if(light_.spotCutoff() < 180.0f) {
......@@ -377,11 +380,15 @@ void LightNode::draw(GLState& _state, const DrawModes::DrawMode& /*_drawMode*/)
_state.rotate(angle, rA[0], rA[1], rA[2]);
// Inverse normal orientation
gluQuadricOrientation(quadric, GLU_INSIDE);
gluCylinder( quadric, light_.radius()/6, light_.radius()/6, light_.radius()*2, 10, 10 );
cone_->setNormalOrientation(ACG::GLPrimitive::INSIDE);
cone_->setBottomRadius(light_.radius()/6.0f);
cone_->setTopRadius(light_.radius()/6.0f);
cone_->draw(_state, light_.radius()*2.0f);
_state.translate(0.0, 0.0, light_.radius()*2);
// Draw arrow tip
gluCylinder( quadric, light_.radius()/2, 0, light_.radius(), 10, 10 );
cone_->setBottomRadius(light_.radius()/2.0f);
cone_->setTopRadius(0.0f);
cone_->draw(_state, light_.radius());
}
// Free light id
......@@ -396,8 +403,6 @@ void LightNode::draw(GLState& _state, const DrawModes::DrawMode& /*_drawMode*/)
// Lighting
if(!lighting_backup) ACG::GLState::disable(GL_LIGHTING);
gluDeleteQuadric(quadric);
_state.pop_modelview_matrix();
}
......@@ -443,14 +448,12 @@ void LightNode::pick(GLState& _state, PickTarget _target) {
ACG::Vec3d spotDir = light_.realSpotDirection_;
ACG::Vec4f c = light_.ambientColor() * light_.brightness_;
GLUquadricObj* quadric = gluNewQuadric();
// Origin
_state.push_modelview_matrix();
// Transform to light origin and direction
_state.translate(p[0], p[1], p[2]);
gluSphere( quadric, light_.radius(), 10, 10 );
sphere_->draw(_state, light_.radius());
// Visualize spot cone (or direction)
if(light_.spotCutoff() < 180.0f) {
......@@ -465,14 +468,17 @@ void LightNode::pick(GLState& _state, PickTarget _target) {
ACG::Vec3d rA = z % spot;
_state.rotate(angle, rA[0], rA[1], rA[2]);
gluCylinder( quadric, light_.radius()/6, light_.radius()/6, light_.radius()*2, 10, 10 );
cone_->setNormalOrientation(ACG::GLPrimitive::OUTSIDE);
cone_->setBottomRadius(light_.radius()/6.0f);
cone_->setTopRadius(light_.radius()/6.0f);
cone_->draw(_state, light_.radius()*2.0f);
_state.translate(0.0, 0.0, light_.radius()*2);
// Draw arrow tip
gluCylinder( quadric, light_.radius()/2, 0, light_.radius(), 10, 10 );
cone_->setBottomRadius(light_.radius()/2.0f);
cone_->setTopRadius(0.0f);
cone_->draw(_state, light_.radius());
}
gluDeleteQuadric(quadric);
_state.pop_modelview_matrix();
ACG::GLState::depthFunc(prev_depth);
......
......@@ -59,6 +59,7 @@
#include <OpenFlipper/common/GlobalDefines.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <ACG/GL/gl.hh>
#include <ACG/GL/GLPrimitives.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <string>
#include <vector>
......@@ -306,6 +307,9 @@ private:
/// Internal light id
GLenum lightId_;
ACG::GLCone* cone_;
ACG::GLSphere* sphere_;
};
/**
......
Markdown is supported
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