changing triangle rendering
This commit is contained in:
parent
1cce870987
commit
263e8543c6
1302
build-fx/map
1302
build-fx/map
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,5 +1,6 @@
|
|||
build-fx/src/controls.o: src/controls.c src/controls.h \
|
||||
src/FxEngine/FxEngine.h src/FxEngine/coord.h src/FxEngine/zbuffer.h
|
||||
src/FxEngine/FxEngine.h src/FxEngine/coord.h src/FxEngine/FxEngine.h \
|
||||
src/FxEngine/zbuffer.h
|
||||
|
||||
src/controls.h:
|
||||
|
||||
|
@ -7,4 +8,6 @@ src/FxEngine/FxEngine.h:
|
|||
|
||||
src/FxEngine/coord.h:
|
||||
|
||||
src/FxEngine/FxEngine.h:
|
||||
|
||||
src/FxEngine/zbuffer.h:
|
||||
|
|
Binary file not shown.
|
@ -1,15 +1,15 @@
|
|||
build-fx/src/main.o: src/main.c src/FxEngine/FxEngine.h \
|
||||
src/FxEngine/coord.h src/FxEngine/zbuffer.h src/FxEngine/face.h \
|
||||
src/FxEngine/FxEngine.h src/controls.h
|
||||
src/FxEngine/coord.h src/FxEngine/FxEngine.h src/FxEngine/zbuffer.h \
|
||||
src/FxEngine/face.h src/controls.h
|
||||
|
||||
src/FxEngine/FxEngine.h:
|
||||
|
||||
src/FxEngine/coord.h:
|
||||
|
||||
src/FxEngine/FxEngine.h:
|
||||
|
||||
src/FxEngine/zbuffer.h:
|
||||
|
||||
src/FxEngine/face.h:
|
||||
|
||||
src/FxEngine/FxEngine.h:
|
||||
|
||||
src/controls.h:
|
||||
|
|
|
@ -41,18 +41,18 @@ static void FE_move()
|
|||
}
|
||||
if (event.key==KEY_5)
|
||||
{
|
||||
py += FE_cos(FE_dh + pi);
|
||||
px += FE_sin(FE_dh + pi);
|
||||
py += FE_cos(FE_dh + FE_PI);
|
||||
px += FE_sin(FE_dh + FE_PI);
|
||||
}
|
||||
if (event.key==KEY_4)
|
||||
{
|
||||
py += FE_cos(FE_dh - pi_sur2);
|
||||
px += FE_sin(FE_dh - pi_sur2);
|
||||
py += FE_cos(FE_dh - FE_PI_SUR_2);
|
||||
px += FE_sin(FE_dh - FE_PI_SUR_2);
|
||||
}
|
||||
if (event.key==KEY_6)
|
||||
{
|
||||
py += FE_cos(FE_dh + pi_sur2);
|
||||
px += FE_sin(FE_dh + pi_sur2);
|
||||
py += FE_cos(FE_dh + FE_PI_SUR_2);
|
||||
px += FE_sin(FE_dh + FE_PI_SUR_2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,17 +99,17 @@ void FE_new_frame()
|
|||
|
||||
#define MICROSECOND 1000000
|
||||
|
||||
unsigned uint32_t FE_get_fps_current()
|
||||
uint32_t FE_get_fps_current()
|
||||
{
|
||||
return MICROSECOND / frame_interval;
|
||||
}
|
||||
|
||||
unsigned uint32_t FE_get_fps_min()
|
||||
uint32_t FE_get_fps_min()
|
||||
{
|
||||
return MICROSECOND / frame_interval_max;
|
||||
}
|
||||
|
||||
unsigned uint32_t FE_get_fps_max()
|
||||
uint32_t FE_get_fps_max()
|
||||
{
|
||||
return MICROSECOND / frame_interval_min;
|
||||
}
|
||||
|
@ -121,4 +121,4 @@ char* FE_get_fps_history()
|
|||
{
|
||||
sprintf(fps_history, "%d/%d/%d", FE_get_fps_min(), FE_get_fps_current(), FE_get_fps_max());
|
||||
return fps_history;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef FENG_H
|
||||
#define FENG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "coord.h"
|
||||
#include "zbuffer.h"
|
||||
#include <libprof.h>
|
||||
|
@ -36,15 +37,15 @@ void FE_new_frame(void); // calls move function
|
|||
|
||||
/* FE_get_fps_current():
|
||||
obtient le nombre d'Images Par Seconde (IPS) calculé à partir du dernier cycle */
|
||||
unsigned int FE_get_fps_current(void);
|
||||
uint32_t FE_get_fps_current(void);
|
||||
|
||||
/* FE_get_fps_min():
|
||||
obtient le nombre d'images par seconde le plus bas ayant existé depuis le démarrage du moteur 3d */
|
||||
unsigned int FE_get_fps_min(void);
|
||||
uint32_t FE_get_fps_min(void);
|
||||
|
||||
/* FE_get_fps_max():
|
||||
obtient le nombre d'images par seconde le plus haut ayant existé depuis le démarrage du moteur 3d */
|
||||
unsigned int FE_get_fps_max(void);
|
||||
uint32_t FE_get_fps_max(void);
|
||||
|
||||
/* FE_get_fps_history():
|
||||
renvoie, dans une version compactée, les nombres minimum, actuel et maximum d'images par seconde
|
||||
|
@ -59,4 +60,4 @@ unsigned int FE_get_fps_max(void);
|
|||
char* FE_get_fps_history(void);
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -19,10 +19,10 @@ static double reducted_cos(const double a)
|
|||
// return a with -pi<=a<pi
|
||||
double FE_modulo_2pi(double a)
|
||||
{
|
||||
while (a<=-pi)
|
||||
a += pi2;
|
||||
while (a>pi)
|
||||
a -= pi2;
|
||||
while (a<=-FE_PI)
|
||||
a += FE_2_PI;
|
||||
while (a>FE_PI)
|
||||
a -= FE_2_PI;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ static double cos_recursive(double angle)
|
|||
if (angle<0)
|
||||
return cos_recursive(-angle);
|
||||
if (angle>=FE_PI_SUR_2)
|
||||
return -reducted_cos(angle - pi);
|
||||
return -reducted_cos(angle - FE_PI);
|
||||
return reducted_cos(angle); // OK
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ double FE_cos(double angle)
|
|||
|
||||
double FE_sin(double angle)
|
||||
{
|
||||
return FE_cos(angle - pi_sur2);
|
||||
return FE_cos(angle - FE_PI_SUR_2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,21 +69,21 @@ void FE_calc(FE_point* point)
|
|||
|
||||
//point->translated.x*=10;
|
||||
//point->translated.y*=10;
|
||||
point->rotated.x*=64;
|
||||
point->rotated.y*=64;
|
||||
point->translated.z=point->rotated.z;
|
||||
point->rotated.x *= 64;
|
||||
point->rotated.y *= 64;
|
||||
point->translated.z = point->rotated.z;
|
||||
if (point->translated.z>0)
|
||||
{
|
||||
point->translated.x=point->rotated.x/point->translated.z;
|
||||
point->translated.y=point->rotated.y/point->translated.z;
|
||||
point->translated.x = point->rotated.x / point->translated.z;
|
||||
point->translated.y = point->rotated.y / point->translated.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
point->translated.x=point->rotated.x*10000*sgn(point->translated.z);
|
||||
point->translated.y=point->rotated.y*10000*sgn(point->translated.z);
|
||||
point->translated.x = point->rotated.x * 10000 * sgn(point->translated.z);
|
||||
point->translated.y = point->rotated.y * 10000 * sgn(point->translated.z);
|
||||
}
|
||||
(point->translated.x*1000)/point->translated.z;
|
||||
(point->translated.y*1000)/point->translated.z;
|
||||
// (point->translated.x*1000)/point->translated.z;
|
||||
// (point->translated.y*1000)/point->translated.z;
|
||||
|
||||
point->translated.x+=63;
|
||||
point->translated.y+=31;
|
||||
|
@ -111,4 +111,4 @@ void FE_set_matrice(void)
|
|||
matrice[2][1]=AD*F+B*E;
|
||||
matrice[2][2]=A*C;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
#ifndef FE_COORD_H
|
||||
#define FE_COORD_H
|
||||
|
||||
#include "FxEngine.h"
|
||||
|
||||
/* FE_position:
|
||||
notion de point dans l'espace simple */
|
||||
typedef struct FE_position FE_position;
|
||||
struct FE_position
|
||||
{int32_t x,y,z;};
|
||||
{int x,y,z;};
|
||||
|
||||
/* FE_point:
|
||||
notion de point dans l'espace destiné à etre utilisé dans l'affichage
|
||||
|
@ -18,6 +16,8 @@ typedef struct FE_point FE_point;
|
|||
struct FE_point
|
||||
{FE_position real,translated,rotated};
|
||||
|
||||
#include "FxEngine.h"
|
||||
|
||||
/* FE_calc():
|
||||
applique la matrice de rotation sur les coordonnées d'un point
|
||||
|
||||
|
@ -58,4 +58,4 @@ double FE_cos(double angle);
|
|||
double FE_sin(const double angle);
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -107,20 +107,24 @@ void FE_draw_face(FE_face const * face)
|
|||
|
||||
for (int x=txmin; x<=txmax; x++)
|
||||
{
|
||||
double vx, vy, z;
|
||||
/*
|
||||
int32_t vx, vy, z;
|
||||
// calcul de vx, vy
|
||||
const int32_t xcalc=x-face->s1->translated.x;
|
||||
const int32_t ycalc=y-face->s1->translated.y;
|
||||
vx=(xcalc*fact_1-ycalc*fact_2); // 0 <vx< 10_000
|
||||
vy=(ycalc*fact_3-xcalc*fact_4); // idem
|
||||
z=face->s1->translated.z + (vx*zAB+vy*zAC)/10000;
|
||||
vx/=10000;
|
||||
vy/=10000;
|
||||
z=face->s1->translated.z + (vx*zAB+vy*zAC)/10000;
|
||||
|
||||
vx /= (double)face->s2->translated.z / ((1-vx) / face->s1->translated.z + vx / (double)face->s2->translated.z);
|
||||
vy /= (double)face->s3->translated.z / ((1-vy) / face->s1->translated.z + vy / (double)face->s3->translated.z);
|
||||
vx *= 100000 / (face->s2->translated.z * ((100-100*vx) / face->s1->translated.z + (100*vx) / face->s2->translated.z));
|
||||
vy *= 100000 / (face->s3->translated.z * ((100-100*vy) / face->s1->translated.z + (vy*100) / face->s3->translated.z));
|
||||
|
||||
// Affichage du point
|
||||
if (FE_zbuffer_set_dist(x,y,z))
|
||||
dpixel(x, y, 3*FE_get_pixel(face->texturenum, 8*vx, 8*vy)); // 3* means cast to black and white, and vx,and vy casted between 0 and 7
|
||||
dpixel(x, y, 3*FE_get_pixel(face->texturenum, vx/125, vy/125)); // 3* means cast to black and white, and vx,and vy casted between 0 and 7
|
||||
*/
|
||||
if (FE_zbuffer_set_dist(x,y,1))
|
||||
dpixel(x, y, C_BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,4 +136,4 @@ void FE_draw_face(FE_face const * face)
|
|||
// soit diviseur_commun = (xAB*yAC-yAB*xAC)
|
||||
// x=xAM*yAC/diviseur_commun-yAM*xAC/diviseur_commun
|
||||
// y=yAM*xAB/diviseur_commun-xAM*yAB/diciseur_commun
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "zbuffer.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <gint/display.h>
|
||||
#include <gint/std/stdio.h>
|
||||
|
@ -10,34 +11,37 @@
|
|||
* taille du zbuffer exprimée en uint32_t
|
||||
* utile pour l'effacement du zbuffer sur sh3
|
||||
**/
|
||||
static const int size_uint32 = FE_ZB_SIZE_X*FE_ZB_SIZE_X;
|
||||
static const uint32_t size_uint32 = FE_ZB_SIZE_X*FE_ZB_SIZE_Y;
|
||||
|
||||
/** size_char
|
||||
* taille du zbuffer exprimée en octets
|
||||
* sera utile pour le DMA Controller
|
||||
**/
|
||||
static const int size_char = size_uint32*sizeof(uint32_t);
|
||||
static const uint32_t size_char = size_uint32*sizeof(int32_t);
|
||||
|
||||
/** address
|
||||
* addresse du zbuffer
|
||||
**/
|
||||
static uint32_t* address=0;
|
||||
static int32_t* address=0;
|
||||
|
||||
void FE_zbuffer_clear()
|
||||
{
|
||||
while (address==0)
|
||||
if (address==0)
|
||||
{
|
||||
address = malloc(size_octets);
|
||||
address = malloc(size_char);
|
||||
if (address==0) // cas de figure où il n'y a plus assez de RAM
|
||||
{
|
||||
dclear(C_WHITE);
|
||||
dtext(1, 1, "Not enough RAM...", C_BLACK, C_NONE);
|
||||
dupdate();
|
||||
while (1==1)
|
||||
getkey();
|
||||
}
|
||||
}
|
||||
// TODO déterminer le type d'effacement
|
||||
|
||||
// effacement fait par le CPU
|
||||
uint32_t indice = 0;
|
||||
uint32_t indice;
|
||||
for (indice = 0; indice < size_uint32; indice ++)
|
||||
address[indice] = 3000;
|
||||
|
||||
|
@ -45,11 +49,11 @@ void FE_zbuffer_clear()
|
|||
// TODO
|
||||
}
|
||||
|
||||
bool FE_zbuffer_set_dist(int x, int y, int dist)
|
||||
bool FE_zbuffer_set_dist(int32_t x, int32_t y, int32_t dist)
|
||||
{
|
||||
x %= FE_ZB_SIZE_X;
|
||||
y %= FE_ZB_SIZE_Y;
|
||||
const int indice = x * 64 + y;
|
||||
const uint32_t indice = x * 64 + y;
|
||||
if (address[indice]>dist && dist>0)
|
||||
{
|
||||
address[indice] = dist;
|
||||
|
@ -57,4 +61,4 @@ bool FE_zbuffer_set_dist(int x, int y, int dist)
|
|||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,12 @@
|
|||
void FE_zbuffer_clear();
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
/** FE_zbuffer_set_dist
|
||||
* change la distance d'un pixel du zbuffer
|
||||
* retourne true si il faut dessiner le pixel
|
||||
* retourne false si le pixel est déjà existant
|
||||
**/
|
||||
bool FE_zbuffer_set_dist(int x, int y, int dist); // if you are allowed to draw the pixel on vram
|
||||
bool FE_zbuffer_set_dist(int32_t x, int32_t y, int32_t dist); // if you are allowed to draw the pixel on vram
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue