Commit 7459c5d8 authored by Jan Möbius's avatar Jan Möbius
Browse files

Tobias new OSD Transform node to render an object always at a screen position



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@13451 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 6c86e563
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
//================================================================
//
// CLASS OSDTransformNode - IMPLEMENTATION
//
//================================================================
//== INCLUDES ====================================================
#include "OSDTransformNode.hh"
#include <ACG/GL/gl.hh>
#include <ACG/Scenegraph/SceneGraph.hh>
//== NAMESPACES ==================================================
namespace ACG {
namespace SceneGraph {
//== IMPLEMENTATION ==============================================
void OSDTransformNode::enterOSD( GLState &_state, const DrawModes::DrawMode &_drawMode )
{
_state.push_modelview_matrix();
int left, bottom, width, height;
_state.get_viewport( left, bottom, width, height );
double aspect = _state.aspect();
_state.push_projection_matrix();
_state.reset_projection();
_state.perspective( 45.0, aspect, 0.8, 20.0 );
_state.push_modelview_matrix();
_state.reset_modelview();
double posX = left + center_[0] * width;
double posY = bottom + center_[1] * height;
ACG::Vec3d pos = _state.unproject( ACG::Vec3d( posX, posY, 0.1 ) );
_state.pop_modelview_matrix();
GLMatrixd modelview = _state.modelview();
modelview(0,3) = 0.0;
modelview(1,3) = 0.0;
modelview(2,3) = 0.0;
_state.set_modelview( modelview );
_state.translate( pos[0], pos[1], pos[2], MULT_FROM_LEFT );
}
//----------------------------------------------------------------
void OSDTransformNode::leaveOSD( GLState &_state, const DrawModes::DrawMode &_drawMode )
{
_state.pop_projection_matrix();
_state.pop_modelview_matrix();
}
//================================================================
} // namespace SceneGraph
} // namespace ACG
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision$ *
* $Author$ *
* $Date$ *
* *
\*===========================================================================*/
//================================================================
//
// CLASS OSDTransformNode
//
//================================================================
#ifndef ACG_OSDTRANSFORMNODE_HH
#define ACG_OSDTRANSFORMNODE_HH
//== INCLUDES ====================================================
#include "BaseNode.hh"
#include "DrawModes.hh"
//== NAMESPACES ==================================================
namespace ACG {
namespace SceneGraph {
//== CLASS DEFINITION ============================================
/** \class OSDTransformNode OSDTransformNode.hh <ACG/Scenegraph/OSDTransformNode.hh>
OSDTransformNode sets up a transformation used to render on screen display geometry.
**/
class ACGDLLEXPORT OSDTransformNode : public BaseNode
{
public:
/// default constructor
inline OSDTransformNode( BaseNode *_parent = 0, const std::string &_name = "<OSDTransformNode>" ) : BaseNode( _parent, _name ), center_( 0.0, 0.0 ) { }
/// destructor
inline ~OSDTransformNode() { }
/// static name of this class
ACG_CLASSNAME( OSDTransformNode );
/// set up transformation used for drawing
inline void enter( GLState &_state, const DrawModes::DrawMode &_drawMode ) { enterOSD( _state, _drawMode ); }
/// restore transformation used for drawing
inline void leave( GLState &_state, const DrawModes::DrawMode &_drawMode ) { leaveOSD( _state, _drawMode ); }
/// set up transformation used for picking
inline void enterPick( GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode ) { enterOSD( _state, _drawMode ); }
/// restore transformation used for picking
inline void leavePick( GLState &_state, PickTarget _target, const DrawModes::DrawMode &_drawMode ) { leaveOSD( _state, _drawMode ); }
/// set center of OSD
inline void setCenter( double _x, double _y ) { center_[0] = _x; center_[1] = _y; }
inline void setCenter( ACG::Vec2d _c ) { center_[0] = _c[0]; center_[1] = _c[1]; }
/// get center of OSD
inline ACG::Vec2d getCenter() const { return center_; }
private:
void enterOSD( GLState &_state, const DrawModes::DrawMode &_drawMode );
void leaveOSD( GLState &_state, const DrawModes::DrawMode &_drawMode );
ACG::Vec2d center_;
};
//================================================================
} // namespace SceneGraph
} // namespace ACG
//================================================================
#endif // ACG_OSDTRANSFORMNODE_HH
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