.. | .. |
---|
286 | 286 | if (scale == 0) |
---|
287 | 287 | { |
---|
288 | 288 | // Zoom |
---|
| 289 | + double factor = Math.exp(-dy/300.0); // (1 + dy/100); |
---|
| 290 | + |
---|
289 | 291 | LA.vecSub(location, lookAt, location); |
---|
290 | 292 | |
---|
291 | 293 | cVector p = location; |
---|
292 | | - |
---|
293 | | - double factor = Math.exp(-dy/300.0); // (1 + dy/100); |
---|
294 | 294 | |
---|
295 | 295 | p.x *= factor; |
---|
296 | 296 | p.y *= factor; |
---|
.. | .. |
---|
303 | 303 | LA.vecSub(location, lookAt, direction); |
---|
304 | 304 | |
---|
305 | 305 | //scale /= Distance(); |
---|
306 | | - scale /= shaper_fovy/20; |
---|
| 306 | + // scale /= shaper_fovy/20; |
---|
307 | 307 | |
---|
308 | 308 | location.x -= dy * direction.x / scale; |
---|
309 | 309 | //location.y -= dy * direction.y / scale; |
---|
.. | .. |
---|
324 | 324 | |
---|
325 | 325 | void RotateInterest(float dx, float dy) |
---|
326 | 326 | { |
---|
| 327 | + right.mul(-1); |
---|
| 328 | + |
---|
327 | 329 | cStatic.point1.set(location); |
---|
328 | 330 | location.set(lookAt); |
---|
329 | 331 | lookAt.set(cStatic.point1); |
---|
330 | | - 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 | + } |
---|
331 | 339 | // UP.mul(-1); |
---|
332 | 340 | |
---|
333 | 341 | RotatePosition(dx,-dy); |
---|
334 | 342 | |
---|
335 | 343 | // UP.mul(-1); |
---|
336 | 344 | right.mul(-1); |
---|
| 345 | + |
---|
337 | 346 | cStatic.point1.set(location); |
---|
338 | 347 | location.set(lookAt); |
---|
339 | 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 | + } |
---|
340 | 356 | |
---|
341 | 357 | computeTransform(); |
---|
342 | 358 | } |
---|
.. | .. |
---|
351 | 367 | fromScreen = LA.newMatrix(); |
---|
352 | 368 | } |
---|
353 | 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 | + |
---|
354 | 420 | cVector up2 = up; |
---|
355 | 421 | cVector right2 = right; |
---|
356 | 422 | |
---|
357 | | - up2.x = UP.x; |
---|
358 | | - up2.y = UP.y; |
---|
359 | | - up2.z = UP.z; |
---|
360 | | - 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); |
---|
361 | 427 | LA.vecNormalize(away); |
---|
362 | 428 | LA.vecCross(away, up2, right2); |
---|
363 | 429 | if (right2.length2() < 0.0001) |
---|
364 | 430 | { |
---|
| 431 | + //System.out.println("right2.length2() < 0.0001"); |
---|
365 | 432 | // UP failed |
---|
366 | 433 | up2.x = UP2.x; |
---|
367 | 434 | up2.y = UP2.y; |
---|
368 | 435 | up2.z = UP2.z; |
---|
369 | | - LA.vecSub(lookAt, location, away); |
---|
370 | | - LA.vecNormalize(away); |
---|
371 | 436 | LA.vecCross(away, up2, right2); |
---|
372 | 437 | if (!(right2.length2() > 0)) |
---|
373 | 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 | + |
---|
374 | 444 | // old problem... |
---|
375 | 445 | assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever |
---|
376 | 446 | up2.x = UP.x = 0; |
---|
377 | 447 | up2.y = UP.y = 1; |
---|
378 | 448 | up2.z = UP.z = 0; |
---|
379 | | - LA.vecSub(lookAt, location, away); |
---|
380 | | - LA.vecNormalize(away); |
---|
381 | 449 | LA.vecCross(away, up2, right2); |
---|
382 | 450 | } |
---|
383 | 451 | } |
---|
.. | .. |
---|
400 | 468 | } |
---|
401 | 469 | |
---|
402 | 470 | for (int i=0; i < 3; i++) |
---|
403 | | - fromScreen[3][i] = location.get(i); |
---|
| 471 | + fromScreen[3][i] = locationBuf.get(i); |
---|
404 | 472 | |
---|
405 | 473 | for (int i=0; i < 3; i++) |
---|
406 | | - temp[3][i] = -location.get(i); |
---|
| 474 | + temp[3][i] = -locationBuf.get(i); |
---|
407 | 475 | |
---|
408 | 476 | LA.matConcat(temp, toScreen, toScreen); |
---|
409 | 477 | |
---|
.. | .. |
---|
490 | 558 | static final int viewFront = 2; |
---|
491 | 559 | static final int viewSide = 3; |
---|
492 | 560 | int viewCode; |
---|
| 561 | + |
---|
493 | 562 | cVector location; |
---|
494 | 563 | cVector lookAt; |
---|
| 564 | + |
---|
| 565 | + transient cVector locationBuf; |
---|
| 566 | + transient cVector lookAtBuf; |
---|
| 567 | + transient cVector upBuf; |
---|
| 568 | + //transient cVector up2Buf; |
---|
| 569 | + |
---|
495 | 570 | cVector direction; |
---|
| 571 | + |
---|
496 | 572 | double[][] toScreen; |
---|
497 | 573 | double[][] fromScreen; |
---|
| 574 | + |
---|
498 | 575 | boolean perspective; |
---|
499 | 576 | int hAspect = 0; // Free camera |
---|
500 | 577 | int vAspect; |
---|