Example #1
0
 void OrbitCamera::startWithTarget(void *target)
 {
     ActionCamera::startWithTarget(target);
     
     // Get spherical radius
     //fzFloat r, zenith, azimuth;
     //sphericalRadius(r, zenith, azimuth);
     
     m_radZ = FZ_DEGREES_TO_RADIANS(m_angleZ);
     m_radX = FZ_DEGREES_TO_RADIANS(m_angleX);
 }
Example #2
0
 OrbitCamera::OrbitCamera(fzFloat duration, fzFloat radius, fzFloat deltaRadius, fzFloat angleZ, fzFloat deltaAngleZ, fzFloat angleX, fzFloat deltaAngleX)
 : ActionCamera(duration)
 , m_radius(radius)
 , m_deltaRadius(deltaRadius)
 , m_angleZ(angleZ)
 , m_deltaAngleZ(deltaAngleZ)
 , m_angleX(angleX)
 , m_deltaAngleX(deltaAngleX)
 , m_radDeltaZ(FZ_DEGREES_TO_RADIANS(deltaAngleZ))
 , m_radDeltaX(FZ_DEGREES_TO_RADIANS(deltaAngleX))
 { }
Example #3
0
    void fzMath_mat4PerspectiveProjection(fzFloat fovY, fzFloat aspect,
                                          fzFloat zNear, fzFloat zFar,
                                          float *output)
    {        
        FZ_ASSERT(output != NULL, "Output matrix cannot be NULL.");

        fzFloat r = FZ_DEGREES_TO_RADIANS(fovY / 2);
        fzFloat deltaZ = zFar - zNear;
        fzFloat s = fzMath_sin(r);
        fzFloat cotangent = 0;
        
        if (deltaZ == 0 || s == 0 || aspect == 0) {
            FZLOGERROR("Perpertive impossible.");
            return;
        }
        
        cotangent = fzMath_cos(r) / s;
        
        fzMath_mat4Identity(output);
        output[0] = cotangent / aspect;
        output[5] = cotangent;
        output[10] = -(zFar + zNear) / deltaZ;
        output[11] = -1;
        output[14] = -2 * zNear * zFar / deltaZ;
        output[15] = 0;
    }
