glm-math

Multiplying a matrix and a vector in GLM (OpenGL)

徘徊边缘 提交于 2019-11-30 17:10:20
I have a transformation matrix, m , and a vector, v . I want to do a linear transformation on the vector using the matrix. I'd expect that I would be able to do something like this: glm::mat4 m(1.0); glm::vec4 v(1.0); glm::vec4 result = v * m; This doesn't seem to work, though. What is the correct way to do this kind of operation in GLM? Edit: Just a note to anyone who runs into a similar problem. GLM requires all operands to use the same type. Don't try multiplying a dvec4 with a mat4 and expect it to work, you need a vec4 . glm::vec4 is represented as a column vector. Therefore, the proper

How do I print vector values of type glm::vec3 that have been passed by reference?

心不动则不痛 提交于 2019-11-30 11:46:01
问题 I have a small obj loader and it takes two parameters and passes them back to the input variables.. however this is my first time doing this and i'm not sure how to print said values now. Here is my main function to test if the loader is working. I have two vectors of type glm::vec3 to hold the vertex and normal data. std::vector<glm::vec3> vertices; std::vector<glm::vec3> normals; int main() { bool test = loadOBJ("cube.obj", vertices, normals); for (int i = 0; i < vertices.size(); i++) { std

3D Scene transformations not quite working

有些话、适合烂在心里 提交于 2019-11-30 10:01:24
问题 In an attempt to convert screen space coordinates into world space coordinates, I've been doing the following calculation: WorldSpace Vector = inverse(Projection Matrix) * inverse(View Matrix) * ScreenSpace vector Up to this point, I believe I have most of my calculations right, however I'm unsure of how to perform the last step needed in order to have my vector transformed to world coordinates. Problem: I've been told that the last step of this process is to divide my results by the variable

glm rotate usage in Opengl

耗尽温柔 提交于 2019-11-30 06:26:06
问题 I am rendering a cone, and I would like to rotate it, 90 degrees anti-clockwise, so that the pointy end faces west! I am using OpenGL 3+. Here is my code in my Cone.cpp so far: //PROJECTION glm::mat4 Projection = glm::perspective(45.0f, 1.0f, 0.1f, 100.0f); //VIEW glm::mat4 View = glm::mat4(1.); View = glm::translate(View, glm::vec3(2.0f,4.0f, -25.0f)); //MODEL glm::mat4 Model = glm::mat4(1.0); //Scale by factor 0.5 Model = glm::scale(glm::mat4(1.0f),glm::vec3(0.5f)); glm::mat4 MVP =

What does left-to-right associativity mean?

别说谁变了你拦得住时间么 提交于 2019-11-30 06:00:03
I am confused about the definition of left-to-right and right-to-left associativity. I have also seen them called left associativity and right associativity and would like to know which corresponds to which. I know that it relates to the order that operations with the same precedence are preformed, as in whether a = x * y * z means a = x * (y * z) or a = (x * y) * z. I don't know which one is left-to-right associative and which is right-to-left associative. I have tried Googleing it but all I have been able to find is tables of what the associativity of different operators are in c++. Looking

glm::perspective explanation

孤街浪徒 提交于 2019-11-30 02:00:11
I am trying to understand what the following code does: glm::mat4 Projection = glm::perspective(35.0f, 1.0f, 0.1f, 100.0f); Does it create a projection matrix ? Clips off anything that is not in the user's view? I wasn't able to find anything on the API page , and the only thing I could find in the pdf on their website was this: gluPerspective: glm::mat4 perspective(float fovy, float aspect, float zNear, float zFar); glm::dmat4 perspective( double fovy, double aspect, double zNear, double zFar); From GLM_GTC_matrix_transform extension: <glm/gtc/matrix_transform.hpp> But it doesn't explain the

3D Scene transformations not quite working

匆匆过客 提交于 2019-11-29 17:59:07
In an attempt to convert screen space coordinates into world space coordinates, I've been doing the following calculation: WorldSpace Vector = inverse(Projection Matrix) * inverse(View Matrix) * ScreenSpace vector Up to this point, I believe I have most of my calculations right, however I'm unsure of how to perform the last step needed in order to have my vector transformed to world coordinates. Problem: I've been told that the last step of this process is to divide my results by the variable "w" because we are using homogeneous coordinates. However I have no idea what "w" represents. I've

OpenGL transforming objects with multiple rotations of Different axis

拈花ヽ惹草 提交于 2019-11-29 11:56:38
I am building a modeling program and I'd like to do transformations on objects in their own space and then assign that single object to a group to rotate around another axis which the group rotates around. However, I'd also like to be able to do transformations in the object's own space when it's combined. Manipulating the individual object, I pick the object's center. glm::mat4 transform; transform = glm::translate(transform, - obj.meshCenter); glm::mat4 transform1; transform1 = glm::translate(transform1, obj.meshCenter); obj.rotation = transform1*obj.thisRot*transform; I then send this off

What does left-to-right associativity mean?

故事扮演 提交于 2019-11-29 06:22:28
问题 I am confused about the definition of left-to-right and right-to-left associativity. I have also seen them called left associativity and right associativity and would like to know which corresponds to which. I know that it relates to the order that operations with the same precedence are preformed, as in whether a = x * y * z means a = x * (y * z) or a = (x * y) * z. I don't know which one is left-to-right associative and which is right-to-left associative. I have tried Googleing it but all I

How to convert Euler Angles to Front, Up, Right vectors

老子叫甜甜 提交于 2019-11-29 05:15:06
I need a function that given Yaw, Pitch, and Roll, can produce the Front (or Looking At), Right, and Up vectors in "world coordinates". In my particular world space, starting from the origin (0,0,0), X is positive to the left, Z is positive going away from the viewer/origin, and Y is positive going up. For for example, given... (angles in degrees) yaw=0, pitch=0, roll=0, the expected output is: front = (0.0,0.0,1.0) right = (-1.0,0.0,0.0) up = (0.0,1.0,0.0) yaw=90, pitch=0, roll=0, the expected output is: front = (1.0,0.0,0.0) right = (0,0,0.0,1.0) up = (0.0,1.0,0.0) yaw=0, pitch=90, roll=0,