|
From: <tre...@us...> - 2007-12-01 00:24:48
|
Revision: 610
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=610&view=rev
Author: trevorolio
Date: 2007-11-30 16:21:24 -0800 (Fri, 30 Nov 2007)
Log Message:
-----------
Added a spline interpolator to the scripting API, the better to do things like test for whether a thrown ball would hit a person without breaking out the hard maths.
Added a announcement function to the script API so scripts can show messages to all people in a space.
Modified Paths:
--------------
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SpaceSimulator.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptPoint.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptQuaternion.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSpace.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSplinePath.java
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/SpaceScriptEngine.java
Added Paths:
-----------
maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSplinePathInterpolator.java
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SpaceSimulator.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SpaceSimulator.java 2007-11-27 13:00:25 UTC (rev 609)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/SpaceSimulator.java 2007-12-01 00:21:24 UTC (rev 610)
@@ -232,7 +232,7 @@
}
user.startMotion(event.getSplinePath());
listener.generatedSpaceEvent(event, SpaceSimulator.this);
- //TODO save motion to sim, lazily updating upon query
+ scriptEngine.handleSpaceEvent(event);
} else if (SpaceEvent.USER_STOP_MOTION_EVENT.equals(event.getName())) {
String username = event.getStringProperty(SpaceEvent.USERNAME);
@@ -243,6 +243,8 @@
}
user.stopMotion(event.getTransform());
listener.generatedSpaceEvent(event, SpaceSimulator.this);
+ scriptEngine.handleSpaceEvent(event);
+
} else if (SpaceEvent.USER_SAT_EVENT.equals(event.getName())) {
String username = event.getStringProperty(SpaceEvent.USERNAME);
User user = space.getUser(username);
@@ -373,6 +375,10 @@
}
page.setContentType(event.getStringProperty(SpaceEvent.CONTENT_TYPE));
listener.generatedSpaceEvent(event, SpaceSimulator.this);
+ } else if(SpaceEvent.ANNOUNCE_EVENT.equals(event.getName())){
+ //TODO limit who can announce
+ listener.generatedSpaceEvent(event, SpaceSimulator.this);
+
} else if (SpaceEvent.TEXT_SAY_EVENT.equals(event.getName())) {
String username = event.getStringProperty(SpaceEvent.USERNAME);
User user = space.getUser(username);
@@ -383,8 +389,7 @@
String chatMessage = event.getStringProperty(SpaceEvent.TSE_MESSAGE);
- // this is a hack to play pre-baked animations
- // TODO create a user animation record and a method to dl and play them
+ // this is a hack to play animations defined by the body data
if (chatMessage.startsWith("/") && chatMessage.length() > 1) {
String command = chatMessage.substring(1);
SpaceEvent playAnimationEvent = new SpaceEvent(SpaceEvent.PLAY_ANIMATION_EVENT);
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptPoint.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptPoint.java 2007-11-27 13:00:25 UTC (rev 609)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptPoint.java 2007-12-01 00:21:24 UTC (rev 610)
@@ -14,6 +14,7 @@
package com.ogoglio.sim.script;
+import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import org.mozilla.javascript.ScriptableObject;
@@ -55,6 +56,13 @@
this.z += z;
}
+ public double jsFunction_getDistance(ScriptPoint remotePoint){
+ if(remotePoint == null){
+ return 0;
+ }
+ return new Point3d(x, y, z).distance(new Point3d(remotePoint.x, remotePoint.y, remotePoint.z));
+ }
+
public double jsGet_x() {
return x;
}
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptQuaternion.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptQuaternion.java 2007-11-27 13:00:25 UTC (rev 609)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptQuaternion.java 2007-12-01 00:21:24 UTC (rev 610)
@@ -21,6 +21,8 @@
import org.mozilla.javascript.ScriptableObject;
+import com.ogoglio.viewer.j3d.J3DRenderer;
+
public class ScriptQuaternion extends ScriptableObject {
private double w = 1, x = 0, y = 0, z = 0;
@@ -89,6 +91,16 @@
setQuat(quat);
}
+ public double[] jsFunction_getEulerOrientation(){
+ Vector3d euler = new Vector3d();
+ J3DRenderer.getEuler(new Quat4d(x, y, z, w), euler);
+ double[] results = new double[3];
+ results[0] = euler.x;
+ results[1] = euler.y;
+ results[2] = euler.z;
+ return results;
+ }
+
public void jsFunction_setEulerOrientation(double x, double y, double z) {
Transform3D transform = new Transform3D();
transform.setEuler(new Vector3d(x, y, z));
@@ -115,18 +127,19 @@
}
public void jsFunction_rotatePoint(ScriptPoint pointOfRotation, ScriptPoint pointToRotate){
- Vector3d vectorOfRot = new Vector3d(); //new Vector3d(pointOfRotation.jsGet_x(), pointOfRotation.jsGet_y(), pointOfRotation.jsGet_z());
- Transform3D rotTransform = new Transform3D(new Quat4d(x, y, z, w), vectorOfRot, 1);
+ Vector3d translation = new Vector3d(0,0,0); //new Vector3d(pointOfRotation.jsGet_x(), pointOfRotation.jsGet_y(), pointOfRotation.jsGet_z());
+ Quat4d quat = new Quat4d(x, y, z, w);
+ Transform3D rotTransform = new Transform3D(quat, translation, 1);
Point3d workingPoint = new Point3d(pointToRotate.jsGet_x(), pointToRotate.jsGet_y(), pointToRotate.jsGet_z());
rotTransform.transform(workingPoint);
pointToRotate.jsSet_x(workingPoint.x);
pointToRotate.jsSet_y(workingPoint.y);
pointToRotate.jsSet_z(workingPoint.z);
}
-
+
public void jsFunction_set(double w, double x, double y, double z) {
this.w = w;
- this.x = w;
+ this.x = x; //ZOMG! this was this.x = w and it just about killed me - TFS
this.y = y;
this.z = z;
}
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSpace.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSpace.java 2007-11-27 13:00:25 UTC (rev 609)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSpace.java 2007-12-01 00:21:24 UTC (rev 610)
@@ -101,6 +101,31 @@
return result;
}
+ public ScriptPoint jsFunction_getUserPosition(String username){
+ User user = spaceSimulator.getSpace().getUser(username);
+ if(user == null){
+ return null;
+ }
+ ScriptPoint point = (ScriptPoint) Context.getCurrentContext().newObject(getParentScope(), "Point", new Object[0]);
+ Vector3d position = new Vector3d();
+ user.getPosition().get(position);
+ point.jsConstructor(position.x, position.y, position.z);
+ return point;
+ }
+
+ public ScriptQuaternion jsFunction_getUserOrientation(String username){
+ User user = spaceSimulator.getSpace().getUser(username);
+ if(user == null){
+ return null;
+ }
+ Quat4d quat = new Quat4d();
+ Transform3D position = user.getPosition();
+ position.get(quat);
+ ScriptQuaternion orientation = (ScriptQuaternion) Context.getCurrentContext().newObject(getParentScope(), "Quaternion", new Object[0]);
+ orientation.jsFunction_set(quat.w, quat.x, quat.y, quat.z);
+ return orientation;
+ }
+
public String jsFunction_getSetting(String key) {
return spaceSimulator.getSetting(key);
}
@@ -117,6 +142,15 @@
spaceSimulator.showInfoPanelToUser((long)sourceThingID, username, nonce);
}
+ public void jsFunction_announce(String message){
+ if(message == null || message.trim().length() == 0){
+ return;
+ }
+ SpaceEvent event = new SpaceEvent(SpaceEvent.ANNOUNCE_EVENT);
+ event.setProperty(SpaceEvent.ANNOUNCE_MESSAGE, message);
+ spaceSimulator.handleSpaceEvent(event);
+ }
+
public void jsFunction_log(String message) {
spaceSimulator.log(message);
}
@@ -263,10 +297,10 @@
}
public void jsFunction_startThingMotion(double thingID, ScriptSplinePath path) {
- if (thingID < 0 || path == null || path.getKeyFrames().length == 0 || path.jsGet_duration() < 100) {
+ if (thingID < 0 || path == null || path.jsFunction_getKeyFrames().length == 0 || path.jsGet_duration() < 100) {
return;
}
- J3DSplinePath newPath = new J3DSplinePath(transcribeKeyFrames(path.getKeyFrames()), (long) path.jsGet_duration(), path.jsGet_looping(), path.jsGet_followsPlatform(), path.jsGet_distanceFromPlatform());
+ J3DSplinePath newPath = new J3DSplinePath(path.getJ3DSplineKeyFrames(), (long) path.jsGet_duration(), path.jsGet_looping(), path.jsGet_followsPlatform(), path.jsGet_distanceFromPlatform());
SpaceEvent event = new SpaceEvent(SpaceEvent.THING_START_MOTION_EVENT);
event.setProperty(SpaceEvent.THING_ID, new Long((long) thingID));
@@ -276,10 +310,10 @@
}
public void jsFunction_startShapeMotion(double thingID, String shapeName, ScriptSplinePath path) {
- if (thingID < 0 || path == null || shapeName == null || path.getKeyFrames().length == 0 || path.jsGet_duration() < 100) {
+ if (thingID < 0 || path == null || shapeName == null || path.jsFunction_getKeyFrames().length == 0 || path.jsGet_duration() < 100) {
return;
}
- J3DSplinePath newPath = new J3DSplinePath(transcribeKeyFrames(path.getKeyFrames()), (long) path.jsGet_duration(), path.jsGet_looping(), path.jsGet_followsPlatform(), path.jsGet_distanceFromPlatform());
+ J3DSplinePath newPath = new J3DSplinePath(path.getJ3DSplineKeyFrames(), (long) path.jsGet_duration(), path.jsGet_looping(), path.jsGet_followsPlatform(), path.jsGet_distanceFromPlatform());
SpaceEvent event = new SpaceEvent(SpaceEvent.SHAPE_START_MOTION_EVENT);
event.setProperty(SpaceEvent.THING_ID, new Long((long) thingID));
@@ -313,10 +347,10 @@
}
public void jsFunction_startUserMotion(String username, ScriptSplinePath path) {
- if (username == null || path == null || path.getKeyFrames().length == 0 || path.jsGet_duration() < 100) {
+ if (username == null || path == null || path.jsFunction_getKeyFrames().length == 0 || path.jsGet_duration() < 100) {
return;
}
- J3DSplinePath newPath = new J3DSplinePath(transcribeKeyFrames(path.getKeyFrames()), (long) path.jsGet_duration(), path.jsGet_looping(), path.jsGet_followsPlatform(), path.jsGet_distanceFromPlatform());
+ J3DSplinePath newPath = new J3DSplinePath(path.getJ3DSplineKeyFrames(), (long) path.jsGet_duration(), path.jsGet_looping(), path.jsGet_followsPlatform(), path.jsGet_distanceFromPlatform());
SpaceEvent event = new SpaceEvent(SpaceEvent.USER_START_MOTION_EVENT);
event.setProperty(SpaceEvent.USERNAME, username);
@@ -325,18 +359,6 @@
spaceSimulator.handleSpaceEvent(event);
}
- private J3DSplineKeyFrame[] transcribeKeyFrames(ScriptSplineKeyFrame[] keyFrames) {
- Point3f position = new Point3f();
- Point3f scale = new Point3f();
- J3DSplineKeyFrame[] newFrames = new J3DSplineKeyFrame[keyFrames.length];
- for (int i = 0; i < newFrames.length; i++) {
- position.set((float) keyFrames[i].jsGet_x(), (float) keyFrames[i].jsGet_y(), (float) keyFrames[i].jsGet_z());
- scale.set((float) keyFrames[i].jsGet_scaleX(), (float) keyFrames[i].jsGet_scaleY(), (float) keyFrames[i].jsGet_scaleZ());
- newFrames[i] = new J3DSplineKeyFrame((float) keyFrames[i].jsGet_knot(), keyFrames[i].jsGet_linear(), position, (float) keyFrames[i].jsGet_heading(), (float) keyFrames[i].jsGet_pitch(), (float) keyFrames[i].jsGet_bank(), scale, (float) keyFrames[i].jsGet_tension(), (float) keyFrames[i].jsGet_continuity(), (float) keyFrames[i].jsGet_bias());
- }
- return newFrames;
- }
-
public void jsFunction_rotateThing(double thingID, double radiansX, double radiansY, double radiansZ) {
Thing thing = spaceSimulator.getSpace().getThing((long) thingID);
if (thing == null) {
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSplinePath.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSplinePath.java 2007-11-27 13:00:25 UTC (rev 609)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSplinePath.java 2007-12-01 00:21:24 UTC (rev 610)
@@ -15,20 +15,25 @@
import java.util.Vector;
+import javax.vecmath.Point3f;
+
import org.mozilla.javascript.ScriptableObject;
+import com.ogoglio.client.model.SplineKeyFrame;
+import com.ogoglio.viewer.j3d.J3DSplineKeyFrame;
+
public class ScriptSplinePath extends ScriptableObject {
private double duration = 1000;
-
+
private boolean looping = false;
-
+
private Vector keyFrames = new Vector();
private boolean followsPlatform = false;
private double distanceFromPlatform = 0;
-
+
public ScriptSplinePath() {
}
@@ -37,23 +42,23 @@
this.looping = looping;
this.followsPlatform = followsPlatform;
}
-
+
public void jsFunction_addKeyFrame(ScriptSplineKeyFrame keyFrame) {
keyFrames.add(keyFrame);
}
-
- public ScriptSplineKeyFrame[] getKeyFrames() {
- return (ScriptSplineKeyFrame[])keyFrames.toArray(new ScriptSplineKeyFrame[0]);
+
+ public ScriptSplineKeyFrame[] jsFunction_getKeyFrames() {
+ return (ScriptSplineKeyFrame[]) keyFrames.toArray(new ScriptSplineKeyFrame[0]);
}
-
+
public int jsGet_length() {
return keyFrames.size();
}
-
+
public String getClassName() {
return "SplinePath";
}
-
+
public Object getDefaultValue(java.lang.Class hint) {
return toString();
}
@@ -81,15 +86,30 @@
public void jsSet_followsPlatform(boolean fp) {
followsPlatform = fp;
}
-
+
public boolean jsGet_followsPlatform() {
return followsPlatform;
}
public void jsSet_distanceFromPlatform(double distanceFromPlatform) {
- this.distanceFromPlatform = distanceFromPlatform;
+ this.distanceFromPlatform = distanceFromPlatform;
}
+
public double jsGet_distanceFromPlatform() {
return distanceFromPlatform;
}
+
+ public J3DSplineKeyFrame[] getJ3DSplineKeyFrames() {
+ ScriptSplineKeyFrame[] keyFrames = jsFunction_getKeyFrames();
+ Point3f position = new Point3f();
+ Point3f scale = new Point3f();
+ J3DSplineKeyFrame[] newFrames = new J3DSplineKeyFrame[keyFrames.length];
+ for (int i = 0; i < newFrames.length; i++) {
+ position.set((float) keyFrames[i].jsGet_x(), (float) keyFrames[i].jsGet_y(), (float) keyFrames[i].jsGet_z());
+ scale.set((float) keyFrames[i].jsGet_scaleX(), (float) keyFrames[i].jsGet_scaleY(), (float) keyFrames[i].jsGet_scaleZ());
+ newFrames[i] = new J3DSplineKeyFrame((float) keyFrames[i].jsGet_knot(), keyFrames[i].jsGet_linear(), position, (float) keyFrames[i].jsGet_heading(), (float) keyFrames[i].jsGet_pitch(), (float) keyFrames[i].jsGet_bank(), scale, (float) keyFrames[i].jsGet_tension(), (float) keyFrames[i].jsGet_continuity(), (float) keyFrames[i].jsGet_bias());
+ }
+ return newFrames;
+ }
+
}
Added: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSplinePathInterpolator.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSplinePathInterpolator.java (rev 0)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/ScriptSplinePathInterpolator.java 2007-12-01 00:21:24 UTC (rev 610)
@@ -0,0 +1,92 @@
+/* Copyright 2007 Transmutable (http://transmutable.com/)
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. */
+package com.ogoglio.sim.script;
+
+import javax.media.j3d.Transform3D;
+import javax.media.j3d.TransformGroup;
+import javax.vecmath.Quat4d;
+import javax.vecmath.Vector3d;
+
+import org.mozilla.javascript.ScriptableObject;
+
+import com.ogoglio.viewer.j3d.RangedAlpha;
+import com.sun.j3d.utils.behaviors.interpolators.KBRotPosScaleSplinePathInterpolator;
+
+public class ScriptSplinePathInterpolator extends ScriptableObject {
+
+ public static final String CLASS_NAME = "SplinePathInterpolator";
+
+ private ScriptSplinePath splinePath = null;
+
+ private KBRotPosScaleSplinePathInterpolator interpolator = null;
+
+ private TransformGroup transformGroup = new TransformGroup();
+
+ private Transform3D transform = new Transform3D();
+
+ private Vector3d vector = new Vector3d();
+
+ private Quat4d quaternion = new Quat4d();
+
+ public ScriptSplinePathInterpolator() {
+ }
+
+ public void jsConstructor(ScriptSplinePath splinePath) {
+ this.splinePath = splinePath;
+ RangedAlpha alpha = new RangedAlpha(1, 1000);
+ interpolator = new KBRotPosScaleSplinePathInterpolator(alpha, transformGroup, transform, splinePath.getJ3DSplineKeyFrames());
+ interpolator.setEnable(true);
+ }
+
+ /**
+ * @param alphaValue must be [0-1]
+ * @param quat
+ */
+ public void jsFunction_interpolateOrientation(double alphaValue, ScriptQuaternion quat){
+ if (interpolator == null) {
+ return;
+ }
+ interpolator.computeTransform((float) alphaValue, transform);
+ transform.get(quaternion);
+ quat.jsFunction_set(quaternion.w, quaternion.x, quaternion.y, quaternion.z);
+ }
+
+ /**
+ * @param alphaValue must be [0-1]
+ * @param point
+ */
+ public void jsFunction_interpolatePosition(double alphaValue, ScriptPoint point) {
+ if (interpolator == null) {
+ return;
+ }
+ interpolator.computeTransform((float) alphaValue, transform);
+ transform.get(vector);
+ point.jsSet_x(vector.x);
+ point.jsSet_y(vector.y);
+ point.jsSet_z(vector.z);
+ }
+
+ public String getClassName() {
+ return toString();
+ }
+
+ public Object getDefaultValue(java.lang.Class hint) {
+ return toString();
+ }
+
+ public String toString() {
+ return CLASS_NAME;
+ }
+
+}
Modified: maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/SpaceScriptEngine.java
===================================================================
--- maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/SpaceScriptEngine.java 2007-11-27 13:00:25 UTC (rev 609)
+++ maven/trunk/ogoglio-server/src/main/java/com/ogoglio/sim/script/SpaceScriptEngine.java 2007-12-01 00:21:24 UTC (rev 610)
@@ -19,6 +19,9 @@
import java.util.Vector;
import javax.media.j3d.Transform3D;
+import javax.vecmath.Point3f;
+import javax.vecmath.Quat4d;
+import javax.vecmath.Vector3d;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.EcmaError;
@@ -30,6 +33,7 @@
import com.ogoglio.client.model.Page;
import com.ogoglio.client.model.Shape;
import com.ogoglio.client.model.Space;
+import com.ogoglio.client.model.SplineKeyFrame;
import com.ogoglio.client.model.SplinePath;
import com.ogoglio.client.model.Template;
import com.ogoglio.client.model.Thing;
@@ -59,12 +63,22 @@
public static final String ONSERVICE_FUNCTION_NAME = "onService";
- private static final String ONCLICK_FUNCTION_NAME = "onClick";
+ public static final String ONCLICK_FUNCTION_NAME = "onClick";
- private static final String ONCONTEXTCLICK_FUNCTION_NAME = "onContextClick";
+ public static final String ONCONTEXTCLICK_FUNCTION_NAME = "onContextClick";
- private static final String ONCONTEXTMENUITEMCHOSEN_FUNCTION_NAME = "onContextMenuItemChosen";
+ public static final String ONCONTEXTMENUITEMCHOSEN_FUNCTION_NAME = "onContextMenuItemChosen";
+ public static final String ONUSERMOTIONSTART_FUNCTION_NAME = "onUserMotionStart";
+
+ private static final String ONUSERSTOPPED_FUNCTION_NAME = "onUserStopped";
+
+ private Vector3d workingPosition = new Vector3d();
+
+ private Quat4d workingOrientation = new Quat4d();
+
+ private Transform3D workingTransform = new Transform3D();
+
public SpaceScriptEngine(SpaceSimulator spaceSimulator) {
ArgumentUtils.assertNotNull(spaceSimulator);
this.spaceSimulator = spaceSimulator;
@@ -77,6 +91,7 @@
ScriptableObject.defineClass(globalScope, ScriptQuaternion.class);
ScriptableObject.defineClass(globalScope, ScriptSplineKeyFrame.class);
ScriptableObject.defineClass(globalScope, ScriptSplinePath.class);
+ ScriptableObject.defineClass(globalScope, ScriptSplinePathInterpolator.class);
ScriptableObject.defineClass(globalScope, ScriptSpace.class);
ScriptableObject.defineClass(globalScope, ScriptMath.class);
ScriptableObject.defineClass(globalScope, ScriptHTTPRequest.class);
@@ -150,7 +165,62 @@
}
public void handleSpaceEvent(SpaceEvent event) {
- if (SpaceEvent.THING_CLICKED_EVENT.equals(event.getName())) {
+ if (SpaceEvent.USER_START_MOTION_EVENT.equals(event.getName())) {
+ String username = event.getStringProperty(SpaceEvent.USERNAME);
+ SplinePath path = event.getSplinePath();
+ if (username == null || path == null) {
+ Log.warn("Got user motion start event in script engine with no username (" + username + ") or path: " + path);
+ return;
+ }
+ Context context = Context.enter();
+ try {
+ ScriptSplinePath scriptPath = (ScriptSplinePath) context.newObject(globalScope, "SplinePath", new Object[0]);
+ scriptPath.jsConstructor(path.getDuration(), path.isLooping(), path.followsPlatform());
+ SplineKeyFrame[] frames = path.getSplineKeyFrames();
+ for (int i = 0; i < frames.length; i++) {
+ ScriptSplineKeyFrame frame = (ScriptSplineKeyFrame) context.newObject(globalScope, "SplineKeyFrame", new Object[0]);
+ Point3f position = frames[i].getPosition();
+ frame.jsConstructor(position.x, position.y, position.z, frames[i].getHeading(), frames[i].getKnot());
+ scriptPath.jsFunction_addKeyFrame(frame);
+ }
+
+ Object[] args = { username, scriptPath };
+ Object[] scopeObjs = thingScopes.getValues();
+ for (int i = 0; i < scopeObjs.length; i++) {
+ callJavascriptFunction(context, (ScriptableObject) scopeObjs[i], ONUSERMOTIONSTART_FUNCTION_NAME, args);
+ }
+ } finally {
+ Context.exit();
+ }
+ } else if (SpaceEvent.USER_STOP_MOTION_EVENT.equals(event.getName())) {
+ String username = event.getStringProperty(SpaceEvent.USERNAME);
+ event.getTransform(workingTransform);
+ if (username == null) {
+ Log.warn("Got user stop event in script engine with no username (" + username + ")");
+ return;
+ }
+
+ Context context = Context.enter();
+ try {
+ workingTransform.get(workingPosition);
+ ScriptPoint scriptPosition = (ScriptPoint) context.newObject(globalScope, "Point", new Object[0]);
+ scriptPosition.jsSet_x(workingPosition.x);
+ scriptPosition.jsSet_y(workingPosition.y);
+ scriptPosition.jsSet_z(workingPosition.z);
+
+ workingTransform.get(workingOrientation);
+ ScriptQuaternion scriptQuat = (ScriptQuaternion)context.newObject(globalScope, "Quaternion", new Object[0]);
+ scriptQuat.jsFunction_set(workingOrientation.w, workingOrientation.x, workingOrientation.y, workingOrientation.z);
+
+ Object[] args = { username, scriptPosition, scriptQuat };
+ Object[] scopeObjs = thingScopes.getValues();
+ for (int i = 0; i < scopeObjs.length; i++) {
+ callJavascriptFunction(context, (ScriptableObject) scopeObjs[i], ONUSERSTOPPED_FUNCTION_NAME, args);
+ }
+ } finally {
+ Context.exit();
+ }
+ } else if (SpaceEvent.THING_CLICKED_EVENT.equals(event.getName())) {
Long thingID = event.getLongProperty(SpaceEvent.THING_ID);
if (thingID == null) {
return;
@@ -191,7 +261,6 @@
return;
}
-
String functionName = ONCONTEXTCLICK_FUNCTION_NAME;
Object[] functionArgs = new Object[2];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|