Go back to a lib

You will have to use it as you use liblog

Signed-off-by: milang <milan.garnier@orange.fr>
This commit is contained in:
milang 2019-09-18 18:51:26 +02:00
parent 9721e08cf5
commit 09cafca8f3
20 changed files with 506 additions and 2834 deletions

2536
Doxyfile

File diff suppressed because it is too large Load Diff

View File

@ -101,7 +101,7 @@ uninstall:
rm -f $(PREFIX)/$(target)
rm -rf $(PREFIX)/include/fxengine
install: $(target)
install:
@make uninstall
install -d $(PREFIX)
install $(target) $(m644) $(PREFIX)

30
include/fxengine/camera.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef FE_CAMERA
#define FE_CAMERA
#include "space.h"
struct fe_camera
{
fe_ipoint pos; // point of view
fe_fpoint pos_temp; // floating copy used while moving
double dh, dv, roll;
};
typedef struct fe_camera fe_camera;
/**
* @brief Sets up the translation matrices for a new rendering cycle
* There is no need to call this function if you have already called render_update()
*
* @param[in] dh Camera's horizontal direction (rad)
* @param[in] dv Camera's vertical direction (rad)
* @param[in] roulis Optionnal rotation around the middle of the screen
* @param[in] camera The camera's coordinates, as an integer position
*/
void fe_view_set_param(const double dh, const double dv, const double roulis, const fe_ipoint * camera);
void fe_view_set(const fe_camera * cam);
#endif

View File

@ -1,48 +0,0 @@
#ifndef FE_TRIANGLE
#define FE_TRIANGLE
#include <fxengine/point.h>
#include <fxengine/texture.h>
#include <stdbool.h>
/**
* @brief Triangle struct used to render fonctions
* @param[out] part choose the used texture half // currently not implemented
* @param[out] clockwised choose the visible side of the face
* @param[out] s1,s2,s3 three points
* @param[out] texture used texture
*/
struct fe_triangle
{
fe_integer_position * s1;
fe_integer_position * s2;
fe_integer_position * s3;
fe_texture_rich * texture;
bool part;
bool clockwised;
};
typedef struct fe_triangle fe_triangle;
/**
* @brief Renders a triangle with perspective deformation
*
* @param[in] face pointer to the face to draw
*/
void fe_display_triangle(const fe_triangle * face);
/**
* @brief Clears vram, zbuffer
*
* @param[in] libprof_channel The libprof channel to be used to count_fps
* if you don't use libprof channel, (default), you send what you want,
* it doesn't matters ;)
*/
void fe_render_update(const uint32_t libprof_channel);
#endif

View File

@ -1,8 +1,8 @@
#ifndef FE_OBJECT
#define FE_OBJECT
#include <fxengine/point.h>
#include <fxengine/triangle.h>
#include "space.h"
#include "triangle.h"
#include <stdint.h>
#include <stdbool.h>
@ -12,7 +12,7 @@ struct fe_object
fe_triangle * faces;
uint32_t f_size;
bool f_owner;
fe_integer_point * points;
fe_ivertex * points;
uint32_t p_size;
bool p_owner;
};
@ -20,7 +20,7 @@ typedef struct fe_object fe_object;
void fe_object_init(fe_object * object);
void fe_object_set_points(fe_object * object, fe_integer_point * points, uint32_t n, bool copy);
void fe_object_set_points(fe_object * object, fe_ivertex * points, uint32_t n, bool copy);
void fe_object_set_faces(fe_object * object, fe_triangle * faces, uint32_t n, bool copy);
@ -28,4 +28,8 @@ void fe_object_delete(fe_object * object);
void fe_object_display(fe_object * object);
void fe_object_debug(const fe_object * object);
fe_ipoint* fe_object_get_vertex(const fe_object * object, const int n);
#endif

View File

@ -3,6 +3,7 @@
// Render param
// You change it as you want before compiling ;)
#define fe_width 128
#define fe_height 64

View File

