History

Refactor new pick parenting system for use with RayPick, ParabolaPick

sabrina-shanman committed 8 years ago

Commit 237022d1 parent d2c41f025 files · +183 −462Browse files

Showing the changes to interface/src/raypick/PickScriptingInterface.cpp (1 of 25 files). Show all

Unified · Split

interface/src/raypick/PickScriptingInterface.cpp+93−80
@@ -14,13 +14,9 @@ · 13 unmodified lines
14#include "Application.h"14#include "Application.h"
15#include <PickManager.h>15#include <PickManager.h>
16 16
17#include "StaticRayPick.h"17#include "RayPick.h"
18#include "JointRayPick.h"
19#include "MouseRayPick.h"
20#include "StylusPick.h"18#include "StylusPick.h"
21#include "StaticParabolaPick.h"19#include "ParabolaPick.h"
22#include "JointParabolaPick.h"
23#include "MouseParabolaPick.h"
24#include "CollisionPick.h"20#include "CollisionPick.h"
25 21
26#include "SpatialParentFinder.h"22#include "SpatialParentFinder.h"
@@ -56,9 +52,9 @@ unsigned int PickScriptingInterface::createPick(const PickQuery::PickType type, · 29 unmodified lines
56 * @property {boolean} [enabled=false] If this Pick should start enabled or not. Disabled Picks do not updated their pick results.52 * @property {boolean} [enabled=false] If this Pick should start enabled or not. Disabled Picks do not updated their pick results.
57 * @property {number} [filter=Picks.PICK_NOTHING] The filter for this Pick to use, constructed using filter flags combined using bitwise OR.53 * @property {number} [filter=Picks.PICK_NOTHING] The filter for this Pick to use, constructed using filter flags combined using bitwise OR.
58 * @property {number} [maxDistance=0.0] The max distance at which this Pick will intersect. 0.0 = no max. < 0.0 is invalid.54 * @property {number} [maxDistance=0.0] The max distance at which this Pick will intersect. 0.0 = no max. < 0.0 is invalid.
59 * @property {string} [joint] Only for Joint or Mouse Ray Picks. If "Mouse", it will create a Ray Pick that follows the system mouse, in desktop or HMD.55 * @property {Uuid} parentID - The ID of the parent, either an avatar, an entity, or an overlay.
60 * If "Avatar", it will create a Joint Ray Pick that follows your avatar's head. Otherwise, it will create a Joint Ray Pick that follows the given joint, if it56 * @property {number} parentJointIndex - The joint of the parent to parent to, for example, the joints on the model of an avatar. (default = 0, no joint)
61 * exists on your current avatar.57 * @property {string} joint - If "Mouse," parents the pick to the mouse. If "Avatar," parents the pick to MyAvatar's head. Otherwise, parents to the joint of the given name on MyAvatar.
62 * @property {Vec3} [posOffset=Vec3.ZERO] Only for Joint Ray Picks. A local joint position offset, in meters. x = upward, y = forward, z = lateral58 * @property {Vec3} [posOffset=Vec3.ZERO] Only for Joint Ray Picks. A local joint position offset, in meters. x = upward, y = forward, z = lateral
63 * @property {Vec3} [dirOffset=Vec3.UP] Only for Joint Ray Picks. A local joint direction offset. x = upward, y = forward, z = lateral59 * @property {Vec3} [dirOffset=Vec3.UP] Only for Joint Ray Picks. A local joint direction offset. x = upward, y = forward, z = lateral
64 * @property {Vec3} [position] Only for Static Ray Picks. The world-space origin of the ray.60 * @property {Vec3} [position] Only for Static Ray Picks. The world-space origin of the ray.
@@ -82,38 +78,30 @@ unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { · 17 unmodified lines
82 maxDistance = propMap["maxDistance"].toFloat();78 maxDistance = propMap["maxDistance"].toFloat();
83 }79 }
84 80
85 if (propMap["joint"].isValid()) {81 glm::vec3 position = Vectors::ZERO;
86 std::string jointName = propMap["joint"].toString().toStdString();82 if (propMap["position"].isValid()) {
87 83 position = vec3FromVariant(propMap["position"]);
88 if (jointName != "Mouse") {84 } else if (propMap["posOffset"].isValid()) {
89 // x = upward, y = forward, z = lateral85 position = vec3FromVariant(propMap["posOffset"]);
90 glm::vec3 posOffset = Vectors::ZERO;86 }
91 if (propMap["posOffset"].isValid()) {
92 posOffset = vec3FromVariant(propMap["posOffset"]);
93 }
94
95 glm::vec3 dirOffset = Vectors::UP;
96 if (propMap["dirOffset"].isValid()) {
97 dirOffset = vec3FromVariant(propMap["dirOffset"]);
98 }
99
100 return DependencyManager::get<PickManager>()->addPick(PickQuery::Ray, std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled));
101
102 } else {
103 return DependencyManager::get<PickManager>()->addPick(PickQuery::Ray, std::make_shared<MouseRayPick>(filter, maxDistance, enabled));
104 }
105 } else if (propMap["position"].isValid()) {
106 glm::vec3 position = vec3FromVariant(propMap["position"]);
107
108 glm::vec3 direction = -Vectors::UP;
109 if (propMap["direction"].isValid()) {
110 direction = vec3FromVariant(propMap["direction"]);
111 }
112 87
113 return DependencyManager::get<PickManager>()->addPick(PickQuery::Ray, std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled));88 // direction has two defaults to ensure compatibility with older scripts
89 // Joint ray picks had default direction = Vec3.UP
90 // Static ray picks had default direction = -Vec3.UP
91 glm::vec3 direction = propMap["joint"].isValid() ? Vectors::UP : -Vectors::UP;
92 if (propMap["orientation"].isValid()) {
93 direction = quatFromVariant(propMap["orientation"]) * Vectors::UP;
94 } else if (propMap["direction"].isValid()) {
95 direction = vec3FromVariant(propMap["direction"]);
96 } else if (propMap["dirOffset"].isValid()) {
97 direction = vec3FromVariant(propMap["dirOffset"]);
114 }98 }
115 99
116 return PickManager::INVALID_PICK_ID;100 auto rayPick = std::make_shared<RayPick>(position, direction, filter, maxDistance, enabled);
101 rayPick->parentTransform = createTransformNode(propMap);
102 rayPick->setJointState(getPickJointState(propMap));
103
104 return DependencyManager::get<PickManager>()->addPick(PickQuery::Ray, rayPick);
117}105}
118 106
119/**jsdoc107/**jsdoc
@@ -153,23 +141,26 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties · 33 unmodified lines
153 return DependencyManager::get<PickManager>()->addPick(PickQuery::Stylus, std::make_shared<StylusPick>(side, filter, maxDistance, enabled));141 return DependencyManager::get<PickManager>()->addPick(PickQuery::Stylus, std::make_shared<StylusPick>(side, filter, maxDistance, enabled));
154}142}
155 143
144// NOTE: Laser pointer still uses scaleWithAvatar. Until scaleWithAvatar is also deprecated for pointers, scaleWithAvatar should not be removed from the pick API.
156/**jsdoc145/**jsdoc
157 * A set of properties that can be passed to {@link Picks.createPick} to create a new Parabola Pick.146 * A set of properties that can be passed to {@link Picks.createPick} to create a new Parabola Pick.
158 * @typedef {object} Picks.ParabolaPickProperties147 * @typedef {object} Picks.ParabolaPickProperties
159 * @property {boolean} [enabled=false] If this Pick should start enabled or not. Disabled Picks do not updated their pick results.148 * @property {boolean} [enabled=false] If this Pick should start enabled or not. Disabled Picks do not updated their pick results.
160 * @property {number} [filter=Picks.PICK_NOTHING] The filter for this Pick to use, constructed using filter flags combined using bitwise OR.149 * @property {number} [filter=Picks.PICK_NOTHING] The filter for this Pick to use, constructed using filter flags combined using bitwise OR.
161 * @property {number} [maxDistance=0.0] The max distance at which this Pick will intersect. 0.0 = no max. < 0.0 is invalid.150 * @property {number} [maxDistance=0.0] The max distance at which this Pick will intersect. 0.0 = no max. < 0.0 is invalid.
162 * @property {string} [joint] Only for Joint or Mouse Parabola Picks. If "Mouse", it will create a Parabola Pick that follows the system mouse, in desktop or HMD.151 * @property {Uuid} parentID - The ID of the parent, either an avatar, an entity, or an overlay.
163 * If "Avatar", it will create a Joint Parabola Pick that follows your avatar's head. Otherwise, it will create a Joint Parabola Pick that follows the given joint, if it152 * @property {number} parentJointIndex - The joint of the parent to parent to, for example, the joints on the model of an avatar. (default = 0, no joint)
164 * exists on your current avatar.153 * @property {string} joint - If "Mouse," parents the pick to the mouse. If "Avatar," parents the pick to MyAvatar's head. Otherwise, parents to the joint of the given name on MyAvatar.
165 * @property {Vec3} [posOffset=Vec3.ZERO] Only for Joint Parabola Picks. A local joint position offset, in meters. x = upward, y = forward, z = lateral154 * @property {Vec3} [posOffset=Vec3.ZERO] Only for Joint Parabola Picks. A local joint position offset, in meters. x = upward, y = forward, z = lateral
166 * @property {Vec3} [dirOffset=Vec3.UP] Only for Joint Parabola Picks. A local joint direction offset. x = upward, y = forward, z = lateral155 * @property {Vec3} [dirOffset=Vec3.UP] Only for Joint Parabola Picks. A local joint direction offset. x = upward, y = forward, z = lateral
167 * @property {Vec3} [position] Only for Static Parabola Picks. The world-space origin of the parabola segment.156 * @property {Vec3} [position] Only for Static Parabola Picks. The world-space origin of the parabola segment.
168 * @property {Vec3} [direction=-Vec3.FRONT] Only for Static Parabola Picks. The world-space direction of the parabola segment.157 * @property {Vec3} [direction=-Vec3.FRONT] Only for Static Parabola Picks. The world-space direction of the parabola segment.
169 * @property {number} [speed=1] The initial speed of the parabola, i.e. the initial speed of the projectile whose trajectory defines the parabola.158 * @property {number} [speed=1] The initial speed of the parabola, i.e. the initial speed of the projectile whose trajectory defines the parabola.
170 * @property {Vec3} [accelerationAxis=-Vec3.UP] The acceleration of the parabola, i.e. the acceleration of the projectile whose trajectory defines the parabola, both magnitude and direction.159 * @property {Vec3} [accelerationAxis=-Vec3.UP] The acceleration of the parabola, i.e. the acceleration of the projectile whose trajectory defines the parabola, both magnitude and direction.
171 * @property {boolean} [rotateAccelerationWithAvatar=true] Whether or not the acceleration axis should rotate with your avatar's local Y axis.160 * @property {boolean} [rotateAccelerationWithAvatar=true] Whether or not the acceleration axis should rotate with the avatar's local Y axis.
172 * @property {boolean} [scaleWithAvatar=false] If true, the velocity and acceleration of the Pick will scale linearly with your avatar.161 * @property {boolean} [rotateAccelerationWithParent=false] Whether or not the acceleration axis should rotate with the parent's local Y axis, if available.
162 * @property {boolean} [scaleWithParent=false] If true, the velocity and acceleration of the Pick will scale linearly with the parent, if available.
163 * @property {boolean} [scaleWithAvatar] Alias for scaleWithParent. <em>Deprecated.</em>
173 */164 */
174unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properties) {165unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properties) {
175 QVariantMap propMap = properties.toMap();166 QVariantMap propMap = properties.toMap();
@@ -204,48 +195,38 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti · 28 unmodified lines
204 rotateAccelerationWithAvatar = propMap["rotateAccelerationWithAvatar"].toBool();195 rotateAccelerationWithAvatar = propMap["rotateAccelerationWithAvatar"].toBool();
205 }196 }
206 197
207 bool scaleWithAvatar = false;198 bool rotateAccelerationWithParent = false;
208 if (propMap["scaleWithAvatar"].isValid()) {199 if (propMap["rotateAccelerationWithParent"].isValid()) {
209 scaleWithAvatar = propMap["scaleWithAvatar"].toBool();200 rotateAccelerationWithParent = propMap["rotateAccelerationWithParent"].toBool();
210 }201 }
211 202
212 if (propMap["joint"].isValid()) {203 bool scaleWithParent = false;
213 std::string jointName = propMap["joint"].toString().toStdString();204 if (propMap["scaleWithParent"].isValid()) {
214 205 scaleWithParent = propMap["scaleWithParent"].toBool();
215 if (jointName != "Mouse") {206 } else if (propMap["scaleWithAvatar"].isValid()) {
216 // x = upward, y = forward, z = lateral207 scaleWithParent = propMap["scaleWithAvatar"].toBool();
217 glm::vec3 posOffset = Vectors::ZERO;208 }
218 if (propMap["posOffset"].isValid()) {
219 posOffset = vec3FromVariant(propMap["posOffset"]);
220 }
221
222 glm::vec3 dirOffset = Vectors::UP;
223 if (propMap["dirOffset"].isValid()) {
224 dirOffset = vec3FromVariant(propMap["dirOffset"]);
225 }
226
227 return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, std::make_shared<JointParabolaPick>(jointName, posOffset, dirOffset,
228 speed, accelerationAxis, rotateAccelerationWithAvatar,
229 scaleWithAvatar, filter, maxDistance, enabled));
230
231 } else {
232 return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, std::make_shared<MouseParabolaPick>(speed, accelerationAxis, rotateAccelerationWithAvatar,
233 scaleWithAvatar, filter, maxDistance, enabled));
234 }
235 } else if (propMap["position"].isValid()) {
236 glm::vec3 position = vec3FromVariant(propMap["position"]);
237
238 glm::vec3 direction = -Vectors::FRONT;
239 if (propMap["direction"].isValid()) {
240 direction = vec3FromVariant(propMap["direction"]);
241 }
242 209
243 return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, std::make_shared<StaticParabolaPick>(position, direction, speed, accelerationAxis,210 glm::vec3 position = glm::vec3();
244 rotateAccelerationWithAvatar, scaleWithAvatar,211 glm::vec3 direction = -Vectors::FRONT;
245 filter, maxDistance, enabled));212 if (propMap["position"].isValid()) {
213 position = vec3FromVariant(propMap["position"]);
214 } else if (propMap["posOffset"].isValid()) {
215 position = vec3FromVariant(propMap["posOffset"]);
216 }
217 if (propMap["orientation"].isValid()) {
218 direction = quatFromVariant(propMap["orientation"]) * Vectors::UP;
219 } else if (propMap["direction"].isValid()) {
220 direction = vec3FromVariant(propMap["direction"]);
221 } else if (propMap["dirOffset"].isValid()) {
222 direction = vec3FromVariant(propMap["dirOffset"]);
246 }223 }
247 224
248 return PickManager::INVALID_PICK_ID;225 auto parabolaPick = std::make_shared<ParabolaPick>(position, direction, speed, accelerationAxis,
226 rotateAccelerationWithAvatar, rotateAccelerationWithParent, scaleWithParent, filter, maxDistance, enabled);
227 parabolaPick->parentTransform = createTransformNode(propMap);
228 parabolaPick->setJointState(getPickJointState(propMap));
229 return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, parabolaPick);
249}230}
250 231
251/**jsdoc232/**jsdoc
@@ -297,6 +278,7 @@ unsigned int PickScriptingInterface::createCollisionPick(const QVariant& propert · 45 unmodified lines
297 CollisionRegion collisionRegion(propMap);278 CollisionRegion collisionRegion(propMap);
298 auto collisionPick = std::make_shared<CollisionPick>(filter, maxDistance, enabled, collisionRegion, qApp->getPhysicsEngine());279 auto collisionPick = std::make_shared<CollisionPick>(filter, maxDistance, enabled, collisionRegion, qApp->getPhysicsEngine());
299 collisionPick->parentTransform = createTransformNode(propMap);280 collisionPick->parentTransform = createTransformNode(propMap);
281 collisionPick->setJointState(getPickJointState(propMap));
300 282
301 return DependencyManager::get<PickManager>()->addPick(PickQuery::Collision, collisionPick);283 return DependencyManager::get<PickManager>()->addPick(PickQuery::Collision, collisionPick);
302}284}
@@ -373,6 +355,37 @@ void PickScriptingInterface::setPerFrameTimeBudget(unsigned int numUsecs) { · 70 unmodified lines
373 DependencyManager::get<PickManager>()->setPerFrameTimeBudget(numUsecs);355 DependencyManager::get<PickManager>()->setPerFrameTimeBudget(numUsecs);
374}356}
375 357
358PickQuery::JointState PickScriptingInterface::getPickJointState(const QVariantMap& propMap) {
359 if (propMap["parentID"].isValid()) {
360 QUuid parentUuid = propMap["parentID"].toUuid();
361 if (propMap["parentJointIndex"].isValid() && parentUuid == DependencyManager::get<AvatarManager>()->getMyAvatar()->getSessionUUID()) {
362 int jointIndex = propMap["parentJointIndes"].toInt();
363 if (jointIndex == CONTROLLER_LEFTHAND_INDEX || jointIndex == CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX) {
364 return PickQuery::JOINT_STATE_LEFT_HAND;
365 } else if (jointIndex == CONTROLLER_RIGHTHAND_INDEX || jointIndex == CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX) {
366 return PickQuery::JOINT_STATE_RIGHT_HAND;
367 } else {
368 return PickQuery::JOINT_STATE_NONE;
369 }
370 } else {
371 return PickQuery::JOINT_STATE_NONE;
372 }
373 } else if (propMap["joint"].isValid()) {
374 QString joint = propMap["joint"].toString();
375 if (joint == "Mouse") {
376 return PickQuery::JOINT_STATE_MOUSE;
377 } else if (joint == "_CONTROLLER_LEFTHAND" || joint == "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND") {
378 return PickQuery::JOINT_STATE_LEFT_HAND;
379 } else if (joint== "_CONTROLLER_RIGHTHAND" || joint == "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND") {
380 return PickQuery::JOINT_STATE_RIGHT_HAND;
381 } else {
382 return PickQuery::JOINT_STATE_NONE;
383 }
384 } else {
385 return PickQuery::JOINT_STATE_NONE;
386 }
387}
388
376std::shared_ptr<TransformNode> PickScriptingInterface::createTransformNode(const QVariantMap& propMap) {389std::shared_ptr<TransformNode> PickScriptingInterface::createTransformNode(const QVariantMap& propMap) {
377 if (propMap["parentID"].isValid()) {390 if (propMap["parentID"].isValid()) {
378 QUuid parentUuid = propMap["parentID"].toUuid();391 QUuid parentUuid = propMap["parentID"].toUuid();