Exemplo n.º 1
0
Sprite* sprite_create(const char* texture_path) {
    Sprite* sprite = malloc(sizeof(*sprite));
    if(sprite == NULL) {
        perror("Sprite creation");
        return NULL;
    }

    strcpy(sprite->path, texture_path);

    sprite->texture = texture_load(sprite->path);
    sprite->width = texture_get_param(sprite->texture, GL_TEXTURE_WIDTH);
    sprite->height = texture_get_param(sprite->texture, GL_TEXTURE_HEIGHT);
    sprite->transform = m4_identity();

    vec3 vertices[num_vertices];
    vec3 scale = {sprite->width, sprite->height, 1};
    int i;
    for(i = 0; i < num_vertices; ++i) {
        v3_scale(&vertices[i], &quad_vertices[i], &scale);
    }

    sprite->attributes[0].buffer = buffer_create(&vertices, sizeof(vertices));
    sprite->attributes[0].size = 3;
    sprite->attributes[1].buffer = buffer_create(&quad_uv, sizeof(quad_uv));
    sprite->attributes[1].size = 2;

    return sprite;
}
Exemplo n.º 2
0
void	m4_rot_z(t_matrix *m, double angle)
{
	m4_identity(m);
	m->a = cos(angle);
	m->b = -sin(angle);
	m->e = sin(angle);
	m->f = cos(angle);
}
Exemplo n.º 3
0
void	m4_rot_y(t_matrix *m, double angle)
{
	m4_identity(m);
	m->a = cos(angle);
	m->c = sin(angle);
	m->i = -sin(angle);
	m->k = cos(angle);
}
Exemplo n.º 4
0
void	m4_rot_x(t_matrix *m, double angle)
{
	m4_identity(m);
	m->f = cos(angle);
	m->g = -sin(angle);
	m->j = sin(angle);
	m->k = cos(angle);
}
Exemplo n.º 5
0
void m4_rotate_z(mat4_t m, scalar_t angle)
{
	mat4_t rm;
	m4_identity(rm);
	rm[0][0] = cos(angle); rm[0][1] = -sin(angle);
	rm[1][0] = sin(angle); rm[1][1] = cos(angle);
	m4_mult(m, m, rm);
}
Exemplo n.º 6
0
void m4_translate(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
{
	mat4_t tm;
	m4_identity(tm);
	tm[0][3] = x;
	tm[1][3] = y;
	tm[2][3] = z;
	m4_mult(m, m, tm);
}
Exemplo n.º 7
0
void m4_scale(mat4_t m, scalar_t x, scalar_t y, scalar_t z)
{
	mat4_t sm;
	m4_identity(sm);
	sm[0][0] = x;
	sm[1][1] = y;
	sm[2][2] = z;
	m4_mult(m, m, sm);
}
Exemplo n.º 8
0
void m4_rotate_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z)
{
	mat4_t xform;
	scalar_t sina = sin(angle);
	scalar_t cosa = cos(angle);
	scalar_t one_minus_cosa = 1.0 - cosa;
	scalar_t nxsq = x * x;
	scalar_t nysq = y * y;
	scalar_t nzsq = z * z;

	m4_identity(xform);
	xform[0][0] = nxsq + (1.0 - nxsq) * cosa;
	xform[0][1] = x * y * one_minus_cosa - z * sina;
	xform[0][2] = x * z * one_minus_cosa + y * sina;
	xform[1][0] = x * y * one_minus_cosa + z * sina;
	xform[1][1] = nysq + (1.0 - nysq) * cosa;
	xform[1][2] = y * z * one_minus_cosa - x * sina;
	xform[2][0] = x * z * one_minus_cosa - y * sina;
	xform[2][1] = y * z * one_minus_cosa + x * sina;
	xform[2][2] = nzsq + (1.0 - nzsq) * cosa;

	m4_mult(m, m, xform);
}