Banjo API 1.0.0-rc.2
Low-level C99 game development API
Loading...
Searching...
No Matches
physics_particle.c File Reference
#include <banjo/app.h>
#include <banjo/main.h>
#include <banjo/assert.h>
#include <banjo/bitmap.h>
#include <banjo/draw.h>
#include <banjo/event.h>
#include <banjo/log.h>
#include <banjo/mat.h>
#include <banjo/physics.h>
#include <banjo/physics_2d.h>
#include <banjo/pixel.h>
#include <banjo/system.h>
#include <banjo/time.h>
#include <banjo/vec.h>
#include <banjo/window.h>
#include <stdlib.h>
Include dependency graph for physics_particle.c:

Go to the source code of this file.

Data Structures

struct  planet_t

Macros

#define SCREEN_WIDTH   800
#define SCREEN_HEIGHT   600
#define CANVAS_WIDTH   SCREEN_WIDTH
#define CANVAS_HEIGHT   SCREEN_HEIGHT
#define FB_PIXEL_MODE   BJ_PIXEL_MODE_XRGB8888
#define G_SUN   BJ_F(120.0)
#define SOFTENING   BJ_F(6.0)
#define M_SUN   BJ_F(1000.0)
#define M_MERCURY   BJ_F(0.055)
#define M_VENUS   BJ_F(0.815)
#define M_EARTH   BJ_F(1.0)
#define M_MARS   BJ_F(0.107)
#define M_JUPITER   BJ_F(317.8)
#define N_PLANETS   5
#define N_ASTEROIDS   800

Functions

static void on_draw (struct bj_window *, struct bj_render_target *, const struct bj_rect *, void *)
static void update_projection ()
static bj_real orbital_speed_soft (bj_real G, bj_real M, bj_real r, bj_real eps)
static void init_sun ()
static void init_planet (planet_t *p, bj_real r, bj_real mass, uint32_t color, bj_real draw_r, bj_real phase)
static void init_asteroids ()
static void initialize ()
static void physics (bj_real dt)
static void draw (bj_bitmap *framebuffer)
static void * setup (struct bj_app *app, void *init_data)
static void fixed_step (struct bj_app *app, struct bj_tick_info tick, void *user_data)
static void step (struct bj_app *app, struct bj_tick_info tick, void *user_data)
static void teardown (struct bj_app *app, void *user_data)
int main (int argc, char *argv[])

Variables

bj_windowwindow = 0
bj_mat3x3 projection
planet_t planets [5]
bj_particle_2d sun = {0}
bj_particle_2d asteroids [800]
uint32_t asteroid_color

Data Structure Documentation

◆ planet_t

struct planet_t
Examples
physics_particle.c.

Definition at line 66 of file physics_particle.c.

Collaboration diagram for planet_t:
Data Fields
bj_particle_2d body
uint32_t color
bj_real radius

Macro Definition Documentation

◆ CANVAS_HEIGHT

#define CANVAS_HEIGHT   SCREEN_HEIGHT
Examples
physics_particle.c.

Definition at line 40 of file physics_particle.c.

Referenced by update_projection().

◆ CANVAS_WIDTH

#define CANVAS_WIDTH   SCREEN_WIDTH
Examples
physics_particle.c.

Definition at line 39 of file physics_particle.c.

Referenced by update_projection().

◆ FB_PIXEL_MODE

#define FB_PIXEL_MODE   BJ_PIXEL_MODE_XRGB8888

Definition at line 42 of file physics_particle.c.

◆ G_SUN

#define G_SUN   BJ_F(120.0)
Examples
physics_particle.c.

Definition at line 54 of file physics_particle.c.

Referenced by init_asteroids(), init_planet(), and physics().

◆ M_EARTH

#define M_EARTH   BJ_F(1.0)
Examples
physics_particle.c.

Definition at line 59 of file physics_particle.c.

Referenced by initialize().

◆ M_JUPITER

#define M_JUPITER   BJ_F(317.8)
Examples
physics_particle.c.

Definition at line 61 of file physics_particle.c.

Referenced by initialize().

◆ M_MARS

#define M_MARS   BJ_F(0.107)
Examples
physics_particle.c.

Definition at line 60 of file physics_particle.c.

Referenced by initialize().

◆ M_MERCURY

#define M_MERCURY   BJ_F(0.055)
Examples
physics_particle.c.

Definition at line 57 of file physics_particle.c.

Referenced by initialize().

◆ M_SUN

#define M_SUN   BJ_F(1000.0)
Examples
physics_particle.c.

Definition at line 56 of file physics_particle.c.

Referenced by init_asteroids(), init_planet(), and init_sun().

◆ M_VENUS

#define M_VENUS   BJ_F(0.815)
Examples
physics_particle.c.

Definition at line 58 of file physics_particle.c.

Referenced by initialize().

◆ N_ASTEROIDS

#define N_ASTEROIDS   800
Examples
physics_particle.c.

Definition at line 76 of file physics_particle.c.

Referenced by draw(), init_asteroids(), and physics().

◆ N_PLANETS

#define N_PLANETS   5
Examples
physics_particle.c.

Definition at line 72 of file physics_particle.c.

Referenced by draw(), and physics().

◆ SCREEN_HEIGHT

#define SCREEN_HEIGHT   600

Definition at line 38 of file physics_particle.c.

◆ SCREEN_WIDTH

#define SCREEN_WIDTH   800

Definition at line 37 of file physics_particle.c.

◆ SOFTENING

#define SOFTENING   BJ_F(6.0)
Examples
physics_particle.c.

Definition at line 55 of file physics_particle.c.

Referenced by init_asteroids(), init_planet(), and physics().

Function Documentation

◆ draw()

void draw ( bj_bitmap * framebuffer)
static

Definition at line 194 of file physics_particle.c.

◆ fixed_step()

void fixed_step ( struct bj_app * app,
struct bj_tick_info tick,
void * user_data )
static

Definition at line 257 of file physics_particle.c.

◆ init_asteroids()

void init_asteroids ( )
static
Examples
physics_particle.c.

Definition at line 125 of file physics_particle.c.

Referenced by initialize().

◆ init_planet()

void init_planet ( planet_t * p,
bj_real r,
bj_real mass,
uint32_t color,
bj_real draw_r,
bj_real phase )
static
Examples
physics_particle.c.

Definition at line 108 of file physics_particle.c.

Referenced by initialize().

◆ init_sun()

void init_sun ( )
static
Examples
physics_particle.c.

Definition at line 97 of file physics_particle.c.

Referenced by initialize().

◆ initialize()

void initialize ( )
static
Examples
physics_particle.c.

Definition at line 147 of file physics_particle.c.

Referenced by setup().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 278 of file physics_particle.c.

◆ on_draw()

void on_draw ( struct bj_window * w,
struct bj_render_target * target,
const struct bj_rect * dirty,
void * user_data )
static

Definition at line 238 of file physics_particle.c.

◆ orbital_speed_soft()

bj_real orbital_speed_soft ( bj_real G,
bj_real M,
bj_real r,
bj_real eps )
static
Examples
physics_particle.c.

Definition at line 91 of file physics_particle.c.

Referenced by init_asteroids(), and init_planet().

◆ physics()

void physics ( bj_real dt)
static
Examples
physics_particle.c.

Definition at line 183 of file physics_particle.c.

Referenced by fixed_step().

◆ setup()

void * setup ( struct bj_app * app,
void * init_data )
static

Definition at line 216 of file physics_particle.c.

◆ step()

void step ( struct bj_app * app,
struct bj_tick_info tick,
void * user_data )
static

Definition at line 262 of file physics_particle.c.

◆ teardown()

void teardown ( struct bj_app * app,
void * user_data )
static

Definition at line 272 of file physics_particle.c.

◆ update_projection()

void update_projection ( )
static
Examples
physics_particle.c.

Definition at line 80 of file physics_particle.c.

Referenced by setup().

Variable Documentation

◆ asteroid_color

uint32_t asteroid_color
Examples
physics_particle.c.

Definition at line 78 of file physics_particle.c.

Referenced by draw(), and init_asteroids().

◆ asteroids

bj_particle_2d asteroids[800]
Examples
physics_particle.c.

Definition at line 77 of file physics_particle.c.

Referenced by draw(), init_asteroids(), and physics().

◆ planets

planet_t planets[5]
Examples
physics_particle.c.

Definition at line 73 of file physics_particle.c.

Referenced by draw(), initialize(), and physics().

◆ projection

bj_mat3x3 projection
Examples
physics_particle.c.

Definition at line 45 of file physics_particle.c.

Referenced by draw(), and update_projection().

◆ sun

bj_particle_2d sun = {0}
Examples
physics_particle.c.

Definition at line 74 of file physics_particle.c.

Referenced by draw(), init_sun(), and physics().

◆ window

bj_window* window = 0

Definition at line 44 of file physics_particle.c.