git.s-ol.nu forks/DiligentTools / 1fccfe2
Cosmetic changes to imGuIZMO Egor Yusov 3 years ago
2 changed file(s) with 21 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
5050
5151 // arrow/axes components
5252 ///////////////////////////////////////
53 int imguiGizmo::coneSlices = 4;
53 int imguiGizmo::coneSlices = 4;
5454 float imguiGizmo::coneRadius = 0.07f;
5555 float imguiGizmo::coneLength = 0.37f;
5656
5757
58 int imguiGizmo::cylSlices = 7;
59 float imguiGizmo::cylRadius = 0.02f; // sizeCylLength = defined in base to control size
58 int imguiGizmo::cylSlices = 7;
59 float imguiGizmo::cylRadius = 0.02f; // sizeCylLength = defined in base to control size
6060
6161
6262 // Sphere components
6363 ///////////////////////////////////////
64 float imguiGizmo::sphereRadius = .27f;
65 int imguiGizmo::sphereTessFactor = imguiGizmo::sphereTess4;
64 float imguiGizmo::sphereRadius = 0.27f;
65 int imguiGizmo::sphereTessFactor = imguiGizmo::sphereTess4;
6666
6767 // Cube components
6868 ///////////////////////////////////////
69 float imguiGizmo::cubeSize = .05f;
69 float imguiGizmo::cubeSize = 0.05f;
7070
7171 // Plane components
7272 ///////////////////////////////////////
73 float imguiGizmo::planeSize = .33f;
74 float imguiGizmo::planeThickness = .015f;
73 float imguiGizmo::planeSize = 0.33f;
74 float imguiGizmo::planeThickness = 0.015f;
7575
7676 // Axes resize
7777 ///////////////////////////////////////
78 Diligent::float3 imguiGizmo::axesResizeFactor(.95f, 1.f , 1.f);
78 Diligent::float3 imguiGizmo::axesResizeFactor(0.95f, 1.f , 1.f);
7979 Diligent::float3 imguiGizmo::savedAxesResizeFactor = imguiGizmo::axesResizeFactor;
8080
8181 // Solid resize
8282 ///////////////////////////////////////
83 float imguiGizmo::solidResizeFactor = 1.0;
83 float imguiGizmo::solidResizeFactor = 1.0;
8484 float imguiGizmo::savedSolidResizeFactor = imguiGizmo::solidResizeFactor;
8585
8686 // Direction arrow color
9595
9696 // Sphere Colors
9797 ///////////////////////////////////////
98 ImU32 imguiGizmo::sphereColors[2] = { 0xff401010, 0xffc0a0a0 }; // Tessellation colors
98 ImU32 imguiGizmo::sphereColors[2] = { 0xff401010, 0xffc0a0a0 }; // Tessellation colors
9999 ImU32 imguiGizmo::savedSphereColors[2] = { 0xff401010, 0xffc0a0a0 };
100100 //ImU32 spherecolorA=0xff005cc0, spherecolorB=0xffc05c00;
101101
163163 bool gizmo3D(const char* label, Diligent::float3& dir, float size, const int mode)
164164 {
165165 imguiGizmo g;
166 g.modeSettings(mode & (imguiGizmo::modeDirection | imguiGizmo::modeDirPlane) ? mode : imguiGizmo::modeDirection);
166 g.modeSettings((mode & (imguiGizmo::modeDirection | imguiGizmo::modeDirPlane)) ? mode : imguiGizmo::modeDirection);
167167
168168 return g.getTransforms(g.qtV, label, dir, size);
169169
184184 imguiGizmo g;
185185 g.setDualMode(mode);
186186
187 g.qtV = axes; g.qtV2 = spot;
187 g.qtV = axes;
188 g.qtV2 = spot;
188189
189190 bool ret = g.drawFunc(label, size);
190191 if(ret) { axes = g.qtV; spot = g.qtV2; }
259260 ////////////////////////////////////////////////////////////////////////////
260261 inline ImU32 addLightEffect(const Diligent::float4 &color, float light, float atten)
261262 {
262 Diligent::float3 l = Diligent::float3(1, 1, 1) * ((light < .5f) ? .5f : light);
263 Diligent::float3 a = Diligent::float3(1, 1, 1) * ((atten > .25f) ? .25f : atten);
264 Diligent::float3 c(((Diligent::float3(color) + l*.5f) * l) *.75f + a*Diligent::float3(color)*.45f +a*.25f);
263 Diligent::float3 l = Diligent::float3(1, 1, 1) * ((light < 0.5f) ? 0.5f : light);
264 Diligent::float3 a = Diligent::float3(1, 1, 1) * ((atten > 0.25f) ? 0.25f : atten);
265 Diligent::float3 c(((Diligent::float3(color) + l * 0.5f) * l) * 0.75f + a * Diligent::float3(color) * 0.45f + a * 0.25f);
265266
266267 const float alpha = color.a * ImGui::GetStyle().Alpha; //ImGui::GetCo(ImGuiCol_FrameBg).w;
267268 return ImGui::ColorConvertFloat4ToU32(ImVec4(c.x, c.y, c.z, alpha));
270271
271272 inline ImU32 addLightEffect(ImU32 color, float light, float atten)
272273 {
273 Diligent::float4 c(float(color & 0xff)/255.f,float((color>>8) & 0xff)/255.f,float((color>>16) & 0xff)/255.f, 1.0);
274 Diligent::float4 c(float(color & 0xff) / 255.f, float((color>>8) & 0xff)/255.f, float((color>>16) & 0xff)/255.f, 1.0);
274275 return addLightEffect(c, light, atten);
275276 }
276277
379380 else if(io.KeyCtrl) { rotationVector = Diligent::float3(0, 1, 0); }
380381 else if(io.KeyAlt || io.KeySuper) { rotationVector = Diligent::float3(0, 0, 1); }
381382
382
383383 Diligent::Quaternion qtStep = {0, 0, 0, 1};
384384 if(!delta.x && !delta.y)
385385 {
386 qtStep = Diligent::Quaternion(0, 0, 0, 1); //no rotation
387386 return;
388387 }
389388
412411 const auto fpsRatio = 1; //auto adjust by FPS (call idle with current FPS)
413412
414413 qtStep = normalize(Diligent::Quaternion::RotationFromAxisAngle(axis * rotationVector, angle * tbScale * fpsRatio));
415 q = qtStep*q;
414 q = qtStep * q;
416415
417416 value_changed = true;
418417 };
4040 ////////////////////////////////////////////////////////////////////////////
4141
4242 #define imguiGizmo_INTERPOLATE_NORMALS
43 static constexpr float STARTING_ALPHA_PLANE = .75f;
43 static constexpr float STARTING_ALPHA_PLANE = 0.75f;
4444
4545 ////////////////////////////////////////////////////////////////////////////
4646 ////////////////////////////////////////////////////////////////////////////
239239 bool getTransforms(Diligent::Quaternion& q, const char* label, Diligent::float3& dir, float size)
240240 {
241241 const float len = Diligent::length(dir);
242 q = Diligent::Quaternion::RotationFromAxisAngle(Diligent::normalize(Diligent::float3(.0f, -dir.z, dir.y)), acosf(dir.x/len));
242 q = Diligent::Quaternion::RotationFromAxisAngle(Diligent::normalize(Diligent::float3(0, -dir.z, dir.y)), acosf(dir.x/len));
243243
244244 bool ret = drawFunc(label, size);
245245 if (ret) dir = q.RotateVector(Diligent::float3(1, 0, 0)) * len; //return vector with original length