86 lines
2.3 KiB
C
86 lines
2.3 KiB
C
|
/* The world is a drop chute, arranged horizontally. The coordinate system is
|
||
|
right-handed, with the following orientation from the top view of the chute:
|
||
|
|
||
|
z
|
||
|
^
|
||
|
|
|
||
|
|
|
||
|
y (x)-----> x
|
||
|
|
||
|
The player primarily moves in the +y direction (... although in practice
|
||
|
objects move towards the player to better use the limited range of fixed-
|
||
|
point values).
|
||
|
|
||
|
We compute directions of rays based on points on the virtual screen placed
|
||
|
in the world, in front of the camera. We make rays start at the camera
|
||
|
position so the distance between the camera and screen does not matter; we
|
||
|
arbitrarily place the screen at a distance which makes the screen height
|
||
|
correspond to 2*HALF_SCREEN_HEIGHT world units. This is to help avoid
|
||
|
precision loss with fixed-point numbers. */
|
||
|
|
||
|
#include <num/num.h>
|
||
|
#include <num/vec.h>
|
||
|
using namespace libnum;
|
||
|
struct mat3;
|
||
|
|
||
|
/* Number of world units that we fix the screen's half height to. The screen is
|
||
|
placed at the correct distance to make that happen. */
|
||
|
#define HALF_SCREEN_HEIGHT 2
|
||
|
/* World boundaries */
|
||
|
#define WORLD_SIZE 8 /* (± 4) */
|
||
|
/* Viewport size, in pixels */
|
||
|
#define VWIDTH 198
|
||
|
#define VHEIGHT 112
|
||
|
|
||
|
struct camera {
|
||
|
num fov;
|
||
|
num screen_distance;
|
||
|
|
||
|
/* Camera position (usually stays at z=0, objects move towards it) */
|
||
|
vec3 pos;
|
||
|
/* Angles of rotation */
|
||
|
float yaw, pitch, roll;
|
||
|
num cos_r, sin_r;
|
||
|
num cos_p, sin_p;
|
||
|
num cos_y, sin_y;
|
||
|
/* Corresponding directions, in world coordinates */
|
||
|
vec3 forward, right, up;
|
||
|
|
||
|
/* Game stuff... */
|
||
|
|
||
|
num neon_position;
|
||
|
};
|
||
|
|
||
|
void camera_set_fov(struct camera *camera, float fov_degrees);
|
||
|
mat3 matrix_camera2world(struct camera const *camera);
|
||
|
void camera_update_angles(struct camera *camera);
|
||
|
void render_fragment(struct camera const *camera, uint16_t *fragment,
|
||
|
int y_start, int y_height);
|
||
|
|
||
|
//=== Azur shader wrapping the raytracing ===//
|
||
|
|
||
|
void cd_raytrace(struct camera const *camera);
|
||
|
void cd_raytrace_configure(void);
|
||
|
|
||
|
//=== Input management ===//
|
||
|
|
||
|
struct input {
|
||
|
bool left;
|
||
|
bool right;
|
||
|
bool up;
|
||
|
bool down;
|
||
|
bool OPTN;
|
||
|
};
|
||
|
|
||
|
//=== Additions to libnum ===//
|
||
|
|
||
|
struct mat3
|
||
|
{
|
||
|
num x11, x12, x13;
|
||
|
num x21, x22, x23;
|
||
|
num x31, x32, x33;
|
||
|
};
|
||
|
|
||
|
mat3 operator *(mat3 const &A, mat3 const &B);
|
||
|
vec3 operator *(mat3 const &M, vec3 const &u);
|