H3D API  2.4.1
ProximitySensor.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __PROXIMITYSENSOR_H__
30 #define __PROXIMITYSENSOR_H__
31 
33 #include <H3D/SFVec3f.h>
34 #include <H3D/SFRotation.h>
35 #include <H3D/X3DViewpointNode.h>
36 #include <H3D/NavigationInfo.h>
37 
38 
39 
40 namespace H3D {
41 
121 
122  class H3DAPI_API ProximitySensor : public X3DEnvironmentalSensorNode {
123  public:
124 
125 
129  class H3DAPI_API SetTime: public AutoUpdate< SFBool > {
130  public:
131  // Sets either the exitTime or enterTime field depending
132  // on the new value.
133  virtual void setValue( const bool &b, int _id = 0 ) {
134  SFBool::setValue( b , _id );
135  ProximitySensor *ps =
136  static_cast< ProximitySensor * >( getOwner() );
137  if( value )
138  ps->enterTime->setValue( TimeStamp() , ps->id );
139  else
140  ps->exitTime->setValue( TimeStamp() , ps->id );
141  }
142  protected:
143  // Sets either the exitTime or enterTime field depending
144  // on the new value.
145  virtual void update() {
146  SFBool::update();
147  ProximitySensor *ps =
148  static_cast< ProximitySensor * >( getOwner() );
149  if( value )
150  ps->enterTime->setValue( TimeStamp() , ps->id );
151  else
152  ps->exitTime->setValue( TimeStamp(), ps->id );
153  }
154  };
155 
157  ProximitySensor( Inst< SFNode > _metadata = 0,
158  Inst< SFVec3f > _center = 0,
159  Inst< SFBool > _enabled = 0,
160  Inst< SFVec3f > _size = 0,
161  Inst< SFTime > _enterTime = 0,
162  Inst< SFTime > _exitTime = 0,
163  Inst< SFBool > _isActive = 0,
164  Inst< SFVec3f > _centerOfRotation_changed = 0,
165  Inst< SFRotation > _orientation_changed = 0,
166  Inst< SFVec3f > _position_changed = 0);
167 
168 
170  virtual void traverseSG( TraverseInfo &ti );
171 
172 
173  // Fields
174 
183  H3DUniquePtr< SFVec3f > centerOfRotation_changed;
184 
193  H3DUniquePtr< SFRotation > orientation_changed;
194 
203  H3DUniquePtr< SFVec3f > position_changed;
204 
205 
211  H3DUniquePtr< SetTime > set_time;
212 
216 
217 
218  // Internal Vectors for previous position of viewpoint
219  Vec3f prev_vp_pos;
220  Vec3f can_prev_vp_pos;
221 
222 
225  };
226 }
227 
228 #endif
Header file for NavigationInfo, X3D scene-graph node.
Contains the SFRotation field class.
Contains the SFVec3f field class.
Header file for X3DEnvironmentalSensorNode, X3D scene-graph node.
Header file for X3DViewpointNode, X3D scene-graph node.
The SetBoolean class is specialize to set the value of either the enterTime or exitTime field in the ...
Definition: ProximitySensor.h:129
virtual void update()
Make the field up to date given that an event has occured.
Definition: ProximitySensor.h:145
The ProximitySensor node generates events when the viewer enters, exits, and moves within a region in...
Definition: ProximitySensor.h:122
H3DUniquePtr< SFRotation > orientation_changed
The orientation_changed fields send events whenever the user is contained within the proximity region...
Definition: ProximitySensor.h:193
TraverseInfo * prev_travinfoadr
Adress of traverseInfo only interested in adress, what it points to will be invalid.
Definition: ProximitySensor.h:215
H3DUniquePtr< SetTime > set_time
Sets enterTime if the set_boolean value is set to TRUE else sets exitTime.
Definition: ProximitySensor.h:211
H3DUniquePtr< SFVec3f > position_changed
The position_changed fields send events whenever the user is contained within the proximity region an...
Definition: ProximitySensor.h:203
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: ProximitySensor.h:224
H3DUniquePtr< SFVec3f > centerOfRotation_changed
The centerOfRotation_changed field sends events whenever the user is contained within the proximity r...
Definition: ProximitySensor.h:183
virtual void setValue(const bool &v, int id=0)
Set the value of the field.
Definition: SField.h:215
virtual void update()
Make the field up to date given that an event has occured.
Definition: SField.h:181
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
This abstract node type is the base type for all sensors.
Definition: X3DEnvironmentalSensorNode.h:43
H3DUniquePtr< SFTime > enterTime
enterTime
Definition: X3DEnvironmentalSensorNode.h:74
H3DUniquePtr< SFTime > exitTime
exitTime
Definition: X3DEnvironmentalSensorNode.h:80
H3D API namespace.
Definition: Anchor.h:38
The AutoUpdate field is a template to force the BaseField to update itself as soon as an event is rec...
Definition: FieldTemplates.h:130
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194