gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > 3d Level

#60684 - Xgame - Sun Nov 13, 2005 6:33 pm

Hi, i am developming a Fps for ds using libnd+opengl.
for move camera i use gluLookAt; but i don' t now how import a 3d model as map. I need collision and calculated height.
I have some .bsp map(quake 3).
can i' ll use it?

#60693 - SevenString - Sun Nov 13, 2005 11:27 pm

On the DS, I know of no common way to "get there from here". A lot of people, including me, are rolling their own tools.

There are some conversion utils that will get various file formats into 3d text-based geometry files or .c code for later interpretation by your DS application. Look at the libnds examples, epsecially the one that uses GBFS and an external "world.txt" file. It's a very simple example of a way to get some data rendered on the DS.

Personally, what I've done is to create a Softimage:XSI script to export objects into a file format that my DS code can read and understand, including stuff like materials, animation, etc.

There's a lot of other stuff that I've done involving scripting, abstracting scene "actors" from the objects, and so forth. However, I don't think there is anything like a free "level editor" or similar around the homebrew DS scene.
_________________
"Artificial Intelligence is no match for natural stupidity."

#60767 - Xgame - Mon Nov 14, 2005 5:24 pm

ok, but how to convert a model in those format?
and how to use collision?
maybe i must calcoulate point for point evry collision place?

#61104 - cybereality - Thu Nov 17, 2005 8:09 am

I haven't gotten into and 3d ds coding yet, so I can't help you getting 3d assets onto the ds. In terms of collision I can offer some general ideas on how that would be implemented. I am actually working on a physics library in flash that I hope to port to the ds some day ;)

To test for collision in an arbitrary 3d mesh you need to first have an array of faces to test for collision. This could be the actual level mesh, or you may want to make a simplified "collision mesh" that dictates where the player can move. At the start of the level you want to precalculate the normals of each of the faces.

I also assume there is a vector velocity to the player which controls the movement. So pressing the Up-button moves the player by a certain force in his forward vector.

To check for the collision you want to see if the angle between the players velocity and the surface normal vector is within a particular range. For instance, if the player is facing a wall the angle would be 0. If he was looking away from the wall the angle is 180. So you can say that only faces with an angle of +-90 from the players are potential collisions. This may be combined with any back-face culling code as an optimization.

Now you have a list of potential collision faces. Within that list do a line-through-plane check and check the distance. If that distance is less than a certain value (i.e. the radius of the player) then you have a collision; return true;

You also need some way to handle the collisions. For an object (health for instance) it may be as simple as calling health++; for other things it may require special care. For wall/floor collision you need to be able to alter the players velocity so that he wont go through the wall or floor.

For wall collision you want to change the players velocity to the line perpendicular to the normal angle. This way the player will slide along the wall and not be stuck. Since there are 2 perpendicular rays from the normal vector, you use the one that the player is closest to (so you can slide both ways on the wall).

For floor collision you want to do the same as with the wall collision except you use the player's downward vector for testing. If you have gravity in the game this is where you add the forces (i.e if the player is more that 10 units off the floor then kick gravity in).

That covers the basic idea of a 3d collision system. I have some code in javascript, but I figured it would be easier to explain the concepts. This is by no means the only way. There are also numerous optimizations that could be done as well (binary space partitians, etc). I just wanted to lay out the basics. Hope its of some help.
_________________
// cybereality