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
1414 #include "Application.h"
1515 #include <PickManager.h>
1616
17−#include "StaticRayPick.h"
18−#include "JointRayPick.h"
19−#include "MouseRayPick.h"
17+#include "RayPick.h"
2018 #include "StylusPick.h"
21−#include "StaticParabolaPick.h"
22−#include "JointParabolaPick.h"
23−#include "MouseParabolaPick.h"
19+#include "ParabolaPick.h"
2420 #include "CollisionPick.h"
2521
2622 #include "SpatialParentFinder.h"
@@ -56,9 +52,9 @@ unsigned int PickScriptingInterface::createPick(const PickQuery::PickType type, · 29 unmodified lines
5652 * @property {boolean} [enabled=false] If this Pick should start enabled or not. Disabled Picks do not updated their pick results.
5753 * @property {number} [filter=Picks.PICK_NOTHING] The filter for this Pick to use, constructed using filter flags combined using bitwise OR.
5854 * @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.
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 it
61− * exists on your current avatar.
55+ * @property {Uuid} parentID - The ID of the parent, either an avatar, an entity, or an overlay.
56+ * @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)
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.
6258 * @property {Vec3} [posOffset=Vec3.ZERO] Only for Joint Ray Picks. A local joint position offset, in meters. x = upward, y = forward, z = lateral
6359 * @property {Vec3} [dirOffset=Vec3.UP] Only for Joint Ray Picks. A local joint direction offset. x = upward, y = forward, z = lateral
6460 * @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
8278 maxDistance = propMap["maxDistance"].toFloat();
8379 }
8480
85− if (propMap["joint"].isValid()) {
86− std::string jointName = propMap["joint"].toString().toStdString();
87−
88− if (jointName != "Mouse") {
89− // x = upward, y = forward, z = lateral
90− glm::vec3 posOffset = Vectors::ZERO;
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− }
81+ glm::vec3 position = Vectors::ZERO;
82+ if (propMap["position"].isValid()) {
83+ position = vec3FromVariant(propMap["position"]);
84+ } else if (propMap["posOffset"].isValid()) {
85+ position = vec3FromVariant(propMap["posOffset"]);
86+ }
11287
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"]);
11498 }
11599
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);
117105 }
118106
119107 /**jsdoc
@@ -153,23 +141,26 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties · 33 unmodified lines
153141 return DependencyManager::get<PickManager>()->addPick(PickQuery::Stylus, std::make_shared<StylusPick>(side, filter, maxDistance, enabled));
154142 }
155143
144+// NOTE: Laser pointer still uses scaleWithAvatar. Until scaleWithAvatar is also deprecated for pointers, scaleWithAvatar should not be removed from the pick API.
156145 /**jsdoc
157146 * A set of properties that can be passed to {@link Picks.createPick} to create a new Parabola Pick.
158147 * @typedef {object} Picks.ParabolaPickProperties
159148 * @property {boolean} [enabled=false] If this Pick should start enabled or not. Disabled Picks do not updated their pick results.
160149 * @property {number} [filter=Picks.PICK_NOTHING] The filter for this Pick to use, constructed using filter flags combined using bitwise OR.
161150 * @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.
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 it
164− * exists on your current avatar.
151+ * @property {Uuid} parentID - The ID of the parent, either an avatar, an entity, or an overlay.
152+ * @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)
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.
165154 * @property {Vec3} [posOffset=Vec3.ZERO] Only for Joint Parabola Picks. A local joint position offset, in meters. x = upward, y = forward, z = lateral
166155 * @property {Vec3} [dirOffset=Vec3.UP] Only for Joint Parabola Picks. A local joint direction offset. x = upward, y = forward, z = lateral
167156 * @property {Vec3} [position] Only for Static Parabola Picks. The world-space origin of the parabola segment.
168157 * @property {Vec3} [direction=-Vec3.FRONT] Only for Static Parabola Picks. The world-space direction of the parabola segment.
169158 * @property {number} [speed=1] The initial speed of the parabola, i.e. the initial speed of the projectile whose trajectory defines the parabola.
170159 * @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.
172− * @property {boolean} [scaleWithAvatar=false] If true, the velocity and acceleration of the Pick will scale linearly with your avatar.
160+ * @property {boolean} [rotateAccelerationWithAvatar=true] Whether or not the acceleration axis should rotate with the avatar's local Y axis.
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>
173164 */
174165 unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properties) {
175166 QVariantMap propMap = properties.toMap();
@@ -204,48 +195,38 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti · 28 unmodified lines
204195 rotateAccelerationWithAvatar = propMap["rotateAccelerationWithAvatar"].toBool();
205196 }
206197
207− bool scaleWithAvatar = false;
208− if (propMap["scaleWithAvatar"].isValid()) {
209− scaleWithAvatar = propMap["scaleWithAvatar"].toBool();
198+ bool rotateAccelerationWithParent = false;
199+ if (propMap["rotateAccelerationWithParent"].isValid()) {
200+ rotateAccelerationWithParent = propMap["rotateAccelerationWithParent"].toBool();
210201 }
211202
212− if (propMap["joint"].isValid()) {
213− std::string jointName = propMap["joint"].toString().toStdString();
214−
215− if (jointName != "Mouse") {
216− // x = upward, y = forward, z = lateral
217− glm::vec3 posOffset = Vectors::ZERO;
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− }
203+ bool scaleWithParent = false;
204+ if (propMap["scaleWithParent"].isValid()) {
205+ scaleWithParent = propMap["scaleWithParent"].toBool();
206+ } else if (propMap["scaleWithAvatar"].isValid()) {
207+ scaleWithParent = propMap["scaleWithAvatar"].toBool();
208+ }
242209
243− return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, std::make_shared<StaticParabolaPick>(position, direction, speed, accelerationAxis,
244− rotateAccelerationWithAvatar, scaleWithAvatar,
245− filter, maxDistance, enabled));
210+ glm::vec3 position = glm::vec3();
211+ glm::vec3 direction = -Vectors::FRONT;
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"]);
246223 }
247224
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);
249230 }
250231
251232 /**jsdoc
@@ -297,6 +278,7 @@ unsigned int PickScriptingInterface::createCollisionPick(const QVariant& propert · 45 unmodified lines
297278 CollisionRegion collisionRegion(propMap);
298279 auto collisionPick = std::make_shared<CollisionPick>(filter, maxDistance, enabled, collisionRegion, qApp->getPhysicsEngine());
299280 collisionPick->parentTransform = createTransformNode(propMap);
281+ collisionPick->setJointState(getPickJointState(propMap));
300282
301283 return DependencyManager::get<PickManager>()->addPick(PickQuery::Collision, collisionPick);
302284 }
@@ -373,6 +355,37 @@ void PickScriptingInterface::setPerFrameTimeBudget(unsigned int numUsecs) { · 70 unmodified lines
373355 DependencyManager::get<PickManager>()->setPerFrameTimeBudget(numUsecs);
374356 }
375357
358+PickQuery::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+
376389 std::shared_ptr<TransformNode> PickScriptingInterface::createTransformNode(const QVariantMap& propMap) {
377390 if (propMap["parentID"].isValid()) {
378391 QUuid parentUuid = propMap["parentID"].toUuid();