@ -1,64 +0,0 @@
#ifndef FE_POINT
#define FE_POINT
#include <stdint.h>
#include <fxengine/parameters.h>
/**
* @brief this struct is a point in 3d, which has coords save as uint32_t
* this is the recommended type for high performance rendering, because the sh3eb-elf architecture
* is 32 bits
* This is also the type used by the rendering triangles.
*/
struct fe_integer_position
{
int32_t x,
y,
z;
};
typedef struct fe_integer_position fe_integer_position;
/**
* @brief this struct is a point in 3d, which has coords save as double
* it is not recommended to use it for high performances rendering,
* because of the sh3eb-elf architecture, which does not support natively floating calculation
*/
struct fe_floating_position
{
double x,
y,
z;
};
typedef struct fe_floating_position fe_floating_position;
/**
* @brief This is a point which is used for 3d translations and rendering
* integer mode is the best solution to increase perfs, and that's why I didn't have implemented
* the floating_points yet. (Maybe I will never add them)
* To render a triangle, you have to set &point.translated as s1, s2 or even s3
*/
struct fe_integer_point
{
fe_integer_position real,
translated;
};
typedef struct fe_integer_point fe_integer_point;
/**
* @brief Translate a point with camera settings
*
* @param point The point to translate
*/
void fe_point_translate(fe_integer_point * point);
/**
* mathematics constants
* TODO déplacer dans caméra
*/
extern const double pi, pi2, pi_sur_2;
#endif

103
include/fxengine/space.h Normal file
View File

@ -0,0 +1,103 @@
#ifndef FE_SPACE
#define FE_SPACE
// Diverses representations de points dans l'espace
#include <stdint.h>
#include "parameters.h"
/**
* @brief this struct is a point in 3d, which has coords save as uint32_t
* this is the recommended type for high performance rendering, because the sh3eb-elf architecture
* is 32 bits
* This is also the type used by the rendering triangles.
*/
struct fe_ipoint
{
int32_t x,
y,
z;
};
typedef struct fe_ipoint fe_ipoint;
/**
* @brief this struct is a point in 3d, which has coords save as double
* it is not recommended to use it for high performances rendering,
* because of the sh3eb-elf architecture, which does not support natively floating calculation
*/
struct fe_fpoint
{
double x,
y,
z;
};
typedef struct fe_fpoint fe_fpoint;
/**
* @brief This is a point which is used for 3d translations and rendering
* integer mode is the best solution to increase perfs, and that's why I didn't have implemented
* the floating_points yet. (Maybe I will never add them)
* To render a triangle, you have to set &point.translated as s1, s2 or even s3
*/
struct fe_ivertex
{
fe_ipoint real,
translated;
};
typedef struct fe_ivertex fe_ivertex;
/**
* @brief Translate a point with camera settings
*
* @param point The point to translate
*/
void fe_vertex_translate(fe_ivertex * v);
/**
* @brief Sets up an angle mesure between -pi and +pi
*
* @param[in] a the angle (rad)
*
* @return angle mesure which respect the following contraint :
* -pi <= angle <= pi
*/
double fe_modulo_2pi(double a);
/**
* @brief Homemade cosinus implementation, which is faster than casio provided cosinus function
*
* @param[in] angle The angle (rad)
*
* @return cos angle
*/
double fe_cos(double angle);
/**
* @brief Homemade sinus implementation, which is faster than casio provided sinus function
*
* @param[in] angle The angle (rad)
*
* @return sin angle
*/
double fe_sin(const double angle);
/**
* mathematics constants
* TODO déplacer dans caméra
*/
#define pi 3.14159265358
#define pi2 6.28318530718
#define pi_sur_2 1.57079632679
// translate matrix
extern double fe_matrix[3][3];
extern fe_ipoint fe_translate_delta;
#endif

View File

