History

parabola picks, started implementing math

SamGondelman committed 8 years ago

Commit 90091d11 parent 1f4346d50 files · +1057 −60Browse files

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

Unified · Split

interface/src/raypick/PickScriptingInterface.cpp+90−0
@@ -17,6 +17,9 @@ · 16 unmodified lines
1717 #include "JointRayPick.h"
1818 #include "MouseRayPick.h"
1919 #include "StylusPick.h"
20+#include "StaticParabolaPick.h"
21+#include "JointParabolaPick.h"
22+#include "MouseParabolaPick.h"
2023
2124 #include <ScriptEngine.h>
2225
@@ -26,6 +29,8 @@ unsigned int PickScriptingInterface::createPick(const PickQuery::PickType type, · 3 unmodified lines
2629 return createRayPick(properties);
2730 case PickQuery::PickType::Stylus:
2831 return createStylusPick(properties);
32+ case PickQuery::PickType::Parabola:
33+ return createParabolaPick(properties);
2934 default:
3035 return PickManager::INVALID_PICK_ID;
3136 }
@@ -134,6 +139,91 @@ unsigned int PickScriptingInterface::createStylusPick(const QVariant& properties · 102 unmodified lines
134139 return DependencyManager::get<PickManager>()->addPick(PickQuery::Stylus, std::make_shared<StylusPick>(side, filter, maxDistance, enabled));
135140 }
136141
142+/**jsdoc
143+ * A set of properties that can be passed to {@link Picks.createPick} to create a new Parabola Pick.
144+ * @typedef {object} Picks.ParabolaPickProperties
145+ * @property {boolean} [enabled=false] If this Pick should start enabled or not. Disabled Picks do not updated their pick results.
146+ * @property {number} [filter=Picks.PICK_NOTHING] The filter for this Pick to use, constructed using filter flags combined using bitwise OR.
147+ * @property {number} [maxDistance=0.0] The max distance at which this Pick will intersect. 0.0 = no max. < 0.0 is invalid.
148+ * @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.
149+ * 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
150+ * exists on your current avatar.
151+ * @property {Vec3} [posOffset=Vec3.ZERO] Only for Joint Parabola Picks. A local joint position offset, in meters. x = upward, y = forward, z = lateral
152+ * @property {Vec3} [dirOffset=Vec3.UP] Only for Joint Parabola Picks. A local joint direction offset. x = upward, y = forward, z = lateral
153+ * @property {Vec3} [position] Only for Static Parabola Picks. The world-space origin of the parabola segment.
154+ * @property {Vec3} [direction=-Vec3.FRONT] Only for Static Parabola Picks. The world-space direction of the parabola segment.
155+ * @property {number} [speed=1] The initial speed of the parabola, i.e. the initial speed of the projectile whose trajectory defines the parabola.
156+ * @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.
157+ * @property {boolean} [rotateWithAvatar=true] Whether or not the acceleration axis should rotate with your avatar's local Y axis.
158+ */
159+unsigned int PickScriptingInterface::createParabolaPick(const QVariant& properties) {
160+ QVariantMap propMap = properties.toMap();
161+
162+ bool enabled = false;
163+ if (propMap["enabled"].isValid()) {
164+ enabled = propMap["enabled"].toBool();
165+ }
166+
167+ PickFilter filter = PickFilter();
168+ if (propMap["filter"].isValid()) {
169+ filter = PickFilter(propMap["filter"].toUInt());
170+ }
171+
172+ float maxDistance = 0.0f;
173+ if (propMap["maxDistance"].isValid()) {
174+ maxDistance = propMap["maxDistance"].toFloat();
175+ }
176+
177+ float speed = 1.0f;
178+ if (propMap["speed"].isValid()) {
179+ speed = propMap["speed"].toFloat();
180+ }
181+
182+ glm::vec3 accelerationAxis = -Vectors::UP;
183+ if (propMap["accelerationAxis"].isValid()) {
184+ accelerationAxis = vec3FromVariant(propMap["accelerationAxis"]);
185+ }
186+
187+ bool rotateWithAvatar = true;
188+ if (propMap["rotateWithAvatar"].isValid()) {
189+ rotateWithAvatar = propMap["rotateWithAvatar"].toBool();
190+ }
191+
192+ if (propMap["joint"].isValid()) {
193+ std::string jointName = propMap["joint"].toString().toStdString();
194+
195+ if (jointName != "Mouse") {
196+ // x = upward, y = forward, z = lateral
197+ glm::vec3 posOffset = Vectors::ZERO;
198+ if (propMap["posOffset"].isValid()) {
199+ posOffset = vec3FromVariant(propMap["posOffset"]);
200+ }
201+
202+ glm::vec3 dirOffset = Vectors::UP;
203+ if (propMap["dirOffset"].isValid()) {
204+ dirOffset = vec3FromVariant(propMap["dirOffset"]);
205+ }
206+
207+ return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, std::make_shared<JointParabolaPick>(jointName, posOffset, dirOffset,
208+ speed, accelerationAxis, rotateWithAvatar, filter, maxDistance, enabled));
209+
210+ } else {
211+ return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, std::make_shared<MouseParabolaPick>(speed, accelerationAxis, rotateWithAvatar, filter, maxDistance, enabled));
212+ }
213+ } else if (propMap["position"].isValid()) {
214+ glm::vec3 position = vec3FromVariant(propMap["position"]);
215+
216+ glm::vec3 direction = -Vectors::FRONT;
217+ if (propMap["direction"].isValid()) {
218+ direction = vec3FromVariant(propMap["direction"]);
219+ }
220+
221+ return DependencyManager::get<PickManager>()->addPick(PickQuery::Parabola, std::make_shared<StaticParabolaPick>(position, direction, speed, accelerationAxis, rotateWithAvatar, filter, maxDistance, enabled));
222+ }
223+
224+ return PickManager::INVALID_PICK_ID;
225+}
226+
137227 void PickScriptingInterface::enablePick(unsigned int uid) {
138228 DependencyManager::get<PickManager>()->enablePick(uid);
139229 }