.. | .. |
---|
288 | 288 | // Zoom |
---|
289 | 289 | double factor = Math.exp(-dy/300.0); // (1 + dy/100); |
---|
290 | 290 | |
---|
291 | | - if (viewCode != 0) |
---|
292 | | - { |
---|
293 | | - LA.vecSub(location, lookAt, location); |
---|
| 291 | + LA.vecSub(location, lookAt, location); |
---|
294 | 292 | |
---|
295 | | - cVector p = location; |
---|
| 293 | + cVector p = location; |
---|
296 | 294 | |
---|
297 | | - p.x *= factor; |
---|
298 | | - p.y *= factor; |
---|
299 | | - p.z *= factor; |
---|
| 295 | + p.x *= factor; |
---|
| 296 | + p.y *= factor; |
---|
| 297 | + p.z *= factor; |
---|
300 | 298 | |
---|
301 | | - LA.vecAdd(location, lookAt, location); |
---|
302 | | - } |
---|
303 | | - else |
---|
304 | | - if (//shaper_fovy < 180 && factor > 1 || |
---|
305 | | - shaper_fovy * factor < 150) |
---|
306 | | - { |
---|
307 | | - shaper_fovy *= factor; |
---|
308 | | - //System.out.println("fovy = " + shaper_fovy); |
---|
309 | | - } |
---|
| 299 | + LA.vecAdd(location, lookAt, location); |
---|
310 | 300 | } |
---|
311 | 301 | else |
---|
312 | 302 | { |
---|
.. | .. |
---|
334 | 324 | |
---|
335 | 325 | void RotateInterest(float dx, float dy) |
---|
336 | 326 | { |
---|
| 327 | + right.mul(-1); |
---|
| 328 | + |
---|
337 | 329 | cStatic.point1.set(location); |
---|
338 | 330 | location.set(lookAt); |
---|
339 | 331 | lookAt.set(cStatic.point1); |
---|
340 | | - 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 | + } |
---|
341 | 339 | // UP.mul(-1); |
---|
342 | 340 | |
---|
343 | 341 | RotatePosition(dx,-dy); |
---|
344 | 342 | |
---|
345 | 343 | // UP.mul(-1); |
---|
346 | 344 | right.mul(-1); |
---|
| 345 | + |
---|
347 | 346 | cStatic.point1.set(location); |
---|
348 | 347 | location.set(lookAt); |
---|
349 | 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 | + } |
---|
350 | 356 | |
---|
351 | 357 | computeTransform(); |
---|
352 | 358 | } |
---|
.. | .. |
---|
361 | 367 | fromScreen = LA.newMatrix(); |
---|
362 | 368 | } |
---|
363 | 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 | + |
---|
364 | 420 | cVector up2 = up; |
---|
365 | 421 | cVector right2 = right; |
---|
366 | 422 | |
---|
367 | | - up2.x = UP.x; |
---|
368 | | - up2.y = UP.y; |
---|
369 | | - up2.z = UP.z; |
---|
370 | | - 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); |
---|
371 | 427 | LA.vecNormalize(away); |
---|
372 | 428 | LA.vecCross(away, up2, right2); |
---|
373 | 429 | if (right2.length2() < 0.0001) |
---|
374 | 430 | { |
---|
| 431 | + //System.out.println("right2.length2() < 0.0001"); |
---|
375 | 432 | // UP failed |
---|
376 | 433 | up2.x = UP2.x; |
---|
377 | 434 | up2.y = UP2.y; |
---|
378 | 435 | up2.z = UP2.z; |
---|
379 | | - LA.vecSub(lookAt, location, away); |
---|
380 | | - LA.vecNormalize(away); |
---|
381 | 436 | LA.vecCross(away, up2, right2); |
---|
382 | 437 | if (!(right2.length2() > 0)) |
---|
383 | 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 | + |
---|
384 | 444 | // old problem... |
---|
385 | 445 | assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever |
---|
386 | 446 | up2.x = UP.x = 0; |
---|
387 | 447 | up2.y = UP.y = 1; |
---|
388 | 448 | up2.z = UP.z = 0; |
---|
389 | | - LA.vecSub(lookAt, location, away); |
---|
390 | | - LA.vecNormalize(away); |
---|
391 | 449 | LA.vecCross(away, up2, right2); |
---|
392 | 450 | } |
---|
393 | 451 | } |
---|
.. | .. |
---|
410 | 468 | } |
---|
411 | 469 | |
---|
412 | 470 | for (int i=0; i < 3; i++) |
---|
413 | | - fromScreen[3][i] = location.get(i); |
---|
| 471 | + fromScreen[3][i] = locationBuf.get(i); |
---|
414 | 472 | |
---|
415 | 473 | for (int i=0; i < 3; i++) |
---|
416 | | - temp[3][i] = -location.get(i); |
---|
| 474 | + temp[3][i] = -locationBuf.get(i); |
---|
417 | 475 | |
---|
418 | 476 | LA.matConcat(temp, toScreen, toScreen); |
---|
419 | 477 | |
---|
.. | .. |
---|
500 | 558 | static final int viewFront = 2; |
---|
501 | 559 | static final int viewSide = 3; |
---|
502 | 560 | int viewCode; |
---|
| 561 | + |
---|
503 | 562 | cVector location; |
---|
504 | 563 | cVector lookAt; |
---|
| 564 | + |
---|
| 565 | + transient cVector locationBuf; |
---|
| 566 | + transient cVector lookAtBuf; |
---|
| 567 | + transient cVector upBuf; |
---|
| 568 | + //transient cVector up2Buf; |
---|
| 569 | + |
---|
505 | 570 | cVector direction; |
---|
| 571 | + |
---|
506 | 572 | double[][] toScreen; |
---|
507 | 573 | double[][] fromScreen; |
---|
| 574 | + |
---|
508 | 575 | boolean perspective; |
---|
509 | 576 | int hAspect = 0; // Free camera |
---|
510 | 577 | int vAspect; |
---|