Sega Saturn Development > Share your code

3D Map tool + FPS demo

(1/5) > >>

XL2:
Hi all,

I wrote a little tool to convert a level's polygons into bounding boxes (axis-aligned).
It merges the bounding boxes (BB) with their neighbour to reduce the amount of boxes.
It also calculates the slopes on one axis (x or z), but it doesn't generate the heigth masks yet (on my to do list).
It will be complicated to explain as I didn't add an example (on my to do list), so read carefuly and don't hesitate if you have questions.

Ok, now for the explanations (I'll try to explain, but I hope you guys will understand)

The idea is like this : you use a function similar to the Jo_intersect, but add the z axis... or just do 2 jo_intersect and replace the x with the z value for the second function.
Do 2 or 3 collision checks (x/z and y, or x and z and y - I suggest you go for 3)

If the collision mask value is -1, then just use it as is : you have a collision and just stop the movement on that direction.

If the mask is 0 or higher, then you just do a lookup in an array of values. The arrays I use are only 2 dimensions (because of memory constraints), but you could do 3 dimensions arrays as well for hills and other shapes.

Example : You know you have a slope if the rotation value on the x-axis isn't 0. So you look for a mask.
As an example, for a 45 degrees slope on the x-axis, your slopeRXangle will be 45 (or -45 depending on the direction).
So you look for the heigth mask returned by the function, and you look it up with your current Z position (not x since the axis of rotation is on the x axis - look for z as you go up or down on the slope), which will return a heigth value.

So let's say your relative Z position to the current BB is 100, and the BB has a length of 200.
Look at the array at position 100 (your z position minus the BB minimum z position), which will return a heigth value.

Just look for that value added to the minimum Y value of the bounding box to see if you have a collision (like, the minimum Y of the BB being -200, Y length being 200, and the heigth mask returns 100, so you look to see if you currently have a collision for an object with Y values ranging from -100 to 0)
.
Do another intersect check with your current Y value, if there is a hit, return it, else there is no collision.

This way, you can have smooth slopes with very little CPU usage. An it works for all 3 axis collision checks.
I need to improve my code to better merge the BB together and improve memory usage and CPU usage.
If you have a slope with side walls (looking "out" of the slope), you will hit an invisible wall as it won't merge them and it will cover your slope.
Just remove these walls for now and only keep the "ground" part (you might have to manualy ajust the heigth as well in the resulting file)
I didn't do much testing, so there might still be bugs I haven't found.

I'll also share my collision code at a later date, but right now I'm pretty much rewriting many parts of it so it's far from complete.

Hope this helps someone creating a 3D game!

EDIT : I added another version of the collision tool (still not good enough, it's buggy with slopes)
EDIT 2 : Added a function to write using Danny's code, but it's not 100% complete (WIP). Also got rid of the need to link to SGL.h, if it's causing issues make sure you tell me as I didn't test properly. I also quickly coded a .Obj exporter to Danny's code, but I didn't test it. Some stuff is wrong for sure and it might not work with all .Obj formatting, I will have to spend more time on this.
EDIT 3 : Added reading .OBJ files and binary file output. The FPS demo now uses the binary file format to load maps. I will add more features to the binary format.
EDIT 4 : Many bug fixed such as unaligned read/write, issues with multiple meshes. The .OBJ to binary seems to work fine now, tell me if you have issues. I also added basic view frustum culling to the FPS demo, put a HUD using Jo Engine functions (causes issues with other VDP2 functions, just uncomment other lines to revert to the RBG0 plane), removed the gouraud shading depth (made the game way too slow on real Saturn).

EDIT (2017-08-16) : Upgraded to Jo Engine 9.0 (make sure you upgrade also). I also fixed the memory allocation, so you should be able to load much bigger files now (try map 3 to see).

EDIT (2017-08-25) : You can now write textures directly in the binary file. The map program will read TGA textures (uncompressed only) and write them. Also added auto-subdivision of the map for culling, you just need to specify how many "cuts" you want (there is a bug that will sometimes "lose" polygons, so just try different values for "cuts" (x, y, z axis) if one setting doesn't work well). I also changed the FPS demo's collision code to reduce CPU usage.

XL2:
Ok, as promised, a small demo (source code attached here) with a simple 3D collision engine.

I haven't spent much time on this, so it's buggy and far from perfect, and isn't modular enough.

I wanted to use the smooth control made by Danny, but I just used a 2-axis system for straffing and really didn't do much control-wise.

So, don't go burn this for your Saturn expecting a Quake-killer or Lobotoby software quality!
That being said, it should still be better than the SGL FPS demo (which had terrible collision detection).

Ingame : D-Pad for turning and going forward/backward, L/R for straffing and B for jumping.

The collision generator tool worked well for the Sonic level I tested, but it didn't work well with the small level I made for this demo (the slopes had problems, getting merged with other BB). I will have to improve the tool and share it again here once I do.

EDIT : Moved the file to the first post. I also added the map changing functions which now reads the binary file format (press L or R + start to switch maps)

Video here :
https://www.youtube.com/watch?v=a2TQrK2ZPJU

mindslight:
Nice demo  :)
This should help people to start an fps style game

Danny:
Hi!
I'm sharing a modified version I made of the "Advanced 3D" that loads the mesh from ROM to RAM using direct memory access instead of a static allocation.
This requires a little bit of knowledge of pointer arithmetic but is worth the effort because it makes loading different meshes easier. The same approach can be used to load other stuff so I guess it's also a good starting point to learn.
I made this to help our friend XL2 with his game and he will be incorporating this on his great tool, but for now I thought it would be nice to share this with all of you in case you are curious :P.

XL2:
Like usual, thank you and amazing work Danny! I integrated your smooth FPS control in the FPS demo.
I didn't make a video of it, but you can see I updated the video in the previous post to show what it looks like with a VDP2 plane (with transparency), and I think it shows how much potential the Saturn has for beautiful effects!
I'll try over the weekend to update the collision tool to output .h files compatible with the format you made and integrate that in the FPS demo as a starting point for others.

Navigation

[0] Message Index

[#] Next page

Sitemap 1 2 3 4 5 6 7 8 9 10 
Go to full version