Hey Leute,
Ich will meine kleine Fenstererstellungsbibliothek zu einer kleinen 3D-Engine machen.
Hat bis jetzt auch alles gut geklappt (GL 1.1 Render Context, Texturen, Vektoren).
Jetzt habe ich mir gerade eine Matrix-Klasse erstellt, sowie einige Funktionen diese zu füllen
(z.B. Translationen, Skalierungen, Perspektivische Projektion, Kamera-Matrix, Rotationen um die Z-Achse),
aber bei den Rotationen um X- und Y-Achse passiert folgendes (X-Achse):
anstatt, dass das Viereck einfach seine Orientierung ändert.
Der Code für Kamera-Matrix und Rotations-Matrix:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
ENGINE_API CMatrix MCamera(CVector3D pos, CVector3D lookAt, CVector3D up) {
CVector3D zAxis(V3Normalize(lookAt - pos));
CVector3D xAxis(V3Normalize(V3Cross(up, zAxis)));
CVector3D yAxis(V3Normalize(V3Cross(zAxis, xAxis)));
float m[] = {
xAxis.x, yAxis.x, zAxis.x, 0.0f,
xAxis.y, yAxis.y, zAxis.y, 0.0f,
xAxis.z, yAxis.z, zAxis.z, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
return MTranslation(-pos) * CMatrix(m);
}
ENGINE_API CMatrix MRotationX(float f) {
float m[] = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, cosf(f), -sinf(f), 0.0f,
0.0f, sinf(f), cosf(f), 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
};
return CMatrix(m);
}
|
Den Code für die Kamera-Matrix habe ich aus der TriBase-Engine, während ich die Rotations-Matrix auf das rechtshändige Koordinatensystem von OpenGL angepasst habe.
Ich habe schon versucht die Funktionen durch gluLookAt und glRotatef auszutauschen, aber dann habe ich nichts mehr gesehen.
In der main.cpp habe ich dann folgendes getan:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
|
MProjection();
MLoadMatrix(MPerspective(45.0f, float(800 / 800), 0.1f, 100.0f)); // MLoadMatrix = glLoadMatrix
MModelView();
CMatrix matModel = MRotationX(45.0f) * MTranslation(CVector3D(0.0f, 0.0f, -5.0f));
CMatrix matView = MCamera(CVector3D(0.0f, 0.0f, 0.0f), CVector3D(0.0f, 0.0f, -1.0f), CVector3D(0.0f, 1.0f, 0.0f));
MLoadMatrix(matModel * matView);
|
Bin dankbar für jede Antwort, weil ich bin echt am verzweifeln