Jump to content
Posted 14 August 2012 - 06:09 PM
Posted 14 August 2012 - 07:15 PM
Posted 14 August 2012 - 07:25 PM
I did think of that. But, I was wandering if there is anyway to get the block with some equation?
You need to use a technique called ray casting. From the position of the player's eye (centre of the viewport) and your camera's direction vector you create a ray and then test that against your geometry to determine where it intersects.
Posted 14 August 2012 - 11:44 PM
Posted 15 August 2012 - 07:11 AM
Posted 15 August 2012 - 08:54 AM
Yeah I think I'm going to do raycasting instead just because it would be a lot cleaner and so I don't have to code a lot more.
to raycast start from the block the ray starts from, if its empty find out where it exits the block and which other block it enters and repeat from that new position on the surface of that next block.
I think picking using the results of rendering would be kind of messy and possibly limiting.
Posted 16 August 2012 - 09:44 AM
Posted 16 August 2012 - 11:53 AM
Posted 16 August 2012 - 12:38 PM
Posted 16 August 2012 - 12:42 PM
Without knowing many relevant things about your engine I'd say picking is pretty ace instead of messy or limiting. You can find all your objects, voxels and gui elements with checking a single value, and your user is guaranteed to pick exactly the pixel he chose. If you do this by rendering to an offline ID framebuffer, you can even do it with practically no performance hit.
The math isn't overwhelmingly hard either, so you can just raycast through the voxels. And it doesn't involve reading back from the GPU, which is a nice feature. Lode's tutorial has a very nice explanation which you should be able to turn into 3D pretty easily.
Posted 16 August 2012 - 12:44 PM
You can find the surface the ray huts by taking the position of the hit (i assume you dont use some laggy raycast which steps in tiny steps and each time checks what voxel its in...) and checling its distance from each 3 planes pointing along an axis.
Like if the distance of the point from the xz plane is about 0.5 (half voxels), it will be on one of the y axis surfaces depending of the sign (either -y or y surface)