253 lines
5.5 KiB
C++
253 lines
5.5 KiB
C++
#ifndef DEF_WINDMILL
|
|
#define DEF_WINDMILL
|
|
|
|
#include <math.h>
|
|
#include <gint/display.h> // pour affichage des coordonnées
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <gint/defs/util.h>
|
|
#include "camera.hpp"
|
|
|
|
#define get_vram_address() ((char *)gint_vram)
|
|
|
|
// parametrage de Windmill
|
|
#define MIN_AREA_CLIP 5
|
|
#define DECORATION_OFFSET 50
|
|
#define MAX_DEPTH_Z_BUFFER 0xffff
|
|
|
|
enum {N, X, Y, Z, Z_BILLBOARD};
|
|
#define FRONT 1
|
|
#define BACK -1
|
|
#define RIEN 0
|
|
#define TRIANGLE 3
|
|
#define RECTANGLE 4
|
|
#define PARA 0
|
|
#define TRAP 1
|
|
|
|
#define INTERIEUR true
|
|
#define EXTERIEUR false
|
|
|
|
// pour la collision
|
|
#define INSIDE -1
|
|
#define ALL 127
|
|
#define NONE 0
|
|
//#define OUT 1
|
|
//#define IN 0
|
|
|
|
|
|
|
|
// definition des structures
|
|
struct Point
|
|
{
|
|
int x, y, z;
|
|
};
|
|
|
|
class Vecteur
|
|
{
|
|
public:
|
|
float x1, y1, x2, y2;
|
|
};
|
|
|
|
struct Sphere
|
|
{
|
|
int x, y, z;
|
|
int radius;
|
|
};
|
|
|
|
class Vertex
|
|
{
|
|
public:
|
|
int x, y, z;
|
|
float w, h;
|
|
unsigned short z_normalized;
|
|
|
|
Vertex();
|
|
void set_xyz(int _x, int _y, int _z);
|
|
void set_wh(float _w, float _h);
|
|
float length(int x, int y, int z);
|
|
};
|
|
|
|
|
|
struct Texture
|
|
{
|
|
const unsigned char* sprite;
|
|
const unsigned char* mask;
|
|
const char pixel_width;
|
|
const char pixel_height;
|
|
const char real_width;
|
|
const char real_height;
|
|
const float offset;
|
|
const bool transparent;
|
|
const bool decoration;
|
|
const bool mirror;
|
|
};
|
|
|
|
|
|
struct Modele
|
|
{
|
|
const int type;
|
|
const Texture* texture_front;
|
|
const Texture* texture_back;
|
|
const short x0, y0, z0;
|
|
const short x1, y1, z1;
|
|
const short x2, y2, z2;
|
|
const char option;
|
|
};
|
|
|
|
|
|
struct Object
|
|
{
|
|
short x, y, z;
|
|
char axe;
|
|
float angle;
|
|
const Modele* modele;
|
|
const int modele_size;
|
|
// ajouter ici
|
|
const char collision;
|
|
//const char for_collision;
|
|
//const char type_collision;
|
|
bool hidden;
|
|
bool on_screen;
|
|
Sphere sphere;
|
|
int distance_to_camera;
|
|
};
|
|
|
|
|
|
struct Map
|
|
{
|
|
Object** object;
|
|
int list_object_length;
|
|
bool horizon;
|
|
bool ground;
|
|
// ajouter ici
|
|
};
|
|
|
|
struct Viewport
|
|
{
|
|
int x1, y1, x2, y2;
|
|
};
|
|
|
|
|
|
float distance(float dx, float dy, float dz);
|
|
int compare_object(void const *a, void const *b);
|
|
|
|
|
|
class Windmill
|
|
{
|
|
public:
|
|
// initialisation et parametrage
|
|
Windmill();
|
|
void set_camera(Camera* _camera);
|
|
void set_viewport(int viewport_x1, int viewport_y1, int viewport_x2, int viewport_y2);
|
|
void load_map(Map* _map);
|
|
|
|
// dessin
|
|
void draw();
|
|
void draw_horizon();
|
|
void draw_ground();
|
|
void draw_objects();
|
|
void draw_post_treatment();
|
|
void draw_body();
|
|
|
|
// transformation 3D des vertex
|
|
void transform_model_to_world(Vertex vertex[], int vertex_length, Object* object, int cosinus, int sinus);
|
|
void transform_world_to_camera(Vertex vertex[], int vertex_length);
|
|
void transform_camera_to_screen(Vertex vertex[], int vertex_length);
|
|
void transform_camera_to_screen2(Vertex vertex[], int vertex_length);
|
|
|
|
// text visiblilite
|
|
bool fast_check(Vertex vertex_list[], int vertex_list_length);
|
|
bool inside_viewport(int x, int y);
|
|
int visible_face(Vertex* a, Vertex* b, Vertex* c);
|
|
|
|
void clip_depth(Vertex vertex_list_input[], int* vertex_list_input_length);
|
|
void clip_depth_edge(Vertex* vertex_in, Vertex* vertex_out, Vertex* vertex_set);
|
|
bool clip_depth_inside_edge(Vertex* vertex);
|
|
|
|
void clip_viewport(Vertex vertex_list_input[], int* vertex_list_input_length);
|
|
void clip_viewport_edge(Vertex* vertex_in, Vertex* vertex_out, Vertex* vertex_set, int edge);
|
|
bool clip_viewport_inside_edge(Vertex* vertex, int edge);
|
|
|
|
// dessin des triangles
|
|
void render_triangle(Vertex* vertex1, Vertex* vertex2, Vertex* vertex3, const Texture *texture);
|
|
void render_triangle_texture(Vertex* vertex1, Vertex* vertex2, Vertex* vertex3, const Texture* texture);
|
|
void render_triangle_black(Vertex* vertex0, Vertex* vertex1, Vertex* vertex2);
|
|
void render_triangle_white(Vertex* vertex0, Vertex* vertex1, Vertex* vertex2);
|
|
void render_triangle_transparent(Vertex* vertex1, Vertex* vertex2, Vertex* vertex3, const Texture* texture);
|
|
|
|
// manipulation
|
|
Point get_point(const Modele* poly, int i);
|
|
Point get_center_poly(const Modele* poly);
|
|
void compute_object_angle(Object* object, int* cosinus, int* sinus);
|
|
void extract_vertex_from_poly(const Modele* poly, Vertex* vertex, int* vertex_length, int* width, int* height);
|
|
void texture_coordinates(const Modele* poly, Vertex* vertex, const Texture* texture, int visible, int width, int height);
|
|
void swap_vertex(Vertex* vertexA, Vertex* vertexB);
|
|
void copy_vertex(Vertex* vertex_source, Vertex* vertex_dest);
|
|
|
|
// sphere
|
|
Sphere transform_sphere_to_world(Sphere* sphere, Object* object, int cosinus, int sinus);
|
|
bool sphere_in_cone(Sphere* sphere);
|
|
|
|
// divers
|
|
void copy_camera();
|
|
void sort_object();
|
|
void clear_z_buffer();
|
|
int edge(Vertex* a, Vertex* b, Vertex* c);
|
|
int edge_start(Vertex* a, Vertex* b, int px, int py);
|
|
int edge_step_x(Vertex* a, Vertex* b);
|
|
int edge_step_y(Vertex* a, Vertex* b);
|
|
|
|
// utilitaires
|
|
void pixel_on_cursor(int x, int y);
|
|
void show_coordinates();
|
|
void show_repere();
|
|
//void show_fps();
|
|
|
|
// destructeurr
|
|
~Windmill();
|
|
|
|
private:
|
|
// camera
|
|
Camera* camera2; // camera a suivre
|
|
Camera camera; // camera_temporaire
|
|
|
|
// carte
|
|
Map* map;
|
|
|
|
// liste objets triee
|
|
Object** object;
|
|
int list_object_length;
|
|
|
|
// z_buffer
|
|
int shift_x, shift_y;
|
|
unsigned short* z_buffer;
|
|
int z_buffer_size;
|
|
int z_buffer_offset;
|
|
int z_buffer_width;
|
|
|
|
// en cours
|
|
int i;
|
|
int j;
|
|
|
|
// variables temporaire pour eviter de lire la valeur en cours de calcul
|
|
int temp_nb_object_on_screen;
|
|
Object* temp_object_cursor;
|
|
int temp_poly_cursor;
|
|
|
|
public:
|
|
// fenetre de visualisation
|
|
Viewport viewport;
|
|
|
|
// utilitaires
|
|
bool loading;
|
|
int nb_object_on_screen;
|
|
Object* object_cursor;
|
|
int poly_cursor;
|
|
int cursor_x;
|
|
int cursor_y;
|
|
};
|
|
|
|
|
|
|
|
#endif
|