Free Electron
SurfaceOSG.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __osg_SurfaceOSG_h__
8 #define __osg_SurfaceOSG_h__
9 namespace fe
10 {
11 namespace ext
12 {
13 
14 /**************************************************************************//**
15  @brief Surface in OpenSceneGraph
16 
17  @ingroup osg
18 *//***************************************************************************/
19 class FE_DL_EXPORT SurfaceOSG: public SurfaceTriangles,
20  public Initialize<SurfaceOSG>
21 {
22  protected:
23  class Impact:
24  public SurfaceSphere::Impact,
25  public CastableAs<Impact>
26  {
27  public:
28  Impact(void) {}
29  virtual ~Impact(void) {}
30 
31  virtual SpatialVector intersection(void) { return m_intersection; }
32  virtual SpatialVector normal(void) { return m_normal; }
33 
34  protected:
35  virtual void resolve(void) {}
36  };
37 
38  public:
39  SurfaceOSG(void);
40 virtual ~SurfaceOSG(void) {}
41 
42 void initialize(void);
43 
44  //* As Protectable
45 virtual Protectable* clone(Protectable* pInstance=NULL);
46 
47  //* As SurfaceI
48 virtual SpatialTransform sample(Vector2 a_uv) const;
49 
50 virtual sp<ImpactI> rayImpact(const SpatialVector& a_origin,
51  const SpatialVector& a_direction,
52  Real a_maxDistance) const;
53 
54  //* As DrawableI
55 virtual void draw(sp<DrawI> a_spDrawI,
56  const Color* a_color) const;
57 
58  private:
59 
60  typedef osg::ref_ptr<osg::DrawArrays> RefArray;
61  typedef osg::ref_ptr<osg::DrawElementsUShort> RefShort;
62 
63  class Array
64  {
65  public:
66  Array(void): which(0) {}
67  void bind(RefArray& a_refArray)
68  {
69  which=0;
70  m_refArray=a_refArray;
71  }
72  void bind(RefShort& a_refShort)
73  {
74  which=1;
75  m_refShort=a_refShort;
76  }
77  U32 count(void)
78  {
79  return which? m_refShort->size():
80  m_refArray->getCount();
81  }
82  U32 operator[](U32 a_index)
83  {
84  return which? m_refShort->at(a_index):
85  m_refArray->index(a_index);
86  }
87 
88  private:
89  U32 which;
90  RefArray m_refArray;
91  RefShort m_refShort;
92  };
93 
94 virtual void cache(void);
95 
96  sp<Component> m_spContextOSG;
97  sp<SceneNodeI> m_spSceneNodeI;
98 
99 mutable CountedPool<Impact> m_osgImpactPool;
100 };
101 
102 } /* namespace ext */
103 } /* namespace fe */
104 
105 #endif /* __osg_SurfaceOSG_h__ */
106 
Discrete Triangle Surface.
Definition: SurfaceTriangles.h:20
Base class providing protection counting for cp<>
Definition: Protectable.h:28
kernel
Definition: namespace.dox:3
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
Special vector for color (RGBA)
Definition: Color.h:21
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
Surface in OpenSceneGraph.
Definition: SurfaceOSG.h:19
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192