Commit ddefb27a authored by Jan Möbius's avatar Jan Möbius

Separated Camera Object Type

parents
include(ACGCommon)
include_directories (
..
${ACG_INCLUDE_DIR}
${OPENMESH_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${GLUT_INCLUDE_DIR}
)
link_directories (
${GLEW_LIBRARY_DIR}
${ADDITIONAL_PLUGINLIB_LINK_DIRS}
)
#=======================================================
# General defines
#=======================================================
# generate dllexport macros on windows
if (WIN32)
add_definitions (
-DPLUGINLIBDLL
-DUSEPLUGINLIBDLL
-DBUILDOBJECTTYPEDLL
-DACGDLL
-DUSEACG
)
endif ()
#=======================================================
# Cleanup
#=======================================================
# collect all header,source files
acg_append_files (headers "*.hh" . )
acg_append_files (sources "*.cc" . )
acg_qt5_automoc (moc_targets ${headers})
# Match our current directory name
string (REGEX MATCH "[^/\\]*$" TYPENAME ${CMAKE_CURRENT_SOURCE_DIR})
string(TOUPPER ${TYPENAME} TYPENAME )
include_directories (
..
${ACG_INCLUDE_DIR}
${OPENMESH_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../..
${CMAKE_CURRENT_BINARY_DIR}
${OPENGL_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${GLUT_INCLUDE_DIR}
)
# remove template cc files from source file list
acg_drop_templates (sources)
acg_add_library ( ${TYPENAME} SHARED ${sources} ${headers} ${moc_targets})
add_dependencies( ${TYPENAME} OpenMeshCore OpenMeshTools ACG OpenFlipperPluginLib)
target_link_libraries (${TYPENAME}
${OPENMESH_LIBRARIES}
ACG
${QT_LIBRARIES}
${OPENGL_LIBRARIES}
${GLEW_LIBRARY}
${GLUT_LIBRARIES}
OpenFlipperPluginLib
)
/* ========================================================================= *
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
/*===========================================================================*\
*
* $Revision$
* $Date$
*
\*===========================================================================*/
/**
* \file Camera.hh
* This File contains all required includes for using Cameras
*/
#ifndef CAMERA_INCLUDE_HH
#define CAMERA_INCLUDE_HH
//== INCLUDES =================================================================
/** \def DATA_CAMERA
* Use this macro to reference cameras
*/
#define DATA_CAMERA typeId("Camera")
#include <ObjectTypes/Camera/CameraObject.hh>
#include <ObjectTypes/Camera/PluginFunctionsCamera.hh>
#include <ObjectTypes/Camera/CameraTypes.hh>
//=============================================================================
#endif // CAMERA_INCLUDE_HH defined
//=============================================================================
This diff is collapsed.
/* ========================================================================= *
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
/*===========================================================================*\
*
* $Revision$
* $Date$
*
\*===========================================================================*/
//=============================================================================
//
// CLASS CameraNode
//
//=============================================================================
#ifndef ACG_CAMERAVIS_NODE_HH
#define ACG_CAMERAVIS_NODE_HH
//== INCLUDES =================================================================
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/GL/GLPrimitives.hh>
#include <ACG/GL/globjects.hh>
#include <string>
#include <vector>
#include <ACG/Math/QuaternionT.hh>
#include <OpenFlipper/common/ObjectTypeDLLDefines.hh>
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== CLASS DEFINITION =========================================================
/** \class CameraNode CameraNode.hh <ACG/Scenegraph/CameraNode.hh>
This class is able to render spheres colorcoding the vertex CameraVis
**/
class OBJECTTYPEDLLEXPORT CameraNode: public BaseNode {
public:
/// Default constructor.
CameraNode( BaseNode* _parent = 0, std::string _name = "<CameraVis>");
/// Destructor
virtual ~CameraNode();
ACG_CLASSNAME( CameraNode);
/// return available draw modes
DrawModes::DrawMode availableDrawModes() const;
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
/// drawing
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// create render objects
void getRenderObjects(IRenderer* _renderer, GLState& _state, const DrawModes::DrawMode& _drawMode, const Material* _mat);
/// picking
void pick(GLState& _state, PickTarget _target);
/// set model view matrix
void setModelView(ACG::GLMatrixd _modelView) { modelView_ = _modelView; modelViewInv_ = _modelView; modelViewInv_.invert(); update_vbo_ = true; }
/// Returns the modelview matrix
const ACG::GLMatrixd& modelview() const {return modelView_;}
/// Set projection Matrix ( used to calculate frustum ... )
void setProjection(ACG::GLMatrixd _projection) { projection_ = _projection; update_vbo_ = true; }
/// Returns the projection matrix
const ACG::GLMatrixd& projection() const {return projection_;}
/// Set viewport size ( This will be used to compute the aspect ratio )
DEPRECATED("setSize() is redundant, because it is already defined by the projection matrix.")
void setSize(int _w, int _h) { /*obsolete*/ }
/// Return encoded view string
void setEncodedView(QString _encodedView) { encodedView_ = _encodedView; }
/// Set distance to far plane ( e.g. scene radius )
DEPRECATED("setFarPlane() is redundant, because it is already defined by the projection matrix.")
void setFarPlane(double _far) { /*obsolete*/ }
/// Set distance to near plane
DEPRECATED("setNearPlane() is redundant, because it is already defined by the projection matrix.")
void setNearPlane(double _near) { /*obsolete*/ }
/// Return encoded view string
QString getEncodedView() { return encodedView_; }
/// Set if viewing frustum should be shown or not
void showFrustum(bool _showFrustum) { showFrustum_ = _showFrustum; }
/// Returns true if camera renders its whole frustum
bool showFrustum() { return showFrustum_; }
private:
void updateVBO();
void updateBoundingBoxes();
// recalculate frustum positions in world space
void updateFrustumWS();
OpenMesh::Vec3d bbmin_;
OpenMesh::Vec3d bbmax_;
ACG::GLMatrixd modelView_;
ACG::GLMatrixd modelViewInv_;
ACG::GLMatrixd projection_;
GLCylinder* cylinder_;
GLCone* cone_;
float axis_length_;
GeometryBuffer vbo_;
IndexBuffer ibo_;
VertexDeclaration vdecl_;
bool update_vbo_;
std::vector<Vec4f> vboData_; // 8 frustum vertices + camera position
int offsetTris_; // offsets into index buffer
int offsetLines_;
int offsetFront_;
QString encodedView_;
bool showFrustum_;
};
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
#endif // ACG_CameraVis_NODE_HH
//=============================================================================
/* ========================================================================= *
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
/*===========================================================================*\
*
* $Revision$
* $Date$
*
\*===========================================================================*/
//=============================================================================
//
// MyTypes
//
//=============================================================================
#define CAMERAOBJECT_C
//== INCLUDES =================================================================
#include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/Camera/Camera.hh>
//== DEFINES ==================================================================
//== TYPEDEFS =================================================================
//== CLASS DEFINITION =========================================================
/** Constructor for Camera Objects. This object class gets a Separator Node giving
* the root node to which it should be connected. The camera is generated internally
* and all nodes for visualization will be added below the scenegraph node.\n
* You dont need to create an object of this type manually. Use
* PluginFunctions::addCamera instead. ( see Types.hh::DataType )
*/
CameraObject::CameraObject( ) :
BaseObjectData( ),
cameraNode_(NULL)
{
setDataType(DATA_CAMERA);
init();
}
//=============================================================================
/**
* Copy Constructor - generates a copy of the given object
*/
CameraObject::CameraObject(const CameraObject & _object) :
BaseObjectData(_object)
{
init(_object.cameraNode_);
setName( name() );
}
/** Destructor for Camera Objects. The destructor deletes the Line and all
* Scenegraph nodes associated with the Camera or the object.
*/
CameraObject::~CameraObject()
{
// Delete the data attached to this object ( this will remove all perObject data)
// Not the best way to do it but it will work.
// This is only necessary if people use references to the camera below and
// they do something with the camera in the destructor of their
// perObjectData.
deleteData();
// No need to delete the scenegraph Nodes as this will be managed by baseplugin
cameraNode_ = NULL;
}
/** Cleanup Function for Camera Objects. Deletes the contents of the whole object and
* calls CameraObject::init afterwards.
*/
void CameraObject::cleanup() {
BaseObjectData::cleanup();
cameraNode_ = NULL;
setDataType(DATA_CAMERA);
init();
}
/**
* Generate a copy
*/
BaseObject* CameraObject::copy() {
CameraObject* object = new CameraObject(*this);
return dynamic_cast< BaseObject* >(object);
}
/** This function initalizes the camera object. It creates the scenegraph nodes.
*/
void CameraObject::init(CameraNode* _camera) {
if ( materialNode() == NULL)
std::cerr << "Error when creating Camera Object! materialNode is NULL!" << std::endl;
cameraNode_ = new CameraNode( materialNode() , "NEW CameraNode");
// TODO: Set initial position
// if (_camera){
// cameraNode_->setPosition( _camera->position(), _camera->normal() );
// cameraNode_->setSize( _camera->xDirection().norm(), _camera->yDirection().norm() );
// } else {
// cameraNode_->setPosition( ACG::Vec3f(0.0, 0.0, 0.0), ACG::Vec3f(0.0, 1.0, 0.0) );
// cameraNode_->setSize( 5.0, 5.0 );
// }
}
// ===============================================================================
// Name/Path Handling
// ===============================================================================
/** Set the name of an object. All Scenegraph nodes are renamed too. It also calls
* BaseObjectData::setName.
*/
void CameraObject::setName( QString _name ) {
BaseObjectData::setName(_name);
std::string nodename = std::string("CameraNode for Camera " + _name.toUtf8() );
cameraNode_->name( nodename );
}
// ===============================================================================
// Visualization
// ===============================================================================
CameraNode* CameraObject::cameraNode() {
return cameraNode_;
}
// ===============================================================================
// Object information
// ===============================================================================
/** Returns a string containing all information about the current object. This also
* includes the information provided by BaseObjectData::getObjectinfo
*
* @return String containing the object information
*/
QString CameraObject::getObjectinfo() {
QString output;
output += "========================================================================\n";
output += BaseObjectData::getObjectinfo();
if ( dataType( DATA_CAMERA ) )
output += "Object Contains Camera : ";
// TODO: Write correct data
// ACG::Vec3f pos = cameraNode_->position();
// ACG::Vec3f nor = cameraNode_->normal();
//
// output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
// output += " Normal ( " + QString::number(nor[0]) + ", " + QString::number(nor[1]) + ", " + QString::number(nor[2]) + ")";
output += "========================================================================\n";
return output;
}
// ===============================================================================
// Picking
// ===============================================================================
/** Given an node index from PluginFunctions::scenegraphPick this function can be used to
* check if the cameraNode of the object has been picked.
*
* @param _node_idx Index of the picked camera node
* @return bool if the cameraNode of this object is the picking target.
*/
bool CameraObject::picked( uint _node_idx ) {
return ( _node_idx == cameraNode_->id() );
}
void CameraObject::enablePicking( bool _enable ) {
cameraNode_->enablePicking( _enable );
}
bool CameraObject::pickingEnabled() {
return cameraNode_->pickingEnabled();
}
// ===============================================================================
// Update
// ===============================================================================
void CameraObject::update(UpdateType _type) {
BaseObject::update(_type);
}
//=============================================================================
/* ========================================================================= *
* *
* OpenFlipper *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openflipper.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenFlipper. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
/*===========================================================================*\
*
* $Revision$
* $Date$
*
\*===========================================================================*/