openscenegraph
SegmentPlacer
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//osgParticle - Copyright (C) 2002 Marco Jez
14
15#ifndef OSGPARTICLE_SEGMENT_PLACER
16#define OSGPARTICLE_SEGMENT_PLACER 1
17
18#include <osgParticle/Placer>
19#include <osgParticle/Particle>
20
21#include <osg/CopyOp>
22#include <osg/Object>
23#include <osg/Vec3>
24
25namespace osgParticle {
26
27 /** A segment-shaped particle placer.
28 To use this placer you have to define a segment, by setting its two vertices (<B>A</B> and <B>B</B>);
29 when an emitter requests a <CODE>SegmentPlacer</CODE> to place a particle, the position is chosen randomly
30 within that segment.
31 */
32 class SegmentPlacer: public Placer {
33 public:
34 inline SegmentPlacer();
35 inline SegmentPlacer(const SegmentPlacer& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
36
37 META_Object(osgParticle, SegmentPlacer);
38
39 /// get vertex <B>A</B>.
40 inline const osg::Vec3& getVertexA() const;
41
42 /// Set vertex <B>A</B> of the segment as a vector.
43 inline void setVertexA(const osg::Vec3& v);
44
45 /// Set vertex <B>A</B> of the segment as three floats.
46 inline void setVertexA(float x, float y, float z);
47
48 /// get vertex <B>B</B>.
49 inline const osg::Vec3& getVertexB() const;
50
51 /// Set vertex <B>B</B> of the segment as a vector.
52 inline void setVertexB(const osg::Vec3& v);
53
54 /// Set vertex <B>B</B> of the segment as three floats.
55 inline void setVertexB(float x, float y, float z);
56
57 /// Set both vertices.
58 inline void setSegment(const osg::Vec3& A, const osg::Vec3& B);
59
60 /// Place a particle. This method is called by <CODE>ModularEmitter</CODE>, do not call it manually.
61 inline void place(Particle* P) const;
62
63 /// return the length of the segment
64 inline float volume() const;
65
66 /// return the control position
67 inline osg::Vec3 getControlPosition() const;
68
69 protected:
70 virtual ~SegmentPlacer() {}
71 SegmentPlacer& operator=(const SegmentPlacer&) { return *this; }
72
73 private:
74 osg::Vec3 _vertexA;
75 osg::Vec3 _vertexB;
76 };
77
78 // INLINE FUNCTIONS
79
80 inline SegmentPlacer::SegmentPlacer()
81 : Placer(), _vertexA(-1, 0, 0), _vertexB(1, 0, 0)
82 {
83 }
84
85 inline SegmentPlacer::SegmentPlacer(const SegmentPlacer& copy, const osg::CopyOp& copyop)
86 : Placer(copy, copyop), _vertexA(copy._vertexA), _vertexB(copy._vertexB)
87 {
88 }
89
90 inline const osg::Vec3& SegmentPlacer::getVertexA() const
91 {
92 return _vertexA;
93 }
94
95 inline const osg::Vec3& SegmentPlacer::getVertexB() const
96 {
97 return _vertexB;
98 }
99
100 inline void SegmentPlacer::setSegment(const osg::Vec3& A, const osg::Vec3& B)
101 {
102 _vertexA = A;
103 _vertexB = B;
104 }
105
106 inline void SegmentPlacer::place(Particle* P) const
107 {
108 P->setPosition(rangev3(_vertexA, _vertexB).get_random());
109 }
110
111 inline float SegmentPlacer::volume() const
112 {
113 return (_vertexB - _vertexA).length();
114 }
115
116 inline void SegmentPlacer::setVertexA(const osg::Vec3& v)
117 {
118 _vertexA = v;
119 }
120
121 inline void SegmentPlacer::setVertexA(float x, float y, float z)
122 {
123 _vertexA.set(x, y, z);
124 }
125
126 inline void SegmentPlacer::setVertexB(const osg::Vec3& v)
127 {
128 _vertexB = v;
129 }
130
131 inline void SegmentPlacer::setVertexB(float x, float y, float z)
132 {
133 _vertexB.set(x, y, z);
134 }
135
136 inline osg::Vec3 SegmentPlacer::getControlPosition() const
137 {
138 return (_vertexA+_vertexB)*0.5f;
139 }
140
141
142}
143
144#endif