Jump to content
  • Advertisement
Sign in to follow this  
xbixi

Automatic Camera/object centering

This topic is 879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

We are working on a nodespace type editor of 2D data.
Vertex and geometry shaders + uniforms transform these static data to dynamic 3D data (projection on a sphere and scaling)
User can select a node through mouse-click : we detect the selected node by framebuffer rendering with a fragment shader encoding the vertexId
corresponding to the node.  Now, we would like to rotate the camera to bring this node in front of us and with a given size. 
Here, we only see to ways :
- iteratively move the camera and use pixel tracking to check the result, which requires to get the framebuffer rendering texture back to CPU and do a very slow CPU search to compute new node center and size
- translate the whole Vertex & Geometry shader glsl code back in C++ to compute the real coordinates of the node and do the math to compute the right camera position achieving our goal.
 
This seems to be a basic functionality but we can't find a way to find the right technique.
 
Any help will be much appreciated!

Share this post


Link to post
Share on other sites
Advertisement

without knowing what kind of camera class do you use we can only guess, basic idea is to find how much camera needs to rotate to face the object.

Share this post


Link to post
Share on other sites

Hi and thanks for the input.

 

To know how much we need to rotate the camera (with classical X & Y rotations + eye translation looking at some fixed point), we need to find out in some way the distance from the camera to the object : but since the object 3D coordinates are computed by the GPU (Vertex & Geometry Shader), we do not have any information at the CPU level...

From a mouseClick, we are just able to identify the object (framebuffer rendering + readPixel + decoding of the vertexId encoded at the fragment level).

 

Thanks

Share this post


Link to post
Share on other sites
I might be a little late on this, but if the problem still exists, you could try to also read the depth value of the pixel. Together with the pixel coordinates and the inverse projection and view matrix you are then able to calculate the 3D world coordinates of the pixel.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!