glm-math

OpenGL, some normals reversed despite counterclockwise order

为君一笑 提交于 2019-12-11 14:12:15
问题 In the code below, I don't understand why some faces have their normals reversed. The triangles looks ordered in the anti-clockwise direction, but some faces remain black. When I modify the fragment shader with color = -vnormal; the two black faces are rendered correctly, but not the others, obviously. Thanks for any help given // minimalist but fonctional code using glew, glfw, glm #include <GL/glew.h> #include <GLFW/glfw3.h> #include <glm/vec3.hpp> #include <glm/vec4.hpp> #include <glm

No appropriate default constructor available in struct with glm vectors

為{幸葍}努か 提交于 2019-12-11 10:29:31
问题 in .h: enum collisionType {AB, BA, AoverB, AunderB}; struct Collision { public: collisionType type; glm::vec2 point1; glm::vec2 point2; Collision(enum collisionType, glm::vec2, glm::vec2); }; in .cpp: Collision::Collision(enum collisionType collisType, glm::vec2 p1, glm::vec2 p2) : type(collisType), point1(p1), point2(p2) { } using it std::vector<Collision> collisions; glm::vec2 point1(11.0, 12.0); glm::vec2 point2(12.0, 13.0); collisions.push_back(Collision(AoverB, point1, point2)); Getting

Converting glm quaternion to rotation matrix and using it with opengl

拜拜、爱过 提交于 2019-12-10 16:46:12
问题 so i have the orientation of my object stored in a glm::fquat and i want to use it to rotate my model. how do i do that? i tried this: glPushMatrix(); glTranslatef(position.x, position.y, position.z); glMultMatrixf(glm::mat4_cast(orientation)); glCallList(modelID); glPopMatrix(); but i got this error: error: cannot convert 'glm::detail::tmat4x4<float>' to 'const GLfloat* {aka const float*}' for argument '1' to 'void glMultMatrixf(const GLfloat*)'| im obviously doing something wrong so whats

some opengl and glm explanation

孤街浪徒 提交于 2019-12-08 03:10:32
问题 Can somebody explain me what the following lines do ? glm::mat4 Projection = glm::perspective(45.0f, 1.0f, 0.1f, 100.0f); angle = (GLfloat) (i % 360); glm::mat4 View = glm::mat4(1.); View = glm::translate(View, glm::vec3(0.f, 0.f, -5.0f)); View = glm::rotate(View, angle * -1.0f, glm::vec3(1.f, 0.f, 0.f)); View = glm::rotate(View, angle * 0.5f, glm::vec3(0.f, 1.f, 0.f)); View = glm::rotate(View, angle * 0.5f, glm::vec3(0.f, 0.f, 1.f)); glm::mat4 Model = glm::mat4(1.0); glm::mat4 MVP =

Arcball camera inverting at 90 deg azimuth

▼魔方 西西 提交于 2019-12-07 23:18:55
问题 I'm attempting to implement an arcball style camera. I use glm::lookAt to keep the camera pointed at a target, and then move it around the surface of a sphere using azimuth/inclination angles to rotate the view. I'm running into an issue where the view gets flipped upside down when the azimuth approaches 90 degrees. Here's the relevant code: Get projection and view martrices. Runs in the main loop void Visual::updateModelViewProjection() { model = glm::mat4(); projection = glm::mat4(); view =

Incorrect order of matrix values in glm?

六月ゝ 毕业季﹏ 提交于 2019-12-06 22:57:00
问题 I started using GLM library to do mathematics operations over OpenGL 3 and GLSL. I need an orthographic projection to draw 2D graphics, so I writed this simple code: glm::mat4 projection(1.0); projection = glm::ortho( 0.0f, 640.0f, 480.0f, 0.0f, 0.0f, 500.0f); Printing on screen the values that glm::ortho has created I get: 0.00313 0.00000 0.00000 0.00000 0.00000 -0.00417 0.00000 0.00000 0.00000 0.00000 -0.00200 0.00000 -1.00000 1.00000 -1.00000 1.00000 As I know this is not the correct order

Arcball camera inverting at 90 deg azimuth

风格不统一 提交于 2019-12-06 12:35:34
I'm attempting to implement an arcball style camera. I use glm::lookAt to keep the camera pointed at a target, and then move it around the surface of a sphere using azimuth/inclination angles to rotate the view. I'm running into an issue where the view gets flipped upside down when the azimuth approaches 90 degrees. Here's the relevant code: Get projection and view martrices. Runs in the main loop void Visual::updateModelViewProjection() { model = glm::mat4(); projection = glm::mat4(); view = glm::mat4(); projection = glm::perspective ( (float)glm::radians(camera.Zoom), (float)width / height,

Convert glm::vec4 to glm::vec3

ぃ、小莉子 提交于 2019-12-05 11:06:29
问题 How do I convert a glm::vec4 to a glm::vec3 ? Only x , y , z is required- the w component can be dropped. In GLSL this can be done with .xyz [1], but in glm this results in a compile error: error: 'glm::vec4' has no member named 'xyz' [1] http://en.wikibooks.org/wiki/GLSL_Programming/Vector_and_Matrix_Operations#Components 回答1: Just use vec3 constructor . Here, on 0.9.5 branch: glm::vec4 v4(1, 2, 3, 4); glm::vec3 v(v4); printf("%s\n", glm::to_string(v).c_str()); and gives this output fvec3(1

How to create billboard matrix in glm

*爱你&永不变心* 提交于 2019-12-04 13:27:12
问题 How to create a billboard translation matrix from a point in space using glm? 回答1: Just set the upper left 3×3 submatrix of the transformation to identity. Update: Fixed function OpenGL variant: void makebillboard_mat4x4(double *BM, double const * const MV) { for(size_t i = 0; i < 3; i++) { for(size_t j = 0; j < 3; j++) { BM[4*i + j] = i==j ? 1 : 0; } BM[4*i + 3] = MV[4*i + 3]; } for(size_t i = 0; i < 4; i++) { BM[12 + i] = MV[12 + i]; } } void mygltoolMakeMVBillboard(void) { GLenum active

glm combine rotation and translation

 ̄綄美尐妖づ 提交于 2019-12-04 10:31:55
问题 I have an object which I first want to rotate (about its own center) then translate it to some point. I have a glm::quat that holds the rotation and a glm::vec3 that holds the point to which it needs to be translated. glm::vec3 position; glm::quat orientation; glm::mat4 modelmatrix; <-- want to combine them both in here modelmatrix = glm::translate(glm::toMat4(orientation),position); Then at my render function, I do. pvm = projectionMatrix*viewMatrix*modelmatrix; glUniformMatrix4fv