50 #include "TypeLight.hh"
52 #define DEF0 "Default Light 0.lgt"
53 #define DEF1 "Default Light 1.lgt"
54 #define DEF2 "Default Light 2.lgt"
56 TypeLightPlugin::TypeLightPlugin() :
65 viewerToolbarAction_(0),
75 hitLightTrackball_(false),
80 light_matrix_.identity();
83 bool TypeLightPlugin::registerType() {
96 void TypeLightPlugin::removeDefaultLights() {
103 emit deleteObject(light0);
105 emit deleteObject(light1);
107 emit deleteObject(light2);
109 defaultLights_ =
false;
112 void TypeLightPlugin::addDefaultLights() {
121 light0 = addDefaultLight(DEF0);
135 lightSrc0->brightness(1.0);
147 light1 = addDefaultLight(DEF1);
160 lightSrc1->brightness(1.0);
171 light2 = addDefaultLight(DEF2);
184 lightSrc2->brightness(1.0);
193 defaultLights_ =
true;
196 void TypeLightPlugin::showReducedUi(
bool reduced) {
197 viewerToolbarAction_->setVisible(!reduced);
202 if ( OpenFlipper::Options::gui() ){
204 emit addPickMode(
"Separator");
205 emit addHiddenPickMode(
"MoveLights");
206 emit setPickModeMouseTracking (
"MoveLights",
true);
207 emit addHiddenPickMode(
"TranslateLights");
208 emit setPickModeMouseTracking (
"TranslateLights",
true);
209 emit addHiddenPickMode(
"RotateLights");
210 emit setPickModeMouseTracking (
"RotateLights",
true);
213 toolbar_ =
new QToolBar(tr(
"Transform light sources"));
215 lightAction_ =
new QAction(tr(
"<B>Light mode</B><br>Transform light sources in 3D."), toolbar_);
216 lightAction_->setStatusTip(tr(
"Transform light sources in 3D."));
217 lightAction_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"light-mode.png") );
218 lightAction_->setCheckable(
true);
219 toolbar_->addAction(lightAction_);
221 connect(lightAction_, SIGNAL(triggered(
bool)),
this, SLOT(slotLightModeRequest(
bool)) );
224 QToolBar* viewerToolbar = 0;
226 emit getToolBar(
"Viewer Toolbar", viewerToolbar );
228 if ( viewerToolbar == 0 ) {
229 emit log(
LOGERR,
"Unable to get Viewer Toolbar!");
233 QList< QAction *> toolbarActions = viewerToolbar->actions();
234 QAction* pickAction = 0;
235 for (
int i = 0 ; i < toolbarActions.size() ; ++i ) {
236 if ( toolbarActions[i]->text() ==
"Pick" )
237 pickAction = toolbarActions[i];
242 viewerToolbarAction_ = viewerToolbar->insertWidget( pickAction, toolbar_ );
244 viewerToolbarAction_ = viewerToolbar->addWidget( toolbar_ );
245 viewerToolbarAction_->setText(tr(
"Light"));
249 lightOptions_ =
new QToolBar(tr(
"Transform light sources"));
250 lightOptions_->setAttribute(Qt::WA_AlwaysShowToolTips,
true);
252 QActionGroup* pickGroup =
new QActionGroup(lightOptions_);
253 pickGroup->setExclusive (
false);
255 moveMode_ =
new QAction(tr(
"Move light source"), pickGroup);
256 moveMode_->setStatusTip(tr(
"Move light source on virtual trackball around trackball center."));
257 moveMode_->setToolTip(tr(
"Move light source on virtual trackball around trackball center."));
258 moveMode_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"light-move.png") );
259 moveMode_->setCheckable(
true);
260 lightOptions_->addAction(moveMode_);
262 translateMode_ =
new QAction(tr(
"Translate light source"), pickGroup);
263 translateMode_->setStatusTip(tr(
"Translate light source on plane parallely to viewing plane."));
264 translateMode_->setToolTip(tr(
"Translate light source on plane parallely to viewing plane."));
265 translateMode_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"light-translate.png") );
266 translateMode_->setCheckable(
true);
267 lightOptions_->addAction(translateMode_);
269 rotateMode_ =
new QAction(tr(
"Rotate spotlight direction"), pickGroup);
270 rotateMode_->setStatusTip(tr(
"Rotate the spotlight direction of a light source."));
271 rotateMode_->setToolTip(tr(
"Rotate the spotlight direction of a light source."));
272 rotateMode_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"light-rotate.png") );
273 rotateMode_->setCheckable(
true);
274 lightOptions_->addAction(rotateMode_);
276 lightOptions_->addSeparator ();
278 allLightsMode_ =
new QAction(tr(
"All lights"), lightOptions_);
279 allLightsMode_->setStatusTip(tr(
"Transform all light sources if checked. If not, only apply to target light sources."));
280 allLightsMode_->setToolTip(tr(
"Transform all light sources if checked. If not, only apply to target light sources."));
281 allLightsMode_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"light-alllights.png") );
282 allLightsMode_->setCheckable(
true);
283 lightOptions_->addAction(allLightsMode_);
285 connect(pickGroup, SIGNAL(triggered(QAction*)),
this, SLOT(slotPickModeRequest(QAction*)) );
286 connect(allLightsMode_, SIGNAL(triggered(
bool)),
this, SLOT(slotSetAllOrTarget(
bool)) );
288 emit setPickModeToolbar (
"MoveLights", lightOptions_);
289 emit setPickModeToolbar (
"TranslateLights", lightOptions_);
290 emit setPickModeToolbar (
"RotateLights", lightOptions_);
303 lightAction_->setChecked(
false);
306 void TypeLightPlugin::slotLightModeRequest(
bool ) {
311 lightAction_->setChecked(
true);
314 moveMode_->setChecked(
true);
315 translateMode_->setChecked(
false);
316 rotateMode_->setChecked(
false);
319 void TypeLightPlugin::slotPickModeRequest(QAction* _action) {
323 if (_action == moveMode_){
326 lightAction_->setChecked(
true);
327 moveMode_->setChecked(
true);
328 translateMode_->setChecked(
false);
329 rotateMode_->setChecked(
false);
331 }
else if (_action == translateMode_){
334 lightAction_->setChecked(
true);
335 moveMode_->setChecked(
false);
336 translateMode_->setChecked(
true);
337 rotateMode_->setChecked(
false);
339 }
else if (_action == rotateMode_){
342 lightAction_->setChecked(
true);
343 moveMode_->setChecked(
false);
344 translateMode_->setChecked(
false);
345 rotateMode_->setChecked(
true);
349 void TypeLightPlugin::slotSetAllOrTarget(
bool _checked) {
351 allLightsMode_->setChecked(_checked);
352 onlyTargets_ = !_checked;
355 int TypeLightPlugin::addDefaultLight(QString _name) {
361 object->setName( _name );
363 object->defaultLight(
true);
369 emit emptyObjectAdded (object->
id() );
379 QString
name = QString(tr(
"New Light %1.lgt").arg( object->
id() ));
383 object->setName( f.fileName() );
385 object->defaultLight(
false);
389 object->enablePicking(
true);
393 emit emptyObjectAdded (object->
id() );
413 removeDefaultLights();
439 if(lightObject != 0) {
455 if(d == FLT_MAX)
return 0.0f;
460 double TypeLightPlugin::getFarthestRadius() {
470 if(lightObject != 0) {
477 double tmp_d = fabs((source->
position() - c).norm());
478 if(tmp_d > d) d = tmp_d;
498 switch (_event->type())
500 case QEvent::MouseButtonPress:
507 radius_ = getFarthestRadius();
524 QPoint p(_event->x(), _event->y());
546 lightRadius_ = (bbMin - bbMax).length()/4;
555 if(lightId_ == -1)
break;
563 case QEvent::MouseButtonRelease:
566 hitLightTrackball_ =
false;
567 hitTrackball_ =
false;
570 case QEvent::MouseMove:
582 if(hitTrackball_ ==
false) {
602 double angle = acos(v1 | v2) * 180/M_PI;
615 ACG::Vec3d p1(lastPoint2D_.x(), lastPoint2D_.y(), planeDepth_);
630 (lightId_ == -1))
break;
634 if(hitLightTrackball_ ==
false) {
654 double angle = acos(v1 | v2) * 180/M_PI;
687 double x = clickRelToC[0];
688 double y = clickRelToC[1];
692 double sq = radius_*radius_ - x*x - y*y;
694 double z = sq > 0.0 ? sqrt(sq) : 0.0;
696 if(sq <= 0.0) hit =
false;
718 double x = clickRelToC[0];
719 double y = clickRelToC[1];
723 double sq = lightRadius_*lightRadius_ - x*x - y*y;
725 double z = sq > 0.0 ? sqrt(sq) : 0.0;
727 if(sq <= 0.0) hit =
false;
738 light_matrix_.
rotate(_angle, _axis[0], _axis[1], _axis[2]);
749 m.
rotate(_angle, _axis[0], _axis[1], _axis[2]);
780 if(lightObject != 0) {
787 std::cerr <<
"Not implemented yet! rotate directional light sources" << std::endl;
830 #if QT_VERSION < 0x050000
void rotateLightDirection(ACG::Vec3d &_axis, double _angle)
Rotate spot light direction.
void pluginsInitialized()
Initialize Plugin step 2.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
DLLEXPORT void setTypeIcon(DataType _id, QString _icon)
Set an Icon for a given DataType.
float findDepth()
Find depth of nearest light source.
const QStringList ALL_OBJECTS
Iterable object range.
int addEmpty()
Create an empty object.
int getObjectId(const QString &_name)
void disableExaminerLightHandling()
Disable the core light handling.
pick any of the prior targets (should be implemented for all nodes)
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
void slotPickModeChanged(const std::string &_pickMode)
The pickingMode has changed.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void diffuseColor(Vec4f _color)
set Diffuse color for LightSource
LightSource * lightSource(BaseObjectData *_object)
Get the lightSource in this Object.
void addedEmptyObject(int _id)
An empty object has been added.
DLLEXPORT DataType addDataType(QString _name, QString _readableName)
Adds a datatype and returns the id for the new type.
bool defaultLight() const
Is light default light source?
void fixedPosition(bool _state)
make LightSource fixed or moveable with ModelViewMatrix
VectorT< double, 3 > Vec3d
const GLMatrixd & modelview() const
get modelview matrix
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)
const QStringList TARGET_OBJECTS("target")
Iterable object range.
const std::string pickMode()
Get the current Picking mode.
const ACG::Vec3d trackBallCenter(int _viewer)
Get the trackball Center.
LightObject * lightObject(BaseObjectData *_object)
Cast an BaseObject to a LightObject if possible.
int viewport_width() const
get viewport width
std::vector< int > lightSources_
Count light sources in scene.
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
bool computeClickOnTrackball(const QPoint &_v2D, ACG::Vec3d &_clickOnSphere, ACG::GLState &_state)
Compute click on trackball containing the light source.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
QString name()
Return a name for the plugin.
Vec3d direction() const
Get direction of the light source.
LightSource * lightSource()
void rotate(Scalar angle, Scalar x, Scalar y, Scalar z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
void objectDeleted(int _id)
An object was deleted.
void setName(QString _name)
Set the name of the Object.
void identity()
setup an identity matrix
void rotateLights(ACG::Vec3d &_axis, double _angle)
Rotate light sources.
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x',y',z',1) = M * (x,y,z,1)
Structure to hold options for one LightSource.
bool directional() const
Check if the light source is a directional light source.
void specularColor(Vec4f _color)
set Specular color for LightSource
void enable()
enable LightSource
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
LightNode * lightNodeVis()
Get the scenegraph Node.
void boundingBox(ACG::Vec3d &, ACG::Vec3d &)
Get bounding box (for visualization purposes)
Viewer::ActionMode actionMode()
Get the current Action mode.
void slotAllCleared()
Called if the whole scene is cleared.
void updateLights()
Update light sources' positions.
bool computeClickOnLightTrackball(const QPoint &_v2D, ACG::Vec3d &_clickOnSphere, ACG::GLState &_state)
Compute click on trackball of light source.
ACG::GLState & glState()
Get the glState of the Viewer.
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
Vec3d project(const Vec3d &_point) const
project point in world coordinates to window coordinates
int viewport_height() const
get viewport height
void position(Vec3d _pos)
Set position for LightSource.
void slotMouseEventLight(QMouseEvent *_event)
Mouse Event from main application ( Light Mode )
void spotDirection(Vec3d _pos)
Set spot direction.
void traverse(ACG::SceneGraph::MouseEventAction &_action)