diff --git a/core/src/rendering/defaultmeshes.cpp b/core/src/rendering/defaultmeshes.cpp index 51bc90d..0a62bfa 100644 --- a/core/src/rendering/defaultmeshes.cpp +++ b/core/src/rendering/defaultmeshes.cpp @@ -39,6 +39,7 @@ static float CUBE_VERTICES[] = { -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, }; + static float SPHERE_VERTICES[] = { // positions // normals // texture coords @@ -1002,15 +1003,160 @@ static float SPHERE_VERTICES[] = { 0.3047735, -0.3287595, 0.221428, 0.6153, -0.5545, 0.5603, 0.250001, 0.118096, 0.3618035, -0.22361, 0.2628625, 0.6153, -0.5545, 0.5603, 0.272728, 0.157461, 0.2659705, -0.251151, 0.340856, 0.6153, -0.5545, 0.5603, 0.227274, 0.157461, +}; + +static float ARROW_VERTICES[] = { + // positions // normals // texture coords + + 0.2373099418149408, 5.551115123125783e-17, 0.2782139328364581, 0.9239, -0.3827, -0.0, 1.0, 1.0, + 0.16780384761607425, -0.16780384761607425, -0.5, 0.9239, -0.3827, -0.0, 0.875, 0.5, + 0.2373099418149408, 5.551115123125783e-17, -0.5, 0.9239, -0.3827, -0.0, 1.0, 0.5, + 0.16780384761607425, -0.16780384761607425, 0.2782139328364581, 0.3827, -0.9239, -0.0, 0.875, 1.0, + 0.0, -0.2373099418149407, -0.5, 0.3827, -0.9239, -0.0, 0.75, 0.5, + 0.16780384761607425, -0.16780384761607425, -0.5, 0.3827, -0.9239, -0.0, 0.875, 0.5, + 0.0, -0.2373099418149407, 0.2782139328364581, -0.3827, -0.9239, -0.0, 0.75, 1.0, + -0.16780258874417453, -0.16780384761607425, -0.5, -0.3827, -0.9239, -0.0, 0.625, 0.5, + 0.0, -0.2373099418149407, -0.5, -0.3827, -0.9239, -0.0, 0.75, 0.5, + -0.16780258874417453, -0.16780384761607425, 0.2782139328364581, -0.9239, -0.3827, -0.0, 0.625, 1.0, + -0.23730868294304108, 5.551115123125783e-17, -0.5, -0.9239, -0.3827, -0.0, 0.5, 0.5, + -0.16780258874417453, -0.16780384761607425, -0.5, -0.9239, -0.3827, -0.0, 0.625, 0.5, + -0.23730868294304108, 5.551115123125783e-17, 0.2782139328364581, -0.9239, 0.3827, -0.0, 0.5, 1.0, + -0.16780258874417453, 0.16780258874417459, -0.5, -0.9239, 0.3827, -0.0, 0.375, 0.5, + -0.23730868294304108, 5.551115123125783e-17, -0.5, -0.9239, 0.3827, -0.0, 0.5, 0.5, + -0.16780258874417453, 0.16780258874417459, 0.2782139328364581, -0.3827, 0.9239, -0.0, 0.375, 1.0, + 0.0, 0.23730868294304114, -0.5, -0.3827, 0.9239, -0.0, 0.25, 0.5, + -0.16780258874417453, 0.16780258874417459, -0.5, -0.3827, 0.9239, -0.0, 0.375, 0.5, + -0.16780258874417453, -0.16780384761607425, 0.2782139328364581, -0.0, -0.0, -1.0, 0.625, 1.0, + -0.5, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 0.5, 1.0, + -0.23730868294304108, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 0.5, 1.0, + 0.0, 0.23730868294304114, 0.2782139328364581, 0.3827, 0.9239, -0.0, 0.25, 1.0, + 0.16780384761607425, 0.16780258874417459, -0.5, 0.3827, 0.9239, -0.0, 0.125, 0.5, + 0.0, 0.23730868294304114, -0.5, 0.3827, 0.9239, -0.0, 0.25, 0.5, + 0.16780384761607425, 0.16780258874417459, 0.2782139328364581, 0.9239, 0.3827, -0.0, 0.125, 1.0, + 0.2373099418149408, 5.551115123125783e-17, -0.5, 0.9239, 0.3827, -0.0, 0.0, 0.5, + 0.16780384761607425, 0.16780258874417459, -0.5, 0.9239, 0.3827, -0.0, 0.125, 0.5, + -0.16780258874417453, -0.16780384761607425, -0.5, -0.0, -0.0, -1.0, 0.919706, 0.080294, + -0.16780258874417453, 0.16780258874417459, -0.5, -0.0, -0.0, -1.0, 0.580294, 0.080294, + 0.16780384761607425, 0.16780258874417459, -0.5, -0.0, -0.0, -1.0, 0.580294, 0.419706, + 0.5, 5.551115123125783e-17, 0.2782139328364581, 0.8676, 0.3594, 0.3438, 0.0, 1.0, + 0.3535529141625606, 0.3535529141625606, 0.2782139328364581, 0.8676, 0.3594, 0.3438, 0.125, 1.0, + 0.0, 0.0026637729397931964, 0.5, 0.8676, 0.3594, 0.3438, 0.0, 1.0, + 0.0, 0.23730868294304114, 0.2782139328364581, -0.0, -0.0, -1.0, 0.25, 1.0, + 0.3535529141625606, 0.3535529141625606, 0.2782139328364581, -0.0, -0.0, -1.0, 0.125, 1.0, + 0.16780384761607425, 0.16780258874417459, 0.2782139328364581, -0.0, -0.0, -1.0, 0.125, 1.0, + 0.16780384761607425, -0.16780384761607425, 0.2782139328364581, -0.0, -0.0, -1.0, 0.875, 1.0, + 0.0, -0.5, 0.2782139328364581, -0.0, -0.0, -1.0, 0.75, 1.0, + 0.0, -0.2373099418149407, 0.2782139328364581, -0.0, -0.0, -1.0, 0.75, 1.0, + -0.23730868294304108, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 0.5, 1.0, + -0.3535529141625606, 0.3535529141625606, 0.2782139328364581, -0.0, -0.0, -1.0, 0.375, 1.0, + -0.16780258874417453, 0.16780258874417459, 0.2782139328364581, -0.0, -0.0, -1.0, 0.375, 1.0, + 0.16780384761607425, 0.16780258874417459, 0.2782139328364581, -0.0, -0.0, -1.0, 0.125, 1.0, + 0.5, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 0.0, 1.0, + 0.2373099418149408, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 0.0, 1.0, + 0.2373099418149408, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 1.0, 1.0, + 0.3535529141625606, -0.3535529141625605, 0.2782139328364581, -0.0, -0.0, -1.0, 0.875, 1.0, + 0.16780384761607425, -0.16780384761607425, 0.2782139328364581, -0.0, -0.0, -1.0, 0.875, 1.0, + 0.0, -0.2373099418149407, 0.2782139328364581, -0.0, -0.0, -1.0, 0.75, 1.0, + -0.3535529141625606, -0.3535529141625605, 0.2782139328364581, -0.0, -0.0, -1.0, 0.625, 1.0, + -0.16780258874417453, -0.16780384761607425, 0.2782139328364581, -0.0, -0.0, -1.0, 0.625, 1.0, + -0.16780258874417453, 0.16780258874417459, 0.2782139328364581, -0.0, -0.0, -1.0, 0.375, 1.0, + 0.0, 0.5, 0.2782139328364581, -0.0, -0.0, -1.0, 0.25, 1.0, + 0.0, 0.23730868294304114, 0.2782139328364581, -0.0, -0.0, -1.0, 0.25, 1.0, + 0.0, 0.5, 0.2782139328364581, -0.3595, 0.8679, 0.3429, 0.25, 1.0, + -0.3535529141625606, 0.3535529141625606, 0.2782139328364581, -0.3595, 0.8679, 0.3429, 0.375, 1.0, + 0.0, 0.0026637729397931964, 0.5, -0.3595, 0.8679, 0.3429, 0.25, 1.0, + -0.5, 5.551115123125783e-17, 0.2782139328364581, -0.8671, -0.3592, 0.3452, 0.5, 1.0, + -0.3535529141625606, -0.3535529141625605, 0.2782139328364581, -0.8671, -0.3592, 0.3452, 0.625, 1.0, + 0.0, 0.0026637729397931964, 0.5, -0.8671, -0.3592, 0.3452, 0.5, 1.0, + 0.0, -0.5, 0.2782139328364581, 0.359, -0.8668, 0.3461, 0.75, 1.0, + 0.3535529141625606, -0.3535529141625605, 0.2782139328364581, 0.359, -0.8668, 0.3461, 0.875, 1.0, + 0.0, 0.0026637729397931964, 0.5, 0.359, -0.8668, 0.3461, 0.75, 1.0, + 0.3535529141625606, 0.3535529141625606, 0.2782139328364581, 0.3595, 0.8679, 0.3429, 0.125, 1.0, + 0.0, 0.5, 0.2782139328364581, 0.3595, 0.8679, 0.3429, 0.25, 1.0, + 0.0, 0.0026637729397931964, 0.5, 0.3595, 0.8679, 0.3429, 0.125, 1.0, + -0.3535529141625606, 0.3535529141625606, 0.2782139328364581, -0.8676, 0.3594, 0.3438, 0.375, 1.0, + -0.5, 5.551115123125783e-17, 0.2782139328364581, -0.8676, 0.3594, 0.3438, 0.5, 1.0, + 0.0, 0.0026637729397931964, 0.5, -0.8676, 0.3594, 0.3438, 0.375, 1.0, + -0.3535529141625606, -0.3535529141625605, 0.2782139328364581, -0.359, -0.8668, 0.3461, 0.625, 1.0, + 0.0, -0.5, 0.2782139328364581, -0.359, -0.8668, 0.3461, 0.75, 1.0, + 0.0, 0.0026637729397931964, 0.5, -0.359, -0.8668, 0.3461, 0.625, 1.0, + 0.3535529141625606, -0.3535529141625605, 0.2782139328364581, 0.8671, -0.3592, 0.3452, 0.875, 1.0, + 0.5, 5.551115123125783e-17, 0.2782139328364581, 0.8671, -0.3592, 0.3452, 1.0, 1.0, + 0.0, 0.0026637729397931964, 0.5, 0.8671, -0.3592, 0.3452, 0.875, 1.0, + 0.2373099418149408, 5.551115123125783e-17, 0.2782139328364581, 0.9239, -0.3827, -0.0, 1.0, 1.0, + 0.16780384761607425, -0.16780384761607425, 0.2782139328364581, 0.9239, -0.3827, -0.0, 0.875, 1.0, + 0.16780384761607425, -0.16780384761607425, -0.5, 0.9239, -0.3827, -0.0, 0.875, 0.5, + 0.16780384761607425, -0.16780384761607425, 0.2782139328364581, 0.3827, -0.9239, -0.0, 0.875, 1.0, + 0.0, -0.2373099418149407, 0.2782139328364581, 0.3827, -0.9239, -0.0, 0.75, 1.0, + 0.0, -0.2373099418149407, -0.5, 0.3827, -0.9239, -0.0, 0.75, 0.5, + 0.0, -0.2373099418149407, 0.2782139328364581, -0.3827, -0.9239, -0.0, 0.75, 1.0, + -0.16780258874417453, -0.16780384761607425, 0.2782139328364581, -0.3827, -0.9239, -0.0, 0.625, 1.0, + -0.16780258874417453, -0.16780384761607425, -0.5, -0.3827, -0.9239, -0.0, 0.625, 0.5, + -0.16780258874417453, -0.16780384761607425, 0.2782139328364581, -0.9239, -0.3827, -0.0, 0.625, 1.0, + -0.23730868294304108, 5.551115123125783e-17, 0.2782139328364581, -0.9239, -0.3827, -0.0, 0.5, 1.0, + -0.23730868294304108, 5.551115123125783e-17, -0.5, -0.9239, -0.3827, -0.0, 0.5, 0.5, + -0.23730868294304108, 5.551115123125783e-17, 0.2782139328364581, -0.9239, 0.3827, -0.0, 0.5, 1.0, + -0.16780258874417453, 0.16780258874417459, 0.2782139328364581, -0.9239, 0.3827, -0.0, 0.375, 1.0, + -0.16780258874417453, 0.16780258874417459, -0.5, -0.9239, 0.3827, -0.0, 0.375, 0.5, + -0.16780258874417453, 0.16780258874417459, 0.2782139328364581, -0.3827, 0.9239, -0.0, 0.375, 1.0, + 0.0, 0.23730868294304114, 0.2782139328364581, -0.3827, 0.9239, -0.0, 0.25, 1.0, + 0.0, 0.23730868294304114, -0.5, -0.3827, 0.9239, -0.0, 0.25, 0.5, + -0.16780258874417453, -0.16780384761607425, 0.2782139328364581, -0.0, -0.0, -1.0, 0.625, 1.0, + -0.3535529141625606, -0.3535529141625605, 0.2782139328364581, -0.0, -0.0, -1.0, 0.625, 1.0, + -0.5, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 0.5, 1.0, + 0.0, 0.23730868294304114, 0.2782139328364581, 0.3827, 0.9239, -0.0, 0.25, 1.0, + 0.16780384761607425, 0.16780258874417459, 0.2782139328364581, 0.3827, 0.9239, -0.0, 0.125, 1.0, + 0.16780384761607425, 0.16780258874417459, -0.5, 0.3827, 0.9239, -0.0, 0.125, 0.5, + 0.16780384761607425, 0.16780258874417459, 0.2782139328364581, 0.9239, 0.3827, -0.0, 0.125, 1.0, + 0.2373099418149408, 5.551115123125783e-17, 0.2782139328364581, 0.9239, 0.3827, -0.0, 0.0, 1.0, + 0.2373099418149408, 5.551115123125783e-17, -0.5, 0.9239, 0.3827, -0.0, 0.0, 0.5, + 0.16780384761607425, 0.16780258874417459, -0.5, -0.0, -0.0, -1.0, 0.580294, 0.419706, + 0.2373099418149408, 5.551115123125783e-17, -0.5, -0.0, -0.0, -1.0, 0.75, 0.49, + 0.16780384761607425, -0.16780384761607425, -0.5, -0.0, -0.0, -1.0, 0.919706, 0.419706, + 0.16780384761607425, -0.16780384761607425, -0.5, -0.0, -0.0, -1.0, 0.919706, 0.419706, + 0.0, -0.2373099418149407, -0.5, -0.0, -0.0, -1.0, 0.99, 0.25, + -0.16780258874417453, -0.16780384761607425, -0.5, -0.0, -0.0, -1.0, 0.919706, 0.080294, + -0.16780258874417453, -0.16780384761607425, -0.5, -0.0, -0.0, -1.0, 0.919706, 0.080294, + -0.23730868294304108, 5.551115123125783e-17, -0.5, -0.0, -0.0, -1.0, 0.75, 0.01, + -0.16780258874417453, 0.16780258874417459, -0.5, -0.0, -0.0, -1.0, 0.580294, 0.080294, + -0.16780258874417453, 0.16780258874417459, -0.5, -0.0, -0.0, -1.0, 0.580294, 0.080294, + 0.0, 0.23730868294304114, -0.5, -0.0, -0.0, -1.0, 0.51, 0.25, + 0.16780384761607425, 0.16780258874417459, -0.5, -0.0, -0.0, -1.0, 0.580294, 0.419706, + 0.16780384761607425, 0.16780258874417459, -0.5, -0.0, -0.0, -1.0, 0.580294, 0.419706, + 0.16780384761607425, -0.16780384761607425, -0.5, -0.0, -0.0, -1.0, 0.919706, 0.419706, + -0.16780258874417453, -0.16780384761607425, -0.5, -0.0, -0.0, -1.0, 0.919706, 0.080294, + 0.0, 0.23730868294304114, 0.2782139328364581, -0.0, -0.0, -1.0, 0.25, 1.0, + 0.0, 0.5, 0.2782139328364581, -0.0, -0.0, -1.0, 0.25, 1.0, + 0.3535529141625606, 0.3535529141625606, 0.2782139328364581, -0.0, -0.0, -1.0, 0.125, 1.0, + 0.16780384761607425, -0.16780384761607425, 0.2782139328364581, -0.0, -0.0, -1.0, 0.875, 1.0, + 0.3535529141625606, -0.3535529141625605, 0.2782139328364581, -0.0, -0.0, -1.0, 0.875, 1.0, + 0.0, -0.5, 0.2782139328364581, -0.0, -0.0, -1.0, 0.75, 1.0, + -0.23730868294304108, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 0.5, 1.0, + -0.5, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 0.5, 1.0, + -0.3535529141625606, 0.3535529141625606, 0.2782139328364581, -0.0, -0.0, -1.0, 0.375, 1.0, + 0.16780384761607425, 0.16780258874417459, 0.2782139328364581, -0.0, -0.0, -1.0, 0.125, 1.0, + 0.3535529141625606, 0.3535529141625606, 0.2782139328364581, -0.0, -0.0, -1.0, 0.125, 1.0, + 0.5, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 0.0, 1.0, + 0.2373099418149408, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 1.0, 1.0, + 0.5, 5.551115123125783e-17, 0.2782139328364581, -0.0, -0.0, -1.0, 1.0, 1.0, + 0.3535529141625606, -0.3535529141625605, 0.2782139328364581, -0.0, -0.0, -1.0, 0.875, 1.0, + 0.0, -0.2373099418149407, 0.2782139328364581, -0.0, -0.0, -1.0, 0.75, 1.0, + 0.0, -0.5, 0.2782139328364581, -0.0, -0.0, -1.0, 0.75, 1.0, + -0.3535529141625606, -0.3535529141625605, 0.2782139328364581, -0.0, -0.0, -1.0, 0.625, 1.0, + -0.16780258874417453, 0.16780258874417459, 0.2782139328364581, -0.0, -0.0, -1.0, 0.375, 1.0, + -0.3535529141625606, 0.3535529141625606, 0.2782139328364581, -0.0, -0.0, -1.0, 0.375, 1.0, + 0.0, 0.5, 0.2782139328364581, -0.0, -0.0, -1.0, 0.25, 1.0, }; Mesh* CUBE_MESH; Mesh* SPHERE_MESH; +Mesh* ARROW_MESH; void initMeshes() { CUBE_MESH = new Mesh(sizeof(CUBE_VERTICES) / sizeof(float) / 8, CUBE_VERTICES); SPHERE_MESH = new Mesh(sizeof(SPHERE_VERTICES) / sizeof(float) / 8, SPHERE_VERTICES); + ARROW_MESH = new Mesh(sizeof(ARROW_VERTICES) / sizeof(float) / 8, ARROW_VERTICES); } /* Python generator: diff --git a/core/src/rendering/defaultmeshes.h b/core/src/rendering/defaultmeshes.h index 41c522b..37f0839 100644 --- a/core/src/rendering/defaultmeshes.h +++ b/core/src/rendering/defaultmeshes.h @@ -3,5 +3,6 @@ extern Mesh* CUBE_MESH; extern Mesh* SPHERE_MESH; +extern Mesh* ARROW_MESH; void initMeshes(); \ No newline at end of file diff --git a/core/src/rendering/renderer.cpp b/core/src/rendering/renderer.cpp index 3c1a425..9a6909e 100644 --- a/core/src/rendering/renderer.cpp +++ b/core/src/rendering/renderer.cpp @@ -187,8 +187,8 @@ void renderHandles() { glm::mat3 normalMatrix = glm::mat3(glm::transpose(glm::inverse(model))); handleShader->set("normalMatrix", normalMatrix); - SPHERE_MESH->bind(); - glDrawArrays(GL_TRIANGLES, 0, SPHERE_MESH->vertexCount); + ARROW_MESH->bind(); + glDrawArrays(GL_TRIANGLES, 0, ARROW_MESH->vertexCount); } // 2d square overlay diff --git a/tools/genmesh.py b/tools/genmesh.py index c8382e8..90e6b7d 100755 --- a/tools/genmesh.py +++ b/tools/genmesh.py @@ -23,16 +23,30 @@ vert_uvs = [] out_vertices = [] -# greatest_coord = 0 -# least_coord = 0 +min_coords: tuple[float, float, float] | None = None +max_coords: tuple[float, float, float] | None = None def normalize(x, y, z): - return (x/2, y/2, z/2) + assert min_coords + assert max_coords + return ((x-max_coords[0])/(max_coords[0]-min_coords[0])+0.5, (y-max_coords[1])/(max_coords[1]-min_coords[1])+0.5, (z-max_coords[2])/(max_coords[2]-min_coords[2])+0.5) for line in file: if line.startswith('v '): coords = line.split(' ')[1:] - vert_coords.append((float(coords[0]), float(coords[1]), float(coords[2]))) + coords = (float(coords[0]), float(coords[1]), float(coords[2])) + vert_coords.append(coords) + + if not min_coords: min_coords = coords + if not max_coords: max_coords = coords + + if coords[0] > max_coords[0]: max_coords = (coords[0], max_coords[1], max_coords[2]) + if coords[1] > max_coords[1]: max_coords = (max_coords[0], coords[1], max_coords[2]) + if coords[2] > max_coords[2]: max_coords = (max_coords[0], max_coords[1], coords[2]) + + if coords[0] < min_coords[0]: min_coords = (coords[0], min_coords[1], min_coords[2]) + if coords[1] < min_coords[1]: min_coords = (min_coords[0], coords[1], min_coords[2]) + if coords[2] < min_coords[2]: min_coords = (min_coords[0], min_coords[1], coords[2]) if line.startswith('vn '): coords = line.split(' ')[1:]