diff --git a/example/src/tools/vGizmo.h b/example/src/tools/vGizmo.h index 64044de..611fd0f 100644 --- a/example/src/tools/vGizmo.h +++ b/example/src/tools/vGizmo.h @@ -476,6 +476,8 @@ using VGIZMO_BASE_CLASS::qtV; // Get Pan (xy) & Dolly (z) position ////////////////////////////////////////////////////////////////// tVec3 getPosition() const { return tVec3(pan.x, pan.y, dolly.z); } + void setPosition(const tVec3 &p) { pan.x = p.x; pan.y = p.y; dolly.z = p.z; } + private: // UI commands that this virtualGizmo responds to (defaults to left mouse button with no modifier key) vgButtons dollyControlButton, panControlButton; diff --git a/example/src/tools/vGizmoConfig.h b/example/src/tools/vGizmoConfig.h index dd4e3d9..9cd743e 100644 --- a/example/src/tools/vGizmoConfig.h +++ b/example/src/tools/vGizmoConfig.h @@ -45,6 +45,7 @@ // // Default ==> use vGizmoMath // If you enable GLM use, automatically is enabled also VGIZMO_USES_TEMPLATE +// if you can, I recommend to use GLM //------------------------------------------------------------------------------ //#define VGIZMO_USES_GLM diff --git a/example/src/tools/vGizmoMath.h b/example/src/tools/vGizmoMath.h index 9804df5..fd9b256 100644 --- a/example/src/tools/vGizmoMath.h +++ b/example/src/tools/vGizmoMath.h @@ -181,10 +181,12 @@ TEMPLATE_TYPENAME_T class Vec4 { }; Vec4() {} - Vec4(T s) : x(s), y(s), z(s), w(s) {} - Vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {} - Vec4(const VEC3_T& v, T s = T(0)) : x(v.x), y(v.y), z(v.z), w(s) {} + Vec4(T s) : x(s), y(s), z(s), w(s) {} + Vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {} + Vec4(const VEC3_T& v, T s = T(0)) : x(v.x), y(v.y), z(v.z), w(s) {} + Vec4(T s, const VEC3_T& v) : x(s), y(v.x), z(v.y), w(v.z) {} + //operator VEC3_T() const { return *((VEC3_T *) &x); } const Vec4 operator-() const { return Vec4(-x, -y, -z, -w); } Vec4& operator+=(const Vec4& v) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; } @@ -461,14 +463,12 @@ TEMPLATE_TYPENAME_T inline const MAT4_T inverse(MAT4_T const &m) { VEC4_T v2(m.m12, m.m02, m.m02, m.m02); VEC4_T v3(m.m13, m.m03, m.m03, m.m03); - VEC4_T i0(v1 * f0 - v2 * f1 + v3 * f2); - VEC4_T i1(v0 * f0 - v2 * f3 + v3 * f4); - VEC4_T i2(v0 * f1 - v1 * f3 + v3 * f5); - VEC4_T i3(v0 * f2 - v1 * f4 + v2 * f5); + VEC4_T signV(T(1), T(-1), T(1), T(-1)); + MAT4_T inv((v1 * f0 - v2 * f1 + v3 * f2) * signV, + (v0 * f0 - v2 * f3 + v3 * f4) * -signV, + (v0 * f1 - v1 * f3 + v3 * f5) * signV, + (v0 * f2 - v1 * f4 + v2 * f5) * -signV); - VEC4_T signA( 1, -1, 1, -1), signB(-1, 1, -1, 1); - MAT4_T inv(i0 * signA, i1 * signB, i2 * signA, i3 * signB); - VEC4_T v0r0(m.v0 * VEC4_T(inv.m00, inv.m10, inv.m20, inv.m30)); return inv * (T(1) / (v0r0.x + v0r0.y + v0r0.z + v0r0.w)); }// 1/determinant ==> "operator *" is faster // external operators @@ -591,6 +591,30 @@ TEMPLATE_TYPENAME_T inline const MAT4_T frustrum(T l, T r, T b, T t, T n, T f) using uvec2 = vgm::Vec2; using uvec3 = vgm::Vec3; using uvec4 = vgm::Vec4; + +#ifdef VGIZMO_USES_HLSL_TYPES // testing phase + using float2 = vgm::Vec2; + using float3 = vgm::Vec3; + using float4 = vgm::Vec4; + using quat = vgm::Quat; + using float3x3 = vgm::Mat3; + using float4x4 = vgm::Mat4; + + using double2 = vgm::Vec2; + using double3 = vgm::Vec3; + using double4 = vgm::Vec4; + using dquat = vgm::Quat; + using double3x3 = vgm::Mat3; + using double4x4 = vgm::Mat4; + + using int2 = vgm::Vec2; + using int3 = vgm::Vec3; + using int4 = vgm::Vec4; + + using uint2 = vgm::Vec2; + using uint3 = vgm::Vec3; + using uint4 = vgm::Vec4; +#endif #else using vec2 = vgm::Vec2; using vec3 = vgm::Vec3; @@ -600,8 +624,18 @@ TEMPLATE_TYPENAME_T inline const MAT4_T frustrum(T l, T r, T b, T t, T n, T f) using mat4 = vgm::Mat4; using mat3x3 = mat3; using mat4x4 = mat4; + +#ifdef VGIZMO_USES_HLSL_TYPES + using float2 = vgm::Vec2; + using float3 = vgm::Vec3; + using float4 = vgm::Vec4; + using quat = vgm::Quat; + using float3x3 = vgm::Mat3; + using float4x4 = vgm::Mat4; #endif +#endif +// Internal vGizmo USES ONLY using tVec2 = vgm::VEC2_PRECISION; using tVec3 = vgm::VEC3_PRECISION; using tVec4 = vgm::VEC4_PRECISION; @@ -609,8 +643,8 @@ TEMPLATE_TYPENAME_T inline const MAT4_T frustrum(T l, T r, T b, T t, T n, T f) using tMat3 = vgm::MAT3_PRECISION; using tMat4 = vgm::MAT4_PRECISION; - using uint8 = uint8_t; - using int8 = int8_t; + using uint8 = uint8_t; + using int8 = int8_t; using uint = uint32_t; using int32 = int32_t; using uint32 = uint32_t; diff --git a/virtualGizmo3D/vGizmo.h b/virtualGizmo3D/vGizmo.h index 64044de..611fd0f 100644 --- a/virtualGizmo3D/vGizmo.h +++ b/virtualGizmo3D/vGizmo.h @@ -476,6 +476,8 @@ using VGIZMO_BASE_CLASS::qtV; // Get Pan (xy) & Dolly (z) position ////////////////////////////////////////////////////////////////// tVec3 getPosition() const { return tVec3(pan.x, pan.y, dolly.z); } + void setPosition(const tVec3 &p) { pan.x = p.x; pan.y = p.y; dolly.z = p.z; } + private: // UI commands that this virtualGizmo responds to (defaults to left mouse button with no modifier key) vgButtons dollyControlButton, panControlButton; diff --git a/virtualGizmo3D/vGizmoConfig.h b/virtualGizmo3D/vGizmoConfig.h index dd4e3d9..9cd743e 100644 --- a/virtualGizmo3D/vGizmoConfig.h +++ b/virtualGizmo3D/vGizmoConfig.h @@ -45,6 +45,7 @@ // // Default ==> use vGizmoMath // If you enable GLM use, automatically is enabled also VGIZMO_USES_TEMPLATE +// if you can, I recommend to use GLM //------------------------------------------------------------------------------ //#define VGIZMO_USES_GLM diff --git a/virtualGizmo3D/vGizmoMath.h b/virtualGizmo3D/vGizmoMath.h index 9804df5..fd9b256 100644 --- a/virtualGizmo3D/vGizmoMath.h +++ b/virtualGizmo3D/vGizmoMath.h @@ -181,10 +181,12 @@ TEMPLATE_TYPENAME_T class Vec4 { }; Vec4() {} - Vec4(T s) : x(s), y(s), z(s), w(s) {} - Vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {} - Vec4(const VEC3_T& v, T s = T(0)) : x(v.x), y(v.y), z(v.z), w(s) {} + Vec4(T s) : x(s), y(s), z(s), w(s) {} + Vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {} + Vec4(const VEC3_T& v, T s = T(0)) : x(v.x), y(v.y), z(v.z), w(s) {} + Vec4(T s, const VEC3_T& v) : x(s), y(v.x), z(v.y), w(v.z) {} + //operator VEC3_T() const { return *((VEC3_T *) &x); } const Vec4 operator-() const { return Vec4(-x, -y, -z, -w); } Vec4& operator+=(const Vec4& v) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; } @@ -461,14 +463,12 @@ TEMPLATE_TYPENAME_T inline const MAT4_T inverse(MAT4_T const &m) { VEC4_T v2(m.m12, m.m02, m.m02, m.m02); VEC4_T v3(m.m13, m.m03, m.m03, m.m03); - VEC4_T i0(v1 * f0 - v2 * f1 + v3 * f2); - VEC4_T i1(v0 * f0 - v2 * f3 + v3 * f4); - VEC4_T i2(v0 * f1 - v1 * f3 + v3 * f5); - VEC4_T i3(v0 * f2 - v1 * f4 + v2 * f5); + VEC4_T signV(T(1), T(-1), T(1), T(-1)); + MAT4_T inv((v1 * f0 - v2 * f1 + v3 * f2) * signV, + (v0 * f0 - v2 * f3 + v3 * f4) * -signV, + (v0 * f1 - v1 * f3 + v3 * f5) * signV, + (v0 * f2 - v1 * f4 + v2 * f5) * -signV); - VEC4_T signA( 1, -1, 1, -1), signB(-1, 1, -1, 1); - MAT4_T inv(i0 * signA, i1 * signB, i2 * signA, i3 * signB); - VEC4_T v0r0(m.v0 * VEC4_T(inv.m00, inv.m10, inv.m20, inv.m30)); return inv * (T(1) / (v0r0.x + v0r0.y + v0r0.z + v0r0.w)); }// 1/determinant ==> "operator *" is faster // external operators @@ -591,6 +591,30 @@ TEMPLATE_TYPENAME_T inline const MAT4_T frustrum(T l, T r, T b, T t, T n, T f) using uvec2 = vgm::Vec2; using uvec3 = vgm::Vec3; using uvec4 = vgm::Vec4; + +#ifdef VGIZMO_USES_HLSL_TYPES // testing phase + using float2 = vgm::Vec2; + using float3 = vgm::Vec3; + using float4 = vgm::Vec4; + using quat = vgm::Quat; + using float3x3 = vgm::Mat3; + using float4x4 = vgm::Mat4; + + using double2 = vgm::Vec2; + using double3 = vgm::Vec3; + using double4 = vgm::Vec4; + using dquat = vgm::Quat; + using double3x3 = vgm::Mat3; + using double4x4 = vgm::Mat4; + + using int2 = vgm::Vec2; + using int3 = vgm::Vec3; + using int4 = vgm::Vec4; + + using uint2 = vgm::Vec2; + using uint3 = vgm::Vec3; + using uint4 = vgm::Vec4; +#endif #else using vec2 = vgm::Vec2; using vec3 = vgm::Vec3; @@ -600,8 +624,18 @@ TEMPLATE_TYPENAME_T inline const MAT4_T frustrum(T l, T r, T b, T t, T n, T f) using mat4 = vgm::Mat4; using mat3x3 = mat3; using mat4x4 = mat4; + +#ifdef VGIZMO_USES_HLSL_TYPES + using float2 = vgm::Vec2; + using float3 = vgm::Vec3; + using float4 = vgm::Vec4; + using quat = vgm::Quat; + using float3x3 = vgm::Mat3; + using float4x4 = vgm::Mat4; #endif +#endif +// Internal vGizmo USES ONLY using tVec2 = vgm::VEC2_PRECISION; using tVec3 = vgm::VEC3_PRECISION; using tVec4 = vgm::VEC4_PRECISION; @@ -609,8 +643,8 @@ TEMPLATE_TYPENAME_T inline const MAT4_T frustrum(T l, T r, T b, T t, T n, T f) using tMat3 = vgm::MAT3_PRECISION; using tMat4 = vgm::MAT4_PRECISION; - using uint8 = uint8_t; - using int8 = int8_t; + using uint8 = uint8_t; + using int8 = int8_t; using uint = uint32_t; using int32 = int32_t; using uint32 = uint32_t;