summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/VelocityBehavior.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/scape/VelocityBehavior.java')
-rw-r--r--NET/worlds/scape/VelocityBehavior.java399
1 files changed, 399 insertions, 0 deletions
diff --git a/NET/worlds/scape/VelocityBehavior.java b/NET/worlds/scape/VelocityBehavior.java
new file mode 100644
index 0000000..1cecae5
--- /dev/null
+++ b/NET/worlds/scape/VelocityBehavior.java
@@ -0,0 +1,399 @@
+/* */ package NET.worlds.scape;
+/* */
+/* */ import java.io.IOException;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public class VelocityBehavior
+/* */ extends SwitchableBehavior
+/* */ implements FrameHandler, BumpHandler
+/* */ {
+/* */ private RollingAttribute attr;
+/* */ private long lastTime;
+/* */ public float linearVel;
+/* */ public float linearDamp;
+/* */ protected Point3 dir;
+/* */ public float angularVel;
+/* */ public float angularDamp;
+/* */ public Point3 axis;
+/* */
+/* */ public VelocityBehavior(Point3Temp linearVectorPerSecond, float linearDampingPerSecond, Point3Temp angularAxis, float angularDegPerSecond, float angularDampingPerSecond)
+/* */ {
+/* 45 */ this.dir = new Point3();
+/* 46 */ this.linearVel = 0.0F;
+/* 47 */ this.linearDamp = linearDampingPerSecond;
+/* 48 */ addVelocity(linearVectorPerSecond);
+/* */
+/* 50 */ this.axis = new Point3(angularAxis);
+/* 51 */ this.axis.normalize();
+/* 52 */ this.angularVel = angularDegPerSecond;
+/* 53 */ this.angularDamp = angularDampingPerSecond;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public VelocityBehavior()
+/* */ {
+/* 62 */ this(Point3Temp.make(0.0F, 0.0F, 0.0F));
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public VelocityBehavior(Point3Temp vel)
+/* */ {
+/* 70 */ this(vel, 0.0F, Point3Temp.make(0.0F, 0.0F, 1.0F), 0.0F, 0.0F);
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public void setDir(Point3Temp d)
+/* */ {
+/* 78 */ double len = Math.sqrt(d.x * d.x + d.y * d.y + d.z * d.z);
+/* */
+/* 80 */ if (len == 0.0D)
+/* */ {
+/* 82 */ this.dir.x = 0.0F;
+/* 83 */ this.dir.y = 0.0F;
+/* 84 */ this.dir.z = 0.0F;
+/* 85 */ return;
+/* */ }
+/* */
+/* */
+/* 89 */ this.dir.x = ((float)(d.x / len));
+/* 90 */ this.dir.y = ((float)(d.y / len));
+/* 91 */ this.dir.z = ((float)(d.z / len));
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public VelocityBehavior addVelocity(Point3Temp vector)
+/* */ {
+/* 99 */ this.dir.times(this.linearVel).plus(vector);
+/* 100 */ float len = this.dir.length();
+/* 101 */ if (len > 0.0F)
+/* 102 */ this.dir.dividedBy(len);
+/* 103 */ this.linearVel = len;
+/* */
+/* 105 */ return this;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public void setNotifyAttribute(RollingAttribute attr)
+/* */ {
+/* 113 */ this.attr = attr;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public boolean handle(FrameEvent e)
+/* */ {
+/* 130 */ this.bumplock = false;
+/* */
+/* 132 */ WObject o = e.receiver;
+/* */
+/* 134 */ float dT = (float)(e.time - this.lastTime) / 1000.0F;
+/* */
+/* */
+/* */
+/* 138 */ if (this.lastTime == 0L)
+/* */ {
+/* 140 */ this.lastTime = e.time;
+/* 141 */ return true;
+/* */ }
+/* */
+/* 144 */ this.lastTime = e.time;
+/* */
+/* 146 */ if (this.linearVel != 0.0F)
+/* */ {
+/* 148 */ Point3Temp dist = Point3Temp.make(this.dir).times(dT * this.linearVel);
+/* 149 */ o.moveThrough(dist);
+/* */
+/* */
+/* 152 */ if (this.linearDamp != 0.0F)
+/* */ {
+/* 154 */ this.linearVel = ((float)(this.linearVel * Math.exp(-this.linearDamp * dT)));
+/* */
+/* 156 */ if (Math.abs(this.linearVel) < this.linearDamp * 16.0F) {
+/* 157 */ this.linearVel = 0.0F;
+/* 158 */ if (this.attr != null) {
+/* 159 */ this.attr.notifyStopped();
+/* */ }
+/* */ }
+/* */ }
+/* */ }
+/* 164 */ if (this.angularVel != 0.0F)
+/* */ {
+/* 166 */ o.spin(this.axis.x, this.axis.y, this.axis.z, this.angularVel * dT);
+/* */
+/* 168 */ if (this.angularDamp != 0.0F)
+/* */ {
+/* 170 */ this.angularVel = ((float)(this.angularVel * Math.exp(-this.angularDamp * dT)));
+/* 171 */ if (Math.abs(this.angularVel) < this.angularDamp * 0.6F)
+/* 172 */ this.angularVel = 0.0F;
+/* */ }
+/* */ }
+/* 175 */ return true;
+/* */ }
+/* */
+/* */
+/* */
+/* 180 */ private boolean bumplock = false;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public boolean handle(BumpEventTemp b)
+/* */ {
+/* 190 */ if (this.bumplock) {
+/* 191 */ return true;
+/* */ }
+/* 193 */ if (this.attr != null) {
+/* 194 */ this.attr.handle(b);
+/* */ } else
+/* 196 */ processBumpEvent(b);
+/* 197 */ this.bumplock = true;
+/* 198 */ return true;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public void processBumpEvent(BumpEventTemp b)
+/* */ {
+/* 208 */ b.postBumpPath.minus(b.postBumpPath);
+/* */
+/* */
+/* */
+/* */
+/* 213 */ if ((this.dir.x == 0.0F) && (this.dir.y == 0.0F) && (this.dir.z == 0.0F))
+/* */ {
+/* 215 */ return;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 225 */ WObject bumper = b.receiver == b.target ?
+/* 226 */ (WObject)b.source : b.target;
+/* */ Point3Temp norm;
+/* 228 */ Point3Temp norm; if (((bumper instanceof Camera)) || ((bumper instanceof Hologram)))
+/* */ {
+/* */
+/* 231 */ float orientation = (float)((360.0F - bumper.getYaw() + 90.0F) *
+/* 232 */ 3.141592653589793D / 180.0D);
+/* 233 */ norm = Point3Temp.make((float)Math.cos(orientation),
+/* 234 */ (float)Math.sin(orientation),
+/* 235 */ 0.0F);
+/* */ }
+/* */ else {
+/* 238 */ norm = Point3Temp.make(b.bumpNormal);
+/* */ }
+/* */
+/* 241 */ float lb = (float)Math.sqrt(norm.x * norm.x +
+/* 242 */ norm.y * norm.y +
+/* 243 */ norm.z * norm.z);
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 249 */ norm.x /= lb;
+/* 250 */ norm.y /= lb;
+/* 251 */ norm.z /= lb;
+/* */
+/* 253 */ float projection = Math.abs(this.dir.x * norm.x +
+/* 254 */ this.dir.y * norm.y +
+/* 255 */ this.dir.z * norm.z);
+/* */
+/* */
+/* 258 */ this.dir.x += norm.x * 2.0F * projection;
+/* 259 */ this.dir.y += norm.y * 2.0F * projection;
+/* 260 */ this.dir.z += norm.z * 2.0F * projection;
+/* */
+/* */
+/* */
+/* 264 */ double n = Math.sqrt(this.dir.x * this.dir.x + this.dir.y * this.dir.y + this.dir.z * this.dir.z);
+/* 265 */ if (n != 0.0D)
+/* */ {
+/* 267 */ Point3 tmp380_377 = this.dir;tmp380_377.x = ((float)(tmp380_377.x / n)); Point3
+/* 268 */ tmp396_393 = this.dir;tmp396_393.y = ((float)(tmp396_393.y / n)); Point3
+/* 269 */ tmp412_409 = this.dir;tmp412_409.z = ((float)(tmp412_409.z / n));
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public Object properties(int index, int offset, int mode, Object value)
+/* */ throws NoSuchPropertyException
+/* */ {
+/* 289 */ Object ret = null;
+/* 290 */ switch (index - offset) {
+/* */ case 0:
+/* 292 */ if (mode == 0) {
+/* 293 */ ret = FloatPropertyEditor.make(
+/* 294 */ new Property(this, index, "Linear Velocity"));
+/* 295 */ } else if (mode == 1) {
+/* 296 */ ret = new Float(this.linearVel);
+/* 297 */ } else if (mode == 2)
+/* 298 */ this.linearVel = ((Float)value).floatValue();
+/* 299 */ break;
+/* */ case 1:
+/* 301 */ if (mode == 0) {
+/* 302 */ ret = FloatPropertyEditor.make(
+/* 303 */ new Property(this, index, "Linear Damping"));
+/* 304 */ } else if (mode == 1) {
+/* 305 */ ret = new Float(this.linearDamp);
+/* 306 */ } else if (mode == 2)
+/* 307 */ this.linearDamp = ((Float)value).floatValue();
+/* 308 */ break;
+/* */ case 2:
+/* 310 */ if (mode == 0) {
+/* 311 */ ret = Point3PropertyEditor.make(
+/* 312 */ new Property(this, index, "Direction"));
+/* 313 */ } else if (mode == 1) {
+/* 314 */ ret = new Point3(this.dir);
+/* 315 */ } else if (mode == 2)
+/* 316 */ this.dir = ((Point3)value);
+/* 317 */ break;
+/* */ case 3:
+/* 319 */ if (mode == 0) {
+/* 320 */ ret = FloatPropertyEditor.make(
+/* 321 */ new Property(this, index, "Angular Velocity"));
+/* 322 */ } else if (mode == 1) {
+/* 323 */ ret = new Float(this.angularVel);
+/* 324 */ } else if (mode == 2)
+/* 325 */ this.angularVel = ((Float)value).floatValue();
+/* 326 */ break;
+/* */ case 4:
+/* 328 */ if (mode == 0) {
+/* 329 */ ret = FloatPropertyEditor.make(
+/* 330 */ new Property(this, index, "Angular Damping"));
+/* 331 */ } else if (mode == 1) {
+/* 332 */ ret = new Float(this.angularDamp);
+/* 333 */ } else if (mode == 2)
+/* 334 */ this.angularDamp = ((Float)value).floatValue();
+/* 335 */ break;
+/* */ case 5:
+/* 337 */ if (mode == 0) {
+/* 338 */ ret = Point3PropertyEditor.make(
+/* 339 */ new Property(this, index, "Axis"));
+/* 340 */ } else if (mode == 1) {
+/* 341 */ ret = new Point3(this.axis);
+/* 342 */ } else if (mode == 2)
+/* 343 */ this.axis = ((Point3)value);
+/* 344 */ break;
+/* */ default:
+/* 346 */ ret = super.properties(index, offset + 6, mode, value);
+/* */ }
+/* 348 */ return ret;
+/* */ }
+/* */
+/* */ public String toString()
+/* */ {
+/* 353 */ return
+/* */
+/* */
+/* */
+/* */
+/* 358 */ super.toString() + "[lin. velocity " + this.linearVel + ", lin. damp " + this.linearDamp + ", direction " + this.dir + ", ang. vel " + this.angularVel + ", ang. damp " + this.angularDamp + ", axis " + this.axis + "]";
+/* */ }
+/* */
+/* 361 */ private static Object classCookie = new Object();
+/* */
+/* */ public void saveState(Saver s) throws IOException
+/* */ {
+/* 365 */ s.saveVersion(0, classCookie);
+/* 366 */ super.saveState(s);
+/* */
+/* 368 */ s.saveFloat(this.linearVel);
+/* 369 */ s.saveFloat(this.linearDamp);
+/* 370 */ s.save(this.dir);
+/* 371 */ s.saveFloat(this.angularVel);
+/* 372 */ s.saveFloat(this.angularDamp);
+/* 373 */ s.save(this.axis);
+/* */ }
+/* */
+/* */ public void restoreState(Restorer r) throws IOException, TooNewException
+/* */ {
+/* 378 */ switch (r.restoreVersion(classCookie)) {
+/* */ case 0:
+/* 380 */ super.restoreState(r);
+/* */
+/* 382 */ this.linearVel = r.restoreFloat();
+/* 383 */ this.linearDamp = r.restoreFloat();
+/* 384 */ this.dir = ((Point3)r.restore());
+/* 385 */ this.angularVel = r.restoreFloat();
+/* 386 */ this.angularDamp = r.restoreFloat();
+/* 387 */ this.axis = ((Point3)r.restore());
+/* 388 */ break;
+/* */ default:
+/* 390 */ throw new TooNewException();
+/* */ }
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\VelocityBehavior.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file