BosonX/src/render.h

76 lines
2.6 KiB
C++

#ifndef __RENDERH__
# define __RENDERH__
#include <num/num.h>
#include <num/vec.h>
using namespace libnum;
/* Vertical FOV, in degrees */
#define RENDER_FOV 150.0
/* Radius of the level cylinder, in world units */
#define RENDER_RADIUS num(4.0)
/* Camera depth in the level cylinder, in world units, should be between 0
and RENDER_RADIUS */
#define RENDER_CAMERA_DEPTH num(2.9)
/* Section lengths, in world units */
#define RENDER_SECTION_LENGTH num(4.0)
/* Number of sections visible in advance */
#define RENDER_SECTION_DISTANCE 8
/* Duration of a camera rotation by one platform */
#define CAMERA_ROTATION_DURATION num(0.1)
struct prect {
vec3 nl, nr; /* Near left and near right points */
vec3 fl, fr; /* Far left and far right points */
};
struct camera {
/* Position in space - we assume looking towards (0,0,z) */
vec3 pos;
/* Current platform (or, when rotating, platform we just left) */
int platform;
/* Current direction of rotation (-1, 0, or +1) */
int rot_direction;
/* How much of the movement in rot_direction has been accomplished yet
(between 0 and CAMERA_ROTATION_DURATION) */
num rot_t;
/* Viewing angle and associated rotation vector. Both of these fields are
computed from the previous. */
num _angle;
vec2 _angle_rotation;
};
/* Initialize the render module. */
void render_init(void);
/* Angle, in radians, of a platform arc (2π / PLATFORM_COUNT) */
num render_platform_arc(void);
/* Position, in world units, of a flat platform in the specified platform slot
(0..PLATFORM_COUNT-1) that has its near side at the specified depth z. */
struct prect render_platform_position(int platform_slot, num z);
/* Project a point from world units to screen units viewed through the provided
camera. screen_size holds sizes in pixels as num values. */
vec3 camera_project(struct camera *camera, vec3 u, vec2 screen_size);
/* Optimized camera_project() that projects an entire prect in-place. */
void camera_project_prect(struct camera *camera, struct prect *p,
vec2 screen_size);
/* Set the camera's viewing angle and recompute its rotation vector. */
void camera_set_angle(struct camera *camera, num angle);
/* Compute the camera's viewing angle based on its platform position. */
num camera_compute_platform_angle(struct camera *camera);
/* Compute the platform's color based on the camera's angle. */
int camera_platform_color(struct camera *camera, int platform_id);
/* 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);
#endif /* __RENDERH__ */