H3D API  2.4.1
PlaneSensor.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 __PLANESENSOR_H__
30 #define __PLANESENSOR_H__
31 
32 #include <H3D/X3DDragSensorNode.h>
33 #include <H3D/SFVec2f.h>
34 #include <H3D/SFRotation.h>
35 
36 namespace H3D {
37 
106  // NOTE: If the scenegraph is changed while isActive is true for a
107  // planeSensor the planeSensor might not be working correctly anymore.
108  class H3DAPI_API PlaneSensor :
109  public X3DDragSensorNode {
110  public:
111 
115  class H3DAPI_API SFOffset :
116  public OnValueChangeSField< AutoUpdate< SFVec3f > > {
117  public:
118  protected:
119  virtual void onValueChange( const Vec3f &/*_new_value*/ ) {
120  PlaneSensor * ps = static_cast< PlaneSensor * >(getOwner());
121  ps->last_offset_axis_rotation_inv =
122  Matrix4f( ps->axisRotation->getValue() ).inverse();
123  }
124  };
125 
127  PlaneSensor( Inst< SFBool > _autoOffset = 0,
128  Inst< SFString > _description = 0,
129  Inst< SFBool > _enabled = 0,
130  Inst< SFVec2f > _maxPosition = 0,
131  Inst< SFNode > _metadata = 0,
132  Inst< SFVec2f > _minPosition = 0,
133  Inst< SFOffset > _offset = 0,
134  Inst< SFBool > _isActive = 0,
135  Inst< SFBool > _isOver = 0,
136  Inst< SFVec3f > _trackPoint_changed = 0,
137  Inst< SFVec3f > _translation_changed = 0,
138  Inst< SFRotation > _axisRotation = 0 );
139 
140  // fields
148  H3DUniquePtr< SFVec2f > maxPosition;
149 
157  H3DUniquePtr< SFVec2f > minPosition;
158 
167  H3DUniquePtr< SFOffset > offset;
168 
177  H3DUniquePtr< SFVec3f > translation_changed;
178 
186  H3DUniquePtr< SFRotation > axisRotation;
187 
190 
191  protected:
192  // Virtual function that should check the isActive field and if it
193  // is true then update specific fields. If isActive field is false then
194  // reset state of internal variables. Do not call enabled->getValue() in
195  // this function.
196  // _enabled - Should be treated as enabled->getValue().
197  // from - The start of the line segment for which to intersect with.
198  // to - The end of the line segment for which to intersect with.
199  virtual void setDragOutputEvents( bool _enabled,
200  const Vec3f &from,
201  const Vec3f &to );
202 
203  // Called to generate isOver events and other events which dependens on
204  // isOver.
205  virtual void onIsOver( NodeIntersectResult *result = 0, unsigned int closest_index = 0,
206  Matrix4f *global_to_local = 0 );
207 
208  // Stores points of intersection with any of the geometry which causes this
209  // sensor to generate isOver events.
210  Vec3f geometry_intersection;
211 
212  // Stores global_to_local matrix of the geometry which causes this
213  // sensor to generate isOver events.
214  Matrix4f geometry_global_to_local;
215 
216  // intersection between the segment from a to b and the plane defined
217  // by planeD and planeNormal (see below). Results are stored in
218  // t and q.
219  int intersectLinePlane( Vec3f a, Vec3f b, float &t, Vec3f &q );
220 
221  // Last intersection point with the cylinder. Only used when sensor is
222  // active.
223  Vec3f last_intersection;
224 
225  // Normal of the plane to intersect with.
226  Vec3f plane_normal;
227  // A number used for plane equation and intersections.
228  H3DFloat plane_d;
229  // The transformation from global to local of the geometry for which this
230  // sensor is active. It will not change while sensor is active.
231  Matrix4f active_global_to_local_matrix;
232  // If true a new plane will be defined.
233  bool new_plane;
234  // The last rotation used when offset was set.
235  Matrix4f last_offset_axis_rotation_inv;
236  };
237 }
238 
239 #endif
Contains the SFRotation field class.
Contains the SFVec2f field class.
Header file for X3DDragSensorNode, X3D scene-graph node.
Template for adding the virtual function onValueChange that can be overridden in subclasses in order ...
Definition: FieldTemplates.h:49
Class used to store some information about axisRotation when offset is set, in order to set the corre...
Definition: PlaneSensor.h:116
The PlaneSensor node maps pointing device motion into two-dimensional translation in a plane parallel...
Definition: PlaneSensor.h:109
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: PlaneSensor.h:189
H3DUniquePtr< SFOffset > offset
Stores the last translation_changed value at deactivation if autoOffset is true.
Definition: PlaneSensor.h:167
H3DUniquePtr< SFVec2f > minPosition
minPosition can be used to clamp translation_changed events
Definition: PlaneSensor.h:157
H3DUniquePtr< SFVec2f > maxPosition
maxPosition can be used to clamp translation_changed events.
Definition: PlaneSensor.h:148
H3DUniquePtr< SFRotation > axisRotation
The local sensor coordinate system is created by applying the axisRotation field value to the local c...
Definition: PlaneSensor.h:186
H3DUniquePtr< SFVec3f > translation_changed
For each subsequent movement of the bearing, a translation_changed event is output which corresponds ...
Definition: PlaneSensor.h:177
This abstract node type is the base type for all drag-style pointing device sensors.
Definition: X3DDragSensorNode.h:42
float H3DFloat
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194
Used as input to intersection functions.
Definition: Node.h:114