Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Berechnung unter C stimmt nicht

Empfohlene Antworten

Veröffentlicht

Hallo,

ich schreibe grade an einem openGL-Programm. Dazu gehören natürlich auch keyboard-Funktionen. Mit w bzw s bewege ich mich vorwärts und rückwärts in einem Raum. Dazu folgendes:


float camspeed = 0.8,directionX,directionZ,moveX,moveZ;
...
case 'w':

//Richtungsvektor
directionX = centerX-eyeX;
directionZ = centerZ-eyeZ;

//Einheitvektor berechnen
moveX+=camspeed*directionX/( sqrt( (directionX*directionX) + (directionZ*directionZ) ) );
moveZ+=camspeed*directionZ/( sqrt( (directionX*directionX) + (directionZ*directionZ) ) );
printf("directionX: %f und directionZ: %f\n",directionX,directionZ);
printf("moveX: %f und moveZ: %f\n",moveX,moveZ);

eyeX += moveX;
eyeZ += moveZ;

centerX += moveX;
centerZ += moveZ;

gluLookAt(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,0,1,0);


break;
...
[/PHP]

Das funktioniert auch wunderbar, nur ist mir aufgefallen, dass ich manchmal beim Drücken der w-Taste gewaltige Sprünge nach vorne mache und nichts mehr von meinen Objekten sehe. Daher hab ich mir mal ausgeben lassen, was in moveX und moveY steht, was einem Punkt mit dem Abstand 1 vom Koordinatenursprung entspricht, welche ich dann mit der Position der Kamera und mit dem Punkt, auf dem sie fokusiert ist, addiere. Ich habe das Programm nur einmal kompiliert und erhalte 2 verschiedene Ergebnisse, nachdem ich nur die w-Taste gedrückt habe:

[code] [kadaj@atheros Computergrafik]$ ./figuren OpenGL Version: |4.3.0 NVIDIA 310.19| directionX: -0.500000 und directionZ: -3.500000 moveX: -0.113137 und moveZ: -0.791960 [kadaj@atheros Computergrafik]$ ./figuren OpenGL Version: |4.3.0 NVIDIA 310.19| directionX: -0.500000 und directionZ: -3.500000 moveX: -213190605925492478661477779111936.000000 und moveZ: -0.791960 [/code]

Was ist denn hier passiert? oO

Wie kann es sein, dass auf einmal totaler Murks rauskommt. Das Programm ist doch das selbe.

Kann vielleicht jemand Abhilfe schaffen?

Gruß

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.