Skip to content

Commit

Permalink
imGuIZMO.quat ver.3.0 - only code formatting/prettifying
Browse files Browse the repository at this point in the history
  • Loading branch information
BrutPitt committed Apr 25, 2020
1 parent 1abb27c commit fcec1fc
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 96 deletions.
81 changes: 35 additions & 46 deletions example/src/tools/imGuIZMOquat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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));
Expand All @@ -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++;
Expand All @@ -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;
Expand All @@ -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);
}
Expand All @@ -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
Expand Down Expand Up @@ -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);


};

//////////////////////////////////////////////////////////////////
Expand All @@ -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!!!
Expand Down Expand Up @@ -864,49 +861,47 @@ 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<meridians; j++, angle+=incAngle)
{
for(int j=0; j<meridians; j++, angle+=incAngle) {
const float x0 = x1; x1 = cosf(T_PI-angle);
const float y0 = y1; y1 = sinf(T_PI-angle);

const int tType = ((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);
}

// 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<parallels-1; i++, angle+=incAngle) {

for(int i=1; i<parallels-1; i++, angle+=incAngle) {
//int div =8;
z0 = z1; z1 = cosf(angle)*radius;
r0 = r1; r1 = sinf(angle)*radius;
float angleJ = incAngle;

for(int j=0; j<meridians; j++, angleJ+=incAngle) {

const float x0 = x1; x1 = cosf(angleJ);
const float y0 = y1; y1 = sinf(angleJ);
for(int j=0; j<meridians; j++, angleJ+=incAngle) {
const float x0 = x1; x1 = cosf(angleJ);
const float y0 = y1; y1 = sinf(angleJ);

const int tType = ((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
Expand All @@ -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<meridians; j++,angle+=incAngle)
{
for(int j=0; j<meridians; j++,angle+=incAngle) {
const float x0 = x1; x1 = cosf(angle+T_PI);
const float y0 = y1; y1 = sinf(angle+T_PI);

Expand All @@ -940,7 +934,6 @@ void imguiGizmo::buildCone(const float x0, const float x1, const float radius, c
const float cosn = height / sq;
const float sinn = radius / sq;


const float incAngle = 2.0f*T_PI/(float)( slices );
float angle = incAngle;

Expand All @@ -955,8 +948,7 @@ void imguiGizmo::buildCone(const float x0, const float x1, const float radius, c
# define V(i,x,y,z) arrowVtx [i].push_back(vec3(x, y, z))
# define N(i,x,y,z) arrowNorm[i].push_back(vec3(x, y, z))

for (int j=0; j<slices; j++, angle+=incAngle)
{
for(int j=0; j<slices; j++, angle+=incAngle) {
const float yt0 = yt1; yt1 = cosf(angle);
const float y0 = y1; y1 = yt1*radius; yt1*=sinn;
const float zt0 = zt1; zt1 = sinf(angle);
Expand Down Expand Up @@ -994,7 +986,6 @@ void imguiGizmo::buildCylinder(const float x0, const float x1, const float radiu
float y1 = 1.0f, yr1 = radius;
float z1 = 0.0f, zr1 = 0.0f; // * radius


const float incAngle = 2.0f*T_PI/(float)( slices );
float angle = incAngle;

Expand All @@ -1004,7 +995,7 @@ void imguiGizmo::buildCylinder(const float x0, const float x1, const float radiu
# define V(i,x,y,z) arrowVtx [i].push_back(vec3(x, y, z))
# define N(i,x,y,z) arrowNorm[i].push_back(vec3(x, y, z))

for (int j=0; j<slices; j++, angle+=incAngle) {
for(int j=0; j<slices; j++, angle+=incAngle) {
const float y0 = y1; y1 = cosf(angle);
const float z0 = z1; z1 = sinf(angle);
const float yr0 = yr1; yr1 = y1 * radius;
Expand All @@ -1018,7 +1009,7 @@ void imguiGizmo::buildCylinder(const float x0, const float x1, const float radiu
N(CYL_CAP, -1.f, 0.f, 0.f);
# ifdef imguiGizmo_INTERPOLATE_NORMALS
N(CYL_CAP, -1.f, 0.f, 0.f);
N(CYL_CAP, -1.f, 0.f, 0.f);
N(CYL_CAP, -1.f, 0.f, 0.f);
#endif
// Cover surface
N(CYL_SURF, 0.f, y0, z0);
Expand All @@ -1029,14 +1020,12 @@ void imguiGizmo::buildCylinder(const float x0, const float x1, const float radiu
N(CYL_SURF, 0.f, y1, z1);
N(CYL_SURF, 0.f, y1, z1);
#endif

V(CYL_SURF, x1, yr0, zr0);
V(CYL_SURF, x0, yr0, zr0);
V(CYL_SURF, x0, yr1, zr1);
V(CYL_SURF, x1, yr0, zr0);
V(CYL_SURF, x0, yr1, zr1);
V(CYL_SURF, x1, yr1, zr1);

#ifdef SHOW_FULL_CYLINDER
// Cover the top ..in the arrow this cap is covered from cone/pyramid
V(CYL_CAP , x1, 0.f, 0.f);
Expand All @@ -1045,7 +1034,7 @@ void imguiGizmo::buildCylinder(const float x0, const float x1, const float radiu
N(CYL_CAP , 1.f, 0.f, 0.f);
# ifdef imguiGizmo_INTERPOLATE_NORMALS
N(CYL_CAP , 1.f, 0.f, 0.f);
N(CYL_CAP , 1.f, 0.f, 0.f);
N(CYL_CAP , 1.f, 0.f, 0.f);
#endif
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions example/src/tools/imGuIZMOquat.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <algorithm>


#include <vGizmo.h>
#include "vGizmo.h"

#if !defined(IMGUIZMO_IMGUI_FOLDER)
#define IMGUIZMO_IMGUI_FOLDER imgui/
Expand Down Expand Up @@ -99,7 +99,7 @@ struct imguiGizmo

enum solidSides{ backSide, frontSide }; // or viceversa...
static ImVector<vec3> sphereVtx;
static ImVector<int> sphereTess;
static ImVector<int> sphereTess;
static ImVector<vec3> cubeVtx;
static ImVector<vec3> cubeNorm;
static ImVector<vec3> planeVtx;
Expand Down
Loading

0 comments on commit fcec1fc

Please sign in to comment.