glm-math

Glm Quaternion lookat function

别来无恙 提交于 2021-02-18 03:38:05
问题 I am trying to write a lookat function that uses glm::quat to represent rotations, based of off this answer. I am running into trouble getting a correct angle however. This is my lookat function: void Camera::LookAt(float x, float y, float z) { glm::vec3 lookVector = glm::vec3(x, y, z); assert(lookVector != position); glm::vec3 direction = glm::normalize(lookVector-position); float dot = glm::dot(glm::vec3(0, 0, -1), direction); if (fabs(dot - (-1.0f)) < 0.000001f) rotation = glm::quat

light shows but the cube does not appear

本小妞迷上赌 提交于 2021-02-17 03:16:45
问题 I am trying to use lighting on a cube but I don't understand where am going wrong. I can be able to view the light source but the rest of the screen appears black so I don't understand why the cube is disappearing. Here is the code: /*Header Inclusions*/ #include <iostream> #include <GL/Glew.h> #include <GL/freeglut.h> // GLM Math inclusions #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include<glm/gtc/type_ptr.hpp> using namespace std; // Uses the standard namespace #define

light shows but the cube does not appear

怎甘沉沦 提交于 2021-02-17 03:16:19
问题 I am trying to use lighting on a cube but I don't understand where am going wrong. I can be able to view the light source but the rest of the screen appears black so I don't understand why the cube is disappearing. Here is the code: /*Header Inclusions*/ #include <iostream> #include <GL/Glew.h> #include <GL/freeglut.h> // GLM Math inclusions #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include<glm/gtc/type_ptr.hpp> using namespace std; // Uses the standard namespace #define

Instancing cubes next to each other OpenGL

自古美人都是妖i 提交于 2021-02-11 07:59:12
问题 I tried to instance many cubes side by side each other. My understanding is that I need to create a MVP matrix for each cube and bind this then somehow change the position. then run this in a for loop for how many cubes you'd want. This is what I've tried: while (!glfwWindowShouldClose(window)) { glClearColor(0.0f / 255.0f, 170.0f / 255.0f, 204.0f / 255.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(programID); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY

OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?

两盒软妹~` 提交于 2021-02-05 09:02:29
问题 I see an issue where I can correctly draw a textured polygon if all vertices remain onscreen within a perspective projection, BUT if I scale the quad large enough such that one more more vertices fall 'too far behind' the viewing volume, then the resulting OpenGL drawing is incorrect (see screenshots). The texture mapping becomes skewed, and it appears as though the offscreen vertex 'moved' and becomes distorted. I am using GLES 2.0 code on a GLES 3.0 compliant driver (details at bottom). I

How does glm get away with not declaring a function inline and defining it inline in another (unconnected?) file?

◇◆丶佛笑我妖孽 提交于 2021-01-29 11:24:13
问题 glm has some code that looks like this, once pre-processor macros are resolved on my particular setup: type_vec3.hpp struct vec3 { /*...*/ vec3& operator=(vec3 const & v); /*...*/ } type_vec3.inl inline vec3& vec3::operator=(vec3 const & v) { /* implementation */ } I couldn't find any related header include within the .inl file. When I try to rewrite with this kind of layout, I either get linker errors (which I believe is due to mismatch between header file declaration and the inline

How can I parse a simple .obj file into triangles?

巧了我就是萌 提交于 2021-01-29 05:32:07
问题 I'm trying to implement a ray caster and I'm starting out with simple .obj files (utah-teapot) and currently I only made classes for Spheres and Triangles, I basically have all the functions for the intersections, generating view rays, etc.. all ready but I just can't seem to be able to parse the .obj file into triangles (three vectors each) so I can have the ray casting possible on custom .obj files instead of just spheres. This is my current .obj file parser (didn't include the full working

Trouble with separating axis theorem C++

人盡茶涼 提交于 2020-12-26 12:45:58
问题 I am trying to perform separating axis theorem on two triangles to test for collisions between them however it is not working. My relevant code is: glm::vec3 CalcSurfaceNormal(glm::vec3 tri1, glm::vec3 tri2, glm::vec3 tri3) { //Get surface normal of a triangle glm::vec3 u = tri2 - tri1; glm::vec3 v = tri3 - tri1; glm::vec3 nrmcross = glm::cross(u, v); nrmcross = glm::normalize(nrmcross); return nrmcross; } bool SATTriangleCheck(glm::vec3 axis, glm::vec3 tri1vert1, glm::vec3 tri1vert2, glm:

How to write a debugging helper for qtcreator?

China☆狼群 提交于 2020-08-23 08:02:06
问题 When debugging my C++ program using the glm::vec3 class with gdb, the vector classes are quite cumbersome to work with: I've read in the manual, that it's possible to write debug helpers. I've managed to get qtcreator to load the file (the debugger exits immediately with an error, if my python file has a syntax error). How can I write a minimalistic debugging helper? What I've already tried: Here's the C++ code #include <glm/glm.hpp> class Foo { }; int main(int, char**) { glm::vec3 vec3(42,