@@ -213,32 +213,7 @@ enum
213213
214214
215215// todo move this somewhere more useful.
216- // ------------------------------------------------------------------------------------------------
217- #if 0
218- static Real angleBetween(const Coord2D &vecA, const Coord2D &vecB)
219- {
220- Real lengthA = vecA->length();
221- if (lengthA < FLT_EPSILON) {
222- return 0.0f;
223- }
224-
225- Real lengthB = vecB->length();
226- if (lengthB < FLT_EPSILON) {
227- return 0.0f;
228- }
229-
230- Real dotProduct = (vecA->x * vecB->x + vecA->y * vecB->y);
231-
232- // If the dotproduct is 0.0, then they are orthogonal
233- if (dotProduct < FLT_EPSILON && dotProduct > -FLT_EPSILON) {
234- return vecB->x > 0.0f ? PI : 0.0f;
235- }
236-
237- Real cosTheta = dotProduct / (lengthA * lengthB);
238- Real theta = ACos(cosTheta);
239- return vecB->x > 0.0f ? theta : -theta;
240- }
241- #endif
216+ static Real angleBetween (const Coord2D *vecA, const Coord2D *vecB);
242217
243218// /////////////////////////////////////////////////////////////////////////////////////////////////
244219// Particle ///////////////////////////////////////////////////////////////////////////////////////
@@ -433,25 +408,11 @@ Bool Particle::update( void )
433408
434409 if (m_particleUpTowardsEmitter) {
435410 // adjust the up position back towards the particle
411+ static const Coord2D upVec = { 0 .0f , 1 .0f };
436412 Coord2D emitterDir;
437413 emitterDir.x = m_pos.x - m_emitterPos.x ;
438414 emitterDir.y = m_pos.y - m_emitterPos.y ;
439- #if 0
440- static const Coord2D upVec = { 0.0f, 1.0f };
441- m_angleZ = angleBetween(upVec, emitterDir) + PI;
442- #else
443- if (emitterDir.y < FLT_EPSILON && emitterDir.y > -FLT_EPSILON ) {
444- m_angleZ = emitterDir.x > 0 .0f ? PI + PI : PI ;
445- } else {
446- Real emitterDirLength = emitterDir.length ();
447- if (emitterDirLength < FLT_EPSILON ) {
448- m_angleZ = PI ;
449- } else {
450- Real theta = ACos (emitterDir.y /emitterDirLength);
451- m_angleZ = emitterDir.x > 0 .0f ? PI + theta : PI - theta;
452- }
453- }
454- #endif
415+ m_angleZ = (angleBetween (&upVec, &emitterDir) + PI );
455416 }
456417
457418 // update size
@@ -3495,3 +3456,33 @@ void ParticleSystemDebugDisplay( DebugDisplayInterface *dd, void *, FILE *fp )
34953456}
34963457
34973458// ------------------------------------------------------------------------------------------------
3459+ // ------------------------------------------------------------------------------------------------
3460+ static Real angleBetween (const Coord2D *vecA, const Coord2D *vecB)
3461+ {
3462+ if (!(vecA && vecA->length () && vecB && vecB->length ())) {
3463+ return 0.0 ;
3464+ }
3465+
3466+ Real lengthA = vecA->length ();
3467+ Real lengthB = vecB->length ();
3468+ Real dotProduct = (vecA->x * vecB->x + vecA->y * vecB->y );
3469+ Real cosTheta = dotProduct / (lengthA * lengthB);
3470+
3471+ // If the dotproduct is 0.0, then they are orthogonal
3472+ if (dotProduct == 0 .0f ) {
3473+ if (vecB->x > 0 ) {
3474+ return PI ;
3475+ }
3476+
3477+ return 0 .0f ;
3478+ }
3479+
3480+ Real theta = ACos ( cosTheta );
3481+
3482+ if (vecB->x > 0 ) {
3483+ return theta;
3484+ }
3485+
3486+ return -theta;
3487+ }
3488+
0 commit comments