From 73e6be9c3705bc53bd36ce584c4307b61b67dd5d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sat, 7 Sep 2019 18:03:58 -0700 Subject: [PATCH] allow drawing DebugDraw spheres with a specific size --- libraries/render-utils/src/AnimDebugDraw.cpp | 4 ++-- libraries/shared/src/DebugDraw.cpp | 12 +++++++----- libraries/shared/src/DebugDraw.h | 16 +++++++++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/libraries/render-utils/src/AnimDebugDraw.cpp b/libraries/render-utils/src/AnimDebugDraw.cpp index bf528ee5f0..c4020cb4c4 100644 --- a/libraries/render-utils/src/AnimDebugDraw.cpp +++ b/libraries/render-utils/src/AnimDebugDraw.cpp @@ -393,7 +393,7 @@ void AnimDebugDraw::update() { glm::quat rot = std::get<0>(iter.second); glm::vec3 pos = std::get<1>(iter.second); glm::vec4 color = std::get<2>(iter.second); - const float radius = POSE_RADIUS; + const float radius = std::get<3>(iter.second) * POSE_RADIUS; addBone(AnimPose::identity, AnimPose(glm::vec3(1), rot, pos), radius, color, v); } @@ -402,7 +402,7 @@ void AnimDebugDraw::update() { glm::quat rot = std::get<0>(iter.second); glm::vec3 pos = std::get<1>(iter.second); glm::vec4 color = std::get<2>(iter.second); - const float radius = POSE_RADIUS; + const float radius = std::get<3>(iter.second) * POSE_RADIUS; addBone(myAvatarPose, AnimPose(glm::vec3(1), rot, pos), radius, color, v); } diff --git a/libraries/shared/src/DebugDraw.cpp b/libraries/shared/src/DebugDraw.cpp index 1b2418f7c7..2539a43672 100644 --- a/libraries/shared/src/DebugDraw.cpp +++ b/libraries/shared/src/DebugDraw.cpp @@ -31,9 +31,10 @@ void DebugDraw::drawRay(const glm::vec3& start, const glm::vec3& end, const glm: _rays.push_back(Ray(start, end, color)); } -void DebugDraw::addMarker(const QString& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color) { +void DebugDraw::addMarker(const QString& key, const glm::quat& rotation, const glm::vec3& position, + const glm::vec4& color, float size) { Lock lock(_mapMutex); - _markers[key] = MarkerInfo(rotation, position, color); + _markers[key] = MarkerInfo(rotation, position, color, size); } void DebugDraw::removeMarker(const QString& key) { @@ -41,9 +42,10 @@ void DebugDraw::removeMarker(const QString& key) { _markers.erase(key); } -void DebugDraw::addMyAvatarMarker(const QString& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color) { +void DebugDraw::addMyAvatarMarker(const QString& key, const glm::quat& rotation, const glm::vec3& position, + const glm::vec4& color, float size) { Lock lock(_mapMutex); - _myAvatarMarkers[key] = MarkerInfo(rotation, position, color); + _myAvatarMarkers[key] = MarkerInfo(rotation, position, color, size); } void DebugDraw::removeMyAvatarMarker(const QString& key) { @@ -83,4 +85,4 @@ void DebugDraw::drawRays(const std::vector>& lin auto point2 = translation + rotation * line.second; _rays.push_back(Ray(point1, point2, color)); } -} \ No newline at end of file +} diff --git a/libraries/shared/src/DebugDraw.h b/libraries/shared/src/DebugDraw.h index 9e3140ca9b..9db48b759b 100644 --- a/libraries/shared/src/DebugDraw.h +++ b/libraries/shared/src/DebugDraw.h @@ -95,19 +95,22 @@ public: * @param {Quat} rotation - The orientation of the marker in world coordinates. * @param {Vec3} position - The position of the market in world coordinates. * @param {Vec4} color - The color of the marker. + * @param {float} size - A float between 0.0 and 1.0 (10 cm) to control the size of the marker. * @example Briefly draw a debug marker in front of your avatar, in world coordinates. * var MARKER_NAME = "my marker"; * DebugDraw.addMarker( * MARKER_NAME, * Quat.ZERO, * Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, { x: 0, y: 0, z: -5})), - * { red: 255, green: 0, blue: 0 } + * { red: 255, green: 0, blue: 0 }, + * 1.0 * ); * Script.setTimeout(function () { * DebugDraw.removeMarker(MARKER_NAME); * }, 5000); */ - Q_INVOKABLE void addMarker(const QString& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color); + Q_INVOKABLE void addMarker(const QString& key, const glm::quat& rotation, const glm::vec3& position, + const glm::vec4& color, float size = 1.0f); /**jsdoc * Removes a debug marker that was added in world coordinates. @@ -125,19 +128,22 @@ public: * @param {Quat} rotation - The orientation of the marker in avatar coordinates. * @param {Vec3} position - The position of the market in avatar coordinates. * @param {Vec4} color - color of the marker. + * @param {float} size - A float between 0.0 and 1.0 (10 cm) to control the size of the marker. * @example Briefly draw a debug marker in front of your avatar, in avatar coordinates. * var MARKER_NAME = "My avatar marker"; * DebugDraw.addMyAvatarMarker( * MARKER_NAME, * Quat.ZERO, * { x: 0, y: 0, z: -5 }, - * { red: 255, green: 0, blue: 0 } + * { red: 255, green: 0, blue: 0 }, + * 1.0 * ); * Script.setTimeout(function () { * DebugDraw.removeMyAvatarMarker(MARKER_NAME); * }, 5000); */ - Q_INVOKABLE void addMyAvatarMarker(const QString& key, const glm::quat& rotation, const glm::vec3& position, const glm::vec4& color); + Q_INVOKABLE void addMyAvatarMarker(const QString& key, const glm::quat& rotation, const glm::vec3& position, + const glm::vec4& color, float size = 1.0f); /**jsdoc * Removes a debug marker that was added in avatar coordinates. @@ -146,7 +152,7 @@ public: */ Q_INVOKABLE void removeMyAvatarMarker(const QString& key); - using MarkerInfo = std::tuple; + using MarkerInfo = std::tuple; using MarkerMap = std::map; using Ray = std::tuple; using Rays = std::vector;