Commit 549464cb authored by Jan Möbius's avatar Jan Möbius

Mike:

Removed light handling from BaseViewer
Added singals to MouseInterface to handle light events

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9801 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 072e60f5
......@@ -108,7 +108,18 @@ class MouseInterface {
*
* @param _event Mousevent
*/
virtual void slotMouseEventIdentify() {};
virtual void slotMouseEventIdentify( QMouseEvent* /*_event */) {};
/** \brief Mouse Event from Main App ( Light Mode )
*
* This slot is called if a mouse event occured in the Viewer
* This slot will only get called in LightMode.
* Right button clicks will not be passed to the plugins as this is reserved for
* the context Menu.
*
* @param _event Mousevent
*/
virtual void slotMouseEventLight( QMouseEvent* /* _event */) {};
public :
......
......@@ -528,6 +528,8 @@ Core::init() {
this , SLOT(slotMouseEvent(QMouseEvent*)));
connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalMouseEventIdentify(QMouseEvent*)),
this , SLOT(slotMouseEventIdentify(QMouseEvent*)));
connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalMouseEventLight(QMouseEvent*)),
this , SLOT(slotMouseEventLight(QMouseEvent*)));
connect( coreWidget_->examiner_widgets_[i], SIGNAL(signalWheelEvent(QWheelEvent *, const std::string &)),
this , SLOT(slotWheelEvent(QWheelEvent *, const std::string &)));
......@@ -668,6 +670,35 @@ Core::slotMouseEventIdentify( QMouseEvent* _event )
emit PluginMouseEventIdentify( _event );
}
//-----------------------------------------------------------------------------
void
Core::slotMouseEventLight( QMouseEvent* _event )
{
const QObject* senderPointer = sender();
unsigned int examinerId = 0;
if ( senderPointer == 0 ) {
std::cerr << "Error : slotMouseEventLight directly called! This should only be called by an examiner" << std::endl;
} else {
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) {
if ( senderPointer == coreWidget_->examiner_widgets_[i] ) {
examinerId = i;
if ( OpenFlipper::Options::doSlotDebugging() )
emit log(LOGINFO,tr("slotMouseEventLight from examiner ") + QString::number(i) );
break;
}
}
}
PluginFunctions::setActiveExaminer( examinerId );
emit PluginMouseEventLight( _event );
}
//-----------------------------------------------------------------------------
......
......@@ -153,6 +153,9 @@ private slots:
/// Handle Mouse events when in Identifier mode
void slotMouseEventIdentify( QMouseEvent* _event );
/// Handle Mouse events when in Light mode
void slotMouseEventLight( QMouseEvent* _event );
protected:
......@@ -178,6 +181,9 @@ signals:
/// Emitted when an identify event occurs
void PluginMouseEventIdentify( QMouseEvent* );
/// Emitted when an light event occurs
void PluginMouseEventLight( QMouseEvent* );
/// This signal is emitted if the object has been changed (source/target)
void objectSelectionChanged( int );
......
......@@ -826,6 +826,10 @@ void Core::loadPlugin(QString filename, bool silent, QObject* _plugin){
if ( checkSlot( plugin , "slotMouseEventIdentify(QMouseEvent*)" ) )
connect(this , SIGNAL(PluginMouseEventIdentify(QMouseEvent*)),
plugin , SLOT(slotMouseEventIdentify(QMouseEvent*)));
if ( checkSlot( plugin , "slotMouseEventLight(QMouseEvent*)" ) )
connect(this , SIGNAL(PluginMouseEventLight(QMouseEvent*)),
plugin , SLOT(slotMouseEventLight(QMouseEvent*)));
}
......
......@@ -174,9 +174,6 @@ glViewer::glViewer( QGraphicsScene* _scene,
projectionMode_ = PERSPECTIVE_PROJECTION;
navigationMode_ = NORMAL_NAVIGATION;
light_matrix_.identity();
trackMouse_ = false;
// stereo
......@@ -728,8 +725,6 @@ void glViewer::drawScene_mono()
cursorPainter_->paintCursor (glstate_);
glstate_->pop_modelview_matrix ();
}
draw_lights();
}
......@@ -977,11 +972,6 @@ void glViewer::initializeGL()
// Update all settings which would require a redraw
applyProperties();
// light sources
light_matrix_.identity();
update_lights();
// scene pos and size
scene_center_ = trackball_center_ = ACG::Vec3d( 0.0, 0.0, 0.0 );
scene_radius_ = trackball_radius_ = 1.0;
......@@ -1022,89 +1012,6 @@ void glViewer::initializeGL()
}
//-----------------------------------------------------------------------------
/**
*
*/
void glViewer::draw_lights() {
// makeCurrent();
// //
// glMatrixMode(GL_MODELVIEW);
// glPushMatrix();
// glLoadIdentity();
// glMultMatrixd(light_matrix_.data());
//
// std::cerr << "light_matrix_\n" << light_matrix_ << std::endl;
// //
// glPointSize(3);
// //
// glColor3f(1.0,1.0,1.0);
// // glDisable(GL_LIGHTING);
// // glDisable(GL_BLEND);
// glBegin(GL_LINES);
// glVertex3f(0.0, 0.0, -1000.0);
// glVertex3f(0.0, 0.0, 10000.0);
// glVertex3f(0.0, -1000.0,0.0);
// glVertex3f(0.0, 1000.0,0.0);
// glVertex3f(1000.0,0.0,0.0);
// glVertex3f(-1000.0,0.0,0.0);
// // glVertex3d(0.0, 0.0, 1.1);
// // glVertex3d(-1.0, 1.0, 0.8);
// // glVertex3d( 1.0, 1.0, 0.8);
//
// glEnd();
// // glEnable(GL_LIGHTING);
// // glEnable(GL_BLEND);
// //
// glPopMatrix();
}
void glViewer::update_lights()
{
// PluginFunction can disable the cores light handling and use its own one
if (!PluginFunctions::examinerLightHandling() )
return;
makeCurrent();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glMultMatrixd(light_matrix_.data());
GLfloat pos[4], col[4];
col[0] = col[1] = col[2] = 0.7;
pos[3] = col[3] = 0.0;
#define SET_LIGHT(i,x,y,z) { \
pos[0]=x; pos[1]=y; pos[2]=z; \
glLightfv(GL_LIGHT##i, GL_POSITION, pos); \
glLightfv(GL_LIGHT##i, GL_DIFFUSE, col); \
glLightfv(GL_LIGHT##i, GL_SPECULAR, col); \
glEnable(GL_LIGHT##i); \
}
SET_LIGHT(0, 0.0, 0.0, 1.0);
SET_LIGHT(1, -1.0, 1.0, 0.7);
SET_LIGHT(2, 1.0, 1.0, 0.7);
col[0] = col[1] = col[2] = 0.3; col[3] = 1.0;
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, col);
glPopMatrix();
}
void glViewer::rotate_lights(ACG::Vec3d& _axis, double _angle)
{
light_matrix_.rotate(_angle, _axis[0], _axis[1], _axis[2], ACG::MULT_FROM_LEFT);
update_lights();
}
//-----------------------------------------------------------------------------
......@@ -1137,9 +1044,6 @@ void glViewer::paintGL()
applyProperties();
// light sources
update_lights();
glstate_->setState ();
glColor4f(1.0,0.0,0.0,1.0);
......@@ -1567,7 +1471,7 @@ void glViewer::mousePressEvent(QGraphicsSceneMouseEvent* _e)
break;
case Viewer::LightMode:
lightMouseEvent(&me);
emit(signalMouseEventLight(&me));
break;
case Viewer::PickingMode: // give event to application
......@@ -1604,7 +1508,7 @@ void glViewer::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* _e)
break;
case Viewer::LightMode:
lightMouseEvent(&me);
emit(signalMouseEventLight(&me));
break;
case Viewer::PickingMode: // give event to application
......@@ -1636,7 +1540,7 @@ void glViewer::mouseMoveEvent(QGraphicsSceneMouseEvent* _e)
break;
case Viewer::LightMode:
lightMouseEvent(&me);
emit(signalMouseEventLight(&me));
break;
case Viewer::PickingMode:
......@@ -1699,7 +1603,7 @@ void glViewer::mouseReleaseEvent(QGraphicsSceneMouseEvent* _e)
break;
case Viewer::LightMode:
lightMouseEvent(&me);
emit(signalMouseEventLight(&me));
break;
case Viewer::PickingMode: // give event to application
......@@ -2028,75 +1932,6 @@ void glViewer::handleNormalNavigation( QMouseEvent* _event ) {
//-----------------------------------------------------------------------------
void
glViewer::lightMouseEvent(QMouseEvent* _event)
{
QPointF f (mapFromScene(QPointF(_event->pos().x(), _event->pos().y())));
QPoint pos (f.x(), f.y());
switch (_event->type())
{
case QEvent::MouseButtonPress:
{
lastPoint_hitSphere_ = mapToSphere( lastPoint2D_= pos,
lastPoint3D_ );
isRotating_ = true;
timer_->stop();
break;
}
case QEvent::MouseMove:
{
// rotate lights
if (_event->buttons() & Qt::LeftButton)
{
QPoint newPoint2D = pos;
if ( (newPoint2D.x()<0) || (newPoint2D.x() > (int)glWidth()) ||
(newPoint2D.y()<0) || (newPoint2D.y() > (int)glHeight()) )
return;
ACG::Vec3d newPoint3D;
bool newPoint_hitSphere = mapToSphere( newPoint2D, newPoint3D );
makeCurrent();
ACG::Vec3d axis(1.0,0.0,0.0);
double angle(0.0);
if ( lastPoint_hitSphere_ )
{
if ( ( newPoint_hitSphere = mapToSphere( newPoint2D, newPoint3D ) ) )
{
axis = lastPoint3D_ % newPoint3D;
double cos_angle = ( lastPoint3D_ | newPoint3D );
if ( fabs(cos_angle) < 1.0 ) {
angle = acos( cos_angle ) * 180.0 / M_PI;
angle *= 2.0;
}
}
rotate_lights(axis, angle);
}
lastPoint2D_ = newPoint2D;
lastPoint3D_ = newPoint3D;
lastPoint_hitSphere_ = newPoint_hitSphere;
updateGL();
}
break;
}
default: // avoid warning
break;
}
}
//-----------------------------------------------------------------------------
void glViewer::viewWheelEvent( QWheelEvent* _event)
{
double factor = properties_.wheelZoomFactor();
......
......@@ -263,17 +263,6 @@ public:
/// get treatment of normals
NormalsMode normalsMode() const { return normalsMode_; }
/// get light rotation matrix
ACG::GLMatrixd& light_matrix() { return light_matrix_; }
/// rotete light sources
void rotate_lights(ACG::Vec3d& _axis, double _angle);
/// update light position
void update_lights();
void draw_lights();
/// copy current framebuffer to an QImage
void copyToImage( QImage& _image, GLenum _buffer=GL_BACK) {
copyToImage(_image, 0, 0, glWidth(), glHeight(), _buffer);
......@@ -417,10 +406,15 @@ signals:
/// Emitted in Pick mode. Uses pick mode.
void signalWheelEvent(QWheelEvent*, const std::string&);
/** Emitted instead o signalMouseEvent() if actionMode()==Question
/** Emitted instead of signalMouseEvent() if actionMode()==Question
and \c _event is a mouse press event.
*/
void signalMouseEventIdentify( QMouseEvent* );
/** Emitted instead of signalMouseEvent() if actionMode()==Light
and \c _event is a mouse press event.
*/
void signalMouseEventLight( QMouseEvent* );
/// scene graph has changed
void signalSceneGraphChanged(ACG::SceneGraph::BaseNode* _root);
......@@ -481,10 +475,7 @@ protected:
/// specialized viewer: hande key events
void viewKeyEvent( QKeyEvent* _event);
/// optional: hande mouse events to rotate light
void lightMouseEvent( QMouseEvent* /* _event */ );
protected:
......@@ -576,10 +567,6 @@ private:
double homeOrthoWidth_;
// matrix for rotating light position
ACG::GLMatrixd light_matrix_;
// modi
NormalsMode normalsMode_;
ProjectionMode projectionMode_;
......
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