H3D API  2.4.1
MatrixTransform.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 __MATRIXTRANSFORM_H__
30 #define __MATRIXTRANSFORM_H__
31 
32 #include <H3D/X3DGroupingNode.h>
33 
34 namespace H3D {
35 
64  class H3DAPI_API MatrixTransform : public X3DGroupingNode {
65  public:
67 
78  class H3DAPI_API SFTransformedBound:
79  public TypedField< SFBound, Types< SFMatrix4f, SFBound > > {
80  public:
81 
86  value = NULL;
87  }
88 
89  protected:
91  virtual void update();
92 
96  virtual void onAdd( Bound *b ) {
97  SFBound::onAdd( b );
98  TransformedBoxBound *tbb = dynamic_cast< TransformedBoxBound * >( b );
99  if( b && tbb ) {
100  MatrixTransform *mt = static_cast< MatrixTransform * >(owner);
101  mt->bound->route( tbb->boxBound );
102  mt->matrix->route( tbb->matrix );
103  }
104  }
105 
107  virtual void onRemove( Bound *b ) {
108  TransformedBoxBound *tbb = dynamic_cast< TransformedBoxBound * >( b );
109  if( b && tbb ) {
110  MatrixTransform *mt = static_cast< MatrixTransform * >(owner);
111  mt->bound->unroute( tbb->boxBound );
112  mt->matrix->unroute( tbb->matrix );
113  }
114  SFBound::onRemove( b );
115  }
116 
117  friend class MatrixTransform;
118  };
119 
121  MatrixTransform( Inst< AddChildren > _addChildren = 0,
122  Inst< RemoveChildren > _removeChildren = 0,
123  Inst< MFChild > _children = 0,
124  Inst< SFNode > _metadata = 0,
125  Inst< SFBound > _bound = 0,
126  Inst< SFVec3f > _bboxCenter = 0,
127  Inst< SFVec3f > _bboxSize = 0,
128  Inst< SFTransformedBound > _transformedBound = 0,
129  Inst< SFMatrix4f > _matrix = 0,
130  Inst< SFMatrix4f > _accumulatedForward = 0,
131  Inst< SFMatrix4f > _accumulatedInverse = 0 );
132 
133  virtual void render();
134 
136  virtual void traverseSG( TraverseInfo &ti );
137 
140  void multiplyGLMatrix();
141 
150  virtual bool lineIntersect(
151  const Vec3f &from,
152  const Vec3f &to,
153  LineIntersectResult &result );
154 
161  virtual void closestPoint( const Vec3f &p,
162  NodeIntersectResult &result );
163 
173  virtual bool movingSphereIntersect( H3DFloat radius,
174  const Vec3f &from,
175  const Vec3f &to,
176  NodeIntersectResult &result );
177 
184  H3DUniquePtr< SFMatrix4f > matrix;
185 
194  H3DUniquePtr< SFMatrix4f > accumulatedForward;
195 
204  H3DUniquePtr< SFMatrix4f > accumulatedInverse;
205 
212  H3DUniquePtr< SFTransformedBound > transformedBound;
213 
216  };
217 }
218 
219 #endif
Header file for X3DGroupingNode, X3D scene-graph node.
The Bound class is the abstract base class for all classes specifying bounding objects.
Definition: Bound.h:44
H3DUniquePtr< SFBound > bound
The field containing the bound object.
Definition: H3DBoundedObject.h:59
SFTransformedBound maintains the routes from the owner Node's bound and matrix field to the contained...
Definition: MatrixTransform.h:79
virtual void onAdd(Bound *b)
Set up the routes from the owner Node's bound and matrix field to the contained TransformedBoxBound i...
Definition: MatrixTransform.h:96
~SFTransformedBound()
Destructor.
Definition: MatrixTransform.h:85
virtual void onRemove(Bound *b)
Remove the routes that were set up in onAdd().
Definition: MatrixTransform.h:107
The MatrixTransform node is a grouping node that defines a coordinate system for its children that is...
Definition: MatrixTransform.h:64
H3DUniquePtr< SFMatrix4f > accumulatedForward
The accumulated forward transform matrix, i.e.
Definition: MatrixTransform.h:194
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: MatrixTransform.h:215
H3DUniquePtr< SFMatrix4f > matrix
The transformation matrix.
Definition: MatrixTransform.h:184
H3DUniquePtr< SFTransformedBound > transformedBound
This is the same as the bound field, but with the transformation applied to the bound.
Definition: MatrixTransform.h:212
H3DUniquePtr< SFMatrix4f > accumulatedInverse
The accumulated inverse transform matrix, i.e.
Definition: MatrixTransform.h:204
The SFMatrix4f field contains a Matrix4f.
Definition: SFMatrix4f.h:41
A TransformedBoxBound is a wrapper around another BoxBound and its values are the values of the BoxBo...
Definition: Bound.h:294
H3DUniquePtr< SFBoxBound > boxBound
The BoxBound which values are to be transformed.
Definition: Bound.h:403
H3DUniquePtr< SFMatrix4f > matrix
The matrix to transform with.
Definition: Bound.h:401
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
This abstract node type indicates that concrete node types derived from it contain children nodes and...
Definition: X3DGroupingNode.h:53
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