🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

3d picking inaccuracy.

Started by
34 comments, last by taby 5 years, 3 months ago
13 hours ago, GoliathForge said:

The quick fix might be to call glfwGetFramebufferSize() just before you build your projection and use those returned values instead of your member held dimensions and get rid of the test flat decoration(window style?) 

finally i have figured out and solve the problem( of course with your help ), after you suggested that, set the frame buffer size as window height and width before projection matrix creation, i tried and it didn't work because problem was something else. I didn't Listen to you (@GoliathForge) because of this (Note :it is not my excuse i am explaining real scenario.)remainder.PNG.4bcd46e46154872cc5f14e88e1bc10e2.PNG

i have been doing this since when i ported to glfw within each iteration, where global is my camera pointer. It didn't work this time too because this was not the problem ( As i mentioned before the ambiguous output ). It is very hard to explain what i thought. In simple words the problem was i didn't updated the drivers of intel gpu and now i have updated them so problem solved( And it also explains why the program was working correctly only on nvidia gpu).

Thanks all of you and Sorry because every single thread i created here on this website for my problem is based on my own dumb mistakes and i always figure them out very late????????.

Advertisement

No wonder why intel gets garbage if you enable nv specific extensions and use them - wanted to post that a week ago

 

I don't know if this code will help, but I just implemented picking yesterday, and it's working good in OpenGL. I got it from https://en.wikipedia.org/wiki/Ray_tracing_(graphics)#Calculate_rays_for_rectangular_viewport

Get intersection point on plane:


custom_math::vector_3 p_ij = main_camera.Get_Screen_Ray(x, y, win_x, win_y);
custom_math::vector_3 N(0, 1, 0);
custom_math::vector_3 D(p_ij.x, p_ij.y, p_ij.z);
D.normalize();
custom_math::vector_3 O(main_camera.eye.x, main_camera.eye.y, main_camera.eye.z);
double u = -(N.dot(O) + 0.0) / N.dot(D);
custom_math::vector_3 P = O + D * u;
	

... where ...


custom_math::vector_3 uv_camera::Get_Screen_Ray(const int x, const int y, const int screen_width, const int screen_height)
{
	custom_math::vector_3 E(eye.x, eye.y, eye.z);
	custom_math::vector_3 T(look_at.x, look_at.y, look_at.z);
	custom_math::vector_3 w(up.x, up.y, up.z);
	w.normalize();

	custom_math::vector_3 t = T - E;
	custom_math::vector_3 b = w.cross(t);

	custom_math::vector_3 t_n = t;
	t_n.normalize();

	custom_math::vector_3 b_n = b;
	b_n.normalize();

	custom_math::vector_3 v_n = t_n.cross(b_n);

	double theta = fov * custom_math::pi / 180.0;
	double d = 1.0;
	double aspect = static_cast<double>(screen_width) / static_cast<double>(screen_height);
	double g_y = -d * tan(theta / 2.0);
	double g_x = g_y * aspect;

	custom_math::vector_3 q_x = b_n * (2.0*g_x) / (static_cast<double>(win_x) - 1.0);
	custom_math::vector_3 q_y = v_n * (2.0*g_y) / (static_cast<double>(win_y) - 1.0);

	custom_math::vector_3 p_1m = t_n * d - b_n * g_x - v_n * g_y;
	custom_math::vector_3 p_ij = p_1m + q_x * x + q_y * y;

	return p_ij;
}

Thanks but my problem is solved???. It's all working perfectly. 

LOL, good to hear! :)

This topic is closed to new replies.

Advertisement