11

I want to transform a glm::vec3 (camera.target) by a glm::mat4 (camera.rotationMatrix). I try multiply this give me an error:error: no match for 'operator*' in 'originalTarget * ((Camera*)this)->Camera::rotationMatrix. I suppose that I can't multiply a vec3 * mat4. Does GLM some function to transform this? Other way to do the transform?

The code:

void Camera::Update(void)
{
// Aplicamos la rotacion sobre el target
glm::vec3 originalTarget = target;
glm::vec3 rotatedTarget = originalTarget * rotationMatrix;

// Aplicamos la rotacion sobre el Up
glm::vec3 originalUp = up;
glm::vec3 rotatedUp = originalUp * rotationMatrix;

// Establecemos las matrices de vista y proyeccion
view = lookAt(
position, //eye
rotatedTarget, //direction
rotatedUp //up
);
projection = perspective(
FOV,
(float) getParent()->getEngine()->GetCurrentWidth() / getParent()->getEngine()->GetCurrentWidth() ,
near_plane,
far_plane);
} 
elect
  • 6,765
  • 10
  • 53
  • 119
user1873578
  • 111
  • 1
  • 1
  • 4
  • Check out the [following answer](https://stackoverflow.com/a/74501722/6908282) to see how its done in JavaScript – Gangula Nov 19 '22 at 16:30

1 Answers1

17

You want to first convert your glm::vec3 into a glm::vec4 with the 4th element a 0, and then multiply them together.

glm::vec4 v(originalUp, 0);
Xymostech
  • 9,710
  • 3
  • 34
  • 44
  • 13
    Guess you meant "with the 4th element equals 1.0", no? Translate transfroms won't work with 0. – Oleg Titov Dec 03 '12 at 20:35
  • 3
    Since it's the up vector for the camera, it does not need to be translated, so a zero is more appropriate in this case – Slicedpan Dec 03 '12 at 21:04