-------------------------------------------------------------------------------------- Description: Implements ITr2AttributeGenerator interface. Generates random values for new particle component (element). Arguments: position - Position of the "parent" particle. velocity - Velocity of the "parent" particle. paticle - (out) New particle data: Tr2ParticleElementData::COUNT of float arrays. The gene
| 67 | // The generator fills position and/or velocity of the new particle. |
| 68 | // -------------------------------------------------------------------------------------- |
| 69 | void Tr2SphereShapeAttributeGenerator::Generate( const Vector3* position, |
| 70 | const Vector3* velocity, |
| 71 | float** particle ) |
| 72 | { |
| 73 | if( !m_valid || ( !m_controlPosition && !m_controlVelocity ) ) |
| 74 | { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | float phi = XMConvertToRadians( frand( m_minPhi, m_maxPhi ) ); |
| 79 | float theta = XMConvertToRadians( frand( m_minTheta, m_maxTheta ) ); |
| 80 | |
| 81 | // This is not exactly uniform, but it doesn't matter |
| 82 | XMVECTOR randomVector = XMVectorSet( sin( phi ) * cos( theta ), |
| 83 | -cos( phi ), |
| 84 | sin( phi ) * sin( theta ), |
| 85 | 0.f ); |
| 86 | |
| 87 | randomVector = XMQuaternionMultiply( |
| 88 | XMQuaternionMultiply( XMQuaternionConjugate( m_rotation ), randomVector ), |
| 89 | m_rotation ); |
| 90 | |
| 91 | if( m_controlVelocity && m_velocityElement.m_offset != -1 ) |
| 92 | { |
| 93 | float speed = frand( m_minSpeed, m_maxSpeed ); |
| 94 | XMVECTOR particleVelocity = XMVectorScale( randomVector, speed ); |
| 95 | if( velocity ) |
| 96 | { |
| 97 | particleVelocity = XMVectorAdd( |
| 98 | particleVelocity, |
| 99 | XMVectorScale( XMLoadFloat4A( reinterpret_cast<const XMFLOAT4A*>( velocity ) ), m_parentVelocityFactor ) ); |
| 100 | } |
| 101 | XMStoreFloat4A( |
| 102 | reinterpret_cast<XMFLOAT4A*>( particle[m_velocityElement.m_bufferType] + m_velocityElement.m_offset ), |
| 103 | particleVelocity ); |
| 104 | } |
| 105 | if( m_controlPosition && m_positionElement.m_offset != -1 ) |
| 106 | { |
| 107 | auto radius = frand( m_minRadius, m_maxRadius, m_distributionExponent ); |
| 108 | randomVector = XMVectorScale( randomVector, radius ); |
| 109 | if( position ) |
| 110 | { |
| 111 | randomVector = XMVectorAdd( |
| 112 | randomVector, |
| 113 | XMLoadFloat4A( reinterpret_cast<const XMFLOAT4A*>( position ) ) ); |
| 114 | } |
| 115 | randomVector = XMVectorAdd( |
| 116 | randomVector, |
| 117 | XMLoadFloat4( reinterpret_cast<const XMFLOAT4*>( &m_position ) ) ); |
| 118 | XMStoreFloat4A( |
| 119 | reinterpret_cast<XMFLOAT4A*>( particle[m_positionElement.m_bufferType] + m_positionElement.m_offset ), |
| 120 | randomVector ); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // -------------------------------------------------------------------------------------- |
| 125 | // Description: |
no test coverage detected