• 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
space_cadet

Effective way to detect whether my 3D cubes are outside the 2D screen boundaries?

6 posts in this topic

I am implementing a screensaver - a starfield made out of cubes that move towards the viewer in 3D space:

[attachment=11138:screenshot.png]

I place the camera away from the origin along the z-axis, generate the cube objects at the origin with random x and y values, and move the cubes towards the viewer along the z-axis.

Naturally, the more cubes I have, the more calculations I have to perform. Therefore I would like to reset any cube as soon as it is outside the screen boundaries, so I can reuse it and restart it at the origin.

I have read [url="http://www.lighthouse3d.com/tutorials/view-frustum-culling/"]lighthouse3d's excellent tutorial about view frustrum culling[/url], but I believe there must be a more efficient way for my special case. The best I came up with was taking the center point of each cube [0,0,0], multiply it with the model-view-projection matrix (which is cheap, because I have that matrix already), transform its x and y values into device coordinates (dividing them by w) and see if either one is smaller than -1.0 or greater than 1.0.

This is quite effective, but of course the cubes disappear as soon as their [i]center[/i] is outside the screen boundaries, while I would like them to be completely outside before disappearing.
0

Share this post


Link to post
Share on other sites
just keep your point method, and multiply the result by 0.9 or something so that you effectiveley increase the virtual size of your screen and the cubes will pop away after they pass the border region.
0

Share this post


Link to post
Share on other sites
[quote name='Lightness1024' timestamp='1347020293' post='4977586']
just keep your point method, and multiply the result by 0.9 or something so that you effectiveley increase the virtual size of your screen and the cubes will pop away after they pass the border region.
[/quote]

No, I believe that would not work properly for all cases.

[quote name='Seabolt' timestamp='1347029439' post='4977655']
Well if you're using only cubes, you can just check based on the center plus half the width of a face, making it a pseudo bounding sphere check.
[/quote]

I think it would have to be [i]diagonal / 2[/i], but in principle, that is what I had in mind. But how much is [i]diagonal / 2[/i] in normalized device coordinates?

[quote name='Lauris Kaplinski' timestamp='1347025073' post='4977619']
What's wrong with the following method?
[/quote]

Actually, I think you may be right. I thought the distance calculation was a bit expensive, but I had a closer look and it's just a few multiplications and additions.
0

Share this post


Link to post
Share on other sites
If you are really worried about a few operations more or less, you can also look at this: http://www.lighthouse3d.com/tutorials/view-frustum-culling/radar-approach-testing-points/ and use the sphere version. Though I have yet to see any performance difference worth mentioning.
0

Share this post


Link to post
Share on other sites
What I would do is I'd compute the out-of-screen check in 2D using bounding spheres instead of the cubes.

Offline: Compute the bounding sphere of the cube (the radius of the sphere that encloses the whole cube)

Online:
1. Transform the center point P of the cube to 2D screen coordinates P'.
2. Transform the radius R of the bounding sphere at the distance of the cube to 2D screen coordinates R'.
3. Compare if the 2D point P' is farther than R' outside of one of the four edges of the screen and if so, discard it.

This method should be considerably more lightweight than SAT of 3D AABB vs 3D frustum.

Another even simpler method would be to just check when the cube passes the camera near plane, and kill it there.
1

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