H3D API  2.4.1
SphereSensor.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 __SPHERESENSOR_H__
30 #define __SPHERESENSOR_H__
31 
32 #include <H3D/X3DDragSensorNode.h>
33 #include <H3D/SFRotation.h>
34 #include <H3D/SFVec2f.h>
35 
36 namespace H3D {
37 
93  class H3DAPI_API SphereSensor :
94  public X3DDragSensorNode {
95  public:
96 
98  SphereSensor( Inst< SFBool > _autoOffset = 0,
99  Inst< SFString > _description = 0,
100  Inst< SFBool > _enabled = 0,
101  Inst< SFNode > _metadata = 0,
102  Inst< SFRotation > _offset = 0,
103  Inst< SFBool > _isActive = 0,
104  Inst< SFBool > _isOver = 0,
105  Inst< SFRotation > _rotation_changed = 0,
106  Inst< SFVec3f > _trackPoint_changed = 0 );
107 
108  // fields
116  H3DUniquePtr< SFRotation > offset;
117 
118 
126  H3DUniquePtr< SFRotation > rotation_changed;
127 
130 
131  protected:
132 
133  // Virtual function that should check the isActive field and if it
134  // is true then update specific fields. If isActive field is false then
135  // reset state of internal variables. Do not call enabled->getValue() in
136  // this function.
137  // _enabled - Should be treated as enabled->getValue().
138  // from - The start of the line segment for which to intersect with.
139  // to - The end of the line segment for which to intersect with.
140  virtual void setDragOutputEvents( bool _enabled,
141  const Vec3f &from,
142  const Vec3f &to );
143 
144  // Called to generate isOver events and other events which dependens on
145  // isOver.
146  virtual void onIsOver( NodeIntersectResult *result = 0, unsigned int closest_index = 0,
147  Matrix4f *global_to_local = 0 );
148 
149  // Stores points of intersection with any of the geometry which causes this
150  // sensor to generate isOver events.
151  Vec3f geometry_intersection;
152 
153  // Stores global_to_local matrix of the geometry which causes this
154  // sensor to generate isOver events.
155  Matrix4f geometry_global_to_local;
156 
160  int intersectSegmentSphere( Vec3f a1, Vec3f a2, H3DFloat & t, Vec3f &q );
161 
162  // Radius of the sphere.
163  H3DFloat radius;
164 
165  // Last intersection point with the cylinder. Only used when sensor is
166  // active.
167  Vec3f last_intersection;
168  // The center of the sphere. Is always Vec3f( 0, 0, 0 ).
169  Vec3f center;
170 
171  // The transformation from global to local of the geometry for which this
172  // sensor is active. It will not change while sensor is active.
173  Matrix4f active_global_to_local_matrix;
175  bool new_radius, prev_new_radius;
176  };
177 }
178 
179 #endif
Contains the SFRotation field class.
Contains the SFVec2f field class.
Header file for X3DDragSensorNode, X3D scene-graph node.
The SphereSensor node maps pointing device motion into spherical rotation about the origin of the loc...
Definition: SphereSensor.h:94
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: SphereSensor.h:129
H3DUniquePtr< SFRotation > rotation_changed
For each position of the bearing when isActive is true, a rotation_changed event is sent which corres...
Definition: SphereSensor.h:126
bool new_radius
If true a new radius will be defined.
Definition: SphereSensor.h:175
H3DUniquePtr< SFRotation > offset
When the pointing device is deactivated and autoOffset is TRUE, offset is set to the last rotation_ch...
Definition: SphereSensor.h:116
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