Commit 26254f9f authored by Jan Möbius's avatar Jan Möbius
Browse files

Added Spher Object Type

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9065 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 7e45cb4a
......@@ -222,6 +222,10 @@ void LightObject::visible(bool _visible) {
hide();
}
bool LightObject::visible() {
return visible_;
}
LightSource* LightObject::lightSource() {
return &lightSource_;
}
......
......@@ -137,6 +137,9 @@ class DLLEXPORT LightObject : public BaseObjectData {
/// Show Light Node
virtual void visible(bool _visible);
/// Show Light Node
virtual bool visible();
/// Show Light Node
virtual void show();
......
......@@ -28,7 +28,6 @@ PlaneObject::PlaneObject( ) :
planeNode_(NULL)
{
setDataType(DATA_PLANE);
setTypeIcon(DATA_PLANE,"PlaneType.png");
init();
}
......
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// 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.
//
// 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 Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 1720 $
// $Author: moebius $
// $Date: 2008-05-09 14:15:53 +0200 (Fri, 09 May 2008) $
//
//=============================================================================
//=============================================================================
//
// Plugin Functions for Spheres
//
//=============================================================================
#include <OpenFlipper/common/Types.hh>
#include "Sphere.hh"
#include "PluginFunctionsSphere.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
namespace PluginFunctions {
// ===============================================================================
// Get objects
// ===============================================================================
bool getObject( int _identifier , SphereObject*& _object ) {
if ( _identifier == -1 ) {
_object = 0;
return false;
}
BaseObject* object = objectRoot()->childExists( _identifier );
_object = dynamic_cast< SphereObject* >(object);
return ( _object != 0 );
}
// ===============================================================================
// Getting data from objects and casting between them
// ===============================================================================
SphereNode* sphereNode( BaseObjectData* _object ) {
if ( _object->dataType(DATA_SPHERE) ) {
SphereObject* object = dynamic_cast< SphereObject* >(_object);
return object->sphereNode();
} else
return 0;
}
SphereObject* sphereObject( BaseObjectData* _object ) {
if ( ! _object->dataType(DATA_SPHERE) )
return 0;
return dynamic_cast< SphereObject* >( _object );
}
}
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// 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.
//
// 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 Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 1720 $
// $Author: moebius $
// $Date: 2008-05-09 14:15:53 +0200 (Fri, 09 May 2008) $
//
//=============================================================================
//=============================================================================
//
// Standard Functions
//
//=============================================================================
/**
* \file PluginFunctionsSphere.hh
* This file contains functions which can be used by plugins to access spheres in the framework.
*/
//
#ifndef PLUGINFUNCTIONSSPHERE_HH
#define PLUGINFUNCTIONSSPHERE_HH
#include <OpenFlipper/common/Types.hh>
/** The Namespace PluginFunctions contains functions for all plugins. */
namespace PluginFunctions {
/** This functions returns the object with the given id if it is a SphereObject.
* See get_object( int _identifier , BaseObject*& _object ) for more details.
*/
DLLEXPORT
bool getObject( int _identifier , SphereObject*& _object );
/** \brief Get a SphereNode from an object.
*
* @param _object The object should be of type BaseDataObject. If the content is a sphere, a
* SphereNode will be returned. Otherwise a NULL pointer is returned.
*/
DLLEXPORT
SphereNode* sphereNode( BaseObjectData* _object );
/** \brief Cast an BaseObject to a SphereObject if possible
*
* @param _object The object should be of type BaseDataObject. If the content is a sphere, a
* a SphereObject is returned. Otherwise a NULL pointer is returned.
*/
DLLEXPORT
SphereObject* sphereObject( BaseObjectData* _object );
}
#endif // PLUGINFUNCTIONSSPHERE_HH
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// 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.
//
// 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 Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 6281 $
// $Author: moebius $
// $Date: 2009-06-03 13:04:29 +0200 (Wed, 03 Jun 2009) $
//
//=============================================================================
/**
* \file Sphere.hh
* This File contains all required includes for using Spheres
*/
#ifndef SPHERE_INCLUDE_HH
#define SPHERE_INCLUDE_HH
//== INCLUDES =================================================================
#define DATA_SPHERE typeId("Sphere")
#include <ObjectTypes/Sphere/SphereObject.hh>
#include <ObjectTypes/Sphere/PluginFunctionsSphere.hh>
#include <ObjectTypes/Sphere/SphereTypes.hh>
//=============================================================================
#endif // SPHERE_INCLUDE_HH defined
//=============================================================================
//=============================================================================
//
// MyTypes
//
//=============================================================================
#define SPHEREOBJECT_C
//== INCLUDES =================================================================
#include <OpenFlipper/common/Types.hh>
#include "Sphere.hh"
//== DEFINES ==================================================================
//== TYPEDEFS =================================================================
//== CLASS DEFINITION =========================================================
/** Constructor for Sphere Objects. This object class gets a Separator Node giving
* the root node to which it should be connected. The plane 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::addSphere instead. ( see Types.hh::DataType )
*/
SphereObject::SphereObject( ) :
BaseObjectData( ),
sphereNode_(NULL)
{
setDataType(DATA_SPHERE);
init();
}
//=============================================================================
/**
* Copy Constructor - generates a copy of the given object
*/
SphereObject::SphereObject(const SphereObject & _object) :
BaseObjectData(_object)
{
init(_object.sphereNode_);
setName( name() );
}
/** Destructor for Sphere Objects. The destructor deletes the Line and all
* Scenegraph nodes associated with the Sphere or the object.
*/
SphereObject::~SphereObject()
{
// 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 plane below and
// they do something with the plane in the destructor of their
// perObjectData.
deleteData();
// No need to delete the scenegraph Nodes as this will be managed by baseplugin
sphereNode_ = NULL;
}
/** Cleanup Function for Sphere Objects. Deletes the contents of the whole object and
* calls SphereObject::init afterwards.
*/
void SphereObject::cleanup() {
BaseObjectData::cleanup();
sphereNode_ = NULL;
setDataType(DATA_SPHERE);
init();
}
/**
* Generate a copy
*/
BaseObject* SphereObject::copy() {
SphereObject* object = new SphereObject(*this);
return dynamic_cast< BaseObject* >(object);
}
/** This function initalizes the plane object. It creates the scenegraph nodes.
*/
void SphereObject::init(SphereNode* _sphere) {
if ( materialNode() == NULL)
std::cerr << "Error when creating Sphere Object! materialNode is NULL!" << std::endl;
sphereNode_ = new SphereNode( SphereNode::SPHERE, materialNode() , "NEW SphereNode");
if (_sphere){
sphereNode_->get_primitive(0).position = _sphere->get_primitive(0).position;
sphereNode_->get_primitive(0).color = _sphere->get_primitive(0).color;
sphereNode_->get_primitive(0).size = _sphere->get_primitive(0).size;
sphereNode_->get_primitive(0).slices = _sphere->get_primitive(0).slices;
sphereNode_->get_primitive(0).stacks = _sphere->get_primitive(0).stacks;
} else {
sphereNode_->get_primitive(0).position = ACG::Vec3f(0.0, 0.0, 0.0);
sphereNode_->get_primitive(0).size = 1.0;
sphereNode_->get_primitive(0).slices = 40;
sphereNode_->get_primitive(0).stacks = 40;
sphereNode_->get_primitive(0).color = ACG::Vec4f(0.5, 0.5, 0.5, 1.0);
}
}
// ===============================================================================
// Name/Path Handling
// ===============================================================================
/** Set the name of an object. All Scenegraph nodes are renamed too. It also calls
* BaseObjectData::setName.
*/
void SphereObject::setName( QString _name ) {
BaseObjectData::setName(_name);
std::string nodename = std::string("SphereNode for Sphere " + _name.toUtf8() );
sphereNode_->name( nodename );
}
// ===============================================================================
// Visualization
// ===============================================================================
SphereNode* SphereObject::sphereNode() {
return sphereNode_;
}
// ===============================================================================
// 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 SphereObject::getObjectinfo() {
QString output;
output += "========================================================================\n";
output += BaseObjectData::getObjectinfo();
if ( dataType( DATA_SPHERE ) )
output += "Object Contains Sphere : ";
ACG::Vec3d pos = sphereNode_->get_primitive(0).position;
double size = sphereNode_->get_primitive(0).size;
output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
output += " Size ( " + QString::number(size) + ")";
output += "========================================================================\n";
return output;
}
// ===============================================================================
// Picking
// ===============================================================================
/** Given an node index from PluginFunctions::scenegraphPick this function can be used to
* check if the planeNode of the object has been picked.
*
* @param _node_idx Index of the picked plane node
* @return bool if the planeNode of this object is the picking target.
*/
bool SphereObject::picked( uint _node_idx ) {
return ( _node_idx == sphereNode_->id() );
}
void SphereObject::enablePicking( bool _enable ) {
sphereNode_->enablePicking( _enable );
}
bool SphereObject::pickingEnabled() {
return sphereNode_->pickingEnabled();
}
//=============================================================================
//=============================================================================
//
// PlaneTypes
//
//=============================================================================
/**
* \file SphereTypes.hh
* This File contains the required types and typedefs for using Spheres
*/
#ifndef SPHERE_TYPES_HH
#define SPHERE_TYPES_HH
//== INCLUDES =================================================================
#include <ACG/Scenegraph/GlutPrimitiveNode.hh>
//== TYPEDEFS FOR SCENEGRAPH ===============================================
/// Simple Name for PlaneNode
typedef ACG::SceneGraph::GlutPrimitiveNode SphereNode;
//=============================================================================
#endif // SPHERE_TYPES_HH defined
//=============================================================================
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