PDA

View Full Version : mesh is wrong positioned



3DPrgmer
12-03-2016, 06:40 AM
Hi,

i have a problem with some wrong placed models.
As you can see on the picture below, the head and leg addon are wrong placed. You cannot see very good the head addon, it is inside the body. If you compare carefully both the original and my displayed model. you notice that these models are not just wrong placed, they are wrong turned by 180, too. All other parts, like the backpack, or the tubes,... are all correctly displayed.

2300

I'm calculating the model's individual translation matrices here: https://git.rwth-aachen.de/carstenf/OpenGL/blob/master/MshViewer/Source/Object.cpp#L285

Notice the conversion between quaternion and Euler: https://git.rwth-aachen.de/carstenf/OpenGL/blob/master/MshViewer/Source/Object.cpp#L575

in the update function i call for every model part the getMVP function: https://git.rwth-aachen.de/carstenf/OpenGL/blob/master/MshViewer/Source/OpenGlController.cpp#L225
In there i calculate

m4x4Projection * m4x4View * m4x4ModelRot * m4x4Normalize * m4x4ModelCenter * getModelMatrix(index);
So in words: get the Model's individual matrix (https://git.rwth-aachen.de/carstenf/OpenGL/blob/master/MshViewer/Source/OpenGlController.cpp#L209), move to Center, scale down to 1, rotate everything the way the user want it, move the camera in place and finally adjust the projection to fit the window size.

I don't understand why there are only 2 parts wrong placed and why they are wrong placed. Maybe you can help me to find the problem.

Silence
12-05-2016, 12:49 AM
My two cents: aren't they related to any parent ? If so, they should be placed torward their parent coordinate system, not the global one.

3DPrgmer
12-05-2016, 02:59 AM
Yes that's right, everything can have a parent. In this case all models have the same parent (as you can see on the picture)
In my code i'm calling getModelMatrix(index); here (git.rwth-aachen.de/carstenf/OpenGL/blob/master/MshViewer/Source/OpenGlController.cpp#L255). And the function is defined here (https://git.rwth-aachen.de/carstenf/OpenGL/blob/master/MshViewer/Source/OpenGlController.cpp#L209). So i get every parent matrix

john_connor
12-05-2016, 04:15 AM
1. if you first resize all the parts to 1 (as i suggested a few days ago), you also are resizing the "center" position
2. if you re-center your model, you have to keep in mind that the center position has been resized, too

example:

you have a cube: [0; 5] x [0; 5] x [0; 5]
center = (2.5 | 2.5 | 2.5)

1. resize to 1:
scale factor = 0.2
center --> (0.5 | 0.5 | 0.5) = scale factor x old center position

2. re-center the cube:
--> move all the vertices: -(0.5 | 0.5 | 0.5) instead of -(2.5 | 2.5 | 2.5)

that means you have to move all the parts belonging to that model with -(0.5 | 0.5 | 0.5)
you also have to scale all the parts with 0.2

3DPrgmer
12-05-2016, 05:10 AM
Ah, i see. I'll see if i find that in my code.

==EDIT==

i looked in the code, but i move everything to Center first and scale it then and i have the same problem without scaling and centering

btw i think i'm gonna switch from glm, glut, glew, glfw,... to Qt. Because i can get everything with just one very nice and powerful library. Already setup everything for Visual Studio and i already got my first Example code from the internet running :D

I hope i can easily switch my whole project to Qt now :D Do you know OpenGL with Qt, too? And do you have a nice tutorial??

john_connor
12-05-2016, 07:24 AM
btw i think i'm gonna switch from glm, glut, glew, glfw,... to Qt. Because i can get everything with just one very nice and powerful library. Already setup everything for Visual Studio and i already got my first Example code from the internet running :D

I hope i can easily switch my whole project to Qt now :D Do you know OpenGL with Qt, too? And do you have a nice tutorial??

if you install Qt as "stand-alone" IDE, there are already simple / advanced examples included
i'm currently trying (struggling) to install the addin to Visual Studio 2015 (because the Qt IDE isnt that good imho)

3DPrgmer
12-05-2016, 02:39 PM
If you need any help with that, let me know. I compiled the qt source multiple times with MinGW for static linking. And I already compiled them for VS with OpenGL Desktop. But I think I forgot exception handling, so I may need to recompile them.