History

Improve pick/pointer debugging. Use unsigned int in Graphics api for compatibility

sabrina-shanman committed 7 years ago

Commit f7c324c1 parent 3108b6935 files · +406 −89Browse files

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

Unified · Split

interface/src/raypick/PickScriptingInterface.cpp+57−22
@@ -34,18 +34,35 @@ static const float WEB_TOUCH_Y_OFFSET = 0.105f; // how far forward (or back wit · 33 unmodified lines
34static const glm::vec3 TIP_OFFSET = glm::vec3(0.0f, StylusPick::WEB_STYLUS_LENGTH - WEB_TOUCH_Y_OFFSET, 0.0f);34static const glm::vec3 TIP_OFFSET = glm::vec3(0.0f, StylusPick::WEB_STYLUS_LENGTH - WEB_TOUCH_Y_OFFSET, 0.0f);
35 35
36unsigned int PickScriptingInterface::createPick(const PickQuery::PickType type, const QVariant& properties) {36unsigned int PickScriptingInterface::createPick(const PickQuery::PickType type, const QVariant& properties) {
37 std::shared_ptr<PickQuery> pick;
38 QVariantMap propMap = properties.toMap();
39
37 switch (type) {40 switch (type) {
38 case PickQuery::PickType::Ray:41 case PickQuery::PickType::Ray:
39 return createRayPick(properties);42 pick = buildRayPick(propMap);
43 break;
40 case PickQuery::PickType::Stylus:44 case PickQuery::PickType::Stylus:
41 return createStylusPick(properties);45 pick = buildStylusPick(propMap);
46 break;
42 case PickQuery::PickType::Parabola:47 case PickQuery::PickType::Parabola:
43 return createParabolaPick(properties);48 pick = buildParabolaPick(propMap);
49 break;
44 case PickQuery::PickType::Collision:50 case PickQuery::PickType::Collision:
45 return createCollisionPick(properties);51 pick = buildCollisionPick(propMap);
52 break;
46 default:53 default:
47 return PickManager::INVALID_PICK_ID;54 break;
55 }
56
57 if (!pick) {
58 return PickManager::INVALID_PICK_ID;
48 }59 }
60
61 propMap["type"] = (int)type;
62
63 pick->setScriptParameters(propMap);
64
65 return DependencyManager::get<PickManager>()->addPick(type, pick);
49}66}
50 67
51PickFilter getPickFilter(unsigned int filter) {68PickFilter getPickFilter(unsigned int filter) {
@@ -82,17 +99,18 @@ PickFilter getPickFilter(unsigned int filter) { · 30 unmodified lines
82 * @property {Vec3} [dirOffset] - Synonym for <code>direction</code>.99 * @property {Vec3} [dirOffset] - Synonym for <code>direction</code>.
83 * @property {Quat} [orientation] - Alternative property for specifying <code>direction</code>. The value is applied to the 100 * @property {Quat} [orientation] - Alternative property for specifying <code>direction</code>. The value is applied to the
84 * default <code>direction</code> value.101 * default <code>direction</code> value.
102 * @property {PickType} type - The type of pick when getting these properties from {@link Picks.getPickProperties}. A ray pick's type is {@link PickType.Ray}.
103 * @property {Vec3} baseScale - Returned from {@link Picks.getPickProperties} when the pick has a parent with varying scale (usually an avatar or an entity).
104 * Its value is the original scale of the parent at the moment the pick was created, and is used to scale the pointer which owns this pick, if any.
85 */105 */
86unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) {106std::shared_ptr<PickQuery> PickScriptingInterface::buildRayPick(const QVariantMap& propMap) {
87 QVariantMap propMap = properties.toMap();
88
89#if defined (Q_OS_ANDROID)107#if defined (Q_OS_ANDROID)
90 QString jointName { "" };108 QString jointName { "" };
91 if (propMap["joint"].isValid()) {109 if (propMap["joint"].isValid()) {
92 QString jointName = propMap["joint"].toString();110 QString jointName = propMap["joint"].toString();
93 const QString MOUSE_JOINT = "Mouse";111 const QString MOUSE_JOINT = "Mouse";
94 if (jointName == MOUSE_JOINT) {112 if (jointName == MOUSE_JOINT) {
95 return PointerEvent::INVALID_POINTER_ID;113 return nullptr;
96 }114 }
97 }115 }
98#endif116#endif
@@ -134,7 +152,7 @@ unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { · 35 unmodified lines
134 auto rayPick = std::make_shared<RayPick>(position, direction, filter, maxDistance, enabled);152 auto rayPick = std::make_shared<RayPick>(position, direction, filter, maxDistance, enabled);
135 setParentTransform(rayPick, propMap);153 setParentTransform(rayPick, propMap);
136 154
137 return DependencyManager::get<PickManager>()->addPick(PickQuery::Ray, rayPick);155 return rayPick;
138}156}
139 157
140/**jsdoc158/**jsdoc
@@ -152,10 +170,9 @@ unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { · 11 unmodified lines
152 * means no maximum.170 * means no maximum.
153 * @property {Vec3} [tipOffset=0,0.095,0] - The position of the stylus tip relative to the hand position at default avatar 171 * @property {Vec3} [tipOffset=0,0.095,0] - The position of the stylus tip relative to the hand position at default avatar
154 * scale.172 * scale.
173 * @property {PickType} type - The type of pick when getting these properties from {@link Picks.getPickProperties}. A stylus pick's type is {@link PickType.Stylus}.
155 */174 */
156unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties) {175std::shared_ptr<PickQuery> PickScriptingInterface::buildStylusPick(const QVariantMap& propMap) {
157 QVariantMap propMap = properties.toMap();
158
159 bilateral::Side side = bilateral::Side::Invalid;176 bilateral::Side side = bilateral::Side::Invalid;
160 {177 {
161 QVariant handVar = propMap["hand"];178 QVariant handVar = propMap["hand"];
@@ -184,7 +201,7 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties · 22 unmodified lines
184 tipOffset = vec3FromVariant(propMap["tipOffset"]);201 tipOffset = vec3FromVariant(propMap["tipOffset"]);
185 }202 }
186 203
187 return DependencyManager::get<PickManager>()->addPick(PickQuery::Stylus, std::make_shared<StylusPick>(side, filter, maxDistance, enabled, tipOffset));204 return std::make_shared<StylusPick>(side, filter, maxDistance, enabled, tipOffset);
188}205}
189 206
190// NOTE: Laser pointer still uses scaleWithAvatar. Until scaleWithAvatar is also deprecated for pointers, scaleWithAvatar should not be removed from the pick API.207// NOTE: Laser pointer still uses scaleWithAvatar. Until scaleWithAvatar is also deprecated for pointers, scaleWithAvatar should not be removed from the pick API.
@@ -228,10 +245,11 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties · 37 unmodified lines
228 * with the avatar or other parent.245 * with the avatar or other parent.
229 * @property {boolean} [scaleWithAvatar=true] - Synonym for <code>scalewithParent</code>.246 * @property {boolean} [scaleWithAvatar=true] - Synonym for <code>scalewithParent</code>.
230 * <p class="important">Deprecated: This property is deprecated and will be removed.</p>247 * <p class="important">Deprecated: This property is deprecated and will be removed.</p>
248 * @property {PickType} type - The type of pick when getting these properties from {@link Picks.getPickProperties}. A parabola pick's type is {@link PickType.Parabola}.
249 * @property {Vec3} baseScale - Returned from {@link Picks.getPickProperties} when the pick has a parent with varying scale (usually an avatar or an entity).
250 * Its value is the original scale of the parent at the moment the pick was created, and is used to rescale the pick, and/or the pointer which owns this pick, if any.
231 */251 */
232unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properties) {252std::shared_ptr<PickQuery> PickScriptingInterface::buildParabolaPick(const QVariantMap& propMap) {
233 QVariantMap propMap = properties.toMap();
234
235 bool enabled = false;253 bool enabled = false;
236 if (propMap["enabled"].isValid()) {254 if (propMap["enabled"].isValid()) {
237 enabled = propMap["enabled"].toBool();255 enabled = propMap["enabled"].toBool();
@@ -292,7 +310,7 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti · 54 unmodified lines
292 auto parabolaPick = std::make_shared<ParabolaPick>(position, direction, speed, accelerationAxis,310 auto parabolaPick = std::make_shared<ParabolaPick>(position, direction, speed, accelerationAxis,
293 rotateAccelerationWithAvatar, rotateAccelerationWithParent, scaleWithParent, filter, maxDistance, enabled);311 rotateAccelerationWithAvatar, rotateAccelerationWithParent, scaleWithParent, filter, maxDistance, enabled);
294 setParentTransform(parabolaPick, propMap);312 setParentTransform(parabolaPick, propMap);
295 return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, parabolaPick);313 return parabolaPick;
296}314}
297 315
298 316
@@ -326,10 +344,11 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti · 27 unmodified lines
326 * the collision region. The depth is in world coordinates but scales with the parent if defined.344 * the collision region. The depth is in world coordinates but scales with the parent if defined.
327 * @property {CollisionMask} [collisionGroup=8] - The type of objects the collision region collides as. Objects whose collision345 * @property {CollisionMask} [collisionGroup=8] - The type of objects the collision region collides as. Objects whose collision
328 * masks overlap with the region's collision group are considered to be colliding with the region.346 * masks overlap with the region's collision group are considered to be colliding with the region.
347 * @property {PickType} type - The type of pick when getting these properties from {@link Picks.getPickProperties}. A collision pick's type is {@link PickType.Collision}.
348 * @property {Vec3} baseScale - Returned from {@link Picks.getPickProperties} when the pick has a parent with varying scale (usually an avatar or an entity).
349 * Its value is the original scale of the parent at the moment the pick was created, and is used to rescale the pick, and/or the pointer which owns this pick, if any.
329 */350 */
330unsigned int PickScriptingInterface::createCollisionPick(const QVariant& properties) {351std::shared_ptr<PickQuery> PickScriptingInterface::buildCollisionPick(const QVariantMap& propMap) {
331 QVariantMap propMap = properties.toMap();
332
333 bool enabled = false;352 bool enabled = false;
334 if (propMap["enabled"].isValid()) {353 if (propMap["enabled"].isValid()) {
335 enabled = propMap["enabled"].toBool();354 enabled = propMap["enabled"].toBool();
@@ -354,7 +373,7 @@ unsigned int PickScriptingInterface::createCollisionPick(const QVariant& propert · 18 unmodified lines
354 auto collisionPick = std::make_shared<CollisionPick>(filter, maxDistance, enabled, scaleWithParent, collisionRegion, qApp->getPhysicsEngine());373 auto collisionPick = std::make_shared<CollisionPick>(filter, maxDistance, enabled, scaleWithParent, collisionRegion, qApp->getPhysicsEngine());
355 setParentTransform(collisionPick, propMap);374 setParentTransform(collisionPick, propMap);
356 375
357 return DependencyManager::get<PickManager>()->addPick(PickQuery::Collision, collisionPick);376 return collisionPick;
358}377}
359 378
360void PickScriptingInterface::enablePick(unsigned int uid) {379void PickScriptingInterface::enablePick(unsigned int uid) {
@@ -365,10 +384,26 @@ void PickScriptingInterface::disablePick(unsigned int uid) { · 4 unmodified lines
365 DependencyManager::get<PickManager>()->disablePick(uid);384 DependencyManager::get<PickManager>()->disablePick(uid);
366}385}
367 386
387bool PickScriptingInterface::isPickEnabled(unsigned int uid) const {
388 return DependencyManager::get<PickManager>()->isPickEnabled(uid);
389}
390
368void PickScriptingInterface::removePick(unsigned int uid) {391void PickScriptingInterface::removePick(unsigned int uid) {
369 DependencyManager::get<PickManager>()->removePick(uid);392 DependencyManager::get<PickManager>()->removePick(uid);
370}393}
371 394
395QVariantMap PickScriptingInterface::getPickProperties(unsigned int uid) const {
396 return DependencyManager::get<PickManager>()->getPickProperties(uid);
397}
398
399QVariantMap PickScriptingInterface::getPickScriptParameters(unsigned int uid) const {
400 return DependencyManager::get<PickManager>()->getPickScriptParameters(uid);
401}
402
403QVector<unsigned int> PickScriptingInterface::getCreatedPicks() const {
404 return DependencyManager::get<PickManager>()->getCreatedPicks();
405}
406
372QVariantMap PickScriptingInterface::getPrevPickResult(unsigned int uid) {407QVariantMap PickScriptingInterface::getPrevPickResult(unsigned int uid) {
373 QVariantMap result;408 QVariantMap result;
374 auto pickResult = DependencyManager::get<PickManager>()->getPrevPickResult(uid);409 auto pickResult = DependencyManager::get<PickManager>()->getPrevPickResult(uid);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t