Example #4
0
    void Director::updateProjection()
    {
        FZ_ASSERT(OSW::Instance(), "OS Wrapper is not defined.");

        updateViewRect();

        if(!(m_dirtyFlags & kFZDDirty_projection))
            return;
        
        // VIEW PORT
        // The view port must be the display size in pixels.
        // Display size is not equal to the screen size, an application could not use the whole screen.
        fzSize viewPort = getViewPort();
        glViewport(0, 0, viewPort.width, viewPort.height);
        
        
        // PROJECTION
        // The projection must be calculated using the canvas size. No pixels here.
        fzSize canvasSize = getCanvasSize();
        fzOrientation orientation = getOrientation();
        if(orientation == kFZOrientation_LandscapeLeft || orientation == kFZOrientation_LandscapeRight)
            FZ_SWAP(canvasSize.width, canvasSize.height);
        
        
        switch (m_projection) {
            case kFZProjection2D:
            {
                fzMath_mat4OrthoProjection(0, canvasSize.width, 0, canvasSize.height, -1024, 1024, m_transformMV);
                break;
            }
            default:
                FZ_RAISE("Director: Unrecognized projection.");
        }
        
        m_orientationTransform = FZAffineTransformIdentity;
        if(orientation == kFZOrientation_LandscapeLeft) {

            m_orientationTransform.translate(canvasSize.width, 0);
            m_orientationTransform.rotate(FZ_DEGREES_TO_RADIANS(90));
            
            fzMat4 mat;
            fzMath_mat4Multiply(m_transformMV, m_orientationTransform, mat);
            fzMath_mat4Copy(mat, m_transformMV);
            
        }else if(orientation == kFZOrientation_LandscapeRight) {
            m_orientationTransform.translate(0, canvasSize.height);
            m_orientationTransform.rotate(FZ_DEGREES_TO_RADIANS(-90));
            
            fzMat4 mat;
            fzMath_mat4Multiply(m_transformMV, m_orientationTransform, mat);
            fzMath_mat4Copy(mat, m_transformMV);
        }
        m_orientationTransform = m_orientationTransform.getInverse();
        
        m_dirtyFlags &= ~kFZDDirty_projection;

        if(p_runningScene) {
            p_runningScene->updateLayout();
            if(p_hud)
                p_hud->updateLayout();
        }
    }
    void ParticleSystem::initParticle(fzParticle& particle)
    {
        // time to live
        particle.timeToLive = m_life + m_lifeVar * FZ_RANDOM_MINUS1_1();
        if(particle.timeToLive < 0) particle.timeToLive = 0;
        
        // position
        particle.pos = m_sourcePosition + m_posVar * FZ_RANDOM_MINUS1_1();
        
        // color
        fzColor4F start(m_startColor.r + m_startColorVar.r * FZ_RANDOM_MINUS1_1(),
                      m_startColor.g + m_startColorVar.g * FZ_RANDOM_MINUS1_1(),
                      m_startColor.b + m_startColorVar.b * FZ_RANDOM_MINUS1_1(),
                      m_startColor.a + m_startColorVar.a * FZ_RANDOM_MINUS1_1());
        
        fzColor4F end(m_endColor.r + m_endColorVar.r * FZ_RANDOM_MINUS1_1(),
                    m_endColor.g + m_endColorVar.g * FZ_RANDOM_MINUS1_1(),
                    m_endColor.b + m_endColorVar.b * FZ_RANDOM_MINUS1_1(),
                    m_endColor.a + m_endColorVar.a * FZ_RANDOM_MINUS1_1());
        
        particle.color = start;
        particle.deltaColor = (end - start) * (1 / particle.timeToLive);
        
        // size
        fzFloat startS = m_startSize + m_startSizeVar * FZ_RANDOM_MINUS1_1();
        if(startS < 0) startS = 0;
        particle.size = startS;
        
        if( m_endSize == kFZParticleStartSizeEqualToEndSize )
            particle.deltaSize = 0;
        
        else {
            fzFloat endS = m_endSize + m_endSizeVar * FZ_RANDOM_MINUS1_1();
            if(endS < 0) endS = 0;

            particle.deltaSize = (endS - startS) / particle.timeToLive;
        }
        
        // rotation
        fzFloat startA = m_startSpin + m_startSpinVar * FZ_RANDOM_MINUS1_1();
        fzFloat endA = m_endSpin + m_endSpinVar * FZ_RANDOM_MINUS1_1();
        particle.rotation = startA;
        particle.deltaRotation = (endA - startA) / particle.timeToLive;
        
        
        // direction
        fzFloat a = FZ_DEGREES_TO_RADIANS( m_angle + m_angleVar * FZ_RANDOM_MINUS1_1() );	
        
        // Mode Gravity: A
        if( m_emitterMode == kFZParticleModeGravity ) {
            
            fzFloat s = mode.A.speed + mode.A.speedVar * FZ_RANDOM_MINUS1_1();
            
            // direction
            particle.mode.A.dir.x = fzMath_cos(a) * s;
            particle.mode.A.dir.y = fzMath_sin(a) * s;
            
            // radial accel
            particle.mode.A.radialAccel = mode.A.radialAccel + mode.A.radialAccelVar * FZ_RANDOM_MINUS1_1();
            
            // tangential accel
            particle.mode.A.tangentialAccel = mode.A.tangentialAccel + mode.A.tangentialAccelVar * FZ_RANDOM_MINUS1_1();
        }
        
        // Mode Radius: B
        else {
            // Set the default diameter of the particle from the source position
            fzFloat startRadius = mode.B.startRadius + mode.B.startRadiusVar * FZ_RANDOM_MINUS1_1();
            fzFloat endRadius = mode.B.endRadius + mode.B.endRadiusVar * FZ_RANDOM_MINUS1_1();
            
            particle.mode.B.radius = startRadius;
            
            particle.mode.B.deltaRadius = (mode.B.endRadius == kFZParticleStartRadiusEqualToEndRadius) ?
            0 : ((endRadius- startRadius) / particle.timeToLive);
            
            
            particle.mode.B.angle = a;
            particle.mode.B.degreesPerSecond = FZ_DEGREES_TO_RADIANS(mode.B.rotatePerSecond + mode.B.rotatePerSecondVar * FZ_RANDOM_MINUS1_1());
        }	
    }
 void ParticleSystemQuad::updateQuadWithParticle(const fzParticle& p)
 {
     // colors
     fzC4_T2_V2_Quad& quad = p_quads[m_particleIdx];
     
     fzColor4B color4B(p.color);
     quad.bl.color = color4B;
     quad.br.color = color4B;
     quad.tl.color = color4B;
     quad.tr.color = color4B;
     
     // vertices
     fzFloat size_2 = p.size/2;
     
     if( p.rotation ) {
         fzFloat x1 = -size_2;
         fzFloat y1 = -size_2;
         
         fzFloat& x2 = size_2;
         fzFloat& y2 = size_2;
         const fzFloat& x = p.pos.x;
         const fzFloat& y = p.pos.y;
         
         fzFloat r = -FZ_DEGREES_TO_RADIANS(p.rotation);
         fzFloat sr = fzMath_sin(r);
         fzFloat cr = fzMath_cos(r);
         
         fzFloat ax = x1 * cr - y1 * sr + x;
         fzFloat ay = x1 * sr + y1 * cr + y;
         fzFloat bx = x2 * cr - y1 * sr + x;
         fzFloat by = x2 * sr + y1 * cr + y;
         fzFloat cx = x2 * cr - y2 * sr + x;
         fzFloat cy = x2 * sr + y2 * cr + y;
         fzFloat dx = x1 * cr - y2 * sr + x;
         fzFloat dy = x1 * sr + y2 * cr + y;
         
         // bottom-left
         quad.bl.vertex.x = ax;
         quad.bl.vertex.y = ay;
         
         // bottom-right vertex:
         quad.br.vertex.x = bx;
         quad.br.vertex.y = by;
         
         // top-left vertex:
         quad.tl.vertex.x = dx;
         quad.tl.vertex.y = dy;
         
         // top-right vertex:
         quad.tr.vertex.x = cx;
         quad.tr.vertex.y = cy;
     } else {
         // bottom-left vertex:
         quad.bl.vertex.x = p.pos.x - size_2;
         quad.bl.vertex.y = p.pos.y - size_2;
         
         // bottom-right vertex:
         quad.br.vertex.x = p.pos.x + size_2;
         quad.br.vertex.y = p.pos.y - size_2;
         
         // top-left vertex:
         quad.tl.vertex.x = p.pos.x - size_2;
         quad.tl.vertex.y = p.pos.y + size_2;
         
         // top-right vertex:
         quad.tr.vertex.x = p.pos.x + size_2;
         quad.tr.vertex.y = p.pos.y + size_2;				
     }
 }