Fixed PSP compiling
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "node.h"
|
||||
#include "util/memory.h"
|
||||
#include "assert/assert.h"
|
||||
#include "display/display.h"
|
||||
|
||||
node_t NODE_DATA[ECS_ENTITY_COUNT_MAX] = { 0 };
|
||||
ecscomponent_t NODE_COMPONENT = ecsComponentInit(
|
||||
@@ -50,4 +51,79 @@ void nodeMatrixSet(const ecsid_t id, mat4 in) {
|
||||
}
|
||||
|
||||
glm_mat4_copy(in, node->transform);
|
||||
|
||||
// Extract position, scale, rotation from the matrix.
|
||||
node->position[0] = in[3][0];
|
||||
node->position[1] = in[3][1];
|
||||
node->position[2] = in[3][2];
|
||||
|
||||
node->scale[0] = glm_vec3_norm((vec3){ in[0][0], in[0][1], in[0][2] });
|
||||
node->scale[1] = glm_vec3_norm((vec3){ in[1][0], in[1][1], in[1][2] });
|
||||
node->scale[2] = glm_vec3_norm((vec3){ in[2][0], in[2][1], in[2][2] });
|
||||
|
||||
// Remove scale from the matrix to extract rotation.
|
||||
if(node->scale[0] != 0.0f) {
|
||||
in[0][0] /= node->scale[0];
|
||||
in[0][1] /= node->scale[0];
|
||||
in[0][2] /= node->scale[0];
|
||||
glm_vec3_copy(in[0], node->rotation);
|
||||
glm_vec3_copy(in[1], node->rotation);
|
||||
glm_vec3_copy(in[2], node->rotation);
|
||||
node->rotation[1] = asinf(-in[0][2]);
|
||||
if (cosf(node->rotation[1]) != 0.0f) {
|
||||
node->rotation[0] = atan2f(in[1][2], in[2][2]);
|
||||
node->rotation[2] = atan2f(in[0][1], in[0][0]);
|
||||
} else {
|
||||
node->rotation[0] = 0.0f;
|
||||
node->rotation[2] = atan2f(-in[1][0], in[1][1]);
|
||||
}
|
||||
} else {
|
||||
node->rotation[0] = 0.0f;
|
||||
node->rotation[1] = 0.0f;
|
||||
node->rotation[2] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void nodePositionGet(const ecsid_t id, vec3 out) {
|
||||
node_t *node;
|
||||
|
||||
if(nodeHas(id)) {
|
||||
node = &NODE_DATA[id];
|
||||
} else {
|
||||
node = nodeAdd(id);
|
||||
}
|
||||
|
||||
glm_vec3_copy(node->position, out);
|
||||
}
|
||||
|
||||
void nodeMatrixUpdate(const ecsid_t id) {
|
||||
node_t *node;
|
||||
|
||||
if(nodeHas(id)) {
|
||||
node = &NODE_DATA[id];
|
||||
} else {
|
||||
node = nodeAdd(id);
|
||||
}
|
||||
|
||||
glm_mat4_identity(node->transform);
|
||||
mat4 rot;
|
||||
glm_euler(node->rotation, rot);
|
||||
glm_mat4_mul(node->transform, rot, node->transform);
|
||||
// glm_scale(node->transform, node->scale);
|
||||
}
|
||||
|
||||
void nodeMatrixPush(const ecsid_t id) {
|
||||
assertTrue(nodeHas(id), "Not a node component");
|
||||
node_t *node = nodeGet(id);
|
||||
|
||||
#if DUSK_DISPLAY_SDL2
|
||||
glPushMatrix();
|
||||
glMultMatrixf((const GLfloat*)node->transform);
|
||||
#endif
|
||||
}
|
||||
|
||||
void nodeMatrixPop(void) {
|
||||
#if DUSK_DISPLAY_SDL2
|
||||
glPopMatrix();
|
||||
#endif
|
||||
}
|
||||
@@ -12,6 +12,10 @@
|
||||
|
||||
typedef struct {
|
||||
mat4 transform;
|
||||
|
||||
vec3 position;
|
||||
vec3 scale;
|
||||
vec3 rotation; // Euler angles in radians
|
||||
} node_t;
|
||||
|
||||
extern node_t NODE_DATA[ECS_ENTITY_COUNT_MAX];
|
||||
@@ -25,15 +29,12 @@ extern ecscomponent_t NODE_COMPONENT;
|
||||
#define nodeRemove(id) ecsComponentDataRemove(&NODE_COMPONENT, id)
|
||||
|
||||
/**
|
||||
* Initialize the scene tree.
|
||||
*
|
||||
* This will initialize the ECS system and prepare the scene tree for use.
|
||||
* Initialize the node component.
|
||||
*/
|
||||
void nodeInit(void);
|
||||
|
||||
/**
|
||||
* Callback for when an entity is added to the ECS.
|
||||
* This will initialize the scene tree data for the entity.
|
||||
*
|
||||
* @param id The ID of the entity being added.
|
||||
*/
|
||||
@@ -41,24 +42,42 @@ void nodeEntityAdded(const ecsid_t id);
|
||||
|
||||
/**
|
||||
* Callback for when an entity is removed from the ECS.
|
||||
* This will clean up any scene tree data associated with the entity.
|
||||
*
|
||||
* @param id The ID of the entity being removed.
|
||||
*/
|
||||
void nodeEntityRemoved(const ecsid_t id);
|
||||
|
||||
/**
|
||||
* Get the local transformation matrix of a scene item.
|
||||
* Get the local transformation matrix of a node.
|
||||
*
|
||||
* @param id The ID of the scene item.
|
||||
* @param id The ID of the node.
|
||||
* @param out Pointer to a mat4 where the local matrix will be stored.
|
||||
*/
|
||||
void nodeMatrixGet(const ecsid_t id, mat4 out);
|
||||
|
||||
/**
|
||||
* Set the local transformation matrix of a scene item.
|
||||
* Set the local transformation matrix of a node.
|
||||
*
|
||||
* @param id The ID of the scene item.
|
||||
* @param id The ID of the node.
|
||||
* @param in Pointer to a mat4 containing the new local matrix.
|
||||
*/
|
||||
void nodeMatrixSet(const ecsid_t id, mat4 in);
|
||||
void nodeMatrixSet(const ecsid_t id, mat4 in);
|
||||
|
||||
/**
|
||||
* Get the local position of a node.
|
||||
*
|
||||
* @param id The ID of the node.
|
||||
*/
|
||||
void nodeMatrixUpdate(const ecsid_t id);
|
||||
|
||||
/**
|
||||
* Push the node's transformation matrix onto the OpenGL matrix stack.
|
||||
*
|
||||
* @param id The ID of the node.
|
||||
*/
|
||||
void nodeMatrixPush(const ecsid_t id);
|
||||
|
||||
/**
|
||||
* Pop the last transformation matrix from the OpenGL matrix stack.
|
||||
*/
|
||||
void nodeMatrixPop(void);
|
||||
Reference in New Issue
Block a user