It is currently Sat Aug 22, 2020 3:39 pm


All times are UTC




Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Get hit face from raycast
PostPosted: Tue Jul 05, 2011 12:25 pm 

Joined: Tue Jun 28, 2011 6:06 am
Posts: 2
Is there a quick way to determine which face of a voxel was hit by a given raycast?

Just getting to grips with polyvox with a simple voxel model editor. If I were in "insert voxel" mode, I'd want to add a voxel adjacent to the clicked face - add a block in (x, y+1, z) if it was the top face, a block at (x-1, y, z) if it was the left face, etc.

Seems like this wouldn't be an unusual problem, so I figured I'd put a quick post up here. See if it was something that's been solved already before I get too deep into the math!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Get hit face from raycast
PostPosted: Tue Jul 05, 2011 7:03 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
That feature isn't implemented at the moment. Part of the reason is that the raycast should be useful for the smooth volumes as well as the cubic ones, and in this case there is no 'face' as such.

I think a solution would be to keep track of the previous voxel as well as the current voxel when casting the ray. This previous voxel would be also be returned in the result, and by comparing the previous voxel with the current one you could work out which face you had come though.

You probably want to modify the Raycast::doRaycast() function to handle this, but if you can't figure it out then let me know and I can add it for you.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Get hit face from raycast
PostPosted: Wed Jul 06, 2011 1:56 am 

Joined: Tue Jun 28, 2011 6:06 am
Posts: 2
Oh, great! I was going to use the face to determine the previous voxel anyway, so this is an even better approach.

Thanks!


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Get hit face from raycast
PostPosted: Wed Jul 06, 2011 2:34 am 

Joined: Sat Sep 18, 2010 9:45 pm
Posts: 189
If you use another library which returns only the intersecting point, you can do something like figure out the direction of the ray, then compare against the normal of the two faces for the two cases of facing the ray casting point or facing away from it. How do get the normal of the faces? You need to hash the intersecting point into a voxel, then get two other points on this voxel to form a face and a normal. We only want the case where the casting ray and the face normal face away from each other. This only works if you assume that you never ray cast from inside a solid voxel.

I do something like this right now but I'm comparing against 6 faces, which is redundant.

BTW: to compute the points on the face, all you need is the intersection point, a vector V from the intersection point to the cube center (hashed cube center from intersection point), and the parallel component of V with respect to the normal of the cube (normal here is simply the Y axis). There are other ways to get the points.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Get hit face from raycast
PostPosted: Thu Jul 07, 2011 9:55 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
I meant to say, if you do implement this then we'll be happy to add the changes to PolyVox. Let us know of you have any problems.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Get hit face from raycast
PostPosted: Mon Sep 19, 2011 1:40 am 

Joined: Mon Sep 05, 2011 6:57 pm
Posts: 3
I implemented this by adding a "previousVoxel" vector3d to the result, how can I contribute it? Branch git, post patch, attach files? I haven't been on the forums for long, my apologies if there's a well defined way to submit code changes that I missed.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Get hit face from raycast
PostPosted: Mon Sep 19, 2011 5:01 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
Great, I think a patch would probably be easiest. There may be a Git-specific solution but to be honest I've got a lot to learn about Git. So just create the patch and attach it here in the forum.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Get hit face from raycast
PostPosted: Mon Sep 19, 2011 8:17 pm 

Joined: Mon Sep 05, 2011 6:57 pm
Posts: 3
Here you go. Great job on the library btw! I hope to have a demo for the showcase soon :D


Attachments:
Raycast.inl.patch [132 Bytes]
Downloaded 226 times
Raycast.h.patch [41 Bytes]
Downloaded 238 times
Top
Offline Profile  
Reply with quote  
 Post subject: Re: Get hit face from raycast
PostPosted: Mon Sep 19, 2011 10:20 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
I'm sorry, but it turns out I don't know enough about Git to apply these. Were they created using the 'git format-patch' command? I placed them in the same folder as Raycast.h and Raycast.inl and tried 'git apply Raycast.h.patch' but it just tells me 'error: no changes'. Do you know if that's the right procedure?

Otherwise just give me the complete files and I'll overwrite my local copy.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Get hit face from raycast
PostPosted: Tue Sep 20, 2011 6:28 am 

Joined: Mon Sep 05, 2011 6:57 pm
Posts: 3
Um I just used winmerge to create the patch as I don't know much about git's patching system either. I've attached the full files, there's only 3 lines changed.


Attachments:
Raycast.h [4.97 KiB]
Downloaded 228 times
Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net