.. | .. |
---|
3 | 3 | // Decompiler options: packimports(3) |
---|
4 | 4 | // Source File Name: Camera.java |
---|
5 | 5 | |
---|
6 | | - |
---|
7 | 6 | class Camera extends Object3D |
---|
8 | 7 | { |
---|
9 | 8 | static final long serialVersionUID = 4754289789178680517L; |
---|
.. | .. |
---|
21 | 20 | //<-2.2,0.7,-2> and pointed it at <-0.61,0.3,-0.6> |
---|
22 | 21 | // location = LA.newVector(2,0.7,-2); |
---|
23 | 22 | // lookAt = new cVector(0.6,0.3,-0.6); |
---|
24 | | - location = LA.newVector(3,2,2); |
---|
| 23 | + location = LA.newVector(6,2,4); |
---|
25 | 24 | lookAt = new cVector(0.0,0.5,0); |
---|
26 | 25 | direction = new cVector(); |
---|
27 | 26 | toParent = LA.newMatrix(); |
---|
.. | .. |
---|
53 | 52 | perspective = true; |
---|
54 | 53 | break; |
---|
55 | 54 | case 1: // '\001' |
---|
56 | | - location = LA.newVector(0, 0, 4); |
---|
| 55 | + location = LA.newVector(0, 0, 4); // Needed for translation direction |
---|
57 | 56 | perspective = false; |
---|
58 | 57 | break; |
---|
59 | 58 | case 2: // '\002' |
---|
.. | .. |
---|
64 | 63 | //LA.matXRotate(fromScreen, LA.toRadians(90)); |
---|
65 | 64 | break; |
---|
66 | 65 | case 3: // '\003' |
---|
67 | | - location = LA.newVector(4, 0, 0); |
---|
| 66 | + location = LA.newVector(4, 0, 0); // Needed for translation direction |
---|
68 | 67 | //LA.matZRotate(toScreen, LA.toRadians(-90)); |
---|
69 | 68 | //LA.matXRotate(toScreen, LA.toRadians(-90)); |
---|
70 | 69 | //LA.matXRotate(fromScreen, LA.toRadians(90)); |
---|
.. | .. |
---|
72 | 71 | perspective = false; |
---|
73 | 72 | break; |
---|
74 | 73 | case 4: // Default light |
---|
75 | | - location = LA.newVector(10, 30, 20); |
---|
| 74 | + location = LA.newVector(-5, 15, 10); |
---|
76 | 75 | perspective = false; |
---|
77 | 76 | break; |
---|
78 | 77 | } |
---|
.. | .. |
---|
105 | 104 | focalLength = 1; |
---|
106 | 105 | setAspect(4, 3); |
---|
107 | 106 | background = LA.newVector(0.8, 0.8, 0.8); |
---|
| 107 | + } |
---|
| 108 | + |
---|
| 109 | + void CreateMaterial(boolean multiply) |
---|
| 110 | + { |
---|
| 111 | + super.CreateMaterial(multiply); |
---|
| 112 | + |
---|
| 113 | + material.shift = 90; |
---|
| 114 | + material.cameralight = 0.2f; |
---|
| 115 | + material.shadowbias = 10; |
---|
108 | 116 | } |
---|
109 | 117 | |
---|
110 | 118 | void setAspect(int width, int height) |
---|
.. | .. |
---|
151 | 159 | void RotatePosition(float dx, float dy) |
---|
152 | 160 | { |
---|
153 | 161 | if(hAspect != 0) return; |
---|
| 162 | + |
---|
| 163 | + if (CameraPane.IMAGEFLIP) |
---|
| 164 | + { |
---|
| 165 | + dx = -dx; |
---|
| 166 | + } |
---|
154 | 167 | |
---|
155 | 168 | if (CameraPane.ROTATECAMERA) |
---|
156 | 169 | { |
---|
.. | .. |
---|
208 | 221 | void Translate(float dx, float dy, float scale) |
---|
209 | 222 | { |
---|
210 | 223 | if(hAspect != 0) return; |
---|
| 224 | + |
---|
| 225 | + if (CameraPane.IMAGEFLIP) |
---|
| 226 | + { |
---|
| 227 | + dx = -dx; |
---|
| 228 | + } |
---|
211 | 229 | |
---|
212 | 230 | if (CameraPane.ROTATECAMERA) |
---|
213 | 231 | { |
---|
.. | .. |
---|
268 | 286 | if (scale == 0) |
---|
269 | 287 | { |
---|
270 | 288 | // Zoom |
---|
| 289 | + double factor = Math.exp(-dy/300.0); // (1 + dy/100); |
---|
| 290 | + |
---|
271 | 291 | LA.vecSub(location, lookAt, location); |
---|
272 | 292 | |
---|
273 | 293 | cVector p = location; |
---|
274 | | - |
---|
275 | | - double factor = Math.exp(-dy/300.0); // (1 + dy/100); |
---|
276 | 294 | |
---|
277 | 295 | p.x *= factor; |
---|
278 | 296 | p.y *= factor; |
---|
.. | .. |
---|
285 | 303 | LA.vecSub(location, lookAt, direction); |
---|
286 | 304 | |
---|
287 | 305 | //scale /= Distance(); |
---|
288 | | - scale /= shaper_fovy/20; |
---|
| 306 | + // scale /= shaper_fovy/20; |
---|
289 | 307 | |
---|
290 | 308 | location.x -= dy * direction.x / scale; |
---|
291 | 309 | //location.y -= dy * direction.y / scale; |
---|
.. | .. |
---|
306 | 324 | |
---|
307 | 325 | void RotateInterest(float dx, float dy) |
---|
308 | 326 | { |
---|
| 327 | + right.mul(-1); |
---|
| 328 | + |
---|
309 | 329 | cStatic.point1.set(location); |
---|
310 | 330 | location.set(lookAt); |
---|
311 | 331 | lookAt.set(cStatic.point1); |
---|
312 | | - right.mul(-1); |
---|
| 332 | + |
---|
| 333 | + if (viewCode == 0 && locationBuf != null) |
---|
| 334 | + { |
---|
| 335 | + cStatic.point1.set(locationBuf); |
---|
| 336 | + locationBuf.set(lookAtBuf); |
---|
| 337 | + lookAtBuf.set(cStatic.point1); |
---|
| 338 | + } |
---|
313 | 339 | // UP.mul(-1); |
---|
314 | 340 | |
---|
315 | 341 | RotatePosition(dx,-dy); |
---|
316 | 342 | |
---|
317 | 343 | // UP.mul(-1); |
---|
318 | 344 | right.mul(-1); |
---|
| 345 | + |
---|
319 | 346 | cStatic.point1.set(location); |
---|
320 | 347 | location.set(lookAt); |
---|
321 | 348 | lookAt.set(cStatic.point1); |
---|
| 349 | + |
---|
| 350 | + if (viewCode == 0 && locationBuf != null) |
---|
| 351 | + { |
---|
| 352 | + cStatic.point1.set(locationBuf); |
---|
| 353 | + locationBuf.set(lookAtBuf); |
---|
| 354 | + lookAtBuf.set(cStatic.point1); |
---|
| 355 | + } |
---|
322 | 356 | |
---|
323 | 357 | computeTransform(); |
---|
324 | 358 | } |
---|
.. | .. |
---|
333 | 367 | fromScreen = LA.newMatrix(); |
---|
334 | 368 | } |
---|
335 | 369 | |
---|
| 370 | + if (locationBuf == null) |
---|
| 371 | + { |
---|
| 372 | + locationBuf = new cVector(); |
---|
| 373 | + locationBuf.set(location); |
---|
| 374 | + lookAtBuf = new cVector(); |
---|
| 375 | + lookAtBuf.set(lookAt); |
---|
| 376 | + upBuf = new cVector(); |
---|
| 377 | + upBuf.set(UP); |
---|
| 378 | +// up2Buf = new cVector(); |
---|
| 379 | +// up2Buf.set(UP2); |
---|
| 380 | + } |
---|
| 381 | + else |
---|
| 382 | + { |
---|
| 383 | + double K = 0.25; |
---|
| 384 | + |
---|
| 385 | + if (!CameraPane.capsLocked || CameraPane.ambientOcclusion) |
---|
| 386 | + K = 1; |
---|
| 387 | + |
---|
| 388 | + locationBuf.y = location.y * K + locationBuf.y * (1 - K); |
---|
| 389 | + lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K); |
---|
| 390 | + |
---|
| 391 | + int Y = 1; |
---|
| 392 | + |
---|
| 393 | + if (UP.y < 0) |
---|
| 394 | + Y = -1; |
---|
| 395 | + |
---|
| 396 | + UP.x = 0 * K + UP.x * (1 - K); |
---|
| 397 | + UP.y = Y * K + UP.y * (1 - K); |
---|
| 398 | + UP.z = 0 * K + UP.z * (1 - K); |
---|
| 399 | + UP.normalize(); |
---|
| 400 | + |
---|
| 401 | + if (CameraPane.capsLocked && !CameraPane.ambientOcclusion) |
---|
| 402 | + K = 0.1; |
---|
| 403 | + |
---|
| 404 | + upBuf.x = UP.x * K + upBuf.x * (1 - K); |
---|
| 405 | + upBuf.y = UP.y * K + upBuf.y * (1 - K); |
---|
| 406 | + upBuf.z = UP.z * K + upBuf.z * (1 - K); |
---|
| 407 | + upBuf.normalize(); |
---|
| 408 | +// up2Buf.x = UP2.x * K + up2Buf.x * (1 - K); |
---|
| 409 | +// up2Buf.y = UP2.y * K + up2Buf.y * (1 - K); |
---|
| 410 | +// up2Buf.z = UP2.z * K + up2Buf.z * (1 - K); |
---|
| 411 | + |
---|
| 412 | + K = 1; |
---|
| 413 | + |
---|
| 414 | + locationBuf.x = location.x * K + locationBuf.x * (1 - K); |
---|
| 415 | + locationBuf.z = location.z * K + locationBuf.z * (1 - K); |
---|
| 416 | + lookAtBuf.x = lookAt.x * K + lookAtBuf.x * (1 - K); |
---|
| 417 | + lookAtBuf.z = lookAt.z * K + lookAtBuf.z * (1 - K); |
---|
| 418 | + } |
---|
| 419 | + |
---|
336 | 420 | cVector up2 = up; |
---|
337 | 421 | cVector right2 = right; |
---|
338 | 422 | |
---|
339 | | - up2.x = UP.x; |
---|
340 | | - up2.y = UP.y; |
---|
341 | | - up2.z = UP.z; |
---|
342 | | - LA.vecSub(lookAt, location, away); |
---|
| 423 | + up2.x = upBuf.x; |
---|
| 424 | + up2.y = upBuf.y; |
---|
| 425 | + up2.z = upBuf.z; |
---|
| 426 | + LA.vecSub(lookAtBuf, locationBuf, away); |
---|
343 | 427 | LA.vecNormalize(away); |
---|
344 | 428 | LA.vecCross(away, up2, right2); |
---|
345 | 429 | if (right2.length2() < 0.0001) |
---|
346 | 430 | { |
---|
| 431 | + //System.out.println("right2.length2() < 0.0001"); |
---|
347 | 432 | // UP failed |
---|
348 | 433 | up2.x = UP2.x; |
---|
349 | 434 | up2.y = UP2.y; |
---|
350 | 435 | up2.z = UP2.z; |
---|
351 | | - LA.vecSub(lookAt, location, away); |
---|
352 | | - LA.vecNormalize(away); |
---|
353 | 436 | LA.vecCross(away, up2, right2); |
---|
354 | 437 | if (!(right2.length2() > 0)) |
---|
355 | 438 | { |
---|
| 439 | + System.out.println("NO UP VECTOR: " + up2); |
---|
| 440 | + System.out.println("lookAtBuf: " + lookAtBuf); |
---|
| 441 | + System.out.println("locationBuf: " + locationBuf); |
---|
| 442 | + System.exit(0); |
---|
| 443 | + |
---|
356 | 444 | // old problem... |
---|
357 | 445 | assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever |
---|
358 | 446 | up2.x = UP.x = 0; |
---|
359 | 447 | up2.y = UP.y = 1; |
---|
360 | 448 | up2.z = UP.z = 0; |
---|
361 | | - LA.vecSub(lookAt, location, away); |
---|
362 | | - LA.vecNormalize(away); |
---|
363 | 449 | LA.vecCross(away, up2, right2); |
---|
364 | 450 | } |
---|
365 | 451 | } |
---|
.. | .. |
---|
382 | 468 | } |
---|
383 | 469 | |
---|
384 | 470 | for (int i=0; i < 3; i++) |
---|
385 | | - fromScreen[3][i] = location.get(i); |
---|
| 471 | + fromScreen[3][i] = locationBuf.get(i); |
---|
386 | 472 | |
---|
387 | 473 | for (int i=0; i < 3; i++) |
---|
388 | | - temp[3][i] = -location.get(i); |
---|
| 474 | + temp[3][i] = -locationBuf.get(i); |
---|
389 | 475 | |
---|
390 | 476 | LA.matConcat(temp, toScreen, toScreen); |
---|
391 | 477 | |
---|
.. | .. |
---|
397 | 483 | LA.matConcat(fromScreen, rotate, fromScreen); |
---|
398 | 484 | //LA.matConcat(toScreen, rotate_1, toScreen); |
---|
399 | 485 | } |
---|
| 486 | + |
---|
| 487 | + if (CameraPane.IMAGEFLIP) |
---|
| 488 | + { |
---|
| 489 | + double[][] flip = { { -1,0,0,0 }, { 0,1,0,0}, { 0,0,1,0}, { 0,0,0,1 } }; |
---|
| 490 | + |
---|
| 491 | + LA.matConcat(fromScreen, flip, fromScreen); |
---|
| 492 | + } |
---|
| 493 | + |
---|
400 | 494 | //if (this == CameraPane.lightCamera) |
---|
401 | 495 | //CameraPane.lighttouched = true; |
---|
402 | | - |
---|
403 | 496 | LA.matInvert(fromScreen, toScreen); |
---|
404 | 497 | } |
---|
405 | 498 | |
---|
.. | .. |
---|
465 | 558 | static final int viewFront = 2; |
---|
466 | 559 | static final int viewSide = 3; |
---|
467 | 560 | int viewCode; |
---|
| 561 | + |
---|
468 | 562 | cVector location; |
---|
469 | 563 | cVector lookAt; |
---|
| 564 | + |
---|
| 565 | + transient cVector locationBuf; |
---|
| 566 | + transient cVector lookAtBuf; |
---|
| 567 | + transient cVector upBuf; |
---|
| 568 | + //transient cVector up2Buf; |
---|
| 569 | + |
---|
470 | 570 | cVector direction; |
---|
471 | | - double toScreen[][]; |
---|
472 | | - double fromScreen[][]; |
---|
| 571 | + |
---|
| 572 | + double[][] toScreen; |
---|
| 573 | + double[][] fromScreen; |
---|
| 574 | + |
---|
473 | 575 | boolean perspective; |
---|
474 | 576 | int hAspect = 0; // Free camera |
---|
475 | 577 | int vAspect; |
---|