summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/PitchDriver.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-03 16:38:41 -0700
committerFuwn <[email protected]>2021-05-03 16:38:41 -0700
commite1e781bb2135ef78592226f1a3eaba4925702f1f (patch)
tree8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/scape/PitchDriver.java
downloadworlds.jar-main.tar.xz
worlds.jar-main.zip
:star:HEADmain
Diffstat (limited to 'NET/worlds/scape/PitchDriver.java')
-rw-r--r--NET/worlds/scape/PitchDriver.java293
1 files changed, 293 insertions, 0 deletions
diff --git a/NET/worlds/scape/PitchDriver.java b/NET/worlds/scape/PitchDriver.java
new file mode 100644
index 0000000..c5293c8
--- /dev/null
+++ b/NET/worlds/scape/PitchDriver.java
@@ -0,0 +1,293 @@
+/* */ package NET.worlds.scape;
+/* */
+/* */ import java.io.IOException;
+/* */ import java.util.Enumeration;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public class PitchDriver
+/* */ extends SwitchableBehavior
+/* */ implements KeyUpHandler, KeyDownHandler, FrameHandler, Persister, MomentumBehavior
+/* */ {
+/* */ protected float pitch_force;
+/* */ protected float pitch_vel;
+/* */ protected int lastTime;
+/* 40 */ protected float maxdvpitch = 166.0F;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 46 */ protected float pitch_damp = -5.0F;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 52 */ protected float minpitch_vel = 3.0F;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public void applyFrameForce(Event e)
+/* */ {
+/* 63 */ if (!(e.receiver instanceof Pilot)) {
+/* 64 */ return;
+/* */ }
+/* 66 */ Camera cam = ((Pilot)e.receiver).getMainCamera();
+/* */
+/* */
+/* 69 */ int now = e.time;
+/* 70 */ float dt = (now - this.lastTime) / 1000.0F;
+/* */
+/* */
+/* */
+/* 74 */ if (dt <= 0.0F) {
+/* 75 */ return;
+/* */ }
+/* 77 */ this.lastTime = now;
+/* */
+/* */
+/* */
+/* 81 */ float dTheta = this.pitch_vel * dt;
+/* */
+/* */
+/* 84 */ float dv = 0.0F;
+/* */
+/* 86 */ if (this.pitch_force != 0.0F)
+/* */ {
+/* 88 */ dv += this.pitch_force * dt;
+/* */
+/* */
+/* */
+/* */
+/* 93 */ dv = this.maxdvpitch * (float)Math.atan(dv / this.maxdvpitch);
+/* */
+/* 95 */ this.pitch_vel += dv;
+/* 96 */ dTheta += dv * dt;
+/* */ }
+/* */
+/* 99 */ if (dTheta != 0.0F) {
+/* 100 */ Point3Temp axis = Point3Temp.make();
+/* 101 */ float angle = cam.lookAround.getSpin(axis);
+/* 102 */ if (axis.x < 0.0F)
+/* 103 */ angle = -angle;
+/* 104 */ if (angle + dTheta > 90.0F) {
+/* 105 */ dTheta = 90.0F - angle;
+/* 106 */ } else if (angle + dTheta < -90.0F)
+/* 107 */ dTheta = -90.0F - angle;
+/* 108 */ cam.lookAround.spin(1.0F, 0.0F, 0.0F, dTheta);
+/* */ }
+/* */
+/* 111 */ this.pitch_vel = ((float)(this.pitch_vel * Math.exp(this.pitch_damp * dt)));
+/* 112 */ if (Math.abs(this.pitch_vel) < this.minpitch_vel) {
+/* 113 */ this.pitch_vel = 0.0F;
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public boolean handle(FrameEvent e)
+/* */ {
+/* 122 */ applyFrameForce(e);
+/* 123 */ return true;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public void resetPitch(Event e)
+/* */ {
+/* 131 */ Camera cam = ((Pilot)e.receiver).getMainCamera();
+/* */
+/* 133 */ cam.lookAround.makeIdentity();
+/* */ }
+/* */
+/* */
+/* 137 */ protected float pitch_key = 500.0F;
+/* */
+/* */
+/* */
+/* */ public boolean handle(KeyDownEvent e)
+/* */ {
+/* */ float pitch;
+/* */
+/* 145 */ if (e.getKey() == 58145) {
+/* 146 */ pitch = this.pitch_key; } else { float pitch;
+/* 147 */ if (e.getKey() == 58146) {
+/* 148 */ pitch = -this.pitch_key;
+/* */ } else {
+/* 150 */ if (e.getKey() == 58148) {
+/* 151 */ resetPitch(e);
+/* */ }
+/* 153 */ return true; } }
+/* */ float pitch;
+/* 155 */ applyFrameForce(e);
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 164 */ this.pitch_force = pitch;
+/* 165 */ return true;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public boolean handle(KeyUpEvent e)
+/* */ {
+/* 174 */ if ((e.getKey() == 58145) || (e.getKey() == 58146))
+/* */ {
+/* 176 */ applyFrameForce(e);
+/* 177 */ this.pitch_force = 0.0F;
+/* */ }
+/* 179 */ return true;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public Object properties(int index, int offset, int mode, Object value)
+/* */ throws NoSuchPropertyException
+/* */ {
+/* 188 */ Object ret = null;
+/* 189 */ switch (index - offset) {
+/* */ case 0:
+/* 191 */ if (mode == 0) {
+/* 192 */ ret = FloatPropertyEditor.make(
+/* 193 */ new Property(this, index, "Pitch max acceleration"));
+/* 194 */ } else if (mode == 1) {
+/* 195 */ ret = new Float(this.maxdvpitch);
+/* 196 */ } else if (mode == 2)
+/* 197 */ this.maxdvpitch = ((Float)value).intValue();
+/* 198 */ break;
+/* */ case 1:
+/* 200 */ if (mode == 0) {
+/* 201 */ ret = FloatPropertyEditor.make(
+/* 202 */ new Property(this, index, "Pitch rate damping"));
+/* 203 */ } else if (mode == 1) {
+/* 204 */ ret = new Float(this.pitch_damp);
+/* 205 */ } else if (mode == 2)
+/* 206 */ this.pitch_damp = ((Float)value).intValue();
+/* 207 */ break;
+/* */ case 2:
+/* 209 */ if (mode == 0) {
+/* 210 */ ret = FloatPropertyEditor.make(
+/* 211 */ new Property(this, index, "Pitch min rate"));
+/* 212 */ } else if (mode == 1) {
+/* 213 */ ret = new Float(this.minpitch_vel);
+/* 214 */ } else if (mode == 2)
+/* 215 */ this.minpitch_vel = ((Float)value).intValue();
+/* 216 */ break;
+/* */ case 3:
+/* 218 */ if (mode == 0) {
+/* 219 */ ret = FloatPropertyEditor.make(
+/* 220 */ new Property(this, index,
+/* 221 */ "Pitch rate increment for up/down arrow keys"));
+/* 222 */ } else if (mode == 1) {
+/* 223 */ ret = new Float(this.pitch_key);
+/* 224 */ } else if (mode == 2)
+/* 225 */ this.pitch_key = ((Float)value).intValue();
+/* 226 */ break;
+/* */ default:
+/* 228 */ ret = super.properties(index, offset + 12, mode, value);
+/* */ }
+/* 230 */ return ret;
+/* */ }
+/* */
+/* */
+/* 234 */ private static Object cookie = new Object();
+/* */
+/* */ public void saveState(Saver s) throws IOException
+/* */ {
+/* 238 */ s.saveVersion(1, cookie);
+/* 239 */ super.saveState(s);
+/* 240 */ s.saveFloat(this.pitch_vel);
+/* 241 */ s.saveFloat(this.maxdvpitch);
+/* 242 */ s.saveFloat(this.pitch_damp);
+/* 243 */ s.saveFloat(this.minpitch_vel);
+/* 244 */ s.saveFloat(this.pitch_key);
+/* */ }
+/* */
+/* */ public void restoreState(Restorer r) throws IOException, TooNewException
+/* */ {
+/* 249 */ switch (r.restoreVersion(cookie)) {
+/* */ case 0:
+/* 251 */ r.setOldFlag();
+/* 252 */ super.restoreState(r);
+/* 253 */ r.restoreFloat();
+/* 254 */ this.pitch_vel = r.restoreFloat();
+/* 255 */ this.maxdvpitch = r.restoreFloat();
+/* 256 */ this.pitch_damp = r.restoreFloat();
+/* 257 */ this.minpitch_vel = r.restoreFloat();
+/* 258 */ this.pitch_key = r.restoreFloat();
+/* 259 */ break;
+/* */ case 1:
+/* 261 */ super.restoreState(r);
+/* 262 */ this.pitch_vel = r.restoreFloat();
+/* 263 */ this.maxdvpitch = r.restoreFloat();
+/* 264 */ this.pitch_damp = r.restoreFloat();
+/* 265 */ this.minpitch_vel = r.restoreFloat();
+/* 266 */ this.pitch_key = r.restoreFloat();
+/* 267 */ break;
+/* */ default:
+/* 269 */ throw new TooNewException();
+/* */ }
+/* */
+/* */ }
+/* */
+/* */ public void transferFrom(Enumeration<Object> oldMBs)
+/* */ {
+/* 276 */ while (oldMBs.hasMoreElements()) {
+/* 277 */ SuperRoot sr = (SuperRoot)oldMBs.nextElement();
+/* 278 */ if ((sr instanceof PitchDriver)) {
+/* 279 */ PitchDriver pd = (PitchDriver)sr;
+/* 280 */ this.pitch_vel = pd.pitch_vel;
+/* 281 */ this.pitch_force = pd.pitch_force;
+/* 282 */ this.lastTime = pd.lastTime;
+/* 283 */ break;
+/* */ }
+/* */ }
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\PitchDriver.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file