Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SkyDomeObject.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5 * www.openflipper.org *
6 * *
7 *--------------------------------------------------------------------------- *
8 * This file is part of OpenFlipper. *
9 * *
10 * OpenFlipper is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenFlipper is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenFlipper. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36 * *
37 * $Revision: 10745 $ *
38 * $LastChangedBy: moebius $ *
39 * $Date: 2011-01-26 10:23:50 +0100 (Mi, 26. Jan 2011) $ *
40 * *
41 \*===========================================================================*/
42 
43 //=============================================================================
44 //
45 // SkyDome Object
46 //
47 //=============================================================================
48 
49 //== INCLUDES =================================================================
50 
52 #include "SkyDomeObject.hh"
53 #include "SkyDome.hh"
54 
55 //== DEFINES ==================================================================
56 
57 //== TYPEDEFS =================================================================
58 
59 //== CLASS DEFINITION =========================================================
60 
68  BaseObjectData( ),
69  skyDomeNode_(NULL)
70 {
72  init();
73 }
74 
75 //=============================================================================
76 
77 
82  BaseObjectData(_object)
83 {
84 
85  init( &_object.skyDome_ );
86 
87  setName( name() );
88 }
89 
94 {
95  // Delete the data attached to this object ( this will remove all perObject data)
96  // Not the best way to do it but it will work.
97  // This is only necessary if people use references to the plane below and
98  // they do something with the plane in the destructor of their
99  // perObjectData.
100  deleteData();
101 
102  // No need to delete the scenegraph Nodes as this will be managed by base plugin
103  skyDomeNode_ = NULL;
104 }
105 
110 
112 
113  skyDomeNode_ = NULL;
114 
116 
117  init();
118 
119 }
120 
125  SkyDomeObject* object = new SkyDomeObject(*this);
126  return dynamic_cast< BaseObject* >(object);
127 }
128 
131 void SkyDomeObject::init( SkyDome* _skyDome) {
132 
133  if ( materialNode() == NULL)
134  std::cerr << "Error when creating SkyDome Object! materialNode is NULL!" << std::endl;
135 
136  skyDomeNode_ = new SkyDomeNode( skyDome_, materialNode() , "NEW SkyDomeNode" );
137 
138  if (_skyDome){
139  skyDome_ = *_skyDome;
140  } else {
141  // Leave at default values
142  }
143 
144 }
145 
146 // ===============================================================================
147 // Name/Path Handling
148 // ===============================================================================
149 
153 void SkyDomeObject::setName( QString _name ) {
155 
156  std::string nodename = std::string("SkyDomeNode for SkyDome " + _name.toUtf8() );
157  skyDomeNode_->name( nodename );
158 }
159 
160 // ===============================================================================
161 // Data
162 // ===============================================================================
163 
165 
166  // Only the texture update is relevant. The other updates
167  // Are uniforms which are required on each draw anyway
168  if (_type.contains(UPDATE_TEXTURE) )
169  skyDomeNode_->update();
170 }
171 
172 // ===============================================================================
173 // Visualization
174 // ===============================================================================
175 
177  return skyDomeNode_;
178 }
179 
180 // ===============================================================================
181 // Object information
182 // ===============================================================================
183 
190  QString output;
191 
192  output += "========================================================================\n";
193  output += BaseObjectData::getObjectinfo();
194 
195  if ( dataType( DATA_SKYDOME ) )
196  output += "Object Contains SkyDome : ";
197 
198  output += " Horizontal FOV: " + QString::number(skyDome_.horizontalFOV());
199  output += " Vertical FOV: " + QString::number(skyDome_.verticalFOV());
200  output += " Top Cutoff : " + QString::number(skyDome_.topOffset());
201  output += " Image File : " + skyDome_.textureFileName();
202 
203  output += "========================================================================\n";
204  return output;
205 }
206 
208  return skyDome_;
209 }
210 
211 
212 
213 // ===============================================================================
214 // Picking
215 // ===============================================================================
216 
223 bool SkyDomeObject::picked( uint _node_idx ) {
224  return ( _node_idx == skyDomeNode_->id() );
225 }
226 
227 //
228 //void SkyDomeObject::enablePicking( bool _enable ) {
229 // SkyDomeNode_->enablePicking( _enable );
230 //}
231 //
232 //bool SkyDomeObject::pickingEnabled() {
233 // return SkyDomeNode_->pickingEnabled();
234 //}
235 
236 //=============================================================================
237 
virtual void init(SkyDome *_SkyDome=0)
Initialize current object, including all related nodes.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
void deleteData()
Delete all data attached to this object ( calls delete on each object )
Definition: BaseObject.cc:823
void update(UpdateType _type=UPDATE_ALL)
Update buffers and data of the scenegraph node.
unsigned int id() const
Definition: BaseNode.hh:454
QString textureFileName()
Returns the texture that will be used.
Definition: SkyDomeType.cc:75
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:446
virtual void cleanup()
BaseObject * copy()
Update type class.
Definition: UpdateType.hh:70
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
Definition: UpdateType.cc:111
virtual void cleanup()
Reset current object, including all related nodes.
MaterialNode * materialNode()
get a pointer to the materialnode
DataType dataType() const
Definition: BaseObject.cc:240
SkyDomeNode * skyDomeNode_
Get the scenegraph Node.
bool picked(uint _node_idx)
detect if the node has been picked
SkyDomeObject()
constructor
void setDataType(DataType _type)
Definition: BaseObject.cc:244
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void update()
Definition: SkyDomeNode.hh:110
SkyDome skyDome_
Get all Info for the Object as a string.
QString getObjectinfo()
Get all Info for the Object as a string.
const UpdateType UPDATE_TEXTURE(UpdateTypeSet(1)<< 11)
Textures have changed.
SkyDome & getSkyDome()
Get all Info for the Object as a string.
SkyDomeNode * skyDomeNode()
Get the scenegraph Node.
void setName(QString _name)
Set the name of the Object.
#define DATA_SKYDOME
Definition: SkyDome.hh:56
virtual ~SkyDomeObject()
destructor