Free Electron
SurfacePlane.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 __surface_SurfacePlane_h__
8 #define __surface_SurfacePlane_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief Planar Surface
17 
18  @ingroup surface
19 
20  A renderer may choose to limit the plane by the radius attribute.
21  Ray casting should not be limited.
22 *//***************************************************************************/
23 class FE_DL_EXPORT SurfacePlane:
24  public SurfaceDisk,
25  public CastableAs<SurfacePlane>
26 {
27  protected:
28  class Impact:
29  public SurfaceDisk::Impact,
30  public CastableAs<Impact>
31  {
32  public:
33  Impact(void)
34  {
35 #if FE_COUNTED_STORE_TRACKER
36  setName("SurfaceDisk::Impact");
37 #endif
38  }
39  virtual ~Impact(void) {}
40 
41  virtual SpatialVector intersection(void)
42  {
43  if(!m_resolved)
44  {
45  resolve();
46  }
47  return m_intersection;
48  }
49 
50  virtual SpatialVector normal(void)
51  {
52  if(!m_resolved)
53  {
54  resolve();
55  }
56  return m_normal;
57  }
58 
59  protected:
60  SpatialVector m_axis;
61  };
62  public:
63 
64  SurfacePlane(void);
65 virtual ~SurfacePlane(void) {}
66 
67  //* As Protectable
68 virtual Protectable* clone(Protectable* pInstance=NULL);
69 
70  using SurfaceDisk::nearestPoint;
71 
72  //* As SurfaceI
73 virtual sp<ImpactI> nearestPoint(const SpatialVector& a_origin,
74  Real a_maxDistance) const
75  {
76  SpatialVector direction;
77  Real distance=
79  m_center,m_span,m_radius,
80  a_origin,direction);
81  if(a_maxDistance>0.0 && distance>a_maxDistance)
82  {
83  return sp<Impact>(NULL);
84  }
85  sp<Impact> spImpact=m_planeImpactPool.get();
86  spImpact->setSurface(this);
87  spImpact->setLocationLocal(m_center);
88  spImpact->setAxis(m_span/m_range);
89  spImpact->setRadius(m_radius);
90  spImpact->setOrigin(a_origin);
91  spImpact->setDirection(direction);
92  spImpact->setDistance(distance);
93  return spImpact;
94  }
95 
96  using SurfaceDisk::rayImpact;
97 
98 virtual sp<ImpactI> rayImpact(const SpatialVector& a_origin,
99  const SpatialVector& a_direction,
100  Real a_maxDistance,BWORD a_anyHit) const
101  {
102  Real distance=
104  m_center,m_span,m_radius,
105  a_origin,a_direction);
106  if(a_maxDistance>0.0 && distance>a_maxDistance)
107  {
108  return sp<Impact>(NULL);
109  }
110 
111  sp<Impact> spImpact=m_planeImpactPool.get();
112  spImpact->setSurface(this);
113  spImpact->setLocationLocal(m_center);
114  spImpact->setAxis(m_span/m_range);
115  spImpact->setRadius(m_radius);
116  spImpact->setOrigin(a_origin);
117  spImpact->setDirection(a_direction);
118  spImpact->setDistance(distance);
119  return spImpact;
120  }
121 
122  using SurfaceDisk::draw;
123 
124 virtual void draw(sp<DrawI> a_spDrawI,const Color* color,
125  sp<PartitionI> a_spPartition) const;
126 
127  protected:
128 
129 virtual void resolveImpact(sp<ImpactI> a_spImpactI) const
130  {
131  // TODO m_baseRadius and m_endRadius scaling
132 
133  sp<Impact> spImpact(a_spImpactI);
134 
135  SpatialVector intersection;
136  SpatialVector normal;
138  spImpact->locationLocal(),
139  spImpact->axis(),
140  spImpact->radius(),
141  spImpact->origin(),
142  spImpact->direction(),
143  spImpact->distance(),
144  intersection,
145  normal);
146  spImpact->setIntersectionLocal(intersection);
147  spImpact->setNormalLocal(normal);
148  }
149 
150  private:
151 mutable CountedPool<Impact> m_planeImpactPool;
152 };
153 
154 } /* namespace ext */
155 } /* namespace fe */
156 
157 #endif /* __surface_SurfacePlane_h__ */
158 
Flat Circular Surface.
Definition: SurfaceDisk.h:20
Find intersection between ray and plane.
Definition: RayPlaneIntersect.h:21
Base class providing protection counting for cp<>
Definition: Protectable.h:28
kernel
Definition: namespace.dox:3
Special vector for color (RGBA)
Definition: Color.h:21
Planar Surface.
Definition: SurfacePlane.h:23
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
Find point nearest to a circular solid.
Definition: PointPlaneNearest.h:21
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192