OpenGL Es 2 Fragen



  • Hallo ich bin recht neu was das Thema OpenGL ES 1 angeht, mache aber Fortschritte und habe dazu noch ein paar
    fragen..

    Ich bin momentan an ein Punkt wo ich eine Camera Function brauche.
    im Ineternet fand ich folgenden interessanten CodeSchnippel

    void setCamera()
    {
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef(CAMERA_X.orientation[0], 1,0,0);
    glRotatef(CAMERA_X.orientation[1], 0,1,0);
    glRotatef(CAMERA_X.orientation[2], 0,0,1);
    glTranslatef(-CAMERA_X.position[0],-CAMERA_X.position[1],CAMERA_X.position[2]);
    }
    
    void checkKeyPresses()
    {
    
    if (GetAsyncKeyState(VK_LEFT) )
    {
    CAMERA_X.position[0] += sin(DEGTORAD(CAMERA_X.orientation[1]-90)) * linearSpeed;
    
    CAMERA_X.position[2] += cos(DEGTORAD(CAMERA_X.orientation[1]-90)) * linearSpeed;
    }
    
    if (GetAsyncKeyState(VK_RIGHT))
    {
    CAMERA_X.position[0] += sin(DEGTORAD(CAMERA_X.orientation[1]+90)) * linearSpeed;
    CAMERA_X.position[2] += cos(DEGTORAD(CAMERA_X.orientation[1]+90)) * linearSpeed;
    }
    
    if (GetAsyncKeyState(VK_UP))
    {
    CAMERA_X.position[0] += sin(DEGTORAD(CAMERA_X.orientation[1])) * linearSpeed;
    CAMERA_X.position[2] += cos(DEGTORAD(CAMERA_X.orientation[1])) * linearSpeed;
    }
    
    if (GetAsyncKeyState(VK_DOWN) )
    {
    CAMERA_X.position[0] -= sin(DEGTORAD(CAMERA_X.orientation[1])) * linearSpeed;
    CAMERA_X.position[2] -= cos(DEGTORAD(CAMERA_X.orientation[1])) * linearSpeed;
    }
    
    if (GetAsyncKeyState(VK_INSERT))
    {
    linearSpeed += .1;
    angularSpeed += .1;
    }
    
    if (GetAsyncKeyState(VK_DELETE))
    {
    if (!(linearSpeed < 0)) linearSpeed -= .1;
    if (!(angularSpeed < 0)) angularSpeed -= .1;
    }
    }
    

    -> wie funktioniert das mit der doppel.variabel[+array] ??
    ich mein wie muss ich das Integieren ?? int position = 0 , int pos_x[0] ???

    //---------------------------

    Für ein Cunck hab ich 5x5x5 Cubes folgendermaße geRendert:

    ...
    static void cube()
    {
     ...
    }
    
    int chunk_x = 5;
    int chunk_y = 5;
    int chunk_z = 5;
    
    float B_SIZE = 0.25f; //abstand
    
    void Render(Uint32 time)
    {
       glClearColor(0.0, 0.0, 0.0, 1.0);
       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
       glMatrixMode(GL_MODELVIEW);
       glLoadIdentity();
    
       int i, j,k;
    
       for (i=0; i<chunk_x; i++)
       {
         for (j=0; j<chunk_y;  j++)
         {
           for (k=0; k<chunk_z;  k++)
           {
             glPushMatrix();
               glTranslatef(j*B_SIZE,i*B_SIZE,k*B_SIZE); //  i und j müssen vertauscht werden
                                                         // dann stellt der das richtig x,y,z sonst ist y,x,z 
                                                         //  ... auch komisch..
               cube();
             glPopMatrix();
           }
          }
        }
    }
    ...
    

    ist das richtig so ?? -> es tuts zumindes 😃

    -> das ganze funktioniert anscheind nur weil ich glPuschMatrix() sowie glPopMatrix()
    benutze ... irgendwer meinte mal das die beiden Funktionen durch glLoadIdentity und glMatrixMode
    ersetzt wurden bzw nicht mehr gäbe ... jetz bin ich verwirrt


Anmelden zum Antworten