Skip to content

zenodante/Basic-3d-lib

Repository files navigation

Basic-3d-lib2

This is a 3d engine for stm32h750 based 32blit game system. It would be quite easy to port to any arm cortex m4/m7 mcu with enough ram.

Several math functions were copy from nvidia cg fast math lib. invert sqrtf is copy from id soft quake.

Left-hand coordinate was used in this lib
^ y
| ^ z
| /
|/
+--------> x

Screen coordinate is x y[0,0] from top left corner. The real render area is defined by the RENDER_RESOLUTION_X/Y, the whole frameBuff is defined by WHOLE_FRAME_BUFF_WIDTH/HEIGHT, the position shift of the render window is controlled by the address given to the init function.
0,0 ---------> x
|
|
|
y v
Always using row vector, so v * mat -> new v

Rotations used quaternion internally in transform struct. You could also set the rotation by euler angles in ZXY order, Positive rotation about an axis follow left-hand method.

  • Light and color shade
  • Texture mapping triangle drawing
  • 2d Sprite drawing in 3d space
  • Polygon drawing
  • 3d particles, common per defined particle (rain)
  • fast flat color triangle drawing
  • Near plane clip option
  • LUT 8bit framebuff and 16bit uint zbuff
  • Customerized heap management (modified from FreeRTOS heap4.c)
  • Heap resource buffering and garbage collection based on reference count

How to use the lib

You could get the 32blit project from :https://github.com/32blit/32blit-sdk.git
This project is based on the default template for 32blit project : https://github.com/32blit/32blit-boilerplate.git
If you use the default setting in the config file for max heap size in stm32h750, you would need to copy the "STM32H750VBTx.ld" to replace the one in 32blit-sdk/32blit-stm32/ folder.
The new ld file move the default heap steak bss data section to DTCM area and left the main ram area for the customerized heap.

You could use the b3d_config.h to change the default values for the engine.
b3d_port.h/c contains the heap and z buffer setting which depends on the hardware.

Call B3L_RenderInit_Simple function to init the render system. It would allocate RAM for buffers and default parameters for the engine.

struct render
|--Scene
|--Camera
|--Light
|--pointer to the framebuffer
|--pointer to the z buffer
|--pointer to the vector buffer
... and other render parameters

Scene contains all the resources and objs. Only objs in the active list would be draw to the screen.
Camera has two type: PERSPECTIVE_PROJECT and OTHROGRAPHIC_PROJECT, you could set the zoom parameter (focuslength) and aspect ratio for the camera

About

rework on the basic 3d lib

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published