-------------------------------------------------------------------------------------- Description: Implements ITr2AttributeGenerator interface. Generates unit-length random vector for new particle component (element). Arguments: position - Position of the "parent" particle (unused). velocity - Velocity of the "parent" particle (unused). paticle - (out) New particle data: Tr2ParticleElementData::C
| 35 | // The generator fills element identified by generator's m_name with random values. |
| 36 | // -------------------------------------------------------------------------------------- |
| 37 | void Tr2RandomDirectionAttributeGenerator::Generate( const Vector3* position, |
| 38 | const Vector3* velocity, |
| 39 | float** particle ) |
| 40 | { |
| 41 | if( !m_valid ) |
| 42 | { |
| 43 | return; |
| 44 | } |
| 45 | Vector4 randomDirection( 0.0f, 0.0f, 0.0f, 0.0f ); |
| 46 | float length = 0; |
| 47 | { |
| 48 | for( unsigned i = 0; i < m_element.m_dimension; ++i ) |
| 49 | { |
| 50 | randomDirection[i] = -1.f + 2.f * Tr2ParticleSystem::RandFloat(); |
| 51 | length += randomDirection[i] * randomDirection[i]; |
| 52 | } |
| 53 | } |
| 54 | if( length == 0.0f ) |
| 55 | { |
| 56 | randomDirection.x = 1.0f; |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | randomDirection /= sqrt( length ); |
| 61 | } |
| 62 | float* data = particle[m_element.m_bufferType] + m_element.m_offset; |
| 63 | for( unsigned i = 0; i < m_element.m_dimension; ++i ) |
| 64 | { |
| 65 | data[i] = randomDirection[i]; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // -------------------------------------------------------------------------------------- |
| 70 | // Description: |
nothing calls this directly
no test coverage detected