200 lines
4.0 KiB
C
200 lines
4.0 KiB
C
/*
|
|
* Sweet is a small library for basic math and small matrix operations.
|
|
* Copyright 2014 Luc Girod.
|
|
*
|
|
* This library is free software: you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation, either
|
|
* version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include "sweet_matrix_stack.h"
|
|
|
|
matrix_stack2
|
|
sweet_matrix_stack2_new ()
|
|
{
|
|
matrix_stack2 m;
|
|
m.position = 0;
|
|
m.matrix[0] = sweet_matrix_identity2 ();
|
|
return m;
|
|
}
|
|
|
|
matrix_stack3
|
|
sweet_matrix_stack3_new ()
|
|
{
|
|
matrix_stack3 m;
|
|
m.position = 0;
|
|
m.matrix[0] = sweet_matrix_identity3 ();
|
|
return m;
|
|
}
|
|
|
|
matrix_stack4
|
|
sweet_matrix_stack4_new ()
|
|
{
|
|
matrix_stack4 m;
|
|
m.position = 0;
|
|
m.matrix[0] = sweet_matrix_identity4 ();
|
|
return m;
|
|
}
|
|
|
|
int
|
|
sweet_matrix_stack2_push (matrix_stack2 * ms)
|
|
{
|
|
if (ms->position >= SWEET_MATRIX_STACK_SIZE) { return 1; }
|
|
|
|
ms->matrix[ms->position + 1] = ms->matrix[ms->position];
|
|
ms->position++;
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
sweet_matrix_stack3_push (matrix_stack3 * ms)
|
|
{
|
|
if (ms->position >= SWEET_MATRIX_STACK_SIZE) { return 1; }
|
|
|
|
ms->matrix[ms->position + 1] = ms->matrix[ms->position];
|
|
ms->position++;
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
sweet_matrix_stack4_push (matrix_stack4 * ms)
|
|
{
|
|
if (ms->position >= SWEET_MATRIX_STACK_SIZE) { return 1; }
|
|
|
|
ms->matrix[ms->position + 1] = ms->matrix[ms->position];
|
|
ms->position++;
|
|
return 0;
|
|
}
|
|
|
|
|
|
int
|
|
sweet_matrix_stack2_pop (matrix_stack2 * ms)
|
|
{
|
|
if (ms->position <= 0) { return 1; }
|
|
|
|
ms->position--;
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
sweet_matrix_stack3_pop (matrix_stack3 * ms)
|
|
{
|
|
if (ms->position <= 0) { return 1; }
|
|
|
|
ms->position--;
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
sweet_matrix_stack4_pop (matrix_stack4 * ms)
|
|
{
|
|
if (ms->position <= 0) { return 1; }
|
|
|
|
ms->position--;
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
sweet_matrix_stack2_mult (matrix_stack2 * ms, mat2 * m)
|
|
{
|
|
sweet_matrix_product2 (ms->matrix + ms->position,
|
|
ms->matrix + ms->position, m);
|
|
}
|
|
|
|
void
|
|
sweet_matrix_stack3_mult (matrix_stack3 * ms, mat3 * m)
|
|
{
|
|
sweet_matrix_product3 (ms->matrix + ms->position,
|
|
ms->matrix + ms->position, m);
|
|
}
|
|
|
|
void
|
|
sweet_matrix_stack4_mult (matrix_stack4 * ms, mat4 * m)
|
|
{
|
|
sweet_matrix_product4 (ms->matrix + ms->position,
|
|
ms->matrix + ms->position, m);
|
|
}
|
|
|
|
void
|
|
sweet_matrix_stack2_identity (matrix_stack2 * ms)
|
|
{
|
|
ms->matrix[ms->position] = sweet_matrix_identity2 ();
|
|
}
|
|
|
|
void
|
|
sweet_matrix_stack3_identity (matrix_stack3 * ms)
|
|
{
|
|
ms->matrix[ms->position] = sweet_matrix_identity3 ();
|
|
}
|
|
|
|
void
|
|
sweet_matrix_stack4_identity (matrix_stack4 * ms)
|
|
{
|
|
ms->matrix[ms->position] = sweet_matrix_identity4 ();
|
|
}
|
|
|
|
void
|
|
sweet_matrix_stack2_set (matrix_stack2 * ms, mat2 * m)
|
|
{
|
|
ms->matrix[ms->position] = *m;
|
|
}
|
|
|
|
void
|
|
sweet_matrix_stack3_set (matrix_stack3 * ms, mat3 * m)
|
|
{
|
|
ms->matrix[ms->position] = *m;
|
|
}
|
|
|
|
void
|
|
sweet_matrix_stack4_set (matrix_stack4 * ms, mat4 * m)
|
|
{
|
|
ms->matrix[ms->position] = *m;
|
|
}
|
|
|
|
mat2 *
|
|
sweet_matrix_stack2_get_matrix_pointer (matrix_stack2 * ms)
|
|
{
|
|
return (ms->matrix + ms->position);
|
|
}
|
|
|
|
mat3 *
|
|
sweet_matrix_stack3_get_matrix_pointer (matrix_stack3 * ms)
|
|
{
|
|
return (ms->matrix + ms->position);
|
|
}
|
|
|
|
mat4 *
|
|
sweet_matrix_stack4_get_matrix_pointer (matrix_stack4 * ms)
|
|
{
|
|
return (ms->matrix + ms->position);
|
|
}
|
|
|
|
mat2
|
|
sweet_matrix_stack2_get_matrix (matrix_stack2 * ms)
|
|
{
|
|
return ms->matrix[ms->position];
|
|
}
|
|
|
|
mat3
|
|
sweet_matrix_stack3_get_matrix (matrix_stack3 * ms)
|
|
{
|
|
return ms->matrix[ms->position];
|
|
}
|
|
|
|
mat4
|
|
sweet_matrix_stack4_get_matrix (matrix_stack4 * ms)
|
|
{
|
|
return ms->matrix[ms->position];
|
|
}
|
|
|