73 lines
1.9 KiB
C
73 lines
1.9 KiB
C
#include <fxengine/matrix.h>
|
|
#include <fxengine/model/vertex.h>
|
|
#include <stdint.h>
|
|
|
|
typedef int32_t matrix_type;
|
|
static matrix_type matrix[3][3]=
|
|
{
|
|
{0,0,0},
|
|
{0,0,0},
|
|
{0,0,0}
|
|
};
|
|
#define matrix_unit 1024
|
|
static fe_vertex pos_delta;
|
|
|
|
#define sgn(x) (x>=0?x:-x)
|
|
|
|
void fe_vertex_translate(fe_vertex const * const source, fe_vertex * target)
|
|
{
|
|
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;
|
|
|
|
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;
|
|
|
|
target->z/=(matrix_unit/8);
|
|
if (target->z>0)
|
|
{
|
|
target->x/=target->z;
|
|
target->y/=target->z;
|
|
}
|
|
else
|
|
{
|
|
target->x*=256*sgn(target->z);
|
|
target->y*=256*sgn(target->z);
|
|
}
|
|
|
|
target->x+=63;
|
|
target->y+=31;
|
|
}
|
|
|
|
void fe_set_matrix(fe_camera const cam)
|
|
{
|
|
pos_delta.x = cam.pos.x;
|
|
pos_delta.y = cam.pos.y;
|
|
pos_delta.z = cam.pos.z;
|
|
|
|
const matrix_type A=matrix_unit*fe_cos(cam.dv);
|
|
const matrix_type B=matrix_unit*fe_sin(cam.dv);
|
|
|
|
const matrix_type C=matrix_unit*fe_cos(cam.roll);
|
|
const matrix_type D=matrix_unit*fe_sin(cam.roll);
|
|
|
|
const matrix_type E=matrix_unit*fe_cos(cam.dh);
|
|
const matrix_type F=matrix_unit*fe_sin(cam.dh);
|
|
|
|
// raccourcis
|
|
const matrix_type AD=A*D/matrix_unit, BD=B*D/matrix_unit;
|
|
|
|
matrix[0][0]=C*E/matrix_unit;
|
|
matrix[0][1]=-C*F/matrix_unit;
|
|
matrix[0][2]=D;
|
|
|
|
matrix[1][0]=(BD*E+A*F)/matrix_unit;
|
|
matrix[1][1]=(-BD*F+A*E)/matrix_unit;
|
|
matrix[1][2]=-B*C/matrix_unit;
|
|
|
|
matrix[2][0]=(-AD*E+B*F)/matrix_unit;
|
|
matrix[2][1]=(AD*F+B*E)/matrix_unit;
|
|
matrix[2][2]=A*C/matrix_unit;
|
|
} |