00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022
00023 #ifndef H_SPK_ORIENTED2DRENDERERINTERFACE
00024 #define H_SPK_ORIENTED2DRENDERERINTERFACE
00025
00026 #include "Core/SPK_Vector3D.h"
00027 #include "Core/SPK_Group.h"
00028
00029 namespace SPK
00030 {
00035 enum Orientation2D
00036 {
00037 ORIENTATION2D_UP,
00038 ORIENTATION2D_DIRECTION,
00039 ORIENTATION2D_POINT,
00040 ORIENTATION2D_AXIS
00041 };
00042
00043
00048 class Oriented2DRendererInterface
00049 {
00050 public :
00051
00053
00055
00066 Vector3D orientationVector;
00067
00069
00071
00073 Oriented2DRendererInterface();
00074
00076
00078
00080 virtual ~Oriented2DRendererInterface() {}
00081
00083
00085
00090 void setOrientation(Orientation2D orientation);
00091
00093
00095
00100 Orientation2D getOrientation() const;
00101
00102 protected :
00103
00104 Orientation2D orientation;
00105
00106 bool hasGlobalOrientation();
00107 void computeGlobalOrientation2D();
00108 void computeSingleOrientation2D(const Particle& particle);
00109
00110 void scaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const;
00111 void rotateAndScaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const;
00112
00113 const Vector3D& quadUp() const;
00114 const Vector3D& quadSide() const;
00115
00116 private :
00117
00118
00119 mutable Vector3D up;
00120 mutable Vector3D side;
00121
00122
00123 mutable Vector3D sideQuad;
00124 mutable Vector3D upQuad;
00125 };
00126
00127
00128 inline Oriented2DRendererInterface::Oriented2DRendererInterface() :
00129 orientation(ORIENTATION2D_UP)
00130 {
00131 orientationVector.set(0.0f,-1.0f);
00132 }
00133
00134 inline void Oriented2DRendererInterface::setOrientation(Orientation2D orientation)
00135 {
00136 this->orientation = orientation;
00137 }
00138
00139 inline Orientation2D Oriented2DRendererInterface::getOrientation() const
00140 {
00141 return orientation;
00142 }
00143
00144 inline const Vector3D& Oriented2DRendererInterface::quadUp() const
00145 {
00146 return upQuad;
00147 }
00148
00149 inline const Vector3D& Oriented2DRendererInterface::quadSide() const
00150 {
00151 return sideQuad;
00152 }
00153
00154 inline bool Oriented2DRendererInterface::hasGlobalOrientation()
00155 {
00156 return ((orientation == ORIENTATION2D_UP)||(ORIENTATION2D_AXIS));
00157 }
00158
00159 inline void Oriented2DRendererInterface::computeGlobalOrientation2D()
00160 {
00161 if (orientation == ORIENTATION2D_UP)
00162 up.set(0.0f,-0.5f);
00163 else if (orientation == ORIENTATION2D_AXIS)
00164 {
00165 up.set(orientationVector.x,orientationVector.y);
00166 up.normalize();
00167 up *= 0.5f;
00168 }
00169 }
00170
00171 inline void Oriented2DRendererInterface::computeSingleOrientation2D(const Particle& particle)
00172 {
00173 if (orientation == ORIENTATION2D_DIRECTION)
00174 up = particle.velocity();
00175 else if (orientation == ORIENTATION2D_POINT)
00176 {
00177 up = orientationVector;
00178 up -= particle.position();
00179 }
00180
00181 up.z = 0.0f;
00182 up.normalize();
00183 up *= 0.5f;
00184 }
00185
00186 inline void Oriented2DRendererInterface::scaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const
00187 {
00188 float size = particle.getParamCurrentValue(PARAM_SIZE);
00189
00190 upQuad.set(up.x,up.y);
00191 upQuad *= size * scaleY;
00192
00193 sideQuad.set(-up.y,up.x);
00194 sideQuad *= size * scaleX;
00195 }
00196
00197 inline void Oriented2DRendererInterface::rotateAndScaleQuadVectors(const Particle& particle,float scaleX,float scaleY) const
00198 {
00199 float size = particle.getParamCurrentValue(PARAM_SIZE);
00200
00201 float angleTexture = particle.getParamCurrentValue(PARAM_ANGLE);
00202 float cosA = std::cos(angleTexture);
00203 float sinA = std::sin(angleTexture);
00204
00205 upQuad.x = cosA * up.x + sinA * up.y;
00206 upQuad.y = -sinA * up.x + cosA * up.y;
00207 upQuad.z = 0.0f;
00208
00209 sideQuad.set(-upQuad.y,upQuad.x);
00210
00211 sideQuad *= size * scaleX;
00212 upQuad *= size * scaleY;
00213 }
00214 }
00215
00216 #endif