1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright ) 2002 Tels <http://bloodgate.com> Based on OgrreBoxEmitter |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreAreaEmitter.h" |
---|
30 | #include "OgreParticle.h" |
---|
31 | #include "OgreQuaternion.h" |
---|
32 | #include "OgreException.h" |
---|
33 | #include "OgreStringConverter.h" |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | namespace Ogre { |
---|
38 | |
---|
39 | // Instatiate statics |
---|
40 | AreaEmitter::CmdWidth AreaEmitter::msWidthCmd; |
---|
41 | AreaEmitter::CmdHeight AreaEmitter::msHeightCmd; |
---|
42 | AreaEmitter::CmdDepth AreaEmitter::msDepthCmd; |
---|
43 | |
---|
44 | //----------------------------------------------------------------------- |
---|
45 | bool AreaEmitter::initDefaults(const String& t) |
---|
46 | { |
---|
47 | // called by the constructor as initDefaults("Type") |
---|
48 | |
---|
49 | // Defaults |
---|
50 | mDirection = Vector3::UNIT_Z; |
---|
51 | mUp = Vector3::UNIT_Y; |
---|
52 | setSize(100,100,100); |
---|
53 | mType = t; |
---|
54 | |
---|
55 | // Set up parameters |
---|
56 | if (createParamDictionary(mType + "Emitter")) |
---|
57 | { |
---|
58 | |
---|
59 | addBaseParameters(); |
---|
60 | ParamDictionary* dict = getParamDictionary(); |
---|
61 | |
---|
62 | // Custom params |
---|
63 | dict->addParameter(ParameterDef("width", |
---|
64 | "Width of the shape in world coordinates.", |
---|
65 | PT_REAL),&msWidthCmd); |
---|
66 | dict->addParameter(ParameterDef("height", |
---|
67 | "Height of the shape in world coordinates.", |
---|
68 | PT_REAL),&msHeightCmd); |
---|
69 | dict->addParameter(ParameterDef("depth", |
---|
70 | "Depth of the shape in world coordinates.", |
---|
71 | PT_REAL),&msDepthCmd); |
---|
72 | return true; |
---|
73 | |
---|
74 | } |
---|
75 | return false; |
---|
76 | } |
---|
77 | |
---|
78 | //----------------------------------------------------------------------- |
---|
79 | unsigned short AreaEmitter::_getEmissionCount(Real timeElapsed) |
---|
80 | { |
---|
81 | // Use basic constant emission |
---|
82 | return genConstantEmissionCount(timeElapsed); |
---|
83 | } |
---|
84 | //----------------------------------------------------------------------- |
---|
85 | void AreaEmitter::setDirection( const Vector3& direction ) |
---|
86 | { |
---|
87 | ParticleEmitter::setDirection( direction ); |
---|
88 | |
---|
89 | // Update the ranges |
---|
90 | genAreaAxes(); |
---|
91 | |
---|
92 | |
---|
93 | } |
---|
94 | //----------------------------------------------------------------------- |
---|
95 | void AreaEmitter::setSize(const Vector3& size) |
---|
96 | { |
---|
97 | mSize = size; |
---|
98 | genAreaAxes(); |
---|
99 | } |
---|
100 | //----------------------------------------------------------------------- |
---|
101 | void AreaEmitter::setSize(Real x, Real y, Real z) |
---|
102 | { |
---|
103 | mSize.x = x; |
---|
104 | mSize.y = y; |
---|
105 | mSize.z = z; |
---|
106 | genAreaAxes(); |
---|
107 | } |
---|
108 | //----------------------------------------------------------------------- |
---|
109 | void AreaEmitter::setWidth(Real width) |
---|
110 | { |
---|
111 | mSize.x = width; |
---|
112 | genAreaAxes(); |
---|
113 | } |
---|
114 | //----------------------------------------------------------------------- |
---|
115 | Real AreaEmitter::getWidth(void) const |
---|
116 | { |
---|
117 | return mSize.x; |
---|
118 | } |
---|
119 | //----------------------------------------------------------------------- |
---|
120 | void AreaEmitter::setHeight(Real height) |
---|
121 | { |
---|
122 | mSize.y = height; |
---|
123 | genAreaAxes(); |
---|
124 | } |
---|
125 | //----------------------------------------------------------------------- |
---|
126 | Real AreaEmitter::getHeight(void) const |
---|
127 | { |
---|
128 | return mSize.y; |
---|
129 | } |
---|
130 | //----------------------------------------------------------------------- |
---|
131 | void AreaEmitter::setDepth(Real depth) |
---|
132 | { |
---|
133 | mSize.z = depth; |
---|
134 | genAreaAxes(); |
---|
135 | } |
---|
136 | //----------------------------------------------------------------------- |
---|
137 | Real AreaEmitter::getDepth(void) const |
---|
138 | { |
---|
139 | return mSize.z; |
---|
140 | } |
---|
141 | //----------------------------------------------------------------------- |
---|
142 | void AreaEmitter::genAreaAxes(void) |
---|
143 | { |
---|
144 | Vector3 mLeft = mUp.crossProduct(mDirection); |
---|
145 | |
---|
146 | mXRange = mLeft * (mSize.x * 0.5f); |
---|
147 | mYRange = mUp * (mSize.y * 0.5f); |
---|
148 | mZRange = mDirection * (mSize.z * 0.5f); |
---|
149 | } |
---|
150 | |
---|
151 | //----------------------------------------------------------------------- |
---|
152 | // Command objects |
---|
153 | //----------------------------------------------------------------------- |
---|
154 | //----------------------------------------------------------------------- |
---|
155 | String AreaEmitter::CmdWidth::doGet(const void* target) const |
---|
156 | { |
---|
157 | return StringConverter::toString( |
---|
158 | static_cast<const AreaEmitter*>(target)->getWidth() ); |
---|
159 | } |
---|
160 | void AreaEmitter::CmdWidth::doSet(void* target, const String& val) |
---|
161 | { |
---|
162 | static_cast<AreaEmitter*>(target)->setWidth(StringConverter::parseReal(val)); |
---|
163 | } |
---|
164 | //----------------------------------------------------------------------- |
---|
165 | String AreaEmitter::CmdHeight::doGet(const void* target) const |
---|
166 | { |
---|
167 | return StringConverter::toString( |
---|
168 | static_cast<const AreaEmitter*>(target)->getHeight() ); |
---|
169 | } |
---|
170 | void AreaEmitter::CmdHeight::doSet(void* target, const String& val) |
---|
171 | { |
---|
172 | static_cast<AreaEmitter*>(target)->setHeight(StringConverter::parseReal(val)); |
---|
173 | } |
---|
174 | //----------------------------------------------------------------------- |
---|
175 | String AreaEmitter::CmdDepth::doGet(const void* target) const |
---|
176 | { |
---|
177 | return StringConverter::toString( |
---|
178 | static_cast<const AreaEmitter*>(target)->getDepth() ); |
---|
179 | } |
---|
180 | void AreaEmitter::CmdDepth::doSet(void* target, const String& val) |
---|
181 | { |
---|
182 | static_cast<AreaEmitter*>(target)->setDepth(StringConverter::parseReal(val)); |
---|
183 | } |
---|
184 | |
---|
185 | |
---|
186 | |
---|
187 | } |
---|
188 | |
---|
189 | |
---|