History

refactoring common path pointer functionality

SamGondelman committed 8 years ago

Commit 86c56191 parent 845ddda6 files · +713 −408Browse files

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

Unified · Split

interface/src/raypick/PointerScriptingInterface.cpp+154−19
@@ -37,6 +37,8 @@ unsigned int PointerScriptingInterface::createPointer(const PickQuery::PickType& · 36 unmodified lines
3737 return createLaserPointer(properties);
3838 case PickQuery::PickType::Stylus:
3939 return createStylus(properties);
40+ case PickQuery::PickType::Parabola:
41+ return createParabolaPointer(properties);
4042 default:
4143 return PointerEvent::INVALID_POINTER_ID;
4244 }
@@ -84,27 +86,20 @@ unsigned int PointerScriptingInterface::createStylus(const QVariant& properties) · 41 unmodified lines
8486 * @property {Overlays.OverlayProperties} [end] All of the properties you would normally pass to {@link Overlays.addOverlay}, plus the type (as a <code>type</code> field).
8587 * An overlay to represent the end of the Ray Pointer, if desired.
8688 */
87−/**jsdoc
88− * A trigger mechanism for Ray Pointers.
89− *
90− * @typedef {object} Pointers.Trigger
91− * @property {Controller.Standard|Controller.Actions|function} action This can be a built-in Controller action, like Controller.Standard.LTClick, or a function that evaluates to >= 1.0 when you want to trigger <code>button</code>.
92− * @property {string} button Which button to trigger. "Primary", "Secondary", "Tertiary", and "Focus" are currently supported. Only "Primary" will trigger clicks on web surfaces. If "Focus" is triggered,
93− * it will try to set the entity or overlay focus to the object at which the Pointer is aimed. Buttons besides the first three will still trigger events, but event.button will be "None".
94− */
9589 /**jsdoc
9690 * A set of properties that can be passed to {@link Pointers.createPointer} to create a new Pointer. Contains the relevant {@link Picks.PickProperties} to define the underlying Pick.
9791 * @typedef {object} Pointers.LaserPointerProperties
98− * @property {boolean} [faceAvatar=false] Ray Pointers only. If true, the end of the Pointer will always rotate to face the avatar.
99− * @property {boolean} [centerEndY=true] Ray Pointers only. If false, the end of the Pointer will be moved up by half of its height.
100− * @property {boolean} [lockEnd=false] Ray Pointers only. If true, the end of the Pointer will lock on to the center of the object at which the laser is pointing.
101− * @property {boolean} [distanceScaleEnd=false] Ray Pointers only. If true, the dimensions of the end of the Pointer will scale linearly with distance.
102− * @property {boolean} [scaleWithAvatar=false] Ray Pointers only. If true, the width of the Pointer's path will scale linearly with your avatar's scale.
92+ * @property {boolean} [faceAvatar=false] If true, the end of the Pointer will always rotate to face the avatar.
93+ * @property {boolean} [centerEndY=true] If false, the end of the Pointer will be moved up by half of its height.
94+ * @property {boolean} [lockEnd=false] If true, the end of the Pointer will lock on to the center of the object at which the laser is pointing.
95+ * @property {boolean} [distanceScaleEnd=false] If true, the dimensions of the end of the Pointer will scale linearly with distance.
96+ * @property {boolean} [scaleWithAvatar=false] If true, the width of the Pointer's path will scale linearly with your avatar's scale.
97+ * @property {boolean} [followNormal=false] If true, the end of the Pointer will rotate to follow the normal of the intersected surface.
10398 * @property {boolean} [enabled=false]
104− * @property {Pointers.RayPointerRenderState[]} [renderStates] Ray Pointers only. A list of different visual states to switch between.
105− * @property {Pointers.DefaultRayPointerRenderState[]} [defaultRenderStates] Ray Pointers only. A list of different visual states to use if there is no intersection.
99+ * @property {Pointers.RayPointerRenderState[]} [renderStates] A list of different visual states to switch between.
100+ * @property {Pointers.DefaultRayPointerRenderState[]} [defaultRenderStates] A list of different visual states to use if there is no intersection.
106101 * @property {boolean} [hover=false] If this Pointer should generate hover events.
107− * @property {Pointers.Trigger[]} [triggers] Ray Pointers only. A list of different triggers mechanisms that control this Pointer's click event generation.
102+ * @property {Pointers.Trigger[]} [triggers] A list of different triggers mechanisms that control this Pointer's click event generation.
108103 */
109104 unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& properties) const {
110105 QVariantMap propertyMap = properties.toMap();
@@ -144,7 +139,7 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope · 33 unmodified lines
144139 enabled = propertyMap["enabled"].toBool();
145140 }
146141
147− LaserPointer::RenderStateMap renderStates;
142+ RenderStateMap renderStates;
148143 if (propertyMap["renderStates"].isValid()) {
149144 QList<QVariant> renderStateVariants = propertyMap["renderStates"].toList();
150145 for (const QVariant& renderStateVariant : renderStateVariants) {
@@ -158,7 +153,7 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope · 7 unmodified lines
158153 }
159154 }
160155
161− LaserPointer::DefaultRenderStateMap defaultRenderStates;
156+ DefaultRenderStateMap defaultRenderStates;
162157 if (propertyMap["defaultRenderStates"].isValid()) {
163158 QList<QVariant> renderStateVariants = propertyMap["defaultRenderStates"].toList();
164159 for (const QVariant& renderStateVariant : renderStateVariants) {
@@ -167,7 +162,7 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope · 2 unmodified lines
167162 if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) {
168163 std::string name = renderStateMap["name"].toString().toStdString();
169164 float distance = renderStateMap["distance"].toFloat();
170− defaultRenderStates[name] = std::pair<float, RenderState>(distance, LaserPointer::buildRenderState(renderStateMap));
165+ defaultRenderStates[name] = std::pair<float, std::shared_ptr<StartEndRenderState>>(distance, LaserPointer::buildRenderState(renderStateMap));
171166 }
172167 }
173168 }
@@ -201,6 +196,146 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope · 27 unmodified lines
201196 scaleWithAvatar, enabled));
202197 }
203198
199+/**jsdoc
200+* The rendering properties of the parabolic path
201+*
202+* @typedef {object} Pointers.ParabolaProperties
203+* @property {Color} color The color of the parabola.
204+* @property {number} alpha The alpha of the parabola.
205+* @property {number} width The width of the parabola, in meters.
206+*/
207+/**jsdoc
208+* A set of properties used to define the visual aspect of a Parabola Pointer in the case that the Pointer is not intersecting something. Same as a {@link Pointers.ParabolaPointerRenderState},
209+* but with an additional distance field.
210+*
211+* @typedef {object} Pointers.DefaultParabolaPointerRenderState
212+* @augments Pointers.ParabolaPointerRenderState
213+* @property {number} distance The distance along the parabola at which to render the end of this Parabola Pointer, if one is defined.
214+*/
215+/**jsdoc
216+* A set of properties used to define the visual aspect of a Parabola Pointer in the case that the Pointer is intersecting something.
217+*
218+* @typedef {object} Pointers.ParabolaPointerRenderState
219+* @property {string} name The name of this render state, used by {@link Pointers.setRenderState} and {@link Pointers.editRenderState}
220+* @property {Overlays.OverlayProperties} [start] All of the properties you would normally pass to {@link Overlays.addOverlay}, plus the type (as a <code>type</code> field).
221+* An overlay to represent the beginning of the Parabola Pointer, if desired.
222+* @property {Pointers.ParabolaProperties} [path] The rendering properties of the parabolic path defined by the Parabola Pointer.
223+* @property {Overlays.OverlayProperties} [end] All of the properties you would normally pass to {@link Overlays.addOverlay}, plus the type (as a <code>type</code> field).
224+* An overlay to represent the end of the Parabola Pointer, if desired.
225+*/
226+/**jsdoc
227+* A set of properties that can be passed to {@link Pointers.createPointer} to create a new Pointer. Contains the relevant {@link Picks.PickProperties} to define the underlying Pick.
228+* @typedef {object} Pointers.LaserPointerProperties
229+* @property {boolean} [faceAvatar=false] If true, the end of the Pointer will always rotate to face the avatar.
230+* @property {boolean} [centerEndY=true] If false, the end of the Pointer will be moved up by half of its height.
231+* @property {boolean} [lockEnd=false] If true, the end of the Pointer will lock on to the center of the object at which the laser is pointing.
232+* @property {boolean} [distanceScaleEnd=false] If true, the dimensions of the end of the Pointer will scale linearly with distance.
233+* @property {boolean} [scaleWithAvatar=false] If true, the width of the Pointer's path will scale linearly with your avatar's scale.
234+* @property {boolean} [followNormal=false] If true, the end of the Pointer will rotate to follow the normal of the intersected surface.
235+* @property {boolean} [enabled=false]
236+* @property {Pointers.ParabolaPointerRenderState[]} [renderStates] A list of different visual states to switch between.
237+* @property {Pointers.DefaultParabolaPointerRenderState[]} [defaultRenderStates] A list of different visual states to use if there is no intersection.
238+* @property {boolean} [hover=false] If this Pointer should generate hover events.
239+* @property {Pointers.Trigger[]} [triggers] A list of different triggers mechanisms that control this Pointer's click event generation.
240+*/
241+unsigned int PointerScriptingInterface::createParabolaPointer(const QVariant& properties) const {
242+ return 0;
243+#if 0
244+ QVariantMap propertyMap = properties.toMap();
245+
246+ bool faceAvatar = false;
247+ if (propertyMap["faceAvatar"].isValid()) {
248+ faceAvatar = propertyMap["faceAvatar"].toBool();
249+ }
250+
251+ bool centerEndY = true;
252+ if (propertyMap["centerEndY"].isValid()) {
253+ centerEndY = propertyMap["centerEndY"].toBool();
254+ }
255+
256+ bool lockEnd = false;
257+ if (propertyMap["lockEnd"].isValid()) {
258+ lockEnd = propertyMap["lockEnd"].toBool();
259+ }
260+
261+ bool distanceScaleEnd = false;
262+ if (propertyMap["distanceScaleEnd"].isValid()) {
263+ distanceScaleEnd = propertyMap["distanceScaleEnd"].toBool();
264+ }
265+
266+ bool scaleWithAvatar = false;
267+ if (propertyMap["scaleWithAvatar"].isValid()) {
268+ scaleWithAvatar = propertyMap["scaleWithAvatar"].toBool();
269+ }
270+
271+ bool followNormal = true;
272+ if (propertyMap["followNormal"].isValid()) {
273+ followNormal = propertyMap["followNormal"].toBool();
274+ }
275+
276+ bool enabled = false;
277+ if (propertyMap["enabled"].isValid()) {
278+ enabled = propertyMap["enabled"].toBool();
279+ }
280+
281+ ParabolaPointer::RenderStateMap renderStates;
282+ if (propertyMap["renderStates"].isValid()) {
283+ QList<QVariant> renderStateVariants = propertyMap["renderStates"].toList();
284+ for (const QVariant& renderStateVariant : renderStateVariants) {
285+ if (renderStateVariant.isValid()) {
286+ QVariantMap renderStateMap = renderStateVariant.toMap();
287+ if (renderStateMap["name"].isValid()) {
288+ std::string name = renderStateMap["name"].toString().toStdString();
289+ renderStates[name] = ParabolaPointer::buildRenderState(renderStateMap);
290+ }
291+ }
292+ }
293+ }
294+
295+ ParabolaPointer::DefaultRenderStateMap defaultRenderStates;
296+ if (propertyMap["defaultRenderStates"].isValid()) {
297+ QList<QVariant> renderStateVariants = propertyMap["defaultRenderStates"].toList();
298+ for (const QVariant& renderStateVariant : renderStateVariants) {
299+ if (renderStateVariant.isValid()) {
300+ QVariantMap renderStateMap = renderStateVariant.toMap();
301+ if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) {
302+ std::string name = renderStateMap["name"].toString().toStdString();
303+ float distance = renderStateMap["distance"].toFloat();
304+ defaultRenderStates[name] = std::pair<float, ParabolaPointer::RenderState>(distance, ParabolaPointer::buildRenderState(renderStateMap));
305+ }
306+ }
307+ }
308+ }
309+
310+ bool hover = false;
311+ if (propertyMap["hover"].isValid()) {
312+ hover = propertyMap["hover"].toBool();
313+ }
314+
315+ PointerTriggers triggers;
316+ auto userInputMapper = DependencyManager::get<UserInputMapper>();
317+ if (propertyMap["triggers"].isValid()) {
318+ QList<QVariant> triggerVariants = propertyMap["triggers"].toList();
319+ for (const QVariant& triggerVariant : triggerVariants) {
320+ if (triggerVariant.isValid()) {
321+ QVariantMap triggerMap = triggerVariant.toMap();
322+ if (triggerMap["action"].isValid() && triggerMap["button"].isValid()) {
323+ controller::Endpoint::Pointer endpoint = userInputMapper->endpointFor(controller::Input(triggerMap["action"].toUInt()));
324+ if (endpoint) {
325+ std::string button = triggerMap["button"].toString().toStdString();
326+ triggers.emplace_back(endpoint, button);
327+ }
328+ }
329+ }
330+ }
331+ }
332+
333+ return DependencyManager::get<PointerManager>()->addPointer(std::make_shared<ParabolaPointer>(properties, renderStates, defaultRenderStates, hover, triggers,
334+ faceAvatar, followNormal, centerEndY, lockEnd, distanceScaleEnd,
335+ scaleWithAvatar, enabled));
336+#endif
337+}
338+
204339 void PointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) const {
205340 QVariantMap propMap = properties.toMap();
206341