Well… I have a bunch of old projects that weren’t published for some reasons…It’s time for them to finally see the light 🙂
Just a few notes:
-These are old, so many things are less professional than I would write now, many things have nothing to do with OOP…
-You’ll need the SFML dlls to run any SFML game.
SFML, OpenGL, C++ (VisualStudoi2008)
Click on image to view animated full size version
A path finding application that finds a path in a 3D maze from one corner to the other..
The maze is generated randomly, can be moved, rotated, zoomed in/out with keyboard…
The console window contains more information..
Actually this application was Read more…
This tutorial is really short..It’s not actually about picking but somehow related to it, I wanted to write this in the same post as Part II but Part II was already long enough.. 🙂
Another use for Viewport.Project:
In part II we used Viewport.Project to get the positions of 3D objects on the 2D screen, well.. that was useful for picking…Another excellent use of Viewport.Project is displaying 2D elements over 3D objects such as units names in a game or the health bar for example…
In part I, I talked about picking single objects, In many cases such as RTS games that’s not enough…
You’ll need to select multiple units together using some sort of a rectangle or selection box that you make by clicking and dragging with your mouse.
Two approaches I know:
1- Unprojecting your selection box and check for collisions in 3D world space.
2- Projecting your 3D objects and perform simple 2D rectangle collision detection.
First approach, Unprojecting a rectangle ( A little tricky ) :
If you unproject a point the result should be a ray ( Part I discussed this issue in some detail) , If you unproject a rectangle the result depends on your projection matrix, We’ll assume it’s a perspective projection matrix, so the result of unprojecting a rectangle is a frustum (BoundingFrustum in XNA), in most cases this BoundingFrustum is not a scaled version of the view frustum, it’s some sort of irregular frustum, images are better than words:
Click on image to see full size
Now how do we get this frustum? Read more…