merge "vertex" and "point"

This commit is contained in:
Milang 2019-10-26 14:18:16 +02:00
parent f2e3c92f65
commit 4dd7b142c4
7 changed files with 35 additions and 49 deletions

View File

@ -4,7 +4,7 @@
#include <fxengine/model/vertex.h>
#include <fxengine/model/camera.h>
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

View File

@ -1,11 +1,11 @@
#ifndef FE_CAMERA
#define FE_CAMERA
#include <fxengine/model/point.h>
#include <fxengine/model/vertex.h>
typedef struct
{
fe_point pos; // point of view
fe_vertex pos; // point of view
double dh, dv, roll;
} fe_camera;

View File

@ -1,20 +0,0 @@
#ifndef FE_MODEL_POINT
#define FE_MODEL_POINT
#include <stdint.h>
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

View File

@ -1,12 +1,18 @@
#ifndef FE_MODEL_VERTEX
#define FE_MODEL_VERTEX
#include <fxengine/model/point.h>
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

View File

@ -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

View File

@ -1,5 +1,5 @@
#include <fxengine/matrix.h>
#include <fxengine/model/point.h>
#include <fxengine/model/vertex.h>
#include <stdint.h>
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)

View File

@ -1,13 +1,13 @@
#include <render/triangle.h>
#include <render/buffer.h>
#include <fxengine/model/point.h>
#include <fxengine/model/vertex.h>
#include <stdint.h>
#include <stdbool.h>
#include <gint/display.h>
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;