@ -0,0 +1,84 @@
#ifndef FE_TEXTURE
#define FE_TEXTURE
#include <stdint.h>
#include <stdbool.h>
/**
* @brief texture rich type
* transparency is in the layout
* @warning Monochrome only !
*/
struct fe_texture_rich
{
uint32_t size_px_x;
uint32_t size_px_y;
uint32_t size_o_y;
uint32_t * color;
bool color_dynamic;
uint32_t * layout;
bool layout_dynamic;
};
typedef struct fe_texture_rich fe_texture_rich;
/**
* @brief { function_description }
*
* @param[in] size_px_x The width in px
* @param[in] size_px_y The height in px
* @param color color origin
* @param[in] copy_color if you want to make a copy, or only to make a link
* @param layout layout origin -> can be set as 0 if it isn't needed
* @param[in] copy_layout if you want to make a copy, or to make a link
*
* @return a rich texture, ready to use !
*/
fe_texture_rich* fe_texture_new_rich(uint32_t size_px_x, uint32_t size_px_y, uint32_t* color, bool copy_color,
uint32_t *layout, bool copy_layout);
/**
* @brief delete a rich texture created with texture_new_rich()
*
* @param txtr The texture to delete
*/
void fe_texture_delete_rich(fe_texture_rich * txtr);
/**
* @brief get the color of pixel from rich texture
*
* @param[in] txtr The texture
* @param[in] x The texture x coordinate (in pixels)
* @param[in] y The texture y coordinate (in pixels)
*
* @return the color coded in a unsigned char :
* if (color >> 1)
* switch (color%2)
* {
* case 0:
* // WHITE
* break;
* case 1:
* // BLACK
* }
* else
*/
uint8_t fe_texture_get_pixel_r(const fe_texture_rich * txtr, uint32_t x, uint32_t y);
/**
* @brief display a specific rich texture pixel on the screen (on vram)
*
* @param[in] txtr The texture
* @param[in] txtr_x The texture x coordinate (in pixels)
* @param[in] txtr_y The texture y coordinate (in pixels)
* @param[in] x screen : x coordinate
* @param[in] y screen : y coordinate
*/
void fe_texture_display_pixel_r(const fe_texture_rich * txtr, uint32_t txtr_x, uint32_t txtr_y, uint32_t x, uint32_t y);
void fe_texture_debug(fe_texture_rich * txtr);
#endif

View File

