Problem with setting transform in C++
by Jack Stone · in Technical Issues · 10/29/2014 (6:13 pm) · 3 replies
Hello,
I am working on a spherical terrain implementation, and one of the steps is to generate six flat terrains in a cube, before projecting the onto a sphere.
I can create the terrains with no difficulty, but for some reason, I can't alighn them into a cube properly! I can align at most three of them, the rest are all rotated incorrectly.
Here is my transform code: (This is not very efficient, but I am just trying to get the concept working!)
The strange thing is, that when I set the rotation in the editor, it works?
So, for example, the third terrain is created with the following quaternion:
"QuatF rot3 = QuatF(EulerF(0,1.57,0));"
This terrain shows up rotated incorrectly, but the editor shows it as "0 -1 -0 89.9544", which is wrong, it should be "0 1 0 89.9544". When I correct this in the editor, the terrain rotates properly.
Something seems to be going wrong with the signs between the set transform function and the editor, any ideas?
Thanks!
I am working on a spherical terrain implementation, and one of the steps is to generate six flat terrains in a cube, before projecting the onto a sphere.
I can create the terrains with no difficulty, but for some reason, I can't alighn them into a cube properly! I can align at most three of them, the rest are all rotated incorrectly.
Here is my transform code: (This is not very efficient, but I am just trying to get the concept working!)
Point3F pos = Point3F(0,0,0); QuatF rot = QuatF(EulerF(0,0,0));//QuatF(0,0,1,0); MatrixF mat; rot.setMatrix(&mat); mat.setColumn(3,pos); //Parent::setTransform(mat); terrain->setTransform(mat); Point3F pos2 = Point3F(0,256,0); QuatF rot2 = QuatF(EulerF(-1.57079633,0,0));//QuatF(0,0,1,0); MatrixF mat2; rot2.setMatrix(&mat2); mat2.setColumn(3,pos2); terrain2->setTransform(mat2); Point3F pos3 = Point3F(0,0,-256); QuatF rot3 = QuatF(EulerF(0,1.57,0)); MatrixF mat3; rot3.setMatrix(&mat3); mat3.setColumn(3,pos3); terrain3->setTransform(mat3); Point3F pos4 = Point3F(0,0,-256); QuatF rot4 = QuatF(EulerF(1.57079633,0,0)); MatrixF mat4; rot4.setMatrix(&mat4); mat4.setColumn(3,pos4); terrain4->setTransform(mat4); Point3F pos5 = Point3F(256,0,0); QuatF rot5 = QuatF(EulerF(0,-1.57079633,0)); MatrixF mat5; rot5.setMatrix(&mat5); mat5.setColumn(3,pos5); terrain5->setTransform(mat5); Point3F pos6 = Point3F(0,resolution,0); QuatF rot6 = QuatF(EulerF(0,-1.57079633,0)); MatrixF mat6; rot6.setMatrix(&mat6); mat6.setColumn(3,pos6); terrain6->setTransform(mat6);
The strange thing is, that when I set the rotation in the editor, it works?
So, for example, the third terrain is created with the following quaternion:
"QuatF rot3 = QuatF(EulerF(0,1.57,0));"
This terrain shows up rotated incorrectly, but the editor shows it as "0 -1 -0 89.9544", which is wrong, it should be "0 1 0 89.9544". When I correct this in the editor, the terrain rotates properly.
Something seems to be going wrong with the signs between the set transform function and the editor, any ideas?
Thanks!
#2
Thank you very much, that link did indeed fix my issue. I couldn't see any problems with it in other areas of my code, although I will be aware of it if I get strange behaviour in future. Hopefully the fix works well enough that I won't need to change it.
Now I just need to figure out how tomap the square terrain to sphere without leaving seams...
10/30/2014 (1:19 pm)
Ah, Mr Buckmaster, my old friend! Do you just follow me around the forums,solving my maths and physics questions? Thank you very much, that link did indeed fix my issue. I couldn't see any problems with it in other areas of my code, although I will be aware of it if I get strange behaviour in future. Hopefully the fix works well enough that I won't need to change it.
Now I just need to figure out how tomap the square terrain to sphere without leaving seams...
#3
11/03/2014 (4:45 pm)
Yep ;).
Torque Owner Daniel Buckmaster
T3D Steering Committee