Search code examples
c++opengl3dclippingglm-math

GLM opengl clipping issues - Game Engine c++


I am currently working on my game-engine and I run into some troubles I can not figure out myself. I changed my mind about setting up my own math library so I went back to use GLM because it is a perfect solution. But here comes the problem, with my Code everything worked well but now with the functions changed I get a problem with object clipping and intersection.

Zoomed In

This first image shows how my scene looks when it is zoomed in. Everything looks almost perfect and the plane intersects the cube properly.

Zoomed Out

Scrolling out the intersection gets randomly dissorted and I cannot explain what's happening nor do I have any clue where my problem is located. This is the way I calculate my projection Matrix:

proj = glm::perspective((double)fovy, (double)aspect, (double)nearPlane,(double) farPlane);

and this is the way I calculate the view:

view = glm::lookAt(pos, tar, gameObject->transform.getUp());

I know I should poste more code but there is so much that I really don't know where to start. So please tell me which code could be of importance and I poste it. Thank you very much in advance and I hope somebody could help me. If more pictures are needed please tell me.


Solution

  • It looks like you don't have enough depth resolution. This happens when nearPlane is very small and farPlane is very large. For example, 0.0001 to 10000.0 will give you low depth resolution.

    Make nearPlane larger and farPlane smaller.