H3D API  2.4.1
Sphere.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 __SPHERE_H__
30 #define __SPHERE_H__
31 
32 #include <H3D/X3DGeometryNode.h>
33 #include <H3D/SFFloat.h>
34 
35 namespace H3D {
36 
62  class H3DAPI_API Sphere : public X3DGeometryNode {
63  public:
64 
70  class SFBound: public TypedField< X3DGeometryNode::SFBound,
71  SFFloat >{
73  virtual void update() {
74  H3DFloat d = 2 * static_cast< SFFloat * >( routes_in[0] )->getValue();
75  BoxBound *bb = new BoxBound;
76  bb->size->setValue( Vec3f( d, d, d ) );
77  value = bb;
78  }
79  };
80 
82  Sphere( Inst< SFNode > _metadata = 0,
83  Inst< SFBound > _bound = 0,
84  Inst< SFFloat> _radius = 0,
85  Inst< SFBool > _solid = 0 );
86 
88  virtual int nrTriangles() {
89  return 2500;//50 * 25 * 2;
90  }
91 
94  virtual H3DShadowObjectNode *getShadowObject();
95 
97  virtual void render();
98 
100  virtual void traverseSG( TraverseInfo &ti );
101 
108  virtual bool lineIntersect(
109  const Vec3f &from,
110  const Vec3f &to,
111  LineIntersectResult &result );
112 
118  virtual void closestPoint( const Vec3f &p,
119  NodeIntersectResult &result );
120 
128  virtual bool movingSphereIntersect( H3DFloat radius,
129  const Vec3f &from,
130  const Vec3f &to,
131  NodeIntersectResult &result );
132 
140  H3DUniquePtr< SFFloat > radius;
141 
149  H3DUniquePtr< SFBool > solid;
150 
153 
154  protected:
155  // Internal variable used to store id for Sphere vbo.
156  // glDeleteBuffersARB is never called for the allocated buffer. The reason
157  // for this is that it is impossible to know when the OpenGL context is
158  // destroyed and glDeleteBuffersARB should be called before that occurrs.
159  // It is therefore assumed that the memory is cleaned up when the OpenGL
160  // context is removed.
161  static GLuint vbo_id[2];
162  // Internal variable used to indicate if vbo_id contains valid ids.
163  // Can not use -1 because vbo_id is an GLuint.
164  static bool vbo_initialized;
165 
166  static vector< GLfloat > sphere_data;
167  static vector< GLuint > sphere_index_data;
168  };
169 }
170 
171 #endif
Contains the SFFloat field class.
Header file for X3DGeometryNode, X3D scene-graph node.
The BoxBound is a Bound class that specifies the bound using an axis-aligned bounding box.
Definition: Bound.h:144
H3DUniquePtr< SFVec3f > size
The size of the bounding box.
Definition: Bound.h:287
The H3DShadowObjectNode is the base class for all shadow objects for use in the ShadowCaster node.
Definition: H3DShadowObjectNode.h:49
The SFFloat field contains one single-precision floating point number.
Definition: SFFloat.h:41
SFBound is specialized update itself from the radius field of the Sphere node.
Definition: Sphere.h:71
The Sphere node specifies a sphere centred at (0, 0, 0) in the local coordinate system.
Definition: Sphere.h:62
H3DUniquePtr< SFFloat > radius
The radius of the Sphere in metres.
Definition: Sphere.h:140
virtual int nrTriangles()
The number of triangles renderered in this geometry.
Definition: Sphere.h:88
H3DUniquePtr< SFBool > solid
Specifies if both sides of the Sphere should be rendered or only the outside.
Definition: Sphere.h:149
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: Sphere.h:152
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 is the base node type for all geometry in X3D.
Definition: X3DGeometryNode.h:61
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