From fcec1fcb28c2a18cfbaaa8d48cf09718e2235246 Mon Sep 17 00:00:00 2001 From: BrutPitt Date: Sat, 25 Apr 2020 02:37:20 +0200 Subject: [PATCH] imGuIZMO.quat ver.3.0 - only code formatting/prettifying --- example/src/tools/imGuIZMOquat.cpp | 81 +++++++++++++----------------- example/src/tools/imGuIZMOquat.h | 4 +- imGuIZMO.quat/imGuIZMOquat.cpp | 81 +++++++++++++----------------- imGuIZMO.quat/imGuIZMOquat.h | 4 +- 4 files changed, 74 insertions(+), 96 deletions(-) diff --git a/example/src/tools/imGuIZMOquat.cpp b/example/src/tools/imGuIZMOquat.cpp index 4a8f834..3260111 100644 --- a/example/src/tools/imGuIZMOquat.cpp +++ b/example/src/tools/imGuIZMOquat.cpp @@ -405,7 +405,7 @@ inline vec3 &adjustSpotCone(vec3 &coord) inline vec3 fastRotate (int axis, vec3 &v) { return ((axis == imguiGizmo::axisIsY) ? vec3(-v.y, v.x, v.z) : // rotation Z 90' - ((axis == imguiGizmo::axisIsZ) ? vec3(-v.z, v.y, v.x) : // rotation Y 90' + ((axis == imguiGizmo::axisIsZ) ? vec3(-v.z, v.y, v.x) : // rotation Y 90' v)); } //////////////////////////////////////////////////////////////////////////// @@ -499,7 +499,7 @@ bool imguiGizmo::drawFunc(const char* label, float size) // LeftClick if (ImGui::IsItemActive()) { highlighted = true; - if(ImGui::IsMouseDragging(0)) getTrackball(qtV); + if(ImGui::IsMouseDragging(0)) getTrackball(qtV); if((drawMode&modeDual) && ImGui::IsMouseDragging(1)) getTrackball(qtV2); // if dual mode... move together //if((drawMode&modeDual) && ImGui::IsMouseDragging(2)) { getTrackball(qtV); getTrackball(qtV2); } // middle if dual mode... move together @@ -578,8 +578,8 @@ bool imguiGizmo::drawFunc(const char* label, float size) for(vec3* itNorm = cubeNorm.begin(), *itVtx = cubeVtx.begin() ; itNorm != cubeNorm.end();) { vec3 coord; vec3 norm = _q * *itNorm; - for (int i = 0; i<4; ) { - coord = _q * (*itVtx++ * solidResizeFactor); + for(int i = 0; i<4; ) { + coord = _q * (*itVtx++ * solidResizeFactor); uv[i++] = normalizeToControlSize(coord.x,coord.y); } addQuad(addLightEffect(vec4(abs(*itNorm++),1.0f), norm.z, coord.z)); @@ -593,8 +593,8 @@ bool imguiGizmo::drawFunc(const char* label, float size) for(auto itNorm = planeNorm.begin(), itVtx = planeVtx.begin() ; itNorm != planeNorm.end();) { vec3 coord; vec3 norm = _q * *itNorm; - for (int i = 0; i<4; ) { - coord = _q * (*itVtx++ * solidResizeFactor); + for(int i = 0; i<4; ) { + coord = _q * (*itVtx++ * solidResizeFactor); uv[i++] = normalizeToControlSize(coord.x,coord.y); } itNorm++; @@ -614,7 +614,7 @@ bool imguiGizmo::drawFunc(const char* label, float size) bool skipCone =true; - if ((side == backSide && arrowCoordZ > 0) || (side == frontSide && arrowCoordZ <= 0)) { + if((side == backSide && arrowCoordZ > 0) || (side == frontSide && arrowCoordZ <= 0)) { if (!showFullAxes && (i == CYL_CAP)) continue; // skip if cylCap is hidden if (i <= CONE_CAP) continue; // do not draw cone else skipCone = false; @@ -623,23 +623,23 @@ bool imguiGizmo::drawFunc(const char* label, float size) auto *ptrVtx = arrowVtx+i; draw_list->PrimReserve(ptrVtx->size(), ptrVtx->size()); // // reserve vtx - for (auto itVtx = ptrVtx->begin(), itNorm = (arrowNorm+i)->begin(); itVtx != ptrVtx->end(); ) { //for all Vtx + for(auto itVtx = ptrVtx->begin(), itNorm = (arrowNorm+i)->begin(); itVtx != ptrVtx->end(); ) { //for all Vtx #if !defined(imguiGizmo_INTERPOLATE_NORMALS) vec3 norm( _q * fastRotate(arrowAxis, *itNorm++)); -#endif +#endif for(int h=0; h<3; h++) { vec3 coord(*itVtx++ * resizeAxes); // reduction // reposition starting point... - if (!skipCone && coord.x > 0) coord.x = -arrowStartingPoint; - if ((skipCone && coord.x <= 0) || + if(!skipCone && coord.x > 0) coord.x = -arrowStartingPoint; + if((skipCone && coord.x <= 0) || (!showFullAxes && (coord.x < arrowStartingPoint)) ) coord.x = arrowStartingPoint; //transform coord = _q * fastRotate(arrowAxis, coord); uv[h] = normalizeToControlSize(coord.x,coord.y); #ifdef imguiGizmo_INTERPOLATE_NORMALS vec3 norm( _q * fastRotate(arrowAxis, *itNorm++)); -#endif +#endif //col[h] = addLightEffect(ImU32(0xFF) << arrowAxis*8, float(0xa0)*norm.z+.5f); col[h] = addLightEffect(vec4(float(arrowAxis==axisIsX),float(arrowAxis==axisIsY),float(arrowAxis==axisIsZ), 1.0), norm.z, coord.z); } @@ -654,7 +654,7 @@ bool imguiGizmo::drawFunc(const char* label, float size) { auto *ptrVtx = arrowVtx+idx; draw_list->PrimReserve(ptrVtx->size(), ptrVtx->size()); // reserve vtx - for (auto itVtx = ptrVtx->begin(), itNorm = (arrowNorm+idx)->begin(); itVtx != ptrVtx->end(); ) { + for(auto itVtx = ptrVtx->begin(), itNorm = (arrowNorm+idx)->begin(); itVtx != ptrVtx->end(); ) { #if !defined(imguiGizmo_INTERPOLATE_NORMALS) vec3 norm = (_q * *itNorm++); #endif @@ -766,8 +766,6 @@ bool imguiGizmo::drawFunc(const char* label, float size) ImVec2(center.x-lenLine+hhLen , center.y-halfLen), ImVec2(center.x-lenLine+hhLen , center.y+halfLen), color); - - }; ////////////////////////////////////////////////////////////////// @@ -784,7 +782,6 @@ bool imguiGizmo::drawFunc(const char* label, float size) ImVec2(center.x-halfLen, center.y-halfLen ), ImVec2(center.x+halfLen, center.y-halfLen ), color); - }; // ... and now.. draw the widget!!! @@ -864,21 +861,20 @@ void imguiGizmo::buildSphere(const float radius, const int tessFactor) const float incAngle = 2.0f*T_PI/(float)( meridians ); float angle = incAngle; - // Adjust z and radius as stacks are drawn. + // Adjust z and radius as stacks are drawn. float z0, z1 = cosf(angle)*radius; float r0, r1 = sinf(angle)*radius; float x1 = -1.0f; float y1 = 0.0f; // The first pole==>parallel is covered with triangles - for (int j=0; j>div)&1); - - V(0.0f, 0.0f, radius); T(tType); + + V(0.0f, 0.0f, radius); T(tType); V(x0*r1,-y0*r1, z1); T(tType); V(x1*r1,-y1*r1, z1); T(tType); } @@ -886,27 +882,26 @@ void imguiGizmo::buildSphere(const float radius, const int tessFactor) // Cover each stack with a quad divided in 2 triangles, except the top and bottom stacks angle = incAngle+incAngle; x1 = 1.f; y1 = 0.f; - - for(int i=1; i>div)&1) ? ((j>>div)&1) : !((j>>div)&1); + const int tType = ((i>>div)&1) ? ((j>>div)&1) : !((j>>div)&1); - V(x0*r1, -y0*r1, z1); T(tType); - V(x0*r0, -y0*r0, z0); T(tType); - V(x1*r0, -y1*r0, z0); T(tType); - V(x0*r1, -y0*r1, z1); T(tType); - V(x1*r0, -y1*r0, z0); T(tType); - V(x1*r1, -y1*r1, z1); T(tType); - } + V(x0*r1, -y0*r1, z1); T(tType); + V(x0*r0, -y0*r0, z0); T(tType); + V(x1*r0, -y1*r0, z0); T(tType); + V(x0*r1, -y0*r1, z1); T(tType); + V(x1*r0, -y1*r0, z0); T(tType); + V(x1*r1, -y1*r1, z1); T(tType); + } } // The last parallel==>pole is covered with triangls @@ -915,8 +910,7 @@ void imguiGizmo::buildSphere(const float radius, const int tessFactor) x1 = -1.0f; y1 = 0.f; angle = incAngle; - for (int j=0; j -#include +#include "vGizmo.h" #if !defined(IMGUIZMO_IMGUI_FOLDER) #define IMGUIZMO_IMGUI_FOLDER imgui/ @@ -99,7 +99,7 @@ struct imguiGizmo enum solidSides{ backSide, frontSide }; // or viceversa... static ImVector sphereVtx; - static ImVector sphereTess; + static ImVector sphereTess; static ImVector cubeVtx; static ImVector cubeNorm; static ImVector planeVtx; diff --git a/imGuIZMO.quat/imGuIZMOquat.cpp b/imGuIZMO.quat/imGuIZMOquat.cpp index 4a8f834..3260111 100644 --- a/imGuIZMO.quat/imGuIZMOquat.cpp +++ b/imGuIZMO.quat/imGuIZMOquat.cpp @@ -405,7 +405,7 @@ inline vec3 &adjustSpotCone(vec3 &coord) inline vec3 fastRotate (int axis, vec3 &v) { return ((axis == imguiGizmo::axisIsY) ? vec3(-v.y, v.x, v.z) : // rotation Z 90' - ((axis == imguiGizmo::axisIsZ) ? vec3(-v.z, v.y, v.x) : // rotation Y 90' + ((axis == imguiGizmo::axisIsZ) ? vec3(-v.z, v.y, v.x) : // rotation Y 90' v)); } //////////////////////////////////////////////////////////////////////////// @@ -499,7 +499,7 @@ bool imguiGizmo::drawFunc(const char* label, float size) // LeftClick if (ImGui::IsItemActive()) { highlighted = true; - if(ImGui::IsMouseDragging(0)) getTrackball(qtV); + if(ImGui::IsMouseDragging(0)) getTrackball(qtV); if((drawMode&modeDual) && ImGui::IsMouseDragging(1)) getTrackball(qtV2); // if dual mode... move together //if((drawMode&modeDual) && ImGui::IsMouseDragging(2)) { getTrackball(qtV); getTrackball(qtV2); } // middle if dual mode... move together @@ -578,8 +578,8 @@ bool imguiGizmo::drawFunc(const char* label, float size) for(vec3* itNorm = cubeNorm.begin(), *itVtx = cubeVtx.begin() ; itNorm != cubeNorm.end();) { vec3 coord; vec3 norm = _q * *itNorm; - for (int i = 0; i<4; ) { - coord = _q * (*itVtx++ * solidResizeFactor); + for(int i = 0; i<4; ) { + coord = _q * (*itVtx++ * solidResizeFactor); uv[i++] = normalizeToControlSize(coord.x,coord.y); } addQuad(addLightEffect(vec4(abs(*itNorm++),1.0f), norm.z, coord.z)); @@ -593,8 +593,8 @@ bool imguiGizmo::drawFunc(const char* label, float size) for(auto itNorm = planeNorm.begin(), itVtx = planeVtx.begin() ; itNorm != planeNorm.end();) { vec3 coord; vec3 norm = _q * *itNorm; - for (int i = 0; i<4; ) { - coord = _q * (*itVtx++ * solidResizeFactor); + for(int i = 0; i<4; ) { + coord = _q * (*itVtx++ * solidResizeFactor); uv[i++] = normalizeToControlSize(coord.x,coord.y); } itNorm++; @@ -614,7 +614,7 @@ bool imguiGizmo::drawFunc(const char* label, float size) bool skipCone =true; - if ((side == backSide && arrowCoordZ > 0) || (side == frontSide && arrowCoordZ <= 0)) { + if((side == backSide && arrowCoordZ > 0) || (side == frontSide && arrowCoordZ <= 0)) { if (!showFullAxes && (i == CYL_CAP)) continue; // skip if cylCap is hidden if (i <= CONE_CAP) continue; // do not draw cone else skipCone = false; @@ -623,23 +623,23 @@ bool imguiGizmo::drawFunc(const char* label, float size) auto *ptrVtx = arrowVtx+i; draw_list->PrimReserve(ptrVtx->size(), ptrVtx->size()); // // reserve vtx - for (auto itVtx = ptrVtx->begin(), itNorm = (arrowNorm+i)->begin(); itVtx != ptrVtx->end(); ) { //for all Vtx + for(auto itVtx = ptrVtx->begin(), itNorm = (arrowNorm+i)->begin(); itVtx != ptrVtx->end(); ) { //for all Vtx #if !defined(imguiGizmo_INTERPOLATE_NORMALS) vec3 norm( _q * fastRotate(arrowAxis, *itNorm++)); -#endif +#endif for(int h=0; h<3; h++) { vec3 coord(*itVtx++ * resizeAxes); // reduction // reposition starting point... - if (!skipCone && coord.x > 0) coord.x = -arrowStartingPoint; - if ((skipCone && coord.x <= 0) || + if(!skipCone && coord.x > 0) coord.x = -arrowStartingPoint; + if((skipCone && coord.x <= 0) || (!showFullAxes && (coord.x < arrowStartingPoint)) ) coord.x = arrowStartingPoint; //transform coord = _q * fastRotate(arrowAxis, coord); uv[h] = normalizeToControlSize(coord.x,coord.y); #ifdef imguiGizmo_INTERPOLATE_NORMALS vec3 norm( _q * fastRotate(arrowAxis, *itNorm++)); -#endif +#endif //col[h] = addLightEffect(ImU32(0xFF) << arrowAxis*8, float(0xa0)*norm.z+.5f); col[h] = addLightEffect(vec4(float(arrowAxis==axisIsX),float(arrowAxis==axisIsY),float(arrowAxis==axisIsZ), 1.0), norm.z, coord.z); } @@ -654,7 +654,7 @@ bool imguiGizmo::drawFunc(const char* label, float size) { auto *ptrVtx = arrowVtx+idx; draw_list->PrimReserve(ptrVtx->size(), ptrVtx->size()); // reserve vtx - for (auto itVtx = ptrVtx->begin(), itNorm = (arrowNorm+idx)->begin(); itVtx != ptrVtx->end(); ) { + for(auto itVtx = ptrVtx->begin(), itNorm = (arrowNorm+idx)->begin(); itVtx != ptrVtx->end(); ) { #if !defined(imguiGizmo_INTERPOLATE_NORMALS) vec3 norm = (_q * *itNorm++); #endif @@ -766,8 +766,6 @@ bool imguiGizmo::drawFunc(const char* label, float size) ImVec2(center.x-lenLine+hhLen , center.y-halfLen), ImVec2(center.x-lenLine+hhLen , center.y+halfLen), color); - - }; ////////////////////////////////////////////////////////////////// @@ -784,7 +782,6 @@ bool imguiGizmo::drawFunc(const char* label, float size) ImVec2(center.x-halfLen, center.y-halfLen ), ImVec2(center.x+halfLen, center.y-halfLen ), color); - }; // ... and now.. draw the widget!!! @@ -864,21 +861,20 @@ void imguiGizmo::buildSphere(const float radius, const int tessFactor) const float incAngle = 2.0f*T_PI/(float)( meridians ); float angle = incAngle; - // Adjust z and radius as stacks are drawn. + // Adjust z and radius as stacks are drawn. float z0, z1 = cosf(angle)*radius; float r0, r1 = sinf(angle)*radius; float x1 = -1.0f; float y1 = 0.0f; // The first pole==>parallel is covered with triangles - for (int j=0; j>div)&1); - - V(0.0f, 0.0f, radius); T(tType); + + V(0.0f, 0.0f, radius); T(tType); V(x0*r1,-y0*r1, z1); T(tType); V(x1*r1,-y1*r1, z1); T(tType); } @@ -886,27 +882,26 @@ void imguiGizmo::buildSphere(const float radius, const int tessFactor) // Cover each stack with a quad divided in 2 triangles, except the top and bottom stacks angle = incAngle+incAngle; x1 = 1.f; y1 = 0.f; - - for(int i=1; i>div)&1) ? ((j>>div)&1) : !((j>>div)&1); + const int tType = ((i>>div)&1) ? ((j>>div)&1) : !((j>>div)&1); - V(x0*r1, -y0*r1, z1); T(tType); - V(x0*r0, -y0*r0, z0); T(tType); - V(x1*r0, -y1*r0, z0); T(tType); - V(x0*r1, -y0*r1, z1); T(tType); - V(x1*r0, -y1*r0, z0); T(tType); - V(x1*r1, -y1*r1, z1); T(tType); - } + V(x0*r1, -y0*r1, z1); T(tType); + V(x0*r0, -y0*r0, z0); T(tType); + V(x1*r0, -y1*r0, z0); T(tType); + V(x0*r1, -y0*r1, z1); T(tType); + V(x1*r0, -y1*r0, z0); T(tType); + V(x1*r1, -y1*r1, z1); T(tType); + } } // The last parallel==>pole is covered with triangls @@ -915,8 +910,7 @@ void imguiGizmo::buildSphere(const float radius, const int tessFactor) x1 = -1.0f; y1 = 0.f; angle = incAngle; - for (int j=0; j -#include +#include "vGizmo.h" #if !defined(IMGUIZMO_IMGUI_FOLDER) #define IMGUIZMO_IMGUI_FOLDER imgui/ @@ -99,7 +99,7 @@ struct imguiGizmo enum solidSides{ backSide, frontSide }; // or viceversa... static ImVector sphereVtx; - static ImVector sphereTess; + static ImVector sphereTess; static ImVector cubeVtx; static ImVector cubeNorm; static ImVector planeVtx;