114 lines
2.4 KiB
C
114 lines
2.4 KiB
C
|
#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;
|
||
|
}
|