示例#1
0
//------------------------------------------------------------------------
// Callback function called before rendering the scene.
//------------------------------------------------------------------------
void LightShadowApp::OnEngineRunningA(void)
{
    FlySceneManager* pManager = FlyKernel::Instance().GetActiveSceneManager();

    FlyQuat qX,qY,quat;
    qX.FromAngleAxis( FlyVector(1.0f,0.0f,0.0f),m_fRotX );
    qY.FromAngleAxis( FlyVector(0.0f,1.0f,0.0f),m_fRotY );
    quat = qX * qY;

    FlySceneNode* pNode = pManager->GetSceneRoot()->GetChildNode(0);
    pNode->SetPosition( m_vPos );
    pNode->SetOrientation( quat );
    pNode->SetScale( FlyVector(m_fScale,m_fScale,m_fScale) );

    // Get the camera of the scene.
    FlyCameraBase* pCamera = FlyKernel::Instance().GetActiveSceneManager()->GetCurrentCamera();

    if( m_bKeystate[0] )
        pCamera->Yaw( -0.05f );
    if( m_bKeystate[1] )
        pCamera->Yaw( 0.05f );
    if( m_bKeystate[2] )
        pCamera->MoveRelativeZ( 1.0f );
    if( m_bKeystate[3] )
        pCamera->MoveRelativeZ( -1.0f );
}
示例#2
0
//------------------------------------------------------------------------
// Callback function called before rendering the scene.
//------------------------------------------------------------------------
void ParticleViewerApp::OnEngineRunningA(void)
{
    FlySceneManager* pManager = FlyKernel::Instance().GetActiveSceneManager();

    FlyQuat qX,qY,quat;
    qX.FromAngleAxis( FlyVector(1.0f,0.0f,0.0f),m_fRotX );
    qY.FromAngleAxis( FlyVector(0.0f,1.0f,0.0f),m_fRotY );
    quat = qX * qY;

    pManager->GetSceneRoot()->SetPosition( m_vPos );
    pManager->GetSceneRoot()->SetOrientation( quat );
    pManager->GetSceneRoot()->SetScale( FlyVector(m_fScale,m_fScale,m_fScale) );
}
示例#3
0
//------------------------------------------------------------------------
// Build the world axis for the application.
//------------------------------------------------------------------------
HRESULT ParticleViewerApp::BuildWorldAxis( FlySceneManager* pManager )
{
    VERTEXL pVerts[94];
    memset( pVerts,0,sizeof(VERTEXL)*94 );

    for( int i=0;i<21;i++ )
    {
        if( i == 10 ) continue;
        int n = i > 10 ? i-1 : i;

        // Fill in the columns.
        pVerts[n*2+0].x = -100.0f + 10.0f * i;
        pVerts[n*2+0].y = 0.0f;
        pVerts[n*2+0].z = -100.0f;
        pVerts[n*2+0].color = 0xffff0000;

        pVerts[n*2+1].x = -100.0f + 10.0f * i;
        pVerts[n*2+1].y = 0.0f;
        pVerts[n*2+1].z = 100.0f;
        pVerts[n*2+1].color = 0xffff0000;

        // Fill in the rows.
        pVerts[40+n*2+0].x = -100.0f;
        pVerts[40+n*2+0].y = 0.0f;
        pVerts[40+n*2+0].z = -100.0f + 10.0f * i;
        pVerts[40+n*2+0].color = 0xffff0000;

        pVerts[40+n*2+1].x = 100.0f;
        pVerts[40+n*2+1].y = 0.0f;
        pVerts[40+n*2+1].z = -100.0f + 10.0f * i;
        pVerts[40+n*2+1].color = 0xffff0000;
    }

    pVerts[80].x = pVerts[82].z = -105.0f;
    pVerts[81].x = pVerts[83].z = 105.0f;
    pVerts[84].x = pVerts[86].x = 110.0f;
    pVerts[85].x = pVerts[87].x = 120.0f;
    pVerts[84].z = pVerts[87].z = 5.0f;
    pVerts[85].z = pVerts[86].z = -5.0f;
    pVerts[88].x = pVerts[91].x = -5.0f;
    pVerts[89].x = pVerts[93].x = 5.0f;
    pVerts[88].z = pVerts[89].z = 120.0f;
    pVerts[91].z = pVerts[93].z = 110.0f;
    pVerts[90] = pVerts[89];
    pVerts[92] = pVerts[91];
    for( int i=80;i<94;i++ ) pVerts[i].color = 0xff00ff00;

    FlyAabb box;
    box.vcMin = FlyVector( -120.0f,-5.0f,-120.0f );
    box.vcMax = FlyVector(  120.0f, 5.0f, 120.0f );

    FlyManualEntity* pEntity = pManager->CreateManualEntity( "WorldAxis" );
    FlyManualSubObj* pSubObj = pEntity->BeginSubObject( VF_DEFAULTNOLIGHT,RT_LINELIST );
    pSubObj->CreateGraphicBuffer( 94,0 );
    pSubObj->AddVertexData( 94,pVerts,box );
    pEntity->EndSubObject( pSubObj );

    pManager->GetSceneRoot()->AttachObject( (FlySceneObject*)pEntity );

    return FLY_OK;
}
示例#4
0
//------------------------------------------------------------------------
// Test the intersect with a segment.
// ----------------------------------------------------------------------
// Param -> IN:
//      const FlyVector&:   First point of the segment.
//      const FlyVector&:   Second point of the segment.
//      FlyVector*:         To store the point of intersection.
//------------------------------------------------------------------------
bool etTile::IntersectSegment( const FlyVector& vStart,const FlyVector& vEnd,
                               FlyVector* pOut )
{
    FlyVector vDir = vEnd - vStart;
    FlyVector vRay = vStart;

    // 1. Special case...
    if( vDir.x == 0 && vDir.z == 0 )
    {
        float h = m_pLevel->GetScaledHeightValue( vRay.x,vRay.z );

        if( (vStart.y <= h && vEnd.y >= h) ||
            (vStart.y >= h && vEnd.y <= h) )
        {
            if( pOut )
            {
                *pOut = vRay;
                pOut->y = h;
            }

            return true;
        }
        else
        {
            if( pOut ) *pOut = FlyVector( -1.0f,-1.0f,-1.0f );

            return false;
        }
    }

    vDir.Normalize();
    vRay += vDir;

    float h = m_pLevel->GetScaledHeightValue( vRay.x,vRay.z );
    while( vRay.x >= m_Bounds.vcMin.x &&
        vRay.x <= m_Bounds.vcMax.x &&
        vRay.z >= m_Bounds.vcMin.z &&
        vRay.z <= m_Bounds.vcMax.z )
    {
        if( vRay.y <= h )
        {
            if( pOut ) *pOut = vRay;

            return true;
        }
        else
        {
            vRay += vDir;
        }

        if( vRay.y - vEnd.y < 1.0f ) break;
    }

    if( vRay.x < m_Bounds.vcMin.x && m_pNeighbors[NB_WEST] != NULL )
        return m_pNeighbors[NB_WEST]->IntersectSegment( vRay,vEnd,pOut );
    else if( vRay.z < m_Bounds.vcMin.z && m_pNeighbors[NB_SOUTH] != NULL )
        return m_pNeighbors[NB_SOUTH]->IntersectSegment( vRay,vEnd,pOut );
    else if( vRay.x > m_Bounds.vcMax.x && m_pNeighbors[NB_EAST] != NULL )
        return m_pNeighbors[NB_EAST]->IntersectSegment( vRay,vEnd,pOut );
    else if( vRay.z > m_Bounds.vcMax.z && m_pNeighbors[NB_NORTH] != NULL )
        return m_pNeighbors[NB_NORTH]->IntersectSegment( vRay,vEnd,pOut );
    else
    {
        if( pOut ) *pOut = FlyVector( -1.0f,-1.0f,-1.0f );

        return false;
    }
}
示例#5
0
//------------------------------------------------------------------------
// Transform the vertices with the bone's matrix.
//------------------------------------------------------------------------
HRESULT FlyAnimation::AnimationVertices(void)
{
    bool bChanged = false;
    AVERTEX* pVertex;
    sVertexOrig* pVertex_Orig;
    FlyMatrix matA,matB;
    FlyVector sVectorA,sVectorB;
    FlyVector vFinal;

    // Get the current animation node.
    sAnimNode* pCurNode = &m_AnimGroup[m_nAnimID];

    FlyVector vBoxMin = FlyVector(  999999.0f, 999999.0f, 999999.0f );
    FlyVector vBoxMax = FlyVector( -999999.0f,-999999.0f,-999999.0f );

    for( UINT i=0;i<m_sHeader.nNumVerts;i++ )
    {
        pVertex = &m_pVertices[i];
        pVertex_Orig = &m_pVertices_Orig[i];

        vFinal.Set( 0.0f,0.0f,0.0f );

        // The first bone's effect.
        if( pVertex->fBone1 != (float)NULL_BONEID )
        {
            matA = pCurNode->pJoints[(UINT)pVertex->fBone1].mMatrix_Absolute;
            sVectorA.x = pVertex_Orig->fXYZ[0];
            sVectorA.y = pVertex_Orig->fXYZ[1];
            sVectorA.z = pVertex_Orig->fXYZ[2];
            sVectorA.RotateWith( matA );
            sVectorA += matA.GetTranslation();
            bChanged = true;
        }

        // The second bone's effect.
        if( pVertex->fBone2 != (float)NULL_BONEID )
        {
            matB = pCurNode->pJoints[(UINT)pVertex->fBone2].mMatrix_Absolute;
            sVectorB.x = pVertex_Orig->fXYZ[0];
            sVectorB.y = pVertex_Orig->fXYZ[1];
            sVectorB.z = pVertex_Orig->fXYZ[2];
            sVectorB.RotateWith( matB );
            sVectorB += matB.GetTranslation();
            bChanged = true;
        }

        // Blend the final position.
        vFinal = sVectorA*pVertex->fWeight1 + sVectorB*pVertex->fWeight2;

        if( bChanged )
        {
            pVertex->x = vFinal.x;
            pVertex->y = vFinal.y;
            pVertex->z = vFinal.z;
        }

//         pVertex->x = pVertex_Orig->fXYZ[0];
//         pVertex->y = pVertex_Orig->fXYZ[1];
//         pVertex->z = pVertex_Orig->fXYZ[2];

        // Calculate the boundingBox.
        if( pVertex->x < vBoxMin.x ) vBoxMin.x = pVertex->x;
        if( pVertex->y < vBoxMin.y ) vBoxMin.y = pVertex->y;
        if( pVertex->z < vBoxMin.z ) vBoxMin.z = pVertex->z;
        if( pVertex->x > vBoxMax.x ) vBoxMax.x = pVertex->x;
        if( pVertex->y > vBoxMax.y ) vBoxMax.y = pVertex->y;
        if( pVertex->z > vBoxMax.z ) vBoxMax.z = pVertex->z;

        bChanged = false;
    }

    m_BBox.vcMin = vBoxMin;
    m_BBox.vcMax = vBoxMax;

    return FLY_OK;
}
示例#6
0
//------------------------------------------------------------------------
void FlyMatrix::Rota(float x, float y, float z)
{
	Rota(FlyVector(x, y, z));
}
示例#7
0
//------------------------------------------------------------------------
FlyVector FlyMatrix::GetTranslation(void)
{
	return FlyVector(_41, _42, _43);
}