//----------------------------------------------------------------------------------------------------------------------------------------
// les 2 poly et les 6 vertx doivent etre a la suite
void CoupleOnePetals3D::Set(PolygonU3D* poly, VertexU3D* vertex, MaterialU3D* mat) {
    p1 = poly;
    p1->SetNbVertex(4);
    p1->m = mat;

    vertex[0].utilisateurs++;
    p1->Vtab[0] = &vertex[0];
    vertex[1].utilisateurs++;
    p1->Vtab[1] = &vertex[1];
    vertex[3].utilisateurs++;
    p1->Vtab[2] = &vertex[3];
    vertex[2].utilisateurs++;
    p1->Vtab[3] = &vertex[2];

    poly++;
    p2 = poly;
    p2->SetNbVertex(4);
    p2->m = mat;

    vertex[2].utilisateurs++;
    p2->Vtab[0] = &vertex[2];
    vertex[3].utilisateurs++;
    p2->Vtab[1] = &vertex[3];
    vertex[5].utilisateurs++;
    p2->Vtab[2] = &vertex[5];
    vertex[4].utilisateurs++;
    p2->Vtab[3] = &vertex[4];

    vertex[0].U = 0.0f;
    vertex[0].V = 0.0f;
    vertex[1].U = 1.0f;
    vertex[1].V = 0.0f;
    vertex[2].U = 0.0f;
    vertex[2].V = 0.5f;
    vertex[3].U = 1.0f;
    vertex[3].V = 0.5f;
    vertex[4].U = 0.0f;
    vertex[4].V = 1.0f;
    vertex[5].U = 1.0f;
    vertex[5].V = 1.0f;

    Ufloat sizex = DEFAULT_SIZEX*GetMass();
    Ufloat sizey = DEFAULT_SIZEY*GetMass();

    coord[0] = vertex[0].c;
    vec3_set(coord[0]->origine, -sizex, -sizey, 0.0f);
    coord[1] = vertex[1].c;
    vec3_set(coord[1]->origine, sizex, -sizey, 0.0f);
    coord[2] = vertex[2].c;
    vec3_set(coord[2]->origine, -sizex, 0.0f, sizex*.5f*Random1() - .25f*sizey);
    coord[3] = vertex[3].c;
    vec3_set(coord[3]->origine, sizex, 0.0f, sizex*.5f*Random1() - .25f*sizey);
    coord[4] = vertex[4].c;
    vec3_set(coord[4]->origine, -sizex, sizey, 0.0f);
    coord[5] = vertex[5].c;
    vec3_set(coord[5]->origine, sizex, sizey, 0.0f);
}
예제 #2
0
파일: kalman.c 프로젝트: jasongwq/readc
//============================================================================//
//==                          卡尔曼滤波                                    ==//
//============================================================================//
//==入口参数: 无                                                            ==//
//==出口参数: 无                                                            ==//
//==返回值:   无                                                            ==//
//============================================================================//
void KalMan(void)
{
  unsigned char   i;
  unsigned short  j;
  
  srand(SEED);
  for (i=0; i<X_LENGTH; i++)
  {
    tOpt.XPreOpt[i] = Temp2[i];           //零值初始化
  }
  for (i=0; i<P_LENGTH; i++)
  {
    tCov.PPreOpt[i] = Temp4[i];           //零值初始化
  }
  
  
  for (j=0; j<N; j++)
  {
    Watch1[j] = sin(2*3.14159265/100.0*j);
    Y[0] = Watch1[j] + Random1(0, 0.4);
    Watch2[j] = Y[0];
    MatrixMul(A, tOpt.XPreOpt, X, A_ROW, X_ROW, X_COLUMN);       //  基于系统的上一状态而预测现在状态; X(k|k-1) = A(k,k-1)*X(k-1|k-1)
    
    MatrixCal1(A, tCov.PPreOpt, Temp4, SYS_ORDER);
    MatrixAdd(Temp4, Q, P, P_ROW, P_COLUMN);                     //  预测数据的协方差矩阵; P(k|k-1) = A(k,k-1)*P(k-1|k-1)*A(k,k-1)'+Q
    
    MatrixCal2(C, P, Temp1, C_ROW, C_COLUMN);
    MatrixAdd(Temp1, R, Temp1, R_ROW, R_COLUMN);
    Gauss_Jordan(Temp1, C_ROW);
    MatrixTrans(C, Temp2, C_ROW, C_COLUMN);
    MatrixMul(P, Temp2, Temp22, P_ROW, C_COLUMN, C_ROW);
    MatrixMul(Temp22, Temp1, K, P_ROW, C_ROW, C_ROW);            //  计算卡尔曼增益; K(k) = P(k|k-1)*C' / (C(k)*P(k|k-1)*C(k)' + R)
    
    MatrixMul(C, X, Temp1, C_ROW, X_ROW, X_COLUMN);
    MatrixMinus(Y, Temp1, Temp1, Y_ROW, Y_COLUMN);
    MatrixMul(K, Temp1, Temp2, K_ROW, Y_ROW, Y_COLUMN);
    MatrixAdd(X, Temp2, tOpt.XNowOpt, X_ROW, X_COLUMN);          //  根据估测值和测量值计算当前最优值; X(k|k) = X(k|k-1)+Kg(k)*(Y(k)-C*X(k|k-1))
    
    MatrixMul(K, C, Temp4, K_ROW, C_ROW, C_COLUMN);
    MatrixMinus(I, Temp4, Temp4, I_ROW, I_COLUMN);
    MatrixMul(Temp4, P, tCov.PNowOpt, I_ROW, P_ROW, P_COLUMN);   //  计算更新后估计协防差矩阵; P(k|k) =(I-Kg(k)*C)*P(k|k-1)
    
    for (i=0; i<X_LENGTH; i++)
    {
      tOpt.XPreOpt[i] = tOpt.XNowOpt[i];
    }
    for (i=0; i<P_LENGTH; i++)
    {
      tCov.PPreOpt[i] = tCov.PNowOpt[i];
    }
    Watch3[j] = tOpt.XNowOpt[0];
    
  }//end of for
}
예제 #3
0
//----------------------------------------------------------------------------------------------------------------------------------------
void OneNebuRayon::Ini() {
    vec3_set(vec, 2.f*Random1() -1.f, 1.f*Random1() -.5f, 2.f*Random1() -1.f);
    vec3_normalize(vec);

    dist = NEBU_RAYON * Random1() * 2.f + BIGPART_SIZE;
    taille  = RAY_SIZE_MIN +    Random1()*RAY_SIZE_RND;

    totalTime = timeToGo =  RAY_LIFE_MIN + Random1()*RAY_LIFE_RND;
}
예제 #4
0
//----------------------------------------------------------------------------------------------------------------------------------------
void NeuroBackground::UpdateFrame(Ufloat laptime) {
    totaltime += laptime;

    DestroyBar->Affiche(laptime);
    DestroyBar->GetMaterial()->SetTex1Pos(0.0f, totaltime*DBAR_SPEED, 1.0f, 2.0f);

    DestroyTexte->Affiche(laptime);
    DestroyTexte->SetAlpha(fabs(sin(totaltime*3.f)));
    DestroyTexte->GetMaterial()->SetTex1Pos(0.0f, totaltime*DTEXTE_SPEED, 1.0f, 1.0f);

    Nenfants->Affiche(laptime);
    if (!Nenfants->IsInterpoYPos()) {
        Nenfants->SetUpLeftPos(GetUniXpos(260.0f), 1.0f);
        Nenfants->InterpoYPos(Nenfants->GetYpos(), -Nenfants->GetYpos(), 4.0f);
    }

    CleanTexte->Affiche(laptime);
    if (!CleanTexte->IsInterpoYPos()) {
        DestroyTexte->SetAlpha(.2f + .8f*fabs(cos(totaltime*5.f)));
        CleanTexte->SetUpLeftPos(GetUniXpos(400.0f)+GetUniXpos(200.0f)*Random1(), -CleanTexte->GetYSize()*.5f);
        CleanTexte->InterpoYPos(CleanTexte->GetYpos(), 1.f+CleanTexte->GetYSize(), 2.0f);
    }
}
//----------------------------------------------------------------------------------------------------------------------------------------
void CoupleOnePetals3D::Ini(Ufloat tapp, Ufloat tres, Ufloat tdisa, Ufloat pos[3], Ufloat vitesse[3]) {
    CoupleOnePetals::Ini(tapp, tres, tdisa, pos, vitesse);

    rot.SetFromAxis(Random1()*2.f - 1.f, Random1()*2.f - 1.f, Random1()*2.f - 1.f, 2.f*M_PI*Random1());
    incrot.SetFromAxis(Random1()*2.f - 1.f, Random1()*2.f - 1.f, Random1()*2.f - 1.f, .5f*M_PI*Random1() -.25f*M_PI);
}
예제 #6
0
//----------------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                  +---------------------------+
//                                  |  Class OneNebuParticule   |
//                                  +---------------------------+
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------------------------------------
OneNebuParticule::OneNebuParticule() {
    PosKeyFileU3D   allKey[11];
    Ufloat          disttmp;
    Ufloat          ydectmp;

    Ufloat  dist = (NEBU_RAYON /*- BIGPART_SIZE*.5f*/) * Random1()  + BIGPART_SIZE;
    Ufloat  angle = 2.f * M_PI * Random1();
    dist = .6f*dist + NEBU_RAYON*0.4f * sin(angle * 2.f * M_PI);
    Ufloat  anglespeed = ((1.0f - dist / NEBU_RAYON)* 30.f + 10.f) * .0174532925f;
    Ufloat  fact = 1.0f - dist / NEBU_RAYON;

    //-------------------- calcul decalage en Y
    Ufloat ydec = dist;
    if (ydec > 900.f)   ydec = 900.f;
    ydec = 350.f * (.5f + .5f*cos(M_PI * ydec / 900.f)) + 50.f * Random1() * (1.0f - dist /NEBU_RAYON);
    if (Random1()>.5f) ydec = -ydec;

    //------------------- calcul les déplacements
    for (U32 a=0; a<11; a++) {
        allKey[a].k.Ini();

        if (a< 6)
            allKey[a].k.time = (U32)(FRAMEPERSECOND* (a*5.f + 2.f*Random1() - 1.f));
        else if (a== 6)
            allKey[a].k.time = (U32)(FRAMEPERSECOND* (28.f + 1.f*Random1()));
        else if (a== 7)
            allKey[a].k.time = (U32)(FRAMEPERSECOND* (29.f + 1.f*Random1()));
        else if (a== 8)
            allKey[a].k.time = (U32)(FRAMEPERSECOND* (30.f + 1.f*Random1()));
        else if (a== 9)
            allKey[a].k.time = (U32)(FRAMEPERSECOND* (31.f + 1.f*Random1()));
        else if (a== 10)
            allKey[a].k.time = (U32)(FRAMEPERSECOND* (32.f + 1.f*Random1()));

        disttmp = dist + NEBU_RAYON*.05f * Random1() - NEBU_RAYON*.025f;
        ydectmp = ydec + ydec * .1f * Random1() - ydec * .05f;

        vec3_set(allKey[a].p, disttmp * cos(-angle) + BIGPART_X ,
                 ydectmp + BIGPART_Y,
                 disttmp * sin(-angle) + BIGPART_Z);

        switch (a) {
        case 7:
        case 8:
        case 9:
        case 10:
            angle += anglespeed*.6f /*+ .08f * Random1() - .04f*/;
            dist *= .9;
            break;

        default:
            angle += anglespeed + .14f * Random1() - .07f;
            break;
        }
    }

    //-------------------- alloue et calcul la spline
    mouvement = new SplineU3D(allKey, 11);

    //-------------------- calcul taille et couleur
    size = PART_SIZE_MIN + PART_SIZE_RND * Random1();
    vec4_set(RVBA, PART_RFACT*(1.f-fact) + fact, PART_VFACT*(1.f-fact) + fact, PART_BFACT*(1.f-fact) + fact, 0.6f);
    vec3_mul(RVBA, RVBA, Random1()*(1.f-fact) + fact);
}
예제 #7
0
void WINAPI OeilPart::SynchrosMess(SynchroTick* sync, Ufloat relativeTime, U32 syncNum, U32 user) {
    switch (syncNum) {
        //----------------- roulement de batterie a la fin
    case 0:
        if (!Deformation) {  // cas ou on serai deja passé par une allocation par synchro 1
            Deformation = new OeilDefor;
            TextureManager::LoadAll();   // load toute les textures

            Deformation->SetEnable(TRUE);
            CilsPart::Initialise(Scheduler,  0);     // ini la partie des cils
            CilsPart::SetFlip(FALSE);
            Scheduler->SuspendAllTask();   // ne lance pas tout de suite la tache d'affichage des cils
        }
        break;

    case 1:
        if (!Deformation) {  // pour prevenir du cas ou on louperai la synchro 0
            Deformation = new OeilDefor;
            TextureManager::LoadAll();   // load toute les textures

            Deformation->SetEnable(TRUE);
            CilsPart::Initialise(Scheduler,  0);     // ini la partie des cils
            CilsPart::SetFlip(FALSE);
            Scheduler->SuspendAllTask();   // ne lance pas tout de suite la tache d'affichage des cils
        }

        if (IncDef >= 5)    Deformation->OnDefoX(Random1()*Pi());
        else                Deformation->OnDefoY(Random1()*Pi());
        Flash->InterpoAlpha(.5f, 0.0f, .15f);
        affCilAdd = FALSE;
        IncDef++;
        break;
    case 2:
        Deformation->OnDefoZoom(Random1()*Pi());
        Flash->InterpoAlpha(.3f, 0.0f, .15f);
        CilsPart::GetCilsSphere()->SetEnable(TRUE);
        CilsPart::GetCilsSphere()->InterpoAlpha(IncDef*.1f, .0f, .15f);
        affCilAdd = TRUE;
        IncDef++;
        break;
    case 3:
        CilsPart::GetCilsSphere()->InterpoAlpha(1.0f, 1.0f, 1.0f);
        Deformation->OnCalcTunel(0.9f);
        affCilAdd = FALSE;
        Scheduler->ReScheduleAllTask();   // op on passe maintenant par la vrai MainLoop des cils
        break;
    case 4:
        Deformation->Goalpha();
        break;

        //---------------- fait defiler des petits textes
    case 5:
        Textes->OnAppearHori();
        break;
    case 6:
        Textes->OnAppearVerti();
        break;

        //--------------- synchros pour apparition du revive
    case 7:
        Textes->OnAppear1Revive(1.4f);
        Textes->OnAttenuateTexte(4.0f);
        break;
    case 8:
        Fondu->InterpoAlpha(1.0f, 0.0f, .45f);
        Fondu->Enable();   // balance un fondu
        Textes->OnAppear2Revive(0.45f);
        break;
    case 9:
        Textes->OnAppear3Revive(0.8f);
        break;
    case 10:
        Textes->OnDisAppearRevive(0.4f);
        break;

        //--------------- synchros pour apparition du VIP II ( yeahhh )
    case 11:
        Fondu->InterpoAlpha(1.0f, 0.0f, 1.36f);
        Fondu->Enable();
        Textes->OnAppear1Vip(.4f);
        Textes->OnAttenuateTexte(5.2f);
        break;
    case 12:
        Textes->OnAppear2Vip(.4f);
        break;
    case 13:
        Textes->OnAppear3Vip(.4f);
        break;
    case 14:
        Textes->OnAppear4Vip(1.0f);
        break;
    case 15:
        Textes->OnDisAppearVip(3.0f);
        break;

        //--------------- synchros pour la deformation des lignes
    case 16:
        Lignes->Deform(.5f);
        break;
    case 17:
        Lignes->Deform(.5f);
        break;
    }
}