setting fxengine as lib
This commit is contained in:
parent
153c707b77
commit
b12d64f45d
|
@ -1,33 +0,0 @@
|
|||
#include "keyboard.h"
|
||||
|
||||
static callback callbacks[3][6][10]={0};
|
||||
|
||||
static inline uint32_t get_x(const uint32_t matrix_code)
|
||||
{
|
||||
return (matrix_code-1) % 0x10;
|
||||
}
|
||||
|
||||
static inline uint32_t get_y(const uint32_t matrix_code)
|
||||
{
|
||||
return (matrix_code-1) / 0x10;
|
||||
}
|
||||
|
||||
void FE_keyboard_reload()
|
||||
{
|
||||
key_event_t event;
|
||||
while (1)
|
||||
{
|
||||
event=pollevent();
|
||||
event.type--;
|
||||
if (event.type==-1)
|
||||
break;
|
||||
callback action = callbacks[event.type][get_x(event.key)][get_y(event.key)];
|
||||
if (action)
|
||||
action();
|
||||
}
|
||||
}
|
||||
|
||||
void FE_keyboard_set_key(uint32_t matrix_code, uint32_t ev_type, callback function)
|
||||
{
|
||||
callbacks[ev_type-1][get_x(matrix_code)][get_y(matrix_code)]=function;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef FE_KEYBOARD
|
||||
#define FE_KEYBOARD
|
||||
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/keycodes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* FE_keyboard: gestion evenementielle du clavier
|
||||
on peut assigner des callbacks à certains evènements définis dans gint
|
||||
les arguments envoyés sont le code de la touche en question (event.key)
|
||||
le type d'evenement (event.type)
|
||||
void (*callback)(void)
|
||||
la fonction à exécuter en cas de pression sur une touche
|
||||
la fonction reload est appelée à la demande de l'utilisateur et appelle tous les callbacks dans l'ordre */
|
||||
|
||||
typedef void (*callback)(void);
|
||||
|
||||
void event_keyboard_set_key(uint32_t matrix_code, uint32_t ev_type, callback function);
|
||||
|
||||
// reload all key events and call callbacks
|
||||
void event_keyboard_reload();
|
||||
|
||||
//void event_keyboard_start();
|
||||
|
||||
//void event_keyboard_stop();
|
||||
|
||||
#endif
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef RENDER_PARAM
|
||||
#define RENDER_PARAM
|
||||
|
||||
|
||||
// Render param
|
||||
|
||||
#define render_width 128
|
||||
#define render_height 64
|
||||
#define render_x_mid ((render_width - 1) / 2) // depends on screen width
|
||||
#define render_y_mid ((render_height - 1) / 2)
|
||||
|
||||
#define render_max_dist 3000
|
||||
#define render_min_dist 1
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,123 +0,0 @@
|
|||
#include "translate.h"
|
||||
|
||||
#include <gint/std/stdlib.h>
|
||||
#include <gint/std/string.h>
|
||||
|
||||
const double pi = 3.141592653589793238462643383279;
|
||||
const double pi2 = pi * 2;
|
||||
const double pi_sur_2 = pi / 2;
|
||||
|
||||
|
||||
static double reducted_cos(const double a)
|
||||
{
|
||||
double u= 1.0;
|
||||
const double a2 = a * a;
|
||||
for(int32_t p = 15; p>=1; p -= 2)
|
||||
u = 1 - a2 / (p * p + p) * u;
|
||||
return u;
|
||||
}
|
||||
|
||||
// return a with -pi<=a<pi
|
||||
double modulo_2pi(double a)
|
||||
{
|
||||
while (a<=-pi)
|
||||
a += pi2;
|
||||
while (a>pi)
|
||||
a -= pi2;
|
||||
return a;
|
||||
}
|
||||
|
||||
static double cos_recursive(double angle)
|
||||
{
|
||||
if (angle<0)
|
||||
return cos_recursive(-angle);
|
||||
if (angle>=pi_sur_2)
|
||||
return -reducted_cos(angle - pi);
|
||||
return reducted_cos(angle); // OK
|
||||
}
|
||||
|
||||
double cos(double angle)
|
||||
{
|
||||
angle = modulo_2pi(angle);
|
||||
return cos_recursive(angle);
|
||||
}
|
||||
|
||||
double sin(double angle)
|
||||
{
|
||||
return cos(angle - pi_sur_2);
|
||||
}
|
||||
|
||||
|
||||
#define sgn(x) (x>=0?x:-x)
|
||||
|
||||
static double matrice[3][3]=
|
||||
{
|
||||
{0,0,0},
|
||||
{0,0,0},
|
||||
{0,0,0}
|
||||
};
|
||||
|
||||
static FE_integer_position delta;
|
||||
|
||||
|
||||
void render_translate(FE_integer_point * point)
|
||||
{
|
||||
static FE_integer_position temp;
|
||||
temp.x = point->real.x - delta.x;
|
||||
temp.y = point->real.y - delta.y;
|
||||
temp.z = point->real.z - delta.z;
|
||||
|
||||
point->translated.x = (double)(matrice[0][0]*(double)temp.x + matrice[0][1]*(double)temp.y + matrice[0][2]*(double)temp.z);
|
||||
point->translated.z = (double)(matrice[1][0]*(double)temp.x + matrice[1][1]*(double)temp.y + matrice[1][2]*(double)temp.z);
|
||||
point->translated.y = (double)(matrice[2][0]*(double)temp.x + matrice[2][1]*(double)temp.y + matrice[2][2]*(double)temp.z);
|
||||
|
||||
//point->translated.x*=10;
|
||||
//point->translated.y*=10;
|
||||
point->translated.x*=64;
|
||||
point->translated.y*=64;
|
||||
if (point->translated.z>0)
|
||||
{
|
||||
point->translated.x/=point->translated.z;
|
||||
point->translated.y/=point->translated.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
point->translated.x*=32768*sgn(point->translated.z);
|
||||
point->translated.y*=32768*sgn(point->translated.z);
|
||||
}
|
||||
//(point->translated.x*1024)/point->translated.z;
|
||||
//(point->translated.y*1024)/point->translated.z;
|
||||
|
||||
point->translated.x+=render_x_mid;
|
||||
point->translated.y+=render_y_mid;
|
||||
}
|
||||
|
||||
void render_set(const double dh, const double dv, const double roulis, const FE_integer_position * camera)
|
||||
{
|
||||
const double A=cos(dv);
|
||||
const double B=sin(dv);
|
||||
|
||||
const double C=cos(roulis);
|
||||
const double D=sin(roulis);
|
||||
|
||||
const double E=cos(dh);
|
||||
const double F=sin(dh);
|
||||
|
||||
// raccourcis
|
||||
const double AD=A*D, BD=B*D;
|
||||
|
||||
matrice[0][0]=C*E;
|
||||
matrice[0][1]=-C*F;
|
||||
matrice[0][2]=D;
|
||||
|
||||
matrice[1][0]=BD*E+A*F;
|
||||
matrice[1][1]=-BD*F+A*E;
|
||||
matrice[1][2]=-B*C;
|
||||
|
||||
matrice[2][0]=-AD*E+B*F;
|
||||
matrice[2][1]=AD*F+B*E;
|
||||
matrice[2][2]=A*C;
|
||||
|
||||
// assigner delta
|
||||
memcpy(&delta, camera, sizeof(FE_integer_position));
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
#ifndef RENDER_TRANSLATE_H
|
||||
#define RENDER_TRANSLATE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "parameters.h"
|
||||
|
||||
/* FE_position:
|
||||
notion de point dans l'espace simple */
|
||||
typedef struct FE_integer_position FE_integer_position;
|
||||
struct FE_integer_position
|
||||
{
|
||||
int32_t x,
|
||||
y,
|
||||
z;
|
||||
};
|
||||
|
||||
typedef struct FE_floating_position FE_floating_position;
|
||||
struct FE_floating_position
|
||||
{
|
||||
double x,
|
||||
y,
|
||||
z;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* FE_point:
|
||||
notion de point dans l'espace destiné à etre utilisé dans l'affichage */
|
||||
typedef struct FE_integer_point FE_integer_point;
|
||||
struct FE_integer_point
|
||||
{
|
||||
FE_integer_position real,
|
||||
translated;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// applique la matrice de rotation et les deltas sur les coordonnées d'un point
|
||||
void render_translate(FE_integer_point * point);
|
||||
|
||||
|
||||
|
||||
// change la matrice de rotation et les deltas pour le cycle à venir
|
||||
void render_set(const double dh, const double dv, const double roulis, const FE_integer_position * camera);
|
||||
|
||||
|
||||
|
||||
// constantes mathématiques
|
||||
|
||||
extern const double pi, pi2, pi_sur_2;
|
||||
|
||||
|
||||
// fonctions mathématiques
|
||||
|
||||
double modulo_2pi(double a);
|
||||
|
||||
double cos(double angle);
|
||||
|
||||
double sin(const double angle);
|
||||
|
||||
#endif
|
|
@ -1,42 +0,0 @@
|
|||
#include "zbuffer.h"
|
||||
#include "parameters.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <gint/display.h>
|
||||
#include <gint/std/stdio.h>
|
||||
#include <gint/std/stdlib.h>
|
||||
#include <gint/keyboard.h>
|
||||
#include <gint/defs/attributes.h>
|
||||
|
||||
|
||||
|
||||
static const int size_uint32 = render_width * render_height;
|
||||
|
||||
static const int size_char = size_uint32 * sizeof(uint32_t);
|
||||
|
||||
// zbuffer et clear val sont 32B alignés pour ajouter éventuellement le DMA
|
||||
|
||||
static int32_t *zbuffer = (void *)0x88080000 - ((size_char / 32) * 32 + 1);
|
||||
|
||||
GALIGNED(32) GSECTION(".rodata") static const int32_t clearval[8]={render_max_dist,render_max_dist,render_max_dist,render_max_dist,render_max_dist,render_max_dist,render_max_dist,render_max_dist};
|
||||
|
||||
void render_zbuffer_clear()
|
||||
{
|
||||
uint32_t indice = 0;
|
||||
|
||||
for (indice = 0; indice < size_uint32; indice ++)
|
||||
zbuffer[indice] = render_max_dist;
|
||||
}
|
||||
|
||||
bool render_zbuffer_set_px(uint32_t x, uint32_t y, uint32_t dist)
|
||||
{
|
||||
const int indice = x * render_height + y;
|
||||
|
||||
if (zbuffer[indice]>dist && dist>=render_min_dist && dist<=render_max_dist)
|
||||
{
|
||||
zbuffer[indice] = dist;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef RENDER_ZBUFFER
|
||||
#define RENDER_ZBUFFER
|
||||
|
||||
#include "parameters.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/** FE_zbuffer_clear
|
||||
* effacer le z buffer pour un nouveau cycle de dessin
|
||||
* TODO : ajouter effacement avec le DMA Controller pour les modèles ayant un processeur SH4-A
|
||||
**/
|
||||
void render_zbuffer_clear();
|
||||
|
||||
#include <stdbool.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 render_zbuffer_set_px(uint32_t x, uint32_t y, uint32_t dist); // if you are allowed to draw the pixel on vram
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue