diff --git a/include/fxengine/matrix.h b/include/fxengine/matrix.h index 20b811b..cde7c14 100644 --- a/include/fxengine/matrix.h +++ b/include/fxengine/matrix.h @@ -4,7 +4,7 @@ #include #include -void fe_vertex_translate(fe_vertex* v); +void fe_vertex_translate(fe_vertex const * const source, fe_vertex * target); void fe_set_matrix(fe_camera const cam); #endif \ No newline at end of file diff --git a/include/fxengine/model/camera.h b/include/fxengine/model/camera.h index 2b1f32b..f8985b7 100644 --- a/include/fxengine/model/camera.h +++ b/include/fxengine/model/camera.h @@ -1,11 +1,11 @@ #ifndef FE_CAMERA #define FE_CAMERA -#include +#include typedef struct { - fe_point pos; // point of view + fe_vertex pos; // point of view double dh, dv, roll; } fe_camera; diff --git a/include/fxengine/model/point.h b/include/fxengine/model/point.h deleted file mode 100644 index 753107b..0000000 --- a/include/fxengine/model/point.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef FE_MODEL_POINT -#define FE_MODEL_POINT - -#include - -typedef struct -{ - int32_t x; - int32_t y; - int32_t z; -} fe_point; - -typedef struct -{ - double x; - double y; - double z; -} fe_point_d; - -#endif \ No newline at end of file diff --git a/include/fxengine/model/vertex.h b/include/fxengine/model/vertex.h index 47d871c..4eee9da 100644 --- a/include/fxengine/model/vertex.h +++ b/include/fxengine/model/vertex.h @@ -1,12 +1,18 @@ #ifndef FE_MODEL_VERTEX #define FE_MODEL_VERTEX -#include +typedef struct +{ + int32_t x; + int32_t y; + int32_t z; +} fe_vertex; typedef struct { - fe_point real; - fe_point translated; -} fe_vertex; + double x; + double y; + double z; +} fe_vertex_d; #endif \ No newline at end of file diff --git a/include/render/triangle.h b/include/render/triangle.h index ce0b7cc..cdae9b6 100644 --- a/include/render/triangle.h +++ b/include/render/triangle.h @@ -16,12 +16,12 @@ /* render_triangle() renders a face supporting backface culling, or dual textures */ -int render_triangle(fe_point const s1, fe_point const s2, fe_point const s3, +int render_triangle(fe_vertex const s1, fe_vertex const s2, fe_vertex const s3, fe_bitmap const * side_0, fe_bitmap const * side_1, bool texture_half); /* render_triangle_nobfc() renders a face without backface culling */ -int render_triangle_nobfc(fe_point const s1, fe_point const s2, fe_point const s3, +int render_triangle_nobfc(fe_vertex const s1, fe_vertex const s2, fe_vertex const s3, fe_bitmap const * side, bool texture_half); // Object overlay diff --git a/src/matrix.c b/src/matrix.c index e82bcf3..7c48f41 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -1,5 +1,5 @@ #include -#include +#include #include typedef int32_t matrix_type; @@ -10,35 +10,35 @@ static matrix_type matrix[3][3]= {0,0,0} }; #define matrix_unit 1024 -static fe_point pos_delta; +static fe_vertex pos_delta; #define sgn(x) (x>=0?x:-x) -void fe_vertex_translate(fe_vertex * v) +void fe_vertex_translate(fe_vertex const * const source, fe_vertex * target) { - static fe_point temp; - temp.x = v->real.x - pos_delta.x; - temp.y = v->real.y - pos_delta.y; - temp.z = v->real.z - pos_delta.z; + static fe_vertex temp; + temp.x = source->x - pos_delta.x; + temp.y = source->y - pos_delta.y; + temp.z = source->z - pos_delta.z; - v->translated.x = matrix[0][0]*temp.x*matrix_unit + matrix[0][1]*temp.y + matrix[0][2]*temp.z; - v->translated.z = matrix[1][0]*temp.x*matrix_unit + matrix[1][1]*temp.y + matrix[1][2]*temp.z; - v->translated.y = matrix[2][0]*temp.x*matrix_unit + matrix[2][1]*temp.y + matrix[2][2]*temp.z; + target->x = matrix[0][0]*temp.x*matrix_unit + matrix[0][1]*temp.y + matrix[0][2]*temp.z; + target->z = matrix[1][0]*temp.x*matrix_unit + matrix[1][1]*temp.y + matrix[1][2]*temp.z; + target->y = matrix[2][0]*temp.x*matrix_unit + matrix[2][1]*temp.y + matrix[2][2]*temp.z; v->translated.z/=(matrix_unit/8); if (v->translated.z>0) { - v->translated.x/=v->translated.z; - v->translated.y/=v->translated.z; + target->x/=target->z; + target->y/=target->z; } else { - v->translated.x*=256*sgn(v->translated.z); - v->translated.y*=256*sgn(v->translated.z); + target->x*=256*sgn(target->z); + target->y*=256*sgn(target->z); } - v->translated.x+=63; - v->translated.y+=31; + target->x+=63; + target->y+=31; } void fe_set_matrix(fe_camera const cam) diff --git a/src/render/triangle.c b/src/render/triangle.c index 18f66e7..2d03f26 100644 --- a/src/render/triangle.c +++ b/src/render/triangle.c @@ -1,13 +1,13 @@ #include #include -#include +#include #include #include #include -int render_triangle(fe_point const s1, fe_point const s2, fe_point const s3, +int render_triangle(fe_vertex const s1, fe_vertex const s2, fe_vertex const s3, fe_bitmap const * side_0, fe_bitmap const * side_1, bool texture_half) { // Backface culling @@ -38,7 +38,7 @@ typedef struct int32_t dx,dy,dz; int8_t no_line; // si les deux points sont confondus (se comporte comme un bool) } line; -static void line_set(line* l,fe_point const * s1, fe_point const * s2) +static void line_set(line* l,fe_vertex const * s1, fe_vertex const * s2) { l->x = s1->x; l->y = s1->y; l->z = s1->z; l->dx = s2->x - s1->x; l->dy = s2->y - s1->y; l->dz = s2->z - s1->z; @@ -63,7 +63,7 @@ static bool line_get_x(int32_t y, line const * l, int32_t * x) // retourne false } -int render_triangle_nobfc(fe_point const s1, fe_point const s2, fe_point const s3, +int render_triangle_nobfc(fe_vertex const s1, fe_vertex const s2, fe_vertex const s3, fe_bitmap const * side, bool texture_half) { if (!side) return RENDER_NOBMP;