Commit 2a16675e authored by Jan Möbius's avatar Jan Möbius

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14366 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 638661f9
......@@ -41,30 +41,34 @@
\*===========================================================================*/
#include "PlaneNode.hh"
#include "../GL/gl.hh"
#include <ACG/GL/gl.hh>
#include <iostream>
#include <math.h>
#include "TranslationManipulatorNode.hh"
namespace ACG {
namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
//== IMPLEMENTATION ==========================================================
PlaneNode::PlaneNode(Plane& _plane, BaseNode *_parent, std::string _name)
:BaseNode(_parent, _name),
plane_(_plane)
{
}
PlaneNode::~PlaneNode()
{
}
void PlaneNode::boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
void PlaneNode::boundingBox(ACG::Vec3d& _bbMin, ACG::Vec3d& _bbMax)
{
Vec3f pos = position_ - xDirection_*0.5 - yDirection_*0.5;
ACG::Vec3f pos = plane_.position - plane_.xDirection * 0.5 - plane_.yDirection * 0.5;
//add a little offset in normal direction
Vec3d pos0 = ACG::Vec3d( pos + normal_*0.1 );
Vec3d pos1 = ACG::Vec3d( pos - normal_*0.1 );
ACG::Vec3d pos0 = ACG::Vec3d( pos + plane_.normal * 0.1 );
ACG::Vec3d pos1 = ACG::Vec3d( pos - plane_.normal * 0.1 );
Vec3d xDird = ACG::Vec3d( xDirection_ );
Vec3d yDird = ACG::Vec3d( yDirection_ );
ACG::Vec3d xDird = ACG::Vec3d( plane_.xDirection );
ACG::Vec3d yDird = ACG::Vec3d( plane_.yDirection );
_bbMin.minimize( pos0 );
_bbMin.minimize( pos0 + xDird);
......@@ -78,22 +82,22 @@ void PlaneNode::boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
//----------------------------------------------------------------------------
DrawModes::DrawMode
ACG::SceneGraph::DrawModes::DrawMode
PlaneNode::availableDrawModes() const
{
return ( DrawModes::POINTS |
DrawModes::POINTS_SHADED |
DrawModes::POINTS_COLORED );
return ( ACG::SceneGraph::DrawModes::POINTS |
ACG::SceneGraph::DrawModes::POINTS_SHADED |
ACG::SceneGraph::DrawModes::POINTS_COLORED );
}
//----------------------------------------------------------------------------
void PlaneNode::drawPlane( GLState& /*_state*/) {
void PlaneNode::drawPlane( ACG::GLState& /*_state*/) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Vec3f origin(0.0, 0.0, 0.0);
Vec3f xy = xDirection_ + yDirection_;
ACG::Vec3f origin(0.0, 0.0, 0.0);
ACG::Vec3f xy = plane_.xDirection + plane_.yDirection;
//first draw the lines
glColor3f( 1.0, 1.0, 1.0 );
......@@ -102,9 +106,9 @@ void PlaneNode::drawPlane( GLState& /*_state*/) {
//draw the plane
glBegin(GL_QUADS);
glVertex3fv( &origin[0] );
glVertex3fv( &xDirection_[0] );
glVertex3fv( &plane_.xDirection[0] );
glVertex3fv( &xy[0] );
glVertex3fv( &yDirection_[0] );
glVertex3fv( &plane_.yDirection[0] );
glEnd();
......@@ -122,9 +126,9 @@ void PlaneNode::drawPlane( GLState& /*_state*/) {
//draw the plane
glBegin(GL_QUADS);
glVertex3fv( &origin[0] );
glVertex3fv( &xDirection_[0] );
glVertex3fv( &plane_.xDirection[0] );
glVertex3fv( &xy[0] );
glVertex3fv( &yDirection_[0] );
glVertex3fv( &plane_.yDirection[0] );
glEnd();
//finally the green back side
......@@ -136,35 +140,35 @@ void PlaneNode::drawPlane( GLState& /*_state*/) {
//draw the plane
glBegin(GL_QUADS);
glVertex3fv( &origin[0] );
glVertex3fv( &xDirection_[0] );
glVertex3fv( &plane_.xDirection[0] );
glVertex3fv( &xy[0] );
glVertex3fv( &yDirection_[0] );
glVertex3fv( &plane_.yDirection[0] );
glEnd();
}
//----------------------------------------------------------------
void PlaneNode::drawPlanePick( GLState& _state) {
void PlaneNode::drawPlanePick( ACG::GLState& _state) {
_state.pick_set_maximum(1);
_state.pick_set_name(0);
Vec3f origin(0.0, 0.0, 0.0);
Vec3f xy = xDirection_ + yDirection_;
ACG::Vec3f origin(0.0, 0.0, 0.0);
ACG::Vec3f xy = plane_.xDirection + plane_.yDirection;
//draw the plane
glBegin(GL_QUADS);
glVertex3fv( &origin[0] );
glVertex3fv( &xDirection_[0] );
glVertex3fv( &plane_.xDirection[0] );
glVertex3fv( &xy[0] );
glVertex3fv( &yDirection_[0] );
glVertex3fv( &plane_.yDirection[0] );
glEnd();
}
//----------------------------------------------------------------
void PlaneNode::draw(GLState& _state , const DrawModes::DrawMode& /*_drawMode*/)
void PlaneNode::draw(ACG::GLState& _state , const ACG::SceneGraph::DrawModes::DrawMode& /*_drawMode*/)
{
_state.push_modelview_matrix();
......@@ -174,7 +178,7 @@ void PlaneNode::draw(GLState& _state , const DrawModes::DrawMode& /*_drawMode*
glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
ACG::GLState::enable(GL_COLOR_MATERIAL);
Vec3f pos = position_ - xDirection_*0.5 - yDirection_*0.5;
ACG::Vec3f pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
_state.translate(pos[0], pos[1], pos[2]);
......@@ -185,115 +189,67 @@ void PlaneNode::draw(GLState& _state , const DrawModes::DrawMode& /*_drawMode*
_state.pop_modelview_matrix();
}
//----------------------------------------------------------------
void PlaneNode::setPosition(const Vec3f& _position, const Vec3f& _normal)
{
//find a non zero component
int comp = -1;
for (int i=0; i < 3; i++)
if ( _normal[i] != 0.0 ){
comp = i;
break;
}
if (comp == -1){
std::cerr << "PlaneNode: normal is invalid!" << std::endl;
return;
}
//compute orthogonal vectors in the plane
xDirection_[comp] = (-_normal[ (comp + 1) % 3 ] - _normal[(comp + 2) % 3]) / _normal[comp];
xDirection_[ (comp + 1) % 3 ] = 1;
xDirection_[ (comp + 2) % 3 ] = 1;
xDirection_ = xDirection_.normalize();
yDirection_ = _normal % xDirection_;
yDirection_ = yDirection_.normalize();
position_ = _position;
normal_ = _normal;
}
//----------------------------------------------------------------
void PlaneNode::setPosition(const Vec3f& _position, const Vec3f& _xDirection, const Vec3f& _yDirection)
void
PlaneNode::pick(ACG::GLState& _state, ACG::SceneGraph::PickTarget _target)
{
position_ = _position;
xDirection_ = _xDirection;
yDirection_ = _yDirection;
normal_ = (_xDirection % _yDirection).normalize();
}
if (_target == ACG::SceneGraph::PICK_ANYTHING) {
//----------------------------------------------------------------
void PlaneNode::transform(const ACG::Matrix4x4d& _mat)
{
position_ = _mat.transform_point(position_);
xDirection_ = _mat.transform_vector(xDirection_);
yDirection_ = _mat.transform_vector(yDirection_);
_state.push_modelview_matrix();
ACG::Vec3f pos = plane_.position - plane_.xDirection*0.5 - plane_.yDirection*0.5;
normal_ = (xDirection_ % yDirection_).normalize();
_state.translate(pos[0], pos[1], pos[2]);
drawPlanePick(_state);
_state.pop_modelview_matrix();
}
}
//----------------------------------------------------------------
void PlaneNode::setSize(double _xDirection, double _yDirection)
ACG::Vec3f PlaneNode::position()
{
xDirection_ = xDirection_.normalize() * _xDirection;
yDirection_ = yDirection_.normalize() * _yDirection;
return plane_.position;
}
//----------------------------------------------------------------
void
PlaneNode::pick(GLState& _state, PickTarget _target)
ACG::Vec3f PlaneNode::normal()
{
if (_target == PICK_ANYTHING) {
_state.push_modelview_matrix();
Vec3f pos = position_ - xDirection_*0.5 - yDirection_*0.5;
_state.translate(pos[0], pos[1], pos[2]);
drawPlanePick(_state);
_state.pop_modelview_matrix();
}
return plane_.normal;
}
//----------------------------------------------------------------
Vec3f PlaneNode::position()
ACG::Vec3f PlaneNode::xDirection()
{
return position_;
return plane_.xDirection;
}
//----------------------------------------------------------------
Vec3f PlaneNode::normal()
ACG::Vec3f PlaneNode::yDirection()
{
return normal_;
return plane_.yDirection;
}
//----------------------------------------------------------------
Vec3f PlaneNode::xDirection()
Plane& PlaneNode::getPlane()
{
return xDirection_;
return plane_;
}
//----------------------------------------------------------------
Vec3f PlaneNode::yDirection()
void PlaneNode::setPlane(Plane plane)
{
return yDirection_;
plane_ = plane;
}
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
......@@ -46,102 +46,77 @@
//
//=============================================================================
#ifndef ACG_PLANENODE_HH
#define ACG_PLANENODE_HH
#ifndef PLANENODE_HH
#define PLANENODE_HH
//== INCLUDES =================================================================
#include "BaseNode.hh"
#include "DrawModes.hh"
#include <vector>
#include "../Math/Matrix4x4T.hh"
#include <ObjectTypes/Plane/PlaneType.hh>
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/Math/Matrix4x4T.hh>
#include <OpenFlipper/common/GlobalDefines.hh>
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== CLASS DEFINITION =========================================================
/** \class PlaneNode PlaneNode.hh <ACG/Scenegraph/PlaneNode.hh>
PlaneNode renders a plane
**/
class ACGDLLEXPORT PlaneNode : public BaseNode
class DLLEXPORT PlaneNode : public ACG::SceneGraph::BaseNode
{
public:
/// constructor
PlaneNode( BaseNode* _parent=0, std::string _name="<PlaneNode>" )
: BaseNode(_parent, _name){};
public:
/** \brief Construct a plane rendering node
*
* @param _parent The parent node in the scenegraph
* @param _name The name of the new node (visible in the scenegraph dialogs)
* @param _plane A pointer to an existing plane
*/
PlaneNode(Plane& _plane, BaseNode *_parent = 0, std::string _name = "<PlaneNode>");
/// destructor
~PlaneNode() {};
~PlaneNode();
/// static name of this class
ACG_CLASSNAME(PlaneNode);
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const;
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
void boundingBox(ACG::Vec3d & _bbMin, ACG::Vec3d & _bbMax);
/// draw Plane
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
void draw(ACG::GLState & _state, const ACG::SceneGraph::DrawModes::DrawMode & _drawMode);
/// draw Plane for object picking
void pick(GLState& _state, PickTarget _target);
/// set center position and normal of plane
void setPosition(const Vec3f& _position, const Vec3f& _normal);
/// set center position, local xdirection (multiplied with width)
/// and local ydirection (multiplied with height)
void setPosition(const Vec3f& _position, const Vec3f& _xDirection, const Vec3f& _yDirection);
/// tranform the plane with given matrix
void transform(const ACG::Matrix4x4d& _mat);
/// set plane size
void setSize(double _xDirection, double _yDirection);
void manipulatorVisible( bool _visible );
bool manipulatorVisible();
void pick(ACG::GLState & _state, ACG::SceneGraph::PickTarget _target);
/// get center position of the plane
Vec3f position();
ACG::Vec3f position();
/// get current normal
Vec3f normal();
ACG::Vec3f normal();
/// local x direction (multiplied with width)
Vec3f xDirection();
ACG::Vec3f xDirection();
/// local y direction (multiplied with height)
Vec3f yDirection();
ACG::Vec3f yDirection();
/// Get the currently rendered plane
Plane& getPlane();
private:
/// Set a new plane for rendering
void setPlane(Plane plane);
void drawPlane(GLState& _state);
void drawManipulator(GLState& _state);
void drawPlanePick(GLState& _state);
void drawManipulatorPick(GLState& _state);
private:
void drawPlane(ACG::GLState & _state);
void drawManipulator(ACG::GLState & _state);
void drawPlanePick(ACG::GLState & _state);
void drawManipulatorPick(ACG::GLState & _state);
Vec3f position_;
Vec3f normal_;
Vec3f xDirection_;
Vec3f yDirection_;
Plane& plane_;
};
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
#endif // ACG_PLANENODE_HH defined
//=============================================================================
......@@ -83,7 +83,7 @@ PlaneObject::PlaneObject(const PlaneObject & _object) :
BaseObjectData(_object)
{
init(_object.planeNode_);
init( &_object.plane_ );
setName( name() );
}
......@@ -130,19 +130,18 @@ BaseObject* PlaneObject::copy() {
/** This function initalizes the plane object. It creates the scenegraph nodes.
*/
void PlaneObject::init(PlaneNode* _plane) {
void PlaneObject::init(const Plane* _plane) {
if ( materialNode() == NULL)
std::cerr << "Error when creating Plane Object! materialNode is NULL!" << std::endl;
planeNode_ = new PlaneNode( materialNode() , "NEW PlaneNode");
planeNode_ = new PlaneNode( plane_, materialNode() , "NEW PlaneNode" );
if (_plane){
planeNode_->setPosition( _plane->position(), _plane->normal() );
planeNode_->setSize( _plane->xDirection().norm(), _plane->yDirection().norm() );
plane_ = *_plane;
} else {
planeNode_->setPosition( ACG::Vec3f(0.0, 0.0, 0.0), ACG::Vec3f(0.0, 1.0, 0.0) );
planeNode_->setSize( 5.0, 5.0 );
plane_.setPlane( ACG::Vec3f(0.0, 0.0, 0.0), ACG::Vec3f(0.0, 1.0, 0.0) );
plane_.setSize( 5.0, 5.0 );
}
}
......@@ -196,6 +195,19 @@ QString PlaneObject::getObjectinfo() {
return output;
}
// ===============================================================================
// Data
// ===============================================================================
Plane& PlaneObject::plane() {
return plane_;
}
void PlaneObject::plane(Plane _plane) {
plane_ = _plane;
}
// ===============================================================================
// Picking
// ===============================================================================
......
......@@ -94,8 +94,8 @@ class DLLEXPORT PlaneObject : public BaseObjectData {
protected:
/// Initialise current object, including all related nodes.
virtual void init(PlaneNode* _plane = 0);
/// Initialize current object, including all related nodes.
virtual void init(const Plane* _plane = 0);
//===========================================================================
/** @name Name and Path handling
......@@ -105,6 +105,19 @@ class DLLEXPORT PlaneObject : public BaseObjectData {
/// Set the name of the Object
void setName( QString _name );
//===========================================================================
/** @name Data
* @{ */
//===========================================================================
public:
Plane& plane();
void plane(Plane _plane);
private:
Plane plane_;
/** @} */
//===========================================================================
/** @name Visualization
......@@ -114,23 +127,23 @@ class DLLEXPORT PlaneObject : public BaseObjectData {
public:
/// Get the scenegraph Node
PlaneNode* planeNode();
private:
PlaneNode* planeNode_;
/** @} */
/** @} */
//===========================================================================
/** @name Object Information
* @{ */
//===========================================================================
//===========================================================================
public:
/// Get all Info for the Object as a string
QString getObjectinfo();
/** @} */
/** @} */
//===========================================================================
/** @name Picking
* @{ */
......
......@@ -57,12 +57,11 @@
//== INCLUDES =================================================================
#include <ACG/Scenegraph/PlaneNode.hh>
#include <ObjectTypes/Plane/PlaneType.hh>
#include <ObjectTypes/Plane/PlaneNode.hh>
//== TYPEDEFS FOR SCENEGRAPH ===============================================
//== TYPEDEFS FOR SIMPLER ACCESS ==============================================
/// Simple Name for PlaneNode
typedef ACG::SceneGraph::PlaneNode PlaneNode;
//=============================================================================
#endif // PLANE_TYPES_HH defined
......
......@@ -86,6 +86,14 @@ PlaneNode* planeNode( BaseObjectData* _object ) {
}
Plane* plane( BaseObjectData* _object ) {
if ( _object->dataType(DATA_PLANE) ) {
PlaneObject* object = dynamic_cast< PlaneObject* >(_object);
return & object->plane();
} else
return 0;
}
PlaneObject* planeObject( BaseObjectData* _object ) {
if ( ! _object->dataType(DATA_PLANE) )
return 0;
......
......@@ -75,6 +75,14 @@ bool getObject( int _identifier , PlaneObject*& _object );
DLLEXPORT
PlaneNode* planeNode( BaseObjectData* _object );
/** \brief Get a Plane from an object.
*
* @param _object The object should be of type BaseDataObject. If the content is a plane, a
* Plane will be returned. Otherwise a NULL pointer is returned.
*/
DLLEXPORT
Plane* plane( BaseObjectData* _object );
/** \brief Cast an BaseObject to a PlaneObject if possible
*
* @param _object The object should be of type BaseDataObject. If the content is a plane, a
......
......@@ -29,7 +29,7 @@ The following datatypes are available in OpenFlipper:
- \subpage CameraType "Camera"
\image html type_camera_thumb.png
\section datatypes_adding_custom Adding custom datatypes
TODO: How to create a custom datatype
\subpage datatypes_adding_custom
A description on how new data types can be added to OpenFlipper can be found here: \ref datatypes_adding_custom
*/
......@@ -108,7 +108,7 @@ int FilePlaPlugin::loadObject(QString _filename)
yDirection[2] = settings.value("YDirection2").toDouble();
settings.endGroup();
plane->planeNode()->setPosition(position, xDirection, yDirection);
plane->plane().setPlane(position, xDirection, yDirection);
plane->setFromFileName(_filename);
}
......
......@@ -501,7 +501,7 @@ void MovePlugin::moveObject(ACG::Matrix4x4d mat, int _id) {
transformSkeleton(mat , *PluginFunctions::skeleton(object) );
#endif
} else if ( object->dataType() == DATA_PLANE ) {
PluginFunctions::planeNode(object)->transform(mat);
PluginFunctions::plane(object)->transform(mat);
} else {
emit log(LOGERR,tr("moveObject called for unsupported Object Type"));
......
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