Ich habe eine Rotationsprobleme.Rotation beim Hochklappen Vektor von Y bis Z
Ich habe die Kamera so eingerichtet, dass der Vektor Z ist, -X ist vorwärts und rechts ist Y. Ich habe Modelle, die in ein anderes Koordinatensystem exportiert werden, wo Y ist, -Z ist vorwärts, X ist richtig.
Meine Herausforderung/Problem ist mit der Rotation. Wie kann man in diesem Fall eine korrekte Drehung vornehmen, ohne das Koordinatensystem der Objekte, die ich importiere, zu ändern? Maßstab und Transformation funktionieren so, wie sie sollten.
Bisher habe ich versucht Swapping Y und Z-Achse in der Rotationsmatrix Hand dabei die Rotationsmatrix getrennt, dabei die Rotation wie wir Steuerdatei lesen, Z und Y Drehachse Spiegeln, die Änderung der Matrix zu
| 1 0 0 |
| 0 0 1 |
| 0 1 0 |
usw.
PS. Ich möchte nicht das Koordinatensystem der Objektdateien ändern, die ich jetzt importiere, und wenn ich in die Steuerdatei rotateY schreibe, wird das Objekt in meiner Y-Achse und nicht in der Y-Achse des Objekts gedreht.
Dies ist der Teil des Codes I
// control file is where i store transform, rotate and scale in a text file and objects that i want to read.
for(int i = 0; i< controls.size(); i++) {
meshStruct tempMesh;
int isMeshLoaded = loadObjFile((char*)controls[i].path, &tempMesh.objectInfo_, &tempMesh.numObjects_);
if(isMeshLoaded)
{
cout<< "Mesh " << controls[i].path << " loaded sucesfully." << endl;
} else {
cout<< "Mesh " << controls[i].path << " loaded failed." << endl;
}
tempModelMatrix = mat4(1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
//mat4 tempModelMatrixFlip = mat4(1.0f, 0.0f, 0.0f, 0.0f,
// 0.0f, 0.0f, 1.0f, 0.0f,
// 0.0f, 1.0f, 0.0f, 0.0f,
// 0.0f, 0.0f, 0.0f, 1.0f);
//tempModelMatrix *= tempModelMatrixFlip;
tempModelMatrix = glm::translate(tempModelMatrix, controls[i].translate);
tempModelMatrix = glm::rotate(tempModelMatrix, radians(controls[i].rotation.x), vec3(1.0, 0.0, 0.0));
// I dont want to flip here Y and Z because some objects are in the correct coordinate system
tempModelMatrix = glm::rotate(tempModelMatrix, radians(controls[i].rotation.y), vec3(0.0, 1.0, 0.0));
tempModelMatrix = glm::rotate(tempModelMatrix, radians(controls[i].rotation.z), vec3(0.0, 0.0, 1.0));
/*
mat4 r = mat4(1.0f);
mat4 rx = mat4(1.0f);
mat4 ry = mat4(1.0f);
mat4 rz = mat4(1.0f);
rx = rotate(radians(controls[i].rotation.x), vec3(1.0, 0.0, 0.0));
ry = rotate(radians(controls[i].rotation.y), vec3(0.0, 1.0, 0.0));
rz = rotate(radians(controls[i].rotation.z), vec3(0.0, 0.0, 1.0));
r = rx * ry * rz;
vec4 temp;
temp = column(r, 1);
cout << to_string(temp) << endl;
r = column(r,1, column(r, 2));
r = column(r,2, temp);
temp = row(r,1);
r = row(r, 1,row(r,2));
r = row(r, 2, temp);
//cout << to_string(column(tempModelMatrix, 1)) << endl;
//tempModelMatrix *= r;
float tempModelMatrix2[16];// = mat4(1.0f);
tempModelMatrix2[0] = controls[i].scale.x * column(r, 0).x;//controls[i].scale.x * controls[i].rotation.x;
tempModelMatrix2[1] = controls[i].scale.x * column(r, 0).y;//controls[i].scale.x * controls[i].rotation.x;
tempModelMatrix2[2] = controls[i].scale.x * column(r, 0).z;//controls[i].scale.x * controls[i].rotation.x;
tempModelMatrix2[3] = 0.0f;
tempModelMatrix2[4] = controls[i].scale.y * column(r, 2).x;//controls[i].scale.y * controls[i].rotation.y;
tempModelMatrix2[5] = controls[i].scale.y * column(r, 2).y;//controls[i].scale.y * controls[i].rotation.y;
tempModelMatrix2[6] = controls[i].scale.y * column(r, 2).z;//controls[i].scale.y * controls[i].rotation.y;
tempModelMatrix2[7] = 0.0f;
tempModelMatrix2[8] = controls[i].scale.z * column(r, 1).x;//controls[i].scale.z * controls[i].rotation.z;
tempModelMatrix2[9] = controls[i].scale.z * column(r, 1).y;//controls[i].scale.z * controls[i].rotation.z;
tempModelMatrix2[10] = controls[i].scale.z * column(r, 1).z;//controls[i].scale.z * controls[i].rotation.z;
tempModelMatrix2[11] = 0.0f;
tempModelMatrix2[12] = controls[i].translate.x;
tempModelMatrix2[13] = controls[i].translate.y;
tempModelMatrix2[14] = controls[i].translate.z;
tempModelMatrix2[15] = 1.0f;*/
tempModelMatrix = glm::scale(tempModelMatrix, controls[i].scale);
//cout << controls[i].path << " controls[i].translate " << to_string(controls[i].translate) << endl;
//cout << controls[i].path << " controls[i].rotation.X " << controls[i].rotation.x << endl;
//cout << controls[i].path << " controls[i].rotation.y " << controls[i].rotation.y << endl;
//cout << controls[i].path << " controls[i].rotation.Z " << controls[i].rotation.z << endl;
//cout << controls[i].path << " controls[i].scale " << to_string(controls[i].scale) << endl;
string basedir = dirname(controls[i].path);
for(int j = 0; j < tempMesh.numObjects_; j++){
//tempMesh.objectInfo_[j].modelMatrix = controls[i].modelMatrix;
tempMesh.objectInfo_[j].modelMatrix = tempModelMatrix;
//tempMesh.objectInfo_[j].modelMatrix = make_mat4(tempModelMatrix2);
@Exide ich die „loadObjFile“ -Funktion bin gegeben und ich kann es jetzt nicht ändern. Aus diesem Grund brauche ich eine Lösung dafür. Auch kann ich keine Objekte mit Blender oder ähnlichem transformieren. Das Problem ist, dass ich mit meinem Professor streite, dass dies keine gute Lösung ist, weil einige Objekte korrekt rotieren und einige nicht auf ein anderes lokales Koordinatensystem zurückzuführen sind. Ich habe heute den ganzen Tag über 10 Stunden damit verbracht, eine Lösung dafür zu finden. Vielen Dank für die Hilfe: D –
Meine Antwort erfordert keine Änderung '' 'loadObjFile''' oder die ursprüngliche Datei. Sie konvertieren es in Ihre Weltkoordinaten ** nachdem ** es geladen wurde. – Exide
Es gibt wenige Objekte, die sich korrekt drehen, da sie sich in der richtigen Weltkoordinate befinden und der Obj Loader Vertexdaten an die GPU sendet. :( –