Example #1
0
void dxRenderSphere(Sphere* sphere, const Color* color, Matrix* ltm)
{    
    Vector circleVertex[SPHERE_DETAILS +1];
    Line   circleLines[SPHERE_DETAILS];

    // generate circle in XY plane
	int i;
    for( i=0; i<SPHERE_DETAILS + 1; i++)
    {
        circleVertex[i].x = cos(i / (SPHERE_DETAILS / 2.0f) * D3DX_PI) * sphere->radius;
        circleVertex[i].y = sin(i / (SPHERE_DETAILS / 2.0f) * D3DX_PI) * sphere->radius; 
        circleVertex[i].z = 0;
    }    
    for( i=0; i<SPHERE_DETAILS; i++ ) 
    {
        circleLines[i].start = circleVertex[i], circleLines[i].end = circleVertex[i+1];
    }

    Matrix m;
    Vector temp( 1,1,0 );
    Vector scale, translation;
    float  transf;
    for( i=0; i<SPHERE_BELTS; i++ )
    {
        D3DXMatrixIdentity( &m );
        dxRotate( &m, &oY, 180.0f / SPHERE_BELTS * i );
        dxTranslate( &m, &sphere->center );
        dxRenderLines( SPHERE_DETAILS, circleLines, color, &m );

        D3DXMatrixIdentity( &m );
        transf = 1.0f/(SPHERE_BELTS)*i;
        scale = temp * sin( acos( transf ) );        
        dxScale( &m, &scale );
        translation = Vector( 0,0, transf * sphere->radius );        
        dxTranslate( &m, &translation );
        dxRotate( &m, &oX, 90 );
        dxTranslate( &m, &sphere->center );       
        dxRenderLines( SPHERE_DETAILS, circleLines, color, &m );

        D3DXMatrixIdentity( &m );
        dxScale( &m, &scale );
        translation = Vector( 0,0, -transf * sphere->radius );        
        dxTranslate( &m, &translation );
        dxRotate( &m, &oX, 90 );
        dxTranslate( &m, &sphere->center );
        dxRenderLines( SPHERE_DETAILS, circleLines, color, &m );
    }
}
Example #2
0
void Frame::rotateRelative(const Vector3f& axis, float angle)
{
    Vector pos = dxPos( &TransformationMatrix );
    TransformationMatrix._41 = 
    TransformationMatrix._42 = 
    TransformationMatrix._43 = 0.0f;
    TransformationMatrix._44 = 1.0f;
    dxRotate( &TransformationMatrix, &wrap( axis ), angle );
    TransformationMatrix._41 = pos.x,
    TransformationMatrix._42 = pos.y,
    TransformationMatrix._43 = pos.z,
    TransformationMatrix._44 = 1.0f;
    dirty();
}
Example #3
0
void Frame::rotate(const Vector3f& axis, float angle)
{
    dxRotate( &TransformationMatrix, &wrap( axis ), angle );
    dirty();
}
Example #4
0
void Rain::onUpdate(float dt)
{
    // actual dt
    dt *= _propTimeSpeed;

    // squared size of emission sphere
    float emissionSphereSq = _emissionSphere * _emissionSphere;

    // offset of emission center
    _centerOffset = _propCenter - _centerOffset;
    bool predictionIsAvaiable = ( D3DXVec3LengthSq( &_centerOffset ) < emissionSphereSq );

    // rough speed of emission center
    D3DXVec3Scale( &_centerVelocity, &_centerOffset, 1.0f/dt );

    // motion direction of of emission center
    Vector centerMotionN;
    D3DXVec3Normalize( &centerMotionN, &_centerVelocity );

    // normal of particle velocity
    Vector velocityN;
    D3DXVec3Normalize( &velocityN, &_propVelocity );

    // magnitude of particle initial velocity
    float velocityM = D3DXVec3Length( &_propVelocity );

    // pass all of particles
    Vector r,axis;
    Matrix m;
    float space;
    RainParticle* particle;    
    unsigned int i;
    for( i=0; i<_numParticles; i++ )
    {
        // current particle
        particle = _particles + i;
        // check particle is outside of emission sphere
        D3DXVec3Subtract( &r, &particle->pos, &_propCenter );
        if( D3DXVec3LengthSq( &r ) > emissionSphereSq )
        {
            // randomize position
            if( predictionIsAvaiable ) 
            {
                r.x = getCore()->getRandToolkit()->getUniform( -1,1 );
                r.y = getCore()->getRandToolkit()->getUniform( -1,1 );
                r.z = getCore()->getRandToolkit()->getUniform( -1,1 );
                D3DXVec3Normalize( &r, &r );
                r += centerMotionN;
            }
            else
            {
                r.x = getCore()->getRandToolkit()->getUniform( -1,1 );
                r.y = getCore()->getRandToolkit()->getUniform( -1,1 );
                r.z = getCore()->getRandToolkit()->getUniform( -1,1 );
            }
            D3DXVec3Normalize( &r, &r );
            space = getCore()->getRandToolkit()->getUniform( 0, _emissionSphere );
            D3DXVec3Scale( &particle->pos, &r, space );
            particle->pos += _propCenter;
            // predict position by velocity of emission center
            if( predictionIsAvaiable ) particle->pos += _centerVelocity * dt;

            // setup particle velocity
            if( _propNBias > 0 )
            {
                m = identity;
                axis.x = getCore()->getRandToolkit()->getUniform( -1,1 );
                axis.y = getCore()->getRandToolkit()->getUniform( -1,1 );
                axis.z = getCore()->getRandToolkit()->getUniform( -1,1 );
                D3DXVec3Normalize( &axis, &axis );
                dxRotate( &m, &axis, getCore()->getRandToolkit()->getUniform( - _propNBias, _propNBias ) );
                D3DXVec3TransformNormal( &r, &velocityN, &m );
                D3DXVec3Scale( &particle->vel, &r, velocityM );
            }
            else
            {
                particle->vel = _propVelocity;
            }
            // carefully move particle towards edge of emission sphere
            // (this feature avaiable is for each second particle)
            if( _useEdgeOffset )
            {
                _useEdgeOffset = 0;
                D3DXVec3Normalize( &r, &particle->vel );
                space = _emissionSphere - space;
                r.x *= space, r.y *= space, r.z *= space;
                particle->pos -= r;
            }
            else
            {
                _useEdgeOffset = 1;
            }
        }
    }

    // pass all of particles
    for( i=0; i<_numParticles; i++ )
    {
        // current particle
        particle = _particles + i;
        // move particle
        particle->pos += particle->vel * dt;
    }

    // store current emission center
    _centerOffset = _propCenter;
}