• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Spa8nky

Closest point on ray to AABB?

10 posts in this topic

I'm sorting all my transparent objects by distance from the camera so they can be drawn correctly. Using their central positions doesn't work well enough so I thought I would use their AABBs instead.

I would like to find the closest point on a ray (cast from the camera's position, along its forward vector) to each transparent object's AABB in the scene.

I know how to find the closest point on a AABB to a point but I'm not certain how to expand that to a ray.

Any ideas?
0

Share this post


Link to post
Share on other sites
If i understand correctly.......

What you really wanna do here is see which side of the AABB is closest to a ray thats being cast,

An AABB has 6 sides, these 6 sides can be represented by 6 planes with boundaries, you can easily find where the these planes will intersect with the ray, and by finding where these planes intersect with the ray you also get the TIME t, or the DISTANCE d (depending which way you want to look at it) that it takes for the ray to get there, Then you simply compare which value of t, or d is smallest for the 6 sides and tada! you then know which is the closest point to the ray.

Hope this helped.
0

Share this post


Link to post
Share on other sites
See [url="http://www.geometrictools.com/LibMathematics/Distance/Distance.html"]this page[/url] , section "Distance between lines, rays, or segments and boxes (3D). "
1

Share this post


Link to post
Share on other sites
[quote name='Spa8nky' timestamp='1311809610' post='4841352']
I'm sorting all my transparent objects by distance from the camera so they can be drawn correctly.
[/quote]

Try to use the distance to the near plane, not to the camera position. Often the distance to the object center is good enough, but if it isn't you can use it's bounding volume.
1

Share this post


Link to post
Share on other sites
[quote name='Dave Eberly' timestamp='1311823284' post='4841423']
See [url="http://www.geometrictools.com/LibMathematics/Distance/Distance.html"]this page[/url] , section "Distance between lines, rays, or segments and boxes (3D). "
[/quote]

Thanks Dave. I hooked that up but it wasn't the test I was looking for as the point on the ray could be closer to an AABB that is further away at certain viewing angles. That scenario didn't occur to me until after I spent an afternoon implementing it! :(

[quote]
[color="#1C2837"][size="2"]Try to use the distance to the near plane, not to the camera position. Often the distance to the object center is good enough, but if it isn't you can use it's bounding volume.[/size][/color]
[/quote]


The object center is currently not good enough so I would like to calculate the distance between an AABB and the near plane. I can compute the distance between the AABB's center and the plane:

[code]
float distance = Vector3.Dot(plane.Normal, aabb.Position) - plane.D;
[/code]

How do I find the smallest distance from the AABB to the plane?


EDIT:

Is this correct?

[code]

float r =
Math.Abs(aabb.Extents.X * plane.Normal.X) +
Math.Abs(aabb.Extents.Y * plane.Normal.Y) +
Math.Abs(aabb.Extents.Z * plane.Normal.Z);

float distance = Math.Abs(Vector3.Dot(plane.Normal, aabb.Position) - plane.D - r);
[/code]
0

Share this post


Link to post
Share on other sites
My idea isn't correct after testing today.

Can some please explain how I can obtain the distance between the closest AABB face and a plane? In other words the distance between the closest point on the AABB to the plane.
0

Share this post


Link to post
Share on other sites
[quote name='Spa8nky' timestamp='1311940818' post='4842104']
Can some please explain how I can obtain the distance between the closest AABB face and a plane? In other words the distance between the closest point on the AABB to the plane.
[/quote]

Surely for a convex shape like a cube it'll be one of of the corners (the points on the face will never meet the plane independently of the corners) - So just do point-to-viewplane distances for all 8 corners (and choose the smallest positive distance)?

However.... Returning to the transparency sorting - do your objects overlap or inter-penetrate? If they do, you'll not make it work using neither centres nor nearest-points.

Jans.
0

Share this post


Link to post
Share on other sites
[quote]
[color="#1C2837"][size="2"]Surely for a convex shape like a cube it'll be one of of the corners (the points on the face will never meet the plane independently of the corners) - So just do point-to-viewplane distances for all 8 corners (and choose the smallest positive distance)?[/size][/color]
[color="#1C2837"][size="2"][/quote][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]I thought about testing all 8 corners but I figured there must be a more elegant solution.[/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"][quote][/size][/color]
[color="#1C2837"][size="2"]Returning to the transparency sorting - do your objects overlap or inter-penetrate?[/size][/color]
[color="#1C2837"][size="2"][/quote][/size][/color]
[color="#1C2837"] [/color]
[size="2"][color="#1c2837"]They don't and they are all convex. However, if I were to have overlaps I guess I would abandon the sorting idea altogether. Triangle sorting would be overkill and I think there is a way (pre multiplied alpha?) that doesn't require sorting of any sort.[/color][/size]
[size="2"] [/size]
[size="2"][color="#1c2837"]EDIT:[/color][/size]
[size="2"] [/size]
[size="2"][color="#1c2837"]Calculating the distance to the plane suffers from the same problems as the ray test in that the plane is infinite and large boxes that are further away can be closer to the plane, which is incorrect for sorting.[/color][/size]
0

Share this post


Link to post
Share on other sites
Iam still going with my initial suggestion of find the value T or D from the Ray to the Walls of the AABB. The shortest one is closest to the screen.
0

Share this post


Link to post
Share on other sites
[quote name='The_Neverending_Loop' timestamp='1311968076' post='4842276']
Iam still going with my initial suggestion of find the value T or D from the Ray to the Walls of the AABB. The shortest one is closest to the screen.
[/quote]

I don't understand how that will work correctly. Forgive me if am being dim but a ray cast from the camera along its forward vector can easily miss a side of the AABB if that side is (almost) parallel to the ray.

What advantage does the ray to plane distance test have over the corner to near plane distance test in this case?
0

Share this post


Link to post
Share on other sites
[quote name='Spa8nky' timestamp='1312065531' post='4842657']
[quote name='The_Neverending_Loop' timestamp='1311968076' post='4842276']
Iam still going with my initial suggestion of find the value T or D from the Ray to the Walls of the AABB. The shortest one is closest to the screen.
[/quote]

I don't understand how that will work correctly. Forgive me if am being dim but a ray cast from the camera along its forward vector can easily miss a side of the AABB if that side is (almost) parallel to the ray.

What advantage does the ray to plane distance test have over the corner to near plane distance test in this case?
[/quote]

Seems like a problem of precision. (Precision of the order of how close is considered parallel, also the precision of the point of intersection is always +/- a small amount) However when thinking about an AABB (or any box), holding it in front of my face, if I get one side nearly parallel to my forward gaze, there seems to be another side which is orthogonal and shares an edge. Additionally, however, the (almost) parallel side is hardly seen (has little influence on the image seen). So I'm not sure if the (almost) parallel side effect would cause a problem (and could be "fixed" by using higher precision?)

So to sort transparent objects you want to know which are closer and do a front to back rendering effect. So you want to sort sides it seems, rather than objects. (What happens if two objects take up some of the same space? An object partially inside another object?) So you want to deal with the closest side, followed by the next closest side (which isn't guaranteed to be from the same object). I guess that's why it seems like sorting by closest side gives an advantage.

But I've never done transparency so I'm just taking a stab in the dark ^^ Goodluck!
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0