OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Projector.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 //osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
14 
15 #ifndef OSGMANIPULATOR_PROJECTOR
16 #define OSGMANIPULATOR_PROJECTOR 1
17 
18 #include <osgManipulator/Export>
19 
20 #include <osg/LineSegment>
21 #include <osgUtil/SceneView>
22 
23 #include <osgManipulator/Dragger>
24 
25 namespace osgManipulator {
26 
31 {
32  public:
33 
34  Projector();
35 
43  virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const = 0;
44 
49  void setLocalToWorld(const osg::Matrix& localToWorld)
50  {
51  _localToWorld = localToWorld;
52  _worldToLocalDirty = true;
53  }
54 
59  inline const osg::Matrix& getLocalToWorld() const { return _localToWorld; }
60 
65  inline const osg::Matrix& getWorldToLocal() const
66  {
67  if (_worldToLocalDirty)
68  {
69  _worldToLocal.invert(_localToWorld);
70  _worldToLocalDirty = false;
71  }
72  return _worldToLocal;
73  }
74 
75  protected:
76 
77  virtual ~Projector();
78 
81 
82  mutable bool _worldToLocalDirty;
83 };
84 
85 
90 {
91  public:
92 
93  LineProjector();
94 
96 
97  inline void setLine(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e) { _line->start() = s; _line->end() = e; }
98 
99  inline const osg::LineSegment::vec_type& getLineStart() const { return _line->start(); }
100  inline osg::LineSegment::vec_type& getLineStart() { return _line->start(); }
101 
102  inline const osg::LineSegment::vec_type& getLineEnd() const { return _line->end(); }
103  inline osg::LineSegment::vec_type& getLineEnd() { return _line->end(); }
104 
110  virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
111 
112  protected:
113 
114  virtual ~LineProjector();
115 
117 };
118 
123 {
124  public:
125 
126  PlaneProjector();
127 
128  PlaneProjector(const osg::Plane& plane);
129 
130  inline void setPlane(const osg::Plane& plane) { _plane = plane; }
131  inline const osg::Plane& getPlane() const { return _plane; }
132 
138  virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
139 
140  protected:
141 
142  virtual ~PlaneProjector();
143 
145 };
146 
151 {
152  public:
153 
154  SphereProjector();
155 
156  SphereProjector(osg::Sphere* sphere);
157 
158  inline void setSphere(osg::Sphere* sphere) { _sphere = sphere; }
159  inline const osg::Sphere* getSphere() const { return _sphere.get(); }
160 
166  virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
167 
172  bool isPointInFront(const PointerInfo& pi, const osg::Matrix& localToWorld) const;
173 
174  void setFront(bool front) { _front = front; }
175 
176  protected:
177 
178  virtual ~SphereProjector();
179 
181  bool _front;
182 };
183 
189 {
190  public:
191 
193 
195 
201  virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
202 
207  bool isProjectionOnSphere() const { return _onSphere; }
208 
209  osg::Quat getRotation(const osg::Vec3d& p1, bool p1OnSphere,
210  const osg::Vec3d& p2, bool p2OnSphere,
211  float radialFactor = 0.0f) const;
212 
213  protected:
214 
215  virtual ~SpherePlaneProjector();
216 
218  mutable bool _onSphere;
219 };
220 
225 {
226  public:
227 
229 
230  CylinderProjector(osg::Cylinder* cylinder);
231 
232  inline void setCylinder(osg::Cylinder* cylinder)
233  {
234  _cylinder = cylinder;
235  _cylinderAxis = osg::Vec3d(0.0,0.0,1.0) * osg::Matrix(cylinder->getRotation());
236  _cylinderAxis.normalize();
237  }
238  inline const osg::Cylinder* getCylinder() const { return _cylinder.get(); }
239 
245  virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
246 
247 
252  bool isPointInFront(const PointerInfo& pi, const osg::Matrix& localToWorld) const;
253 
254  void setFront(bool front) { _front = front; }
255 
256  protected:
257 
258  virtual ~CylinderProjector();
259 
262  bool _front;
263 };
264 
273 {
274  public:
275 
277 
279 
288  virtual bool project(const PointerInfo& pi, osg::Vec3d& projectedPoint) const;
289 
297  osg::Quat getRotation(const osg::Vec3d& p1, const osg::Vec3d& p2) const;
298 
299  protected:
300 
301  virtual ~CylinderPlaneProjector();
302 
304  mutable osg::Vec3d _planeLineStart, _planeLineEnd;
305  mutable bool _parallelPlane;
306 };
307 
308 }
309 
310 #endif
void setSphere(osg::Sphere *sphere)
Definition: Projector.h:158
#define OSGMANIPULATOR_EXPORT
Definition: Export.h:27
const osg::Plane & getPlane() const
Definition: Projector.h:131
osg::LineSegment::vec_type & getLineStart()
Definition: Projector.h:100
osg::Matrix _localToWorld
Definition: Projector.h:79
const osg::Matrix & getWorldToLocal() const
Definition: Projector.h:65
osg::Matrix _worldToLocal
Definition: Projector.h:80
void setLocalToWorld(const osg::Matrix &localToWorld)
Definition: Projector.h:49
const osg::LineSegment::vec_type & getLineStart() const
Definition: Projector.h:99
osg::ref_ptr< osg::LineSegment > _line
Definition: Projector.h:116
void setCylinder(osg::Cylinder *cylinder)
Definition: Projector.h:232
const osg::LineSegment::vec_type & getLineEnd() const
Definition: Projector.h:102
A plane class. It can be used to represent an infinite plane.
Definition: Plane.h:33
const Quat & getRotation() const
Definition: Shape.h:345
osg::LineSegment::vec_type & getLineEnd()
Definition: Projector.h:103
osg::ref_ptr< osg::Sphere > _sphere
Definition: Projector.h:180
bool invert(const Matrixd &rhs)
Definition: Matrixd.h:233
Definition: Quat.h:29
osg::ref_ptr< osg::Cylinder > _cylinder
Definition: Projector.h:260
const osg::Cylinder * getCylinder() const
Definition: Projector.h:238
const osg::Matrix & getLocalToWorld() const
Definition: Projector.h:59
Matrixd Matrix
Definition: Matrix.h:27
const osg::Sphere * getSphere() const
Definition: Projector.h:159
void setLine(const osg::LineSegment::vec_type &s, const osg::LineSegment::vec_type &e)
Definition: Projector.h:97
void setPlane(const osg::Plane &plane)
Definition: Projector.h:130