PDA

View Full Version : GLM::translate



OceanJeff40
12-14-2016, 02:34 PM
So, I've been experimenting, and ran across an odd compiler/opengl issue???? I am honestly not sure why this doesn't work, so I thought I would post it on here and see what anyone else thinks.

So I have a project where this DOES WORK FINE, then I started a new project, and IT DOESN'T WORK, I've tested, and it sends ZEROES to the OpenGL engine, and it displays as if the translate function was receiving all zeroes.


transform = glm::translate(transform, coinPosition[0]);

First of all, are there any circumstances, why this wouldn't work from one project to the next? I've checked putting the raw data in. Instead of coinPosition[0], I put in: glm::vec(-0.5f,-0.5f,0.0f), and it works fine, so everything else about the program is fine.

I am working by copying and pasting code from another project, and it works fine in the other project. I even copied the entire project's source code into this project, and it compiled fine, I'm apparently just having trouble with this array?????

What could I possibly be doing wrong? rofl Any help is appreciated. Thanks

And I wouldn't even bother with such a trivial problem, but I've been stumped for a few hours now..... and I'm taking a break to eat now.

Also, I'm trying to use an array for position (so glm::vec3) and a separate array for texture coordinate offset to the vertex shader (so glm::vec2). Both accept raw data and work fine, but when I try to send the array, they don't work.....

Jeff

john_connor
12-14-2016, 02:55 PM
do you know what happens if you create a glm::mat4 without arguments ?
you'll get a matrix full of 0s

glm::mat4 mymat4x4; // each element is 0

glm::mat4 mymat4x4(1); // identity matrix

multiplying the first matrix with anything else will result in another matrix full of 0s
multiplying the second matrix with X will result in X

glm::translate just multiplies your imput matrix with a "translation matrix"
if you dont pass any matrix into glm::translate, you will get only the "translation matrix"

what i'd use is:
glm::mat4 mymat4x4 = glm::translate(glm::vec3(1, 2, 3));

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

OceanJeff40
12-14-2016, 03:17 PM
Thanks for the link to the tutorial, that is awesome, I will have a look through it, I am currently working through learnopengl.com, and it's great.


glm::mat4 transform(1);
transform = glm::translate(transform, coinPosition[0]);


I added the change to create an identity matrix, which is what I thought I was doing in the first place, but it still has the same effect.

If I change just the one line to this, it works: (I've left your transform(1) line to be sure).


transform = glm::translate(transform, glm::vec3(-0.5, -0.5, 0.0f));


I went ahead and changed the glm::mat4 transform line in my working project, to glm::mat4 transform(1), and they both behave the same, leading me to believe what learnopengl.com taught me, was that they both create an identity matrix.

Jeff

OceanJeff40
12-14-2016, 04:11 PM
Um, hey, I figured this one out too.

The array is initialized with data in a function that is separate from main().

........ I didn't call that function.

OMG.

Jeff