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 6 of 6

Thread: simple translational code giving what appear to be wrong answers

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

    simple translational code giving what appear to be wrong answers

    Code :
     
    using namespace glm;
     
    int main()
    {
    	glm::vec4 vec(1.0f, 0.0f, 0.0f, 1.0f);
    		glm::mat4 trans;
    		trans = glm::translate(trans, glm::vec3(1.0f, 1.0f, 0.0f));
    		vec = trans * vec;
    		std::cout << vec.x << vec.y << vec.z << std::endl;
    		std::cout<<"snippet is supposed to be 2 1 0";
    	return 0;
    }


    The result is supposed to be 2 1 0. Instead I get:

    -1.18134e-0111.26952e+0349.56182e+033

    What gives?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,522
    I get 210. Does the code compile without warnings?

  3. #3
    Intern Contributor
    Join Date
    Mar 2017
    Posts
    51
    I'm also getting 210. Here's my console output:

    210
    snippet is supposed to be 2 1 0
    Your code looks right in printing out 210 for your vec printing line. Maybe a recompile will do? My only other thought is using a new set of glm include files, maybe you might've accidentally modified one of them.

  4. #4
    Intern Contributor
    Join Date
    May 2017
    Posts
    80
    Quote Originally Posted by DragonautX View Post
    I'm also getting 210. Here's my console output:



    Your code looks right in printing out 210 for your vec printing line. Maybe a recompile will do? My only other thought is using a new set of glm include files, maybe you might've accidentally modified one of them.
    I've cleaned the worksite, restarted the IDE, and, restarted the machine. Same result. Open to any ideas.


    UPDATE: ran the program on Qt - same result.
    Last edited by technologist; 11-25-2017 at 11:54 AM. Reason: update

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

    what's the culprit

    Code :
    #define GLM_ENABLE_EXPERIMENTAL
    #include <iomanip>
    #include <glm/glm.hpp>
    #include <glm/gtc/matrix_transform.hpp>
    #include <glm/gtx/transform.hpp>
    #include "glm/gtx/string_cast.hpp"
    #include <glm/gtc/type_ptr.hpp>
    #include <iostream>
     
    using namespace glm;
     
    int main()
    {
    	glm::vec4 vec(1.0f, 0.0f, 0.0f, 1.0f);
    		glm::mat4 trans;
    		trans = glm::translate(trans, glm::vec3(1.0f, 1.0f, 0.0f));
                    std::cout << vec.x << vec.y << vec.z << std::endl;
    		vec = trans * vec;
    		std::cout << vec.x << vec.y << vec.z << std::endl;
    		std::cout<<"snippet is supposed to be 2 1 0";
    	return 0;
    }

    doing a little debugging it looks like the numbers get trashed in this step:
    Code :
    vec = trans * vec;

    I've put the extended includes for brevity; maybe something is happening there?

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

    solved

    Yay:

    From the tutorial site:
    Since GLM version 0.9.9, GLM default initializates matrix types to a 0-initalized matrix, instead of the identity matrix. From that version it is required to initialize matrix types as: glm::mat4 mat = glm::mat4(1.0f). For consistency with the tutorials' code it's advised to use a version of GLM lower than 0.9.9 or initialize all matrices as mentioned above.
    Code :
    using namespace glm;
     
    int main()
    {
    	glm::vec4 vec(1.0f, 0.0f, 0.0f, 1.0f);
    	std::cout << vec.x << vec.y << vec.z << std::endl;
    		glm::mat4 trans = glm::mat4(1.0);
    		trans = glm::translate(trans, glm::vec3(1.0f, 1.0f, 0.0f));
    	std::cout << vec.x << vec.y << vec.z << std::endl;
    		vec = trans * vec;
    		std::cout << vec.x << vec.y << vec.z << std::endl;
    		std::cout<<"snippet is supposed to be 2 1 0";
    	return 0;
    }

    output:
    100
    100
    210
    snippet is supposed to be 2 1 0
    Last edited by technologist; 11-25-2017 at 12:41 PM.

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
  •