0

I have a object placed on a mouse ray. I want align object toward to camera, clear rotation with saving another components of camera as scale and translation. Ofcourse, I could to make it without any matrix transformation based on mouse position, but I need 3d object. What is a best way to do that? My calculations MVP sends to shaders and I guessing I need to prepare View matrix without rotation components. Something like that (find that on stackoverflow) :

    glm::mat4 newView = view;
    float d = sqrt((newView [0][0] * newView [0][0]) + (newView [1][0] * newView [1][0]) + (newView [2][0] * newView [2][0]));
    newView [0][0] = d;
    newView [0][1] = 0;
    newView [0][2] = 0;
    newView [0][3] = 0;
    newView [1][0] = 0;
    newView [1][1] = d;
    newView [1][2] = 0;
    newView [1][3] = 0;
    newView [2][0] = 0;
    newView [2][1] = 0;
    newView [2][2] = d;
    newView [2][3] = 0;

Is it correct? Is it a best way for my purpose? Thanks!

NOoB
  • 45
  • 1
  • 4
  • Does it work with this code? – BDL Mar 06 '17 at 20:07
  • Unfourtanetly no. At least as expected. This code to clear any transformation.As if I declare new mat4 view - object not scaled and not folow to camera movement. – NOoB Mar 06 '17 at 20:33
  • clear just the 3x3 matrix ... otherwise you overwrite position see [Understanding 4x4 homogenous transform matrices](http://stackoverflow.com/a/28084380/2521214) – Spektre Mar 07 '17 at 08:58

0 Answers0