instinct
2010-01-28, 20:16:20
Es werden 3D-Objekte aller Art visualisiert. Der Benutzer soll die Möglichkeit haben mit einer FPS-Kamera durch die Szene zu bewegen (Fly-Mode).
Allerdings gelingt es mir nicht so richtig.
Ich mache folgendes:
Eingabe: Kamera-Punkt, LookAt-Punkt, Up-Vector, FOV, Screen-Resolution
Daraus errechne ich mir mein Kamerasystem und speichere die drei Vektoren
spaltenweise in eine Matrix.
Sobald der Benutzer in das Fenster klickt, wird die Maus zentriert und ab dann wird die Rotation anhand des relativen Pixelunterschieds berechnet.
Mein Code tut folgendes:
{
// Compute rotation angles
float angleX = DEG2RAD((pixelPos.second - newPixelPos.second) / SENSITIVITY_X);
float angleY = -DEG2RAD((pixelPos.first - newPixelPos.first) / SENSITIVITY_Y);
// Set up rotation matrix around x axis
float rotMatrixX[] =
{
1, 0, 0,
0, cosf(angleX), -sinf(angleX),
0, sinf(angleX), cosf(angleX)
};
// Set up rotation matrix around y axis
float rotMatrixY[] =
{
cosf(angleY), 0, -sinf(angleY),
0, 1, 0,
sinf(angleY), 0, cosf(angleY),
};
mat33 rotx, roty;
memcpy(rotx.data, rotMatrixX, 9 * sizeof(float));
memcpy(roty.data, rotMatrixY, 9 * sizeof(float));
rotx *= roty;
base *= rotx;
// Accumulate matrices
pixelPos = newPixelPos;
}
'base' ist hierbei die oben beschriebene Matrix.
Lasse ich entweder nur die Rotation um X oder um Y zu funktionierts prima. Der Benutzer kann sich nach links/rechts oder oben/unten drehen. Sobald ich aber beide Rotationen (wie im Code oben) anwende und ich mir der Maus kleine Kreise im Fenster drehe, dann wird ebenfalls um die z-Achse des Kamerakoordinatensystems rotiert. Das sollte aber nicht sein. Kann mir jemand sagen, was ich hier falsch mache?
Allerdings gelingt es mir nicht so richtig.
Ich mache folgendes:
Eingabe: Kamera-Punkt, LookAt-Punkt, Up-Vector, FOV, Screen-Resolution
Daraus errechne ich mir mein Kamerasystem und speichere die drei Vektoren
spaltenweise in eine Matrix.
Sobald der Benutzer in das Fenster klickt, wird die Maus zentriert und ab dann wird die Rotation anhand des relativen Pixelunterschieds berechnet.
Mein Code tut folgendes:
{
// Compute rotation angles
float angleX = DEG2RAD((pixelPos.second - newPixelPos.second) / SENSITIVITY_X);
float angleY = -DEG2RAD((pixelPos.first - newPixelPos.first) / SENSITIVITY_Y);
// Set up rotation matrix around x axis
float rotMatrixX[] =
{
1, 0, 0,
0, cosf(angleX), -sinf(angleX),
0, sinf(angleX), cosf(angleX)
};
// Set up rotation matrix around y axis
float rotMatrixY[] =
{
cosf(angleY), 0, -sinf(angleY),
0, 1, 0,
sinf(angleY), 0, cosf(angleY),
};
mat33 rotx, roty;
memcpy(rotx.data, rotMatrixX, 9 * sizeof(float));
memcpy(roty.data, rotMatrixY, 9 * sizeof(float));
rotx *= roty;
base *= rotx;
// Accumulate matrices
pixelPos = newPixelPos;
}
'base' ist hierbei die oben beschriebene Matrix.
Lasse ich entweder nur die Rotation um X oder um Y zu funktionierts prima. Der Benutzer kann sich nach links/rechts oder oben/unten drehen. Sobald ich aber beide Rotationen (wie im Code oben) anwende und ich mir der Maus kleine Kreise im Fenster drehe, dann wird ebenfalls um die z-Achse des Kamerakoordinatensystems rotiert. Das sollte aber nicht sein. Kann mir jemand sagen, was ich hier falsch mache?