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
3434 static const glm::vec3 TIP_OFFSET = glm::vec3(0.0f, StylusPick::WEB_STYLUS_LENGTH - WEB_TOUCH_Y_OFFSET, 0.0f);
3535
3636 unsigned int PickScriptingInterface::createPick(const PickQuery::PickType type, const QVariant& properties) {
37+ std::shared_ptr<PickQuery> pick;
38+ QVariantMap propMap = properties.toMap();
39+
3740 switch (type) {
3841 case PickQuery::PickType::Ray:
39− return createRayPick(properties);
42+ pick = buildRayPick(propMap);
43+ break;
4044 case PickQuery::PickType::Stylus:
41− return createStylusPick(properties);
45+ pick = buildStylusPick(propMap);
46+ break;
4247 case PickQuery::PickType::Parabola:
43− return createParabolaPick(properties);
48+ pick = buildParabolaPick(propMap);
49+ break;
4450 case PickQuery::PickType::Collision:
45− return createCollisionPick(properties);
51+ pick = buildCollisionPick(propMap);
52+ break;
4653 default:
47− return PickManager::INVALID_PICK_ID;
54+ break;
55+ }
56+
57+ if (!pick) {
58+ return PickManager::INVALID_PICK_ID;
4859 }
60+
61+ propMap["type"] = (int)type;
62+
63+ pick->setScriptParameters(propMap);
64+
65+ return DependencyManager::get<PickManager>()->addPick(type, pick);
4966 }
5067
5168 PickFilter getPickFilter(unsigned int filter) {
@@ -82,17 +99,18 @@ PickFilter getPickFilter(unsigned int filter) { · 30 unmodified lines
8299 * @property {Vec3} [dirOffset] - Synonym for <code>direction</code>.
83100 * @property {Quat} [orientation] - Alternative property for specifying <code>direction</code>. The value is applied to the
84101 * 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.
85105 */
86−unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) {
87− QVariantMap propMap = properties.toMap();
88−
106+std::shared_ptr<PickQuery> PickScriptingInterface::buildRayPick(const QVariantMap& propMap) {
89107 #if defined (Q_OS_ANDROID)
90108 QString jointName { "" };
91109 if (propMap["joint"].isValid()) {
92110 QString jointName = propMap["joint"].toString();
93111 const QString MOUSE_JOINT = "Mouse";
94112 if (jointName == MOUSE_JOINT) {
95− return PointerEvent::INVALID_POINTER_ID;
113+ return nullptr;
96114 }
97115 }
98116 #endif
@@ -134,7 +152,7 @@ unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { · 35 unmodified lines
134152 auto rayPick = std::make_shared<RayPick>(position, direction, filter, maxDistance, enabled);
135153 setParentTransform(rayPick, propMap);
136154
137− return DependencyManager::get<PickManager>()->addPick(PickQuery::Ray, rayPick);
155+ return rayPick;
138156 }
139157
140158 /**jsdoc
@@ -152,10 +170,9 @@ unsigned int PickScriptingInterface::createRayPick(const QVariant& properties) { · 11 unmodified lines
152170 * means no maximum.
153171 * @property {Vec3} [tipOffset=0,0.095,0] - The position of the stylus tip relative to the hand position at default avatar
154172 * 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}.
155174 */
156−unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties) {
157− QVariantMap propMap = properties.toMap();
158−
175+std::shared_ptr<PickQuery> PickScriptingInterface::buildStylusPick(const QVariantMap& propMap) {
159176 bilateral::Side side = bilateral::Side::Invalid;
160177 {
161178 QVariant handVar = propMap["hand"];
@@ -184,7 +201,7 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties · 22 unmodified lines
184201 tipOffset = vec3FromVariant(propMap["tipOffset"]);
185202 }
186203
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);
188205 }
189206
190207 // 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
228245 * with the avatar or other parent.
229246 * @property {boolean} [scaleWithAvatar=true] - Synonym for <code>scalewithParent</code>.
230247 * <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.
231251 */
232−unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properties) {
233− QVariantMap propMap = properties.toMap();
234−
252+std::shared_ptr<PickQuery> PickScriptingInterface::buildParabolaPick(const QVariantMap& propMap) {
235253 bool enabled = false;
236254 if (propMap["enabled"].isValid()) {
237255 enabled = propMap["enabled"].toBool();
@@ -292,7 +310,7 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti · 54 unmodified lines
292310 auto parabolaPick = std::make_shared<ParabolaPick>(position, direction, speed, accelerationAxis,
293311 rotateAccelerationWithAvatar, rotateAccelerationWithParent, scaleWithParent, filter, maxDistance, enabled);
294312 setParentTransform(parabolaPick, propMap);
295− return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, parabolaPick);
313+ return parabolaPick;
296314 }
297315
298316
@@ -326,10 +344,11 @@ unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properti · 27 unmodified lines
326344 * the collision region. The depth is in world coordinates but scales with the parent if defined.
327345 * @property {CollisionMask} [collisionGroup=8] - The type of objects the collision region collides as. Objects whose collision
328346 * 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.
329350 */
330−unsigned int PickScriptingInterface::createCollisionPick(const QVariant& properties) {
331− QVariantMap propMap = properties.toMap();
332−
351+std::shared_ptr<PickQuery> PickScriptingInterface::buildCollisionPick(const QVariantMap& propMap) {
333352 bool enabled = false;
334353 if (propMap["enabled"].isValid()) {
335354 enabled = propMap["enabled"].toBool();
@@ -354,7 +373,7 @@ unsigned int PickScriptingInterface::createCollisionPick(const QVariant& propert · 18 unmodified lines
354373 auto collisionPick = std::make_shared<CollisionPick>(filter, maxDistance, enabled, scaleWithParent, collisionRegion, qApp->getPhysicsEngine());
355374 setParentTransform(collisionPick, propMap);
356375
357− return DependencyManager::get<PickManager>()->addPick(PickQuery::Collision, collisionPick);
376+ return collisionPick;
358377 }
359378
360379 void PickScriptingInterface::enablePick(unsigned int uid) {
@@ -365,10 +384,26 @@ void PickScriptingInterface::disablePick(unsigned int uid) { · 4 unmodified lines
365384 DependencyManager::get<PickManager>()->disablePick(uid);
366385 }
367386
387+bool PickScriptingInterface::isPickEnabled(unsigned int uid) const {
388+ return DependencyManager::get<PickManager>()->isPickEnabled(uid);
389+}
390+
368391 void PickScriptingInterface::removePick(unsigned int uid) {
369392 DependencyManager::get<PickManager>()->removePick(uid);
370393 }
371394
395+QVariantMap PickScriptingInterface::getPickProperties(unsigned int uid) const {
396+ return DependencyManager::get<PickManager>()->getPickProperties(uid);
397+}
398+
399+QVariantMap PickScriptingInterface::getPickScriptParameters(unsigned int uid) const {
400+ return DependencyManager::get<PickManager>()->getPickScriptParameters(uid);
401+}
402+
403+QVector<unsigned int> PickScriptingInterface::getCreatedPicks() const {
404+ return DependencyManager::get<PickManager>()->getCreatedPicks();
405+}
406+
372407 QVariantMap PickScriptingInterface::getPrevPickResult(unsigned int uid) {
373408 QVariantMap result;
374409 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