@ -1,8 +1,9 @@
#ifndef FE_TRIANGLE
#define FE_TRIANGLE
#include <fxengine/point.h>
#include <fxengine/texture.h>
#include "space.h"
#include "texture.h"
#include <stdbool.h>
/**
@ -14,9 +15,9 @@
*/
struct fe_triangle
{
fe_integer_position * s1;
fe_integer_position * s2;
fe_integer_position * s3;
fe_ipoint * s1;
fe_ipoint * s2;
fe_ipoint * s3;
fe_texture_rich * texture;

View File

@ -1,7 +1,7 @@
#ifndef RENDER_ZBUFFER
#define RENDER_ZBUFFER
#include <fxengine/parameters.h>
#include "parameters.h"
#include <stdint.h>
/** FE_zbuffer_clear

View File

@ -1,47 +0,0 @@
#ifndef RENDER_TRANSLATE_H
#define RENDER_TRANSLATE_H
#include <fxengine/point.h>
/**
* @brief Sets up the translation matrices for a new rendering cycle
* There is no need to call this function if you have already called render_update()
*
* @param[in] dh Camera's horizontal direction (rad)
* @param[in] dv Camera's vertical direction (rad)
* @param[in] roulis Optionnal rotation around the middle of the screen
* @param[in] camera The camera's coordinates, as an integer position
*/
void render_set(const double dh, const double dv, const double roulis, const fe_integer_position * camera);
/**
* @brief Sets up an angle mesure between -pi and +pi
*
* @param[in] a the angle (rad)
*
* @return angle mesure which respect the following contraint :
* -pi <= angle <= pi
*/
double modulo_2pi(double a);
/**
* @brief Homemade cosinus implementation, which is faster than casio provided cosinus function
*
* @param[in] angle The angle (rad)
*
* @return cos angle
*/
double cos(double angle);
/**
* @brief Homemade sinus implementation, which is faster than casio provided sinus function
*
* @param[in] angle The angle (rad)
*
* @return sin angle
*/
double sin(const double angle);
#endif

Binary file not shown.

39
src/camera.c Normal file
View File

@ -0,0 +1,39 @@
#include "camera.h"
#include <gint/std/string.h>
void fe_view_set(const fe_camera * cam)
{
fe_view_set_param(cam->dh, cam->dv, cam->roll, &cam->pos);
}
void fe_view_set_param(const double dh, const double dv, const double roulis, const fe_ipoint * camera)
{
const double A=fe_cos(dv);
const double B=fe_sin(dv);
const double C=fe_cos(roulis);
const double D=fe_sin(roulis);
const double E=fe_cos(dh);
const double F=fe_sin(dh);
// raccourcis
const double AD=A*D, BD=B*D;
fe_matrix[0][0]=C*E;
fe_matrix[0][1]=-C*F;
fe_matrix[0][2]=D;
fe_matrix[1][0]=BD*E+A*F;
fe_matrix[1][1]=-BD*F+A*E;
fe_matrix[1][2]=-B*C;
fe_matrix[2][0]=-AD*E+B*F;
fe_matrix[2][1]=AD*F+B*E;
fe_matrix[2][2]=A*C;
// assigner delta
memcpy(&fe_translate_delta, camera, sizeof(fe_ipoint));
}

113
src/object.c Normal file
View File

@ -0,0 +1,113 @@
#include "object.h"
#include <gint/std/stdlib.h>
#include <gint/std/stdio.h>
#include <gint/std/string.h>
#include <gint/display.h>
#include <gint/keyboard.h>
void fe_object_init(fe_object * object)
{
memset(object, 0, sizeof(fe_object));
}
void fe_object_set_points(fe_object * object, fe_ivertex * points, uint32_t n, bool copy)
{
if (copy)
{
object->points = malloc(n*sizeof(fe_ipoint));
if (!object->points)
return;
memcpy(object->points, points, n*sizeof(fe_ipoint));
//memcpy()
}
else
{
object->points = points;
}
object->p_owner = copy;
object->p_size = n;
}
void fe_object_set_faces(fe_object * object, fe_triangle * faces, uint32_t n, bool copy)
{
if (copy)
{
object->faces = malloc(n*sizeof(fe_ipoint));
if (!object->faces)
return;
memcpy(object->faces, faces, n*sizeof(fe_ipoint));
}
else
{
object->faces = faces;
}
object->f_owner = copy;
object->f_size = n;
}
void fe_object_delete(fe_object * object)
{
if (object->points && object->p_owner)
free(object->points);
if (object->faces && object->f_owner)
free(object->faces);
fe_object_init(object);
}
void fe_object_display(fe_object * object)
{
for (int i = 0; i < object->p_size; i++)
fe_vertex_translate(&object->points[i]);
for (int i = 0; i < object->f_size; i++)
fe_display_triangle(&object->faces[i]);
for (int i = 0; i < object->p_size; i++)
dpixel(object->points[i].translated.x, object->points[i].translated.y, C_BLACK);
}
void fe_object_debug(const fe_object * object)
{
dclear(C_WHITE);
if (object)
{
char text[21];
sprintf(text, "ADDRESS : %p", object);
dtext(1,1, text, C_BLACK, C_NONE);
sprintf(text, "f-t %p %d", object->faces, object->f_owner);
dtext(1,9, text, C_BLACK, C_NONE);
sprintf(text, " -size = %d", object->f_size);
dtext(1,17, text, C_BLACK, C_NONE);
sprintf(text, "v-t %p %d", object->points, object->p_owner);
dtext(1,25, text, C_BLACK, C_NONE);
sprintf(text, " -size = %d", object->p_size);
dtext(1,33, text, C_BLACK, C_NONE);
}
else
{
dtext(1,1, "No object sent !", C_BLACK, C_NONE);
}
dupdate();
getkey();
}
fe_ipoint* fe_object_get_vertex(const fe_object * object, const int n)
{
return &object->points[n].translated;
}

84
src/space.c Normal file
View File

@ -0,0 +1,84 @@
#include "space.h"
#include "camera.h"
#include <gint/std/stdlib.h>
#include <gint/std/string.h>
double fe_matrix[3][3]=
{
{0,0,0},
{0,0,0},
{0,0,0}
};
fe_ipoint fe_translate_delta;
static double reducted_cos(const double a)
{
double u= 1.0;
const double a2 = a * a;
for(int32_t p = 17; p>=1; p -= 2)
u = 1 - a2 / (p * p + p) * u;
return u;
}
// return a with -pi<=a<pi
double fe_modulo_2pi(double a)
{
while (a<=-pi)
a += pi2;
while (a>pi)
a -= pi2;
return a;
}
double fe_cos(double angle)
{
angle = fe_modulo_2pi(angle);
if (angle<0)
angle=-angle;
if (angle>=pi_sur_2)
return -reducted_cos(angle - pi);
return reducted_cos(angle);
}
double fe_sin(double angle)
{
return fe_cos(angle - pi_sur_2);
}
#define sgn(x) (x>=0?x:-x)
void fe_vertex_translate(fe_ivertex * v)
{
static fe_ipoint temp;
temp.x = v->real.x - fe_translate_delta.x;
temp.y = v->real.y - fe_translate_delta.y;
temp.z = v->real.z - fe_translate_delta.z;
v->translated.x = (double)(fe_matrix[0][0]*(double)temp.x + fe_matrix[0][1]*(double)temp.y + fe_matrix[0][2]*(double)temp.z);
v->translated.z = (double)(fe_matrix[1][0]*(double)temp.x + fe_matrix[1][1]*(double)temp.y + fe_matrix[1][2]*(double)temp.z);
v->translated.y = (double)(fe_matrix[2][0]*(double)temp.x + fe_matrix[2][1]*(double)temp.y + fe_matrix[2][2]*(double)temp.z);
//v->translated.x*=10;
//v->translated.y*=10;
v->translated.x*=64;
v->translated.y*=64;
if (v->translated.z>0)
{
v->translated.x/=v->translated.z;
v->translated.y/=v->translated.z;
}
else
{
v->translated.x*=32768*sgn(v->translated.z);
v->translated.y*=32768*sgn(v->translated.z);
}
//(v->translated.x*1024)/v->translated.z;
//(v->translated.y*1024)/v->translated.z;
v->translated.x+=fe_x_mid;
v->translated.y+=fe_y_mid;
}

View File

@ -1,4 +1,4 @@
#include <fxengine/texture.h>
#include "texture.h"
#include <gint/display.h>
#include <gint/std/string.h>
@ -52,6 +52,32 @@ fe_texture_rich* fe_texture_new_rich(uint32_t size_px_x, uint32_t size_px_y, uin
return bmp;
}
void fe_texture_debug(fe_texture_rich * txtr)
{
dclear(C_WHITE);
if (txtr)
{
char text[21];
sprintf(text, "ADDRESS : %p", txtr);
dtext(1,1, text, C_BLACK, C_NONE);
sprintf(text, "size %d %d", txtr->size_px_x, txtr->size_px_y);
dtext(1,9, text, C_BLACK, C_NONE);
sprintf(text, "color %p %d", txtr->color, txtr->color_dynamic);
dtext(1,17, text, C_BLACK, C_NONE);
sprintf(text, "layout %p %d", txtr->layout, txtr->layout_dynamic);
dtext(1,25, text, C_BLACK, C_NONE);
}
else
{
dtext(1,1, "Texture set as NULL", C_BLACK, C_NONE);
}
dupdate();
getkey();
}
void fe_texture_delete_rich(fe_texture_rich * bmp)
{
if (!bmp)

View File

@ -1,118 +0,0 @@
#include <fxengine/point.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;
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;
}
double cos(double angle)
{
angle = modulo_2pi(angle);
if (angle<0)
angle=-angle;
if (angle>=pi_sur_2)
return -reducted_cos(angle - pi);
return reducted_cos(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 fe_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+=fe_x_mid;
point->translated.y+=fe_y_mid;
}
void fe_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));
}

