-------------------------------------------------------------------------------------- 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
| 62 | // The generator fills position and/or velocity of the new particle. |
| 63 | // -------------------------------------------------------------------------------------- |
| 64 | void Tr2CapsuleShapeAttributeGenerator::Generate( const Vector3* position, |
| 65 | const Vector3* velocity, |
| 66 | float** particle ) |
| 67 | { |
| 68 | if( !m_valid ) |
| 69 | { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | float phi = XMConvertToRadians( frand( m_minPhi, m_maxPhi ) ); |
| 74 | float theta = XMConvertToRadians( frand( m_minTheta, m_maxTheta ) ); |
| 75 | |
| 76 | // This is not exactly uniform, but it doesn't matter |
| 77 | XMVECTOR randomVector = XMVectorSet( sin( phi ) * cos( theta ), |
| 78 | -cos( phi ), |
| 79 | sin( phi ) * sin( theta ), |
| 80 | 0.f ); |
| 81 | float t = frand( 0.f, 1.f ); |
| 82 | XMVECTOR rotation = XMQuaternionSlerp( m_rotationStart, m_rotationEnd, t ); |
| 83 | randomVector = XMQuaternionMultiply( |
| 84 | XMQuaternionMultiply( XMQuaternionConjugate( rotation ), randomVector ), |
| 85 | rotation ); |
| 86 | |
| 87 | if( m_controlVelocity && m_velocityElement.m_offset != -1 ) |
| 88 | { |
| 89 | float speed = frand( m_minSpeed, m_maxSpeed ); |
| 90 | XMVECTOR particleVelocity = XMVectorScale( randomVector, speed ); |
| 91 | if( velocity ) |
| 92 | { |
| 93 | particleVelocity = XMVectorAdd( |
| 94 | particleVelocity, |
| 95 | XMVectorScale( XMLoadFloat4A( reinterpret_cast<const XMFLOAT4A*>( velocity ) ), m_parentVelocityFactor ) ); |
| 96 | } |
| 97 | XMStoreFloat4A( |
| 98 | reinterpret_cast<XMFLOAT4A*>( particle[m_velocityElement.m_bufferType] + m_velocityElement.m_offset ), |
| 99 | particleVelocity ); |
| 100 | } |
| 101 | if( m_positionElement.m_offset != -1 ) |
| 102 | { |
| 103 | randomVector = XMVectorScale( randomVector, frand( m_minRadius, m_maxRadius ) ); |
| 104 | if( position ) |
| 105 | { |
| 106 | randomVector = XMVectorAdd( |
| 107 | randomVector, |
| 108 | XMLoadFloat4A( reinterpret_cast<const XMFLOAT4A*>( position ) ) ); |
| 109 | } |
| 110 | randomVector = XMVectorAdd( |
| 111 | randomVector, |
| 112 | XMVectorLerp( |
| 113 | XMLoadFloat4( reinterpret_cast<const XMFLOAT4*>( &m_positionStart ) ), |
| 114 | XMLoadFloat4( reinterpret_cast<const XMFLOAT4*>( &m_positionEnd ) ), |
| 115 | t ) ); |
| 116 | XMStoreFloat4A( |
| 117 | reinterpret_cast<XMFLOAT4A*>( particle[m_positionElement.m_bufferType] + m_positionElement.m_offset ), |
| 118 | randomVector ); |
| 119 | } |
| 120 | } |
| 121 |