axis gizmo
[gba_blender] / src / xgl.c
index 4880aba..2632473 100644 (file)
--- a/src/xgl.c
+++ b/src/xgl.c
@@ -74,7 +74,7 @@ void xgl_pop_matrix(void)
        if(mtop > 0) mtop--;
 }
 
-static const int32_t id[] = {
+static int32_t id[] = {
        0x10000, 0, 0, 0,
        0, 0x10000, 0, 0,
        0, 0, 0x10000, 0,
@@ -83,7 +83,7 @@ static const int32_t id[] = {
 
 void xgl_load_identity(void)
 {
-       xgl_load_matrix(id);
+       memcpy(mat[mtop], id, sizeof mat[0]);
 }
 
 void xgl_load_matrix(const int32_t *m)
@@ -91,6 +91,11 @@ void xgl_load_matrix(const int32_t *m)
        memcpy(mat[mtop], m, sizeof mat[0]);
 }
 
+void xgl_get_matrix(int32_t *m)
+{
+       memcpy(m, mat[mtop], sizeof mat[0]);
+}
+
 #define M(i,j) (((i) << 2) + (j))
 #define XMUL(a, b)     (((a) >> 8) * ((b) >> 8))
 void xgl_mult_matrix(const int32_t *m2)
@@ -243,6 +248,19 @@ void xgl_draw(int prim, const struct xvertex *varr, int vcount)
        }
 }
 
+void xgl_transform(const struct xvertex *vin, int *x, int *y)
+{
+       struct xvertex v;
+       xform(&v, vin, mat[mtop]);
+
+       v.x = (v.x << 1) / (v.z >> 8);  /* assume aspect: ~2 */
+       v.y = (v.y << 2) / (v.z >> 8);  /* the shift is * PROJ_D */
+       /* projection result is 24.8 */
+       /* viewport */
+       *x = ((((v.x + 0x100) >> 1) * vp[2]) >> 8) + vp[0];
+       *y = ((((0x100 - v.y) >> 1) * vp[3]) >> 8) + vp[1];
+}
+
 static void draw_ptlines(int prim, const struct xvertex *varr, int vcount)
 {
        int i;