157 lines
4.4 KiB
C
157 lines
4.4 KiB
C
|
/* *****************************************************************************
|
||
|
* libwindmill.h -- 3D rendering engine.
|
||
|
* Copyright (C) 2017 Olivier "Ninestars" Lanneau
|
||
|
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||
|
*
|
||
|
* This file is part of libwindmill.
|
||
|
* libwindmill is free software; you can redistribute it and/or modify it
|
||
|
* under the terms of the GNU Lesser General Public License as published by
|
||
|
* the Free Software Foundation; either version 3.0 of the License,
|
||
|
* or (at your option) any later version.
|
||
|
*
|
||
|
* libwindmill is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||
|
* See the GNU Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public License
|
||
|
* along with libwindmill; if not, see <http://www.gnu.org/licenses/>.
|
||
|
* ************************************************************************** */
|
||
|
#ifndef LIBWINDMILL_H
|
||
|
# define LIBWINDMILL_H
|
||
|
# include <stdlib.h>
|
||
|
# include <string.h>
|
||
|
# include <math.h>
|
||
|
# define N 0
|
||
|
# define X 1
|
||
|
# define Y 2
|
||
|
# define Z 3
|
||
|
# define XC 4
|
||
|
# define YC 5
|
||
|
# define ZC 6
|
||
|
|
||
|
/* ************************************************************************** */
|
||
|
/* Types */
|
||
|
/* ************************************************************************** */
|
||
|
/* a vertex */
|
||
|
typedef struct Vertex {
|
||
|
int x, y, z;
|
||
|
char tx, ty;
|
||
|
int z_normalized;
|
||
|
} wml_vertex_t;
|
||
|
|
||
|
/* a texture */
|
||
|
typedef struct Texture {
|
||
|
const unsigned char *sprite;
|
||
|
char width, height, offset;
|
||
|
} wml_texture_t;
|
||
|
|
||
|
/* a triangle */
|
||
|
typedef struct Triangle {
|
||
|
/* coordinates */
|
||
|
short x0, y0, z0;
|
||
|
short x1, y1, z1;
|
||
|
short x2, y2, z2;
|
||
|
|
||
|
/* textures */
|
||
|
struct Texture *texture_front;
|
||
|
struct Texture *texture_back;
|
||
|
} wml_triangle_t;
|
||
|
|
||
|
/* a rectangle */
|
||
|
typedef struct Rectangle {
|
||
|
/* coordinates */
|
||
|
short x0, y0, z0;
|
||
|
short x1, y1, z1;
|
||
|
short x2, y2, z2;
|
||
|
|
||
|
/* textures */
|
||
|
struct Texture *texture_front;
|
||
|
struct Texture *texture_back;
|
||
|
} wml_rectangle_t;
|
||
|
|
||
|
/* an object */
|
||
|
typedef struct Object {
|
||
|
/* coordinates */
|
||
|
int x, y, z;
|
||
|
char axe; float angle;
|
||
|
|
||
|
/* rectangles */
|
||
|
wml_rectangle_t *list_rect;
|
||
|
int list_rect_size;
|
||
|
|
||
|
/* triangles */
|
||
|
wml_triangle_t *list_tri;
|
||
|
int list_tri_size;
|
||
|
} wml_object_t;
|
||
|
|
||
|
/* a map */
|
||
|
typedef struct Map {
|
||
|
int id;
|
||
|
|
||
|
/* objects */
|
||
|
struct Object **list_object;
|
||
|
int list_object_size;
|
||
|
} wml_map_t;
|
||
|
|
||
|
/* a scene */
|
||
|
typedef struct Scene {
|
||
|
/* flow control */
|
||
|
int stop_execution;
|
||
|
|
||
|
/* camera */
|
||
|
float camera_x, camera_y, camera_z;
|
||
|
float camera_yaw, camera_pitch;
|
||
|
int scale_coef, near, far;
|
||
|
float near_coef;
|
||
|
int far_coef;
|
||
|
float div_coef;
|
||
|
int viewport_x1, viewport_y1, viewport_x2, viewport_y2;
|
||
|
int shift_x, shift_y;
|
||
|
unsigned short *z_buffer;
|
||
|
int z_buffer_size, z_buffer_offset, z_buffer_width;
|
||
|
|
||
|
/* texture, map, background */
|
||
|
struct Texture *hidden, *black, *white;
|
||
|
struct Map map;
|
||
|
const unsigned char *background;
|
||
|
|
||
|
/* i don't know what this is, yet */
|
||
|
int a1, a2, a3, a4, a5, a6, a7, a8, a9;
|
||
|
} wml_scene_t;
|
||
|
|
||
|
/* ************************************************************************** */
|
||
|
/* Functions */
|
||
|
/* ************************************************************************** */
|
||
|
/* update things */
|
||
|
void wml_update_camera(wml_scene_t *scene);
|
||
|
void wml_update_viewport(wml_scene_t *scene);
|
||
|
|
||
|
/* render */
|
||
|
void wml_render_draw(wml_scene_t *scene);
|
||
|
|
||
|
void wml_dynamic(wml_vertex_t *vertex,
|
||
|
int axe, int x, int y, int z,
|
||
|
float cosinus, float sinus);
|
||
|
void wml_transform(wml_scene_t *scene, wml_vertex_t *vertex);
|
||
|
|
||
|
void wml_render_triangle(wml_scene_t *scene,
|
||
|
wml_vertex_t *vertex1, wml_vertex_t *vertex2, wml_vertex_t *vertex3,
|
||
|
wml_texture_t *texture);
|
||
|
void wml_render_triangle_black(wml_scene_t *scene,
|
||
|
wml_vertex_t *vertex1, wml_vertex_t *vertex2, wml_vertex_t *vertex3,
|
||
|
wml_texture_t *texture);
|
||
|
void wml_render_triangle_white(wml_scene_t *scene,
|
||
|
wml_vertex_t *vertex1, wml_vertex_t *vertex2, wml_vertex_t *vertex3,
|
||
|
wml_texture_t *texture);
|
||
|
|
||
|
void wml_edge(wml_vertex_t *a, wml_vertex_t *b, wml_vertex_t *c);
|
||
|
void wml_edge_start(wml_vertex_t *a, wml_vertex_t *b, int px, int py);
|
||
|
void wml_edge_step_x(wml_vertex_t *a, wml_vertex_t *b);
|
||
|
void wml_edge_step_y(wml_vertex_t *a, wml_vertex_t *b);
|
||
|
|
||
|
void wml_move_camera_face(wml_scene_t *scene, float value);
|
||
|
void wml_move_camera_side(wml_scene_t *scene, float value);
|
||
|
|
||
|
#endif /* LIBWINDMILL_H */
|