H3D API  2.4.1
X3DViewpointNode.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 __X3DX3DViewpointNodeNODE_H__
30 #define __X3DX3DViewpointNodeNODE_H__
31 
32 #include <H3D/X3DBindableNode.h>
33 #include <H3D/FieldTemplates.h>
34 #include <H3DUtil/Exception.h>
35 #include <H3D/SFVec3f.h>
36 #include <H3D/SFString.h>
37 #include <H3D/SFFloat.h>
38 #include <H3D/SFRotation.h>
39 #include <H3D/SFMatrix4f.h>
40 #include <H3D/StereoInfo.h>
41 
42 namespace H3D {
239  class H3DAPI_API X3DViewpointNode : public X3DBindableNode {
240  public:
241 
244  enum EyeMode {
246  MONO = 0,
248  LEFT_EYE = 1,
250  RIGHT_EYE = 2,
252  BOTH_EYE = 3
253  };
254 
258  class H3DAPI_API SFPosition: public SFVec3f {
259  public:
260  virtual void setValue( const Vec3f &v, int _id = 0 ) {
261  SFVec3f::setValue( v, _id );
262  X3DViewpointNode * temp_owner =
263  static_cast< X3DViewpointNode * >( getOwner() );
264  temp_owner->relPos->setValue( Vec3f() );
265  temp_owner->relOrn->setValue( Rotation() );
266  }
267 
268  protected:
269  virtual void update() {
270  SFVec3f::update();
271  X3DViewpointNode * temp_owner =
272  static_cast< X3DViewpointNode * >( getOwner() );
273  temp_owner->relPos->setValue( Vec3f() );
274  temp_owner->relOrn->setValue( Rotation() );
275  }
276  };
277 #ifdef __BORLANDC__
278  friend class SFPosition;
279 #endif
280 
284  class H3DAPI_API SFOrientation: public SFRotation {
285  public:
286  virtual void setValue( const Rotation &v, int _id = 0 ) {
287  SFRotation::setValue( v, _id );
288  X3DViewpointNode * temp_owner =
289  static_cast< X3DViewpointNode * >( getOwner() );
290  temp_owner->relPos->setValue( Vec3f() );
291  temp_owner->relOrn->setValue( Rotation() );
292  }
293 
294  protected:
295  virtual void update() {
297  X3DViewpointNode * temp_owner =
298  static_cast< X3DViewpointNode * >( getOwner() );
299  temp_owner->relPos->setValue( Vec3f() );
300  temp_owner->relOrn->setValue( Rotation() );
301  }
302  };
303 #ifdef __BORLANDC__
304  friend class SFOrientation;
305 #endif
306 
308  class H3DAPI_API SFSumVec3f:
309  public TypedField< SFVec3f, Types< SFPosition, SFVec3f > > {
310  protected:
311  virtual void update() {
312  SFVec3f::update();
313  value = static_cast< SFPosition * >( routes_in[0] )->getValue() +
314  static_cast< SFVec3f * >( routes_in[1] )->getValue();
315  }
316  };
317 #ifdef __BORLANDC__
318  friend class SFSumVec3f;
319 #endif
320 
322  class H3DAPI_API SFSumRotation: public TypedField< SFRotation,
323  Types< SFOrientation, SFRotation > > {
324  protected:
325  virtual void update() {
327  Rotation temp_rot =
328  static_cast< SFOrientation * >( routes_in[0] )->getValue();
329  temp_rot.axis.normalizeSafe();
330  value = temp_rot *
331  static_cast< SFRotation * >( routes_in[1] )->getValue();
332  }
333  };
334 #ifdef __BORLANDC__
335  friend class SFSumRotation;
336 #endif
337 
339  X3DViewpointNode( Inst< SFSetBind > _set_bind = 0,
340  Inst< SFVec3f > _centerOfRotation = 0,
341  Inst< SFString > _description = 0,
342  Inst< SFBool > _jump = 0,
343  Inst< SFNode > _metadata = 0,
344  Inst< SFOrientation > _orientation = 0,
345  Inst< SFPosition > _position = 0,
346  Inst< SFBool > _retainUserOffsets = 0,
347  Inst< SFTime > _bindTime = 0,
348  Inst< SFBool > _isBound = 0,
349  Inst< SFMatrix4f > _accForwardMatrix = 0,
350  Inst< SFMatrix4f > _accInverseMatrix = 0,
351  Inst< SFSumVec3f > _totalPosition = 0,
352  Inst< SFSumRotation > _totalOrientation = 0 );
353 
355  virtual ~X3DViewpointNode() {
356  removeFromStack();
357  viewpoints.remove( this );
358  viewpoints_changed = true;
359  }
360 
366  virtual void traverseSG( TraverseInfo &ti );
367 
369  static inline X3DViewpointNode *getActive() {
370  return static_cast< X3DViewpointNode * >(
371  X3DBindableNode::getActive( "X3DViewpointNode" ) );
372  }
373 
384  virtual bool windowFromfieldOfView( H3DFloat width, H3DFloat height,
385  H3DFloat clip_near,
386  H3DFloat &top, H3DFloat &bottom,
387  H3DFloat &right, H3DFloat &left )
388 #ifndef H3D_GENERATE_DOTROUTE_FILES
389  = 0;
390 #else
391  { return false; }
392 #endif
393 
395  virtual void toStackTop();
396 
398  virtual void removeFromStack();
399 
406  virtual void rotateAround( Rotation rotation, bool collision,
407  Vec3f rotation_center );
408 
409  // Function for rotating the viewpoint around rotation_center = position
411  virtual void rotateAroundSelf( Rotation rotation );
412 
422  virtual void translate( Vec3f direction, bool collision,
423  const vector< H3DFloat > &avatar_size,
424  X3DChildNode * topNode );
425 
428  virtual void moveTo( Vec3f new_pos );
429 
431  virtual bool detectCollision( const vector< H3DFloat > &avatar_size,
432  X3DChildNode * topNode );
433 
434  typedef list< X3DViewpointNode * > ViewpointList;
435 
437  static const ViewpointList &getAllViewpoints() {
438  return viewpoints;
439  }
440 
443  static bool viewpointsChanged() {
444  bool status = viewpoints_changed;
445  viewpoints_changed = false;
446  return status;
447  }
448 
460  virtual void setupProjection( EyeMode eye_mode,
461  H3DFloat width, H3DFloat height,
462  H3DFloat clip_near, H3DFloat clip_far,
463  StereoInfo * stereo_info = 0,
464  bool update_stereo_proj_shift = false )
465 #ifndef H3D_GENERATE_DOTROUTE_FILES
466  = 0;
467 #else
468  {}
469 #endif
470 
473  virtual Matrix4f getProjectionMatrix( EyeMode eye_mode,
474  H3DFloat width, H3DFloat height,
475  H3DFloat clip_near, H3DFloat clip_far,
476  StereoInfo * stereo_info = 0,
477  bool mirrored_in_y = false );
478 
486  virtual void setupViewMatrix( EyeMode eye_mode,
487  StereoInfo * stereo_info = 0,
488  bool update_stereo_view_shift = false );
489 
490 
493  virtual Matrix4f getViewMatrix( EyeMode eye_mode,
494  StereoInfo * stereo_info = 0 );
495 
497  inline bool isTopLevel() {
498  return is_top_level;
499  }
500 
502  inline bool inSceneGraph() {
503  return in_scene_graph;
504  }
505 
513  H3DUniquePtr< SFVec3f > centerOfRotation;
514 
522  H3DUniquePtr< SFString > description;
523 
532  H3DUniquePtr< SFBool > jump;
533 
543  H3DUniquePtr< SFOrientation > orientation;
544 
552  H3DUniquePtr< SFPosition > position;
553 
562  H3DUniquePtr< SFBool > retainUserOffsets;
563 
569  H3DUniquePtr< SFMatrix4f > accForwardMatrix;
570 
577  H3DUniquePtr< SFMatrix4f > accInverseMatrix;
578 
585  H3DUniquePtr< SFSumVec3f > totalPosition;
586 
593  H3DUniquePtr< SFSumRotation > totalOrientation;
594 
595  static H3DNodeDatabase database;
596 
600  H3DUniquePtr< SFVec3f > relPos;
601 
605  H3DUniquePtr< SFRotation > relOrn;
606 
607  protected:
608  static ViewpointList viewpoints;
609  static bool viewpoints_changed;
610 
613 
616 
617  // Internal function for easier calculations of parameters sent to
618  // glFrustum or glOrtho. For usage see function setupProjection in
619  // Viewpoint or OrthoViewpoint.
620  void getProjectionDimensions( EyeMode eye_mode,
621  H3DFloat width,
622  H3DFloat height,
623  H3DFloat clip_near,
624  H3DFloat &top,
625  H3DFloat &bottom,
626  H3DFloat &right,
627  H3DFloat &left,
628  StereoInfo * stereo_info = 0,
629  bool update_stereo_proj_shift = false );
630 
631  };
632 }
633 
634 #endif
Contains different templates to modify field behaviour.
Contains the SFFloat field class.
Contains the SFMatrix4f field class.
Contains the SFRotation field class.
Contains the SFString field class.
Contains the SFVec3f field class.
Header file for StereoInfo, X3D scene-graph node.
Header file for X3DBindableNode, X3D scene-graph node.
The SFRotation field contains one arbitrary Rotation.
Definition: SFRotation.h:41
The SFVec3f field contains a Vec3f.
Definition: SFVec3f.h:41
virtual void setValue(const Vec3f &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
The StereoInfo nis a bindable node that contains information used when rendering the scene in stereo.
Definition: StereoInfo.h:51
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
X3DBindableNode is the abstract base type for all bindable children nodes, including Background,...
Definition: X3DBindableNode.h:108
static X3DBindableNode * getActive(const string &bindable_stack_name)
Returns the active bindable instance, i.e.
Definition: X3DBindableNode.h:149
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
This field is used for the orientation field in order to reset the internal variables rel_pos and rel...
Definition: X3DViewpointNode.h:284
virtual void update()
Make the field up to date given that an event has occured.
Definition: X3DViewpointNode.h:295
This field is used for the position field in order to reset the internal variables rel_pos and rel_or...
Definition: X3DViewpointNode.h:258
virtual void update()
Make the field up to date given that an event has occured.
Definition: X3DViewpointNode.h:269
This field sums the value of the two SFRotation routed to it.
Definition: X3DViewpointNode.h:323
virtual void update()
Make the field up to date given that an event has occured.
Definition: X3DViewpointNode.h:325
This field sums the value of the two SFVec3f routed to it.
Definition: X3DViewpointNode.h:309
virtual void update()
Make the field up to date given that an event has occured.
Definition: X3DViewpointNode.h:311
The X3DViewpointNode node defines a specific location in the local coordinate system from which the u...
Definition: X3DViewpointNode.h:239
static bool viewpointsChanged()
True on any addition/deletion/in_scene_graph status change of viewpoints, reset once inquired.
Definition: X3DViewpointNode.h:443
bool inSceneGraph()
True if this viewpoint node exists in scene graph.
Definition: X3DViewpointNode.h:502
bool is_top_level
True if the viewpooint exists outside a ViewpointGroup.
Definition: X3DViewpointNode.h:612
static const ViewpointList & getAllViewpoints()
Returns a list of all current X3DViewpointNode instances.
Definition: X3DViewpointNode.h:437
bool in_scene_graph
True is the viewpoint exists in scene graph.
Definition: X3DViewpointNode.h:615
H3DUniquePtr< SFSumRotation > totalOrientation
Returns the sum of the field orientation and the internal field relOrn used for navigation.
Definition: X3DViewpointNode.h:593
virtual bool windowFromfieldOfView(H3DFloat width, H3DFloat height, H3DFloat clip_near, H3DFloat &top, H3DFloat &bottom, H3DFloat &right, H3DFloat &left)=0
Calculates the top, bottom, right and left clipping values for the view frustum at the near plane.
bool isTopLevel()
True if this viewpoint node exists outside a ViewpointGroup.
Definition: X3DViewpointNode.h:497
H3DUniquePtr< SFSumVec3f > totalPosition
Returns the sum of the field position and the internal field relPos used for navigation.
Definition: X3DViewpointNode.h:585
virtual ~X3DViewpointNode()
Destructor.
Definition: X3DViewpointNode.h:355
H3DUniquePtr< SFMatrix4f > accInverseMatrix
The matrix from global space to the local space the X3DViewpointNode resides in.
Definition: X3DViewpointNode.h:577
virtual void setupProjection(EyeMode eye_mode, H3DFloat width, H3DFloat height, H3DFloat clip_near, H3DFloat clip_far, StereoInfo *stereo_info=0, bool update_stereo_proj_shift=false)=0
Adds a projection matrix to the current OpenGL matrix based on the viewpoint values.
H3DUniquePtr< SFPosition > position
Specifies the position of the X3DViewpointNode the local coordinate system.
Definition: X3DViewpointNode.h:552
H3DUniquePtr< SFString > description
The description field specifies a textual description of the X3DViewpointNode node.
Definition: X3DViewpointNode.h:522
H3DUniquePtr< SFVec3f > relPos
Internal field that stores the relative offset from the position set by the user.
Definition: X3DViewpointNode.h:600
H3DUniquePtr< SFOrientation > orientation
Specifies the orientation of the X3DViewpointNode relative to the default orientation.
Definition: X3DViewpointNode.h:543
static X3DViewpointNode * getActive()
Convenience function to get the top of the X3DViewpointNode stack.
Definition: X3DViewpointNode.h:369
H3DUniquePtr< SFRotation > relOrn
Internal field that stores the relative offset from the orientation set by the user.
Definition: X3DViewpointNode.h:605
EyeMode
Used with setupProjection function to indicate for which eye the frustum should be calculated.
Definition: X3DViewpointNode.h:244
H3DUniquePtr< SFBool > retainUserOffsets
The retainUserOffsets field indicates whether a viewpoint needs to retain (TRUE) or reset to zero (FA...
Definition: X3DViewpointNode.h:562
H3DUniquePtr< SFVec3f > centerOfRotation
The centerOfRotation field specifies a center about which to rotate the user's eyepoint when in EXAMI...
Definition: X3DViewpointNode.h:513
H3DUniquePtr< SFBool > jump
The jump field specifies whether the user's view "jumps" to the position and orientation of a bound X...
Definition: X3DViewpointNode.h:532
H3DUniquePtr< SFMatrix4f > accForwardMatrix
The matrix from local space to global space.
Definition: X3DViewpointNode.h:569
Rotation()
float H3DFloat
Type getValue(const char *s, const char *&rest)
Function that reads characters from a char * and converts them to a given type.
Definition: X3DFieldConversion.h:134
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