Free Electron
SurfaceDisk.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_SurfaceDisk_h__
8 #define __surface_SurfaceDisk_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief Flat Circular Surface
17 
18  @ingroup surface
19 *//***************************************************************************/
20 class FE_DL_EXPORT SurfaceDisk:
21  public SurfaceSphere,
22  public CastableAs<SurfaceDisk>
23 {
24  protected:
25  class Impact:
26  public SurfaceSphere::Impact,
27  public CastableAs<Impact>
28  {
29  public:
30  Impact(void)
31  {
32 #if FE_COUNTED_STORE_TRACKER
33  setName("SurfaceDisk::Impact");
34 #endif
35  }
36  virtual ~Impact(void) {}
37 
38  virtual SpatialVector intersection(void)
39  {
40  return transformVector(m_transform,
41  m_intersection);
42  }
43  virtual SpatialVector intersectionLocal(void) const
44  { return m_intersection; }
45 
46  virtual SpatialVector normal(void)
47  { return m_normal; }
48 
49  virtual SpatialVector axis(void)
50  { return m_normal; }
51  void setAxis(SpatialVector a_axis)
52  { m_normal=a_axis; }
53  };
54 
55  public:
56  SurfaceDisk(void);
57 virtual ~SurfaceDisk(void) {}
58 
59  //* As Protectable
60 virtual Protectable* clone(Protectable* pInstance=NULL);
61 
62  using SurfaceSphere::sample;
63 
64  //* As SurfaceI
65 virtual SpatialTransform sample(Vector2 a_uv) const;
66 
67  using SurfaceSphere::nearestPoint;
68 
69 virtual sp<ImpactI> nearestPoint(const SpatialVector& a_origin,
70  Real a_maxDistance) const
71  {
72  SpatialVector direction;
73  SpatialVector intersection;
74  Real distance=
76  m_center,m_span,m_radius,
77  a_origin,direction,intersection);
78  if(a_maxDistance>0.0 && distance>a_maxDistance)
79  {
80  return sp<Impact>(NULL);
81  }
82 
83  sp<Impact> spImpact=m_diskImpactPool.get();
84  spImpact->setSurface(this);
85  spImpact->setLocationLocal(m_center);
86  spImpact->setAxis(m_span/m_range);
87  spImpact->setRadius(m_radius);
88  spImpact->setOrigin(a_origin);
89  spImpact->setDirection(direction);
90  spImpact->setIntersectionLocal(intersection);
91  spImpact->setDistance(distance);
92  return spImpact;
93  }
94 
95  using SurfaceSphere::rayImpact;
96 
97 virtual sp<ImpactI> rayImpact(const SpatialVector& a_origin,
98  const SpatialVector& a_direction,
99  Real a_maxDistance,BWORD a_anyHit) const
100  {
101  SpatialVector intersection;
102  Real distance=
104  m_center,m_span,m_radius,
105  a_origin,a_direction,intersection);
106  if(a_maxDistance>0.0 && distance>a_maxDistance)
107  {
108  return sp<Impact>(NULL);
109  }
110 
111  sp<Impact> spImpact=m_diskImpactPool.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->setIntersectionLocal(intersection);
119  spImpact->setDistance(distance);
120  return spImpact;
121  }
122 
123  using SurfaceSphere::draw;
124 
125 virtual void draw(const SpatialTransform& a_transform,
126  sp<DrawI> a_spDrawI,
127  const fe::Color* a_color,
128  sp<DrawBufferI> a_spDrawBuffer,
129  sp<PartitionI> a_spPartition) const;
130 
131  void setSpan(const SpatialVector& a_rSpan)
132  { m_span=a_rSpan;
133  m_range=magnitude(m_span);
134  updateSphere(); }
135  SpatialVector span(void)
136  { checkCache();
137  return m_span; }
138  SpatialVector span(void) const
139  { return m_span; }
140 
141  protected:
142 
143 virtual void updateSphere(void) {}
144 virtual void cache(void);
145 virtual void resolveImpact(sp<ImpactI> a_spImpactI) const
146  {
147 /*
148  sp<Impact> spImpact(a_spImpactI);
149 
150  SpatialVector normal;
151  RayDiskIntersect<Real>::resolveContact(
152  spImpact->locationLocal(),
153  spImpact->axis(),
154  spImpact->radius(),
155  spImpact->origin(),
156  spImpact->direction(),
157  spImpact->distance(),
158  spImpact->intersectionLocal(),
159  normal);
160 */
161  }
162 
163  SpatialTransform m_transform;
164  SpatialVector m_span;
165  Real m_range; //* magnitude of span (used by cylinder)
166 
167  private:
168 mutable CountedPool<Impact> m_diskImpactPool;
169 };
170 
171 } /* namespace ext */
172 } /* namespace fe */
173 
174 #endif /* __surface_SurfaceDisk_h__ */
175 
176 
Flat Circular Surface.
Definition: SurfaceDisk.h:20
Find intersection between ray and circular solid.
Definition: RayDiskIntersect.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
Spherical Surface.
Definition: SurfaceSphere.h:20
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
Find point nearest to a circular solid.
Definition: PointDiskNearest.h:21
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192