# Tag Info

4

You get the error because there is no operator*= for vec4 that takes a matrix as a parameter. It then tries to convert the matrix to a float, but just can't. To work around this, you should try to not use the operator*= and write it all in the long form: Off = Off * Util::createTransform(offset); Also, as pointed out in the comments to the OP, what you ...

2

One way is to disable GL_DEPTH_TEST for rendering 2D stuff. So draw everything of the 3D world like normal, then disable depth testing and then draw your UI at last. Another approach would make use of the depth test by setting the z-component of the vertices for the 2D stuff to 0 (and the near plane in the prohection matrix to something greater than 0) to ...

2

Short answer: To store position, use a single vec3. To store rotation, use a quaternion and normalize it after every multiplication or after every n (1-1000) multiplications. You shall only use mat4s when it comes to drawing or transforming lots of vertices: Convert vec3+quaternion pair to mat4 and pass it to your shader or use it to transform vertices ...

2

Making a model always face a point is trickier in 3d than it is in 2d: the added dimension makes one wonder "what about the UP?". This here assumes that you want your model to stay vertical as much as possible, and it uses the following coordinate system. // z+ y+ // | / // | / // | / // | / // |/ // ¯¯¯¯¯¯¯¯¯¯¯¯ x+ This also assumes that the '...

1

You just need the standard lookat function. #include <glm/gtc/matrix_transform.hpp> glm::vec3 const up(0.f, 0.f, 1.f); object->setRotationMatrix(glm::lookAt(pos, target, up)); That’s all! Replace (0.f, 0.f, 1.f) with whatever you want your “up” vector to be.

1

I did several changes to the code and something of the following fixed my problem: changed the order so that all the block binding was done before initializing the uniform buffer added "layout (std140)" to the uniform block in the vertex shader i made sure that i unbound everything after binding and executing series of commands thanks wondra for the link,...

1

Turns out the manual matrix creation method was on the right track, I just wasn't building it in the correct order. This appears to do what I want (though oriented on the -Z axis rather than the +X axis, but that'll be easy to change on my rectangle vertices). glm::vec3 direction = glm::normalize( glm::vec3( p2 - p1 ) ); glm::vec3 rotationZ = direction; glm:...

1

There are a few issues that are preventing your code from behaving like you expect. First of all, your pitch and yaw rotations are applied in the wrong order. Remember non-coplanar 3D rotations are non-commutative, so euler angle (yaw/pitch/roll) rotations need to be applied in the proper order. So your rotation matrix should be constructed like this: ...

1

It's unclear where your issue lies. To rotate a vector about the origin, you create a rotation matrix, and then you multiply the vertex by the matrix. In order to create the rotation matrix, you need a rotation axis and an angle. With glm, you can do it this way: glm::vec3 v3RotAxis( 0.0f, 0.0f, 1.0f ); // Rotate about z+ float angleRad = glm::half_pi&...

1

If you have v-sync enabled ( SDL_GL_SetSwapInterval(1) ), SDL_GL_SwapWindow will wait until your monitor refreshes.

1

Rotations occur relative to the origin, so you want the camera to be 100 units away already before you rotate it if you want the camera to stay focused on the origin. This image will hopefully make it clear (source page): The view matrix you would use is then (I apply the transformations from right-to-left): view = inverse( rotate(90) * translate(100) * ...

1

When you rotate your camera you should apply the same rotation matrix to your up vector. That should result in an up vector in the same direction as your view matrix's up direction.

Only top voted, non community-wiki answers of a minimum length are eligible