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
37 return createLaserPointer(properties);37 return createLaserPointer(properties);
38 case PickQuery::PickType::Stylus:38 case PickQuery::PickType::Stylus:
39 return createStylus(properties);39 return createStylus(properties);
40 case PickQuery::PickType::Parabola:
41 return createParabolaPointer(properties);
40 default:42 default:
41 return PointerEvent::INVALID_POINTER_ID;43 return PointerEvent::INVALID_POINTER_ID;
42 }44 }
@@ -84,27 +86,20 @@ unsigned int PointerScriptingInterface::createStylus(const QVariant& properties) · 41 unmodified lines
84 * @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).86 * @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).
85 * An overlay to represent the end of the Ray Pointer, if desired.87 * An overlay to represent the end of the Ray Pointer, if desired.
86 */88 */
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 */
95/**jsdoc89/**jsdoc
96 * 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.90 * 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.
97 * @typedef {object} Pointers.LaserPointerProperties91 * @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.92 * @property {boolean} [faceAvatar=false] 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.93 * @property {boolean} [centerEndY=true] 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.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.
101 * @property {boolean} [distanceScaleEnd=false] Ray Pointers only. If true, the dimensions of the end of the Pointer will scale linearly with distance.95 * @property {boolean} [distanceScaleEnd=false] 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.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.
103 * @property {boolean} [enabled=false]98 * @property {boolean} [enabled=false]
104 * @property {Pointers.RayPointerRenderState[]} [renderStates] Ray Pointers only. A list of different visual states to switch between.99 * @property {Pointers.RayPointerRenderState[]} [renderStates] 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.100 * @property {Pointers.DefaultRayPointerRenderState[]} [defaultRenderStates] A list of different visual states to use if there is no intersection.
106 * @property {boolean} [hover=false] If this Pointer should generate hover events.101 * @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.
108 */103 */
109unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& properties) const {104unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& properties) const {
110 QVariantMap propertyMap = properties.toMap();105 QVariantMap propertyMap = properties.toMap();
@@ -144,7 +139,7 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope · 33 unmodified lines
144 enabled = propertyMap["enabled"].toBool();139 enabled = propertyMap["enabled"].toBool();
145 }140 }
146 141
147 LaserPointer::RenderStateMap renderStates;142 RenderStateMap renderStates;
148 if (propertyMap["renderStates"].isValid()) {143 if (propertyMap["renderStates"].isValid()) {
149 QList<QVariant> renderStateVariants = propertyMap["renderStates"].toList();144 QList<QVariant> renderStateVariants = propertyMap["renderStates"].toList();
150 for (const QVariant& renderStateVariant : renderStateVariants) {145 for (const QVariant& renderStateVariant : renderStateVariants) {
@@ -158,7 +153,7 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope · 7 unmodified lines
158 }153 }
159 }154 }
160 155
161 LaserPointer::DefaultRenderStateMap defaultRenderStates;156 DefaultRenderStateMap defaultRenderStates;
162 if (propertyMap["defaultRenderStates"].isValid()) {157 if (propertyMap["defaultRenderStates"].isValid()) {
163 QList<QVariant> renderStateVariants = propertyMap["defaultRenderStates"].toList();158 QList<QVariant> renderStateVariants = propertyMap["defaultRenderStates"].toList();
164 for (const QVariant& renderStateVariant : renderStateVariants) {159 for (const QVariant& renderStateVariant : renderStateVariants) {
@@ -167,7 +162,7 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope · 2 unmodified lines
167 if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) {162 if (renderStateMap["name"].isValid() && renderStateMap["distance"].isValid()) {
168 std::string name = renderStateMap["name"].toString().toStdString();163 std::string name = renderStateMap["name"].toString().toStdString();
169 float distance = renderStateMap["distance"].toFloat();164 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));
171 }166 }
172 }167 }
173 }168 }
@@ -201,6 +196,146 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope · 27 unmodified lines
201 scaleWithAvatar, enabled));196 scaleWithAvatar, enabled));
202}197}
203 198
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*/
241unsigned 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
204void PointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) const {339void PointerScriptingInterface::editRenderState(unsigned int uid, const QString& renderState, const QVariant& properties) const {
205 QVariantMap propMap = properties.toMap();340 QVariantMap propMap = properties.toMap();
206 341