View File

@ -1,7 +1,7 @@
#include <fxengine/face.h>
#include <fxengine/texture.h>
#include <fxengine/point.h>
#include <render/zbuffer.h>
#include "triangle.h"
#include "texture.h"
#include "space.h"
#include "zbuffer.h"
#ifdef USE_LIBPROF
#include <libprof.h>
@ -17,7 +17,7 @@
void fe_render_update(const uint32_t libprof_channel)
{
//dupdate();
dupdate();
#ifdef USE_LIBPROF
// gestion du temps avec libprof
if (prof_elapsed)
@ -42,7 +42,7 @@ void fe_render_update(const uint32_t libprof_channel)
///fe_set(dh, dv, roulis, camera);
//dclear(C_WHITE);
dclear(C_WHITE);
}
/**
@ -85,7 +85,7 @@ struct line
* @param s1 The s 1
* @param s2 The s 2
*/
static void line_set(line* l,fe_integer_position const * s1, fe_integer_position const * s2)
static void line_set(line* l,fe_ipoint const * s1, fe_ipoint const * s2)
{
l->x = s1->x;
l->y = s1->y;

View File

@ -1,5 +1,5 @@
#include <render/zbuffer.h>
#include <fxengine/parameters.h>
#include "zbuffer.h"
#include "parameters.h"
#include <stdbool.h>
#include <stdint.h>