Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: vector not rotating, probably syntax

  1. #1
    Intern Contributor
    Join Date
    May 2017
    Posts
    80

    vector not rotating, probably syntax

    Code :
    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?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,516
    Quote Originally Posted by technologist View Post
    Code :
    	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.

  3. #3
    Intern Contributor
    Join Date
    May 2017
    Posts
    80

    update on vector rotation question

    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.:
    Code :
            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.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,516
    Quote Originally Posted by technologist View Post
    Code :
            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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •