#ifndef __RENDERH__ # define __RENDERH__ #include "settings.h" #include "util.h" #include #include struct camera { //======= Fixed settings =======// /* Vertical FOV, in degrees. */ num fov; void set_fov(num fov); /* Distance to the screen (world units). */ num screen_distance() const { return this->_sd; } /* Distance to the near plane, for clipping. TODO: Figure out a better choice of a near plane. */ num near_plane() const { return this->screen_distance() * num(0.25); } //======= World data =======// /* Position in space; always looking towards +z. */ vec3 pos; /* Current platform (used to assign colors). */ int platform; /* Vector canceling the player's angular rotation around z. */ vec2 angle_vector; //======= Screen settings =======// /* Screen size. */ vec2 screen_size; private: num _sd; }; struct anim { /* Number of frames in the animation. */ int frame_count; /* List of cropped frames. */ image_t **frames; /* x/y offsets to add to desired render coordinates to render each frame at the proper position. */ uint8_t *x_offsets; uint8_t *y_offsets; /* Position of the x and y anchors. */ int16_t x_anchor; int16_t y_anchor; }; struct player; /* Move the camera to track behind a player. */ void camera_track(struct camera *, struct player const *); /* Project a world point to the screen as viewed through a camera. The returned vector has its x/y members set to screen coordinates stored as num; the z member is kept unchanged. */ vec3 camera_project_point(struct camera *, vec3 point); /* Optimized camera_project_point() that projects an entire prect in-place. */ void camera_project_prect(struct camera *, struct prect *rect); /* Compute the platform's color based on the camera's angle. */ int camera_platform_color(struct camera const *camera, int platform_id); //======= Rendering tools =======// /* Initialize/precompute globals. */ void render_init(void); /* Color of a blue platform at the specified world time. */ uint16_t render_color_blue_platform(num t); /* Color of the provided platform viewed from the provided camera at the given world time. */ uint16_t render_platform_color(struct platform const *p, struct camera const *camera, num t); /* Queue an Azur command to render the triangle defined by p1/p2/p3. Only the x/y coordinates are used, z is ignored. */ void render_triangle(vec3 *p1, vec3 *p2, vec3 *p3, int color); /* Queue Azur commands to render a list of dots. Only x/y coordinates are used, z is ignored. */ void render_dots(std::initializer_list const &&points); /* Render an energy string (energy font, characters supported: 0-9.%) */ void render_energy_str(int x, int y, int halign, char const *str); /* Render a frame of an animation. */ void render_anim_frame(int x, int y, struct anim *anim, int frame); /* Render the blue platform particle effect at time t. If *image is NULL, creates it automatically. */ void render_effect_bpp(image_t **image, num t); #endif /* __RENDERH__ */