开发者

converting a 2d window point to a 3d point

开发者 https://www.devze.com 2023-03-19 21:02 出处:网络
i am writing a 3d modeler similar to Blender for a game i am making. Since programs like blender export very complicated file types with alot of unneeded data i wanted to write a simple editor for my

i am writing a 3d modeler similar to Blender for a game i am making. Since programs like blender export very complicated file types with alot of unneeded data i wanted to write a simple editor for my game. what i cannot figure out is how to map a point from a 2d projection on the window to where i have clicked in the 3d world with the world开发者_如何学JAVA being rotated.

If anyone knows any good tutorials on how to do this or the method any help would be appreciated. I know i could use ray tracing but that would be to complicated i think.


The two main methods of mouse picking are:

  1. Intersection Testing
  2. Color Picking

Intersection tests are the more popular of the two, and at the simplest level involves 'shooting' out a ray and checking if it has intersected any points. The ray can also be replaced by a polytope if one wants to achieve more sensitive picking (useful for choosing points on vertices).

Color picking involves disabling AA, blending, shadows, etc. and re-drawing the scene using solid colors for the objects. glReadPixels is then used to find the color at the point of the mouse and this color is used to determine if it clicked on an applicable object.

Ray Picking:

  • Mouse Ray Picking Explained
  • Picking, Alpha Blending, Alpha Testing, Sorting

Color Picking:

  • OpenGL Selection Using Unique Color IDs
  • Picking Tutorial


The term you are looking for is mouse picking.


The method you need is gluUnProject. You'll need window x,y and the depth.

I think, in your case, it might be a lot easier to write a simple exporter for Blender.

0

精彩评论

暂无评论...
验证码 换一张
取 消