PDA

View Full Version : Picking/ particle effect



drew21
03-04-2017, 09:13 AM
I have a bunch of spheres that i drew in open gl. I am trying to make it to where when the user clicks on one with the mouse it explodes. I am guessing i would use both picking and the particle effect for this?

Any sources online that could help with the code would be great.

john_connor
03-05-2017, 01:57 AM
I have a bunch of spheres that i drew in open gl. I am trying to make it to where when the user clicks on one with the mouse it explodes. I am guessing i would use both picking and the particle effect for this?

Any sources online that could help with the code would be great.

it depends on how detailed (= complex) you want it to be:
"explosion" effects can be done using a bunch of textures, which you have to render to a primitive on the screen sequentially, or you use a "geometry shader" in which you transform each face of a (lets say) sphere away from the sphere center, in addition to that you rotate each face randomly (to make it appear "real")
https://learnopengl.com/#!Advanced-OpenGL/Geometry-Shader

particles can be simulated on the gpu using either "transform feedback" or "compute shader", otherwise you can do the particle simulation offline (on the cpu) which will be much slower
(a transform feedback example is described in the book "OpenGL Programming Guide 8th Edition")
https://www.google.com/#q=transform+feedback+particles&*
https://sites.google.com/site/john87connor/compute-shader/tu

to determine the 3D position where to do the explosion effect, you can do "raycasting" or "picking", but there has to be a face under the cursor (otherwise you can only determine 2D position, without the depth)