PDA

View Full Version : vector not rotating, probably syntax



technologist
11-23-2017, 10:53 AM
std::cout<<"Set Euler angles: "<<std::endl;
std::cout<<"Pitch THETA (elevation) = ";
std::cin>>pEuler->pitchAngle;
std::cout<<"Yaw PHI (heading) = ";
std::cin>>pEuler->yawAngle;
std::cout<<"Roll PSI = ";
std::cin>>pEuler->rollAngle;
//convert Euler angles to a unit vector from a unit circle
float Vx = 0, Vy = 0, Vz = 0;
Vx = cos(pEuler->yawAngle) * cos(pEuler->pitchAngle);
Vy = sin(pEuler->pitchAngle);
Vz = sin(pEuler->yawAngle) * cos(pEuler->pitchAngle);
pEulerVec->Eulervec3D = {Vx, Vy, Vz};
std::cout<<glm::to_string(pEulerVec->Eulervec3D)<<std::endl;
pNorm->normalize_it();
glm::rotate(12.0f, pEulerVec->Eulervec3D);
std::cout<<glm::to_string(pEulerVec->Eulervec3D)<<std::endl;
return 0;


After I apply rotate 12.0f to Eulervec3D vector, the values are the same. I expected them to be not the same.

Set Euler angles:
Pitch THETA (elevation) = 34
Yaw PHI (heading) = 32
Roll PSI = -200
vec3(-0.707897, 0.529083, -0.467924)
<--- rotation occurs?
vec3(-0.707897, 0.529083, -0.467924)

What am I doing wrong?

GClements
11-23-2017, 02:55 PM
glm::rotate(12.0f, pEulerVec->Eulervec3D);

This returns a matrix corresponding to a rotation of 12 radians about the axis defined by pEulerVec->Eulervec3D. It doesn't modify its arguments, and you aren't using its return value.

technologist
11-25-2017, 06:28 PM
I understand rotations better. I have a question: when the axis of rotation(s) is(are) set, are the ones spared unaffected by the function?
For e.g.:


std::cout<<"Rotate it:";
glm::mat4 trans = glm::mat4(1.0);
trans = glm::rotate(trans, 12.0f, glm::vec3(1, 0, 0));
pEulerVec4D->Eulervec4D = trans * pEulerVec4D->Eulervec4D;
std::cout<<glm::to_string(pEulerVec4D->Eulervec4D)<<std::endl;


Rotate it:vec4(-5.605715, 14.849055, -2.020269, 1.000000)

---->glm::vec3(1, 0, 0))

This indicates rotating a vector on the x axis?;
But peering deeper into the code the other axes have some changes too.

GClements
11-25-2017, 11:34 PM
std::cout<<"Rotate it:";
glm::mat4 trans = glm::mat4(1.0);
trans = glm::rotate(trans, 12.0f, glm::vec3(1, 0, 0));
pEulerVec4D->Eulervec4D = trans * pEulerVec4D->Eulervec4D;
std::cout<<glm::to_string(pEulerVec4D->Eulervec4D)<<std::endl;


Rotate it:vec4(-5.605715, 14.849055, -2.020269, 1.000000)

---->glm::vec3(1, 0, 0))

This indicates rotating a vector on the x axis?;

Yes, you're rotating about the X axis. The X coordinate will remain unchanged, the Y and Z coordinates will change.