PDA

View Full Version : Cube resize when mouse over



mgs_oleg
03-27-2018, 11:37 AM
Hi Team,

I am relatively new to OPENGL and need to accomplish task of resize (say 2 times from original size) cube(3D) once mouse over it. And after mouse is not on the cube it has to back normal size.

Do yu know how to do that ?
Maybe there is some good material to read? like tutorials...

Thanks for your help!

thealik
03-27-2018, 04:10 PM
Maybe there is some good material to read? like tutorials...

I'd suggest you to start from https://learnopengl.com . It has some great explanations of transformations and coordinate systems. All examples are on GitHub, so you can try them yourself.

mgs_oleg
03-28-2018, 03:08 PM
thanks for link, but I need explicitly some tutorials or ideas how to select cube, which is seems to be more advanced thing

ProgrammerX
03-29-2018, 03:08 AM
What you need to do does not really involve OpenGL at all. The technique is called ray picking.

First you need to get the position of the mouse in your windows coordinate system (freeglut, glfw etc. functions). Than you calculate a ray. This ray depends on your projection matrix. If you have got the correct ray you just perform a simple collision test between your object and the ray. If there is a collision, just pass a scaling factor of 2 to your vertex shader.
But watch out: If you don't use the same scaling factor during your collision tests, the object shrinks back to normal size if you leave the area of the unscaled cube. Adjust you code depending on what you want to achieve.

For a start on ray casting:

http://antongerdelan.net/opengl/raycasting.html

There are other techniques that also do the trick, like color picking, but I think thats a little bit to much, since it involves a lot of knowledge about OpenGL.