2022-08-20 16:31:49 +02:00
|
|
|
#ifndef __RENDERH__
|
|
|
|
# define __RENDERH__
|
|
|
|
|
2022-08-27 14:03:44 +02:00
|
|
|
#include "settings.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include <utility>
|
|
|
|
|
2022-09-03 16:42:53 +02:00
|
|
|
#include <gint/display.h>
|
|
|
|
|
2022-08-27 14:03:44 +02:00
|
|
|
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. */
|
2023-05-24 19:59:36 +02:00
|
|
|
num near_plane() const { return this->screen_distance() * num(0.25); }
|
2022-08-20 16:31:49 +02:00
|
|
|
|
2022-08-27 14:03:44 +02:00
|
|
|
//======= World data =======//
|
|
|
|
|
|
|
|
/* Position in space; always looking towards +z. */
|
2022-08-20 16:31:49 +02:00
|
|
|
vec3 pos;
|
2022-08-27 14:03:44 +02:00
|
|
|
/* Current platform (used to assign colors). */
|
2022-08-20 23:08:30 +02:00
|
|
|
int platform;
|
2022-08-27 14:03:44 +02:00
|
|
|
/* Vector canceling the player's angular rotation around z. */
|
|
|
|
vec2 angle_vector;
|
|
|
|
|
|
|
|
//======= Screen settings =======//
|
2022-08-20 22:40:03 +02:00
|
|
|
|
2022-08-27 14:03:44 +02:00
|
|
|
/* Screen size. */
|
|
|
|
vec2 screen_size;
|
2022-08-20 23:08:30 +02:00
|
|
|
|
2022-08-27 14:03:44 +02:00
|
|
|
private:
|
|
|
|
num _sd;
|
2022-08-20 16:31:49 +02:00
|
|
|
};
|
|
|
|
|
2022-09-04 19:12:06 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2022-08-27 14:03:44 +02:00
|
|
|
struct player;
|
2022-08-20 19:46:41 +02:00
|
|
|
|
2022-08-27 14:03:44 +02:00
|
|
|
/* Move the camera to track behind a player. */
|
|
|
|
void camera_track(struct camera *, struct player const *);
|
2022-08-20 19:46:41 +02:00
|
|
|
|
2022-08-27 14:03:44 +02:00
|
|
|
/* 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);
|
2022-08-20 16:31:49 +02:00
|
|
|
|
2022-08-24 20:40:21 +02:00
|
|
|
/* Compute the platform's color based on the camera's angle. */
|
|
|
|
int camera_platform_color(struct camera *camera, int platform_id);
|
|
|
|
|
2022-08-20 23:08:30 +02:00
|
|
|
/* Queue an Azur command to render the triangle defined by p1/p2/p3. Only the
|
|
|
|
x/y coordinates are used, z is ignored. */
|
2022-08-20 16:31:49 +02:00
|
|
|
void render_triangle(vec3 *p1, vec3 *p2, vec3 *p3, int color);
|
|
|
|
|
2022-08-27 14:03:44 +02:00
|
|
|
/* Queue Azur commands to render a list of dots. Only x/y coordinates are
|
|
|
|
used, z is ignored. */
|
2022-09-04 19:12:06 +02:00
|
|
|
void render_dots(std::initializer_list<vec3> const &&points);
|
|
|
|
|
|
|
|
/* Render a frame of an animation. */
|
|
|
|
void render_anim_frame(int x, int y, struct anim *anim, int frame);
|
2022-08-27 14:03:44 +02:00
|
|
|
|
2022-08-20 16:31:49 +02:00
|
|
|
#endif /* __RENDERH__ */
|