.. | .. |
---|
160 | 160 | { |
---|
161 | 161 | if(hAspect != 0) return; |
---|
162 | 162 | |
---|
| 163 | + if (CameraPane.IMAGEFLIP) |
---|
| 164 | + { |
---|
| 165 | + dx = -dx; |
---|
| 166 | + } |
---|
| 167 | + |
---|
163 | 168 | if (CameraPane.ROTATECAMERA) |
---|
164 | 169 | { |
---|
165 | 170 | float t = dx; |
---|
.. | .. |
---|
216 | 221 | void Translate(float dx, float dy, float scale) |
---|
217 | 222 | { |
---|
218 | 223 | if(hAspect != 0) return; |
---|
| 224 | + |
---|
| 225 | + if (CameraPane.IMAGEFLIP) |
---|
| 226 | + { |
---|
| 227 | + dx = -dx; |
---|
| 228 | + } |
---|
219 | 229 | |
---|
220 | 230 | if (CameraPane.ROTATECAMERA) |
---|
221 | 231 | { |
---|
.. | .. |
---|
276 | 286 | if (scale == 0) |
---|
277 | 287 | { |
---|
278 | 288 | // Zoom |
---|
279 | | - LA.vecSub(location, lookAt, location); |
---|
280 | | - |
---|
281 | | - cVector p = location; |
---|
282 | | - |
---|
283 | 289 | double factor = Math.exp(-dy/300.0); // (1 + dy/100); |
---|
284 | 290 | |
---|
285 | | - p.x *= factor; |
---|
286 | | - p.y *= factor; |
---|
287 | | - p.z *= factor; |
---|
| 291 | + if (viewCode != 0) |
---|
| 292 | + { |
---|
| 293 | + LA.vecSub(location, lookAt, location); |
---|
288 | 294 | |
---|
289 | | - LA.vecAdd(location, lookAt, location); |
---|
| 295 | + cVector p = location; |
---|
| 296 | + |
---|
| 297 | + p.x *= factor; |
---|
| 298 | + p.y *= factor; |
---|
| 299 | + p.z *= factor; |
---|
| 300 | + |
---|
| 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 | + } |
---|
290 | 310 | } |
---|
291 | 311 | else |
---|
292 | 312 | { |
---|
293 | 313 | LA.vecSub(location, lookAt, direction); |
---|
294 | 314 | |
---|
295 | 315 | //scale /= Distance(); |
---|
296 | | - scale /= shaper_fovy/20; |
---|
| 316 | + // scale /= shaper_fovy/20; |
---|
297 | 317 | |
---|
298 | 318 | location.x -= dy * direction.x / scale; |
---|
299 | 319 | //location.y -= dy * direction.y / scale; |
---|
.. | .. |
---|
314 | 334 | |
---|
315 | 335 | void RotateInterest(float dx, float dy) |
---|
316 | 336 | { |
---|
| 337 | + right.mul(-1); |
---|
| 338 | + |
---|
317 | 339 | cStatic.point1.set(location); |
---|
318 | 340 | location.set(lookAt); |
---|
319 | 341 | lookAt.set(cStatic.point1); |
---|
320 | | - right.mul(-1); |
---|
| 342 | + |
---|
| 343 | + cStatic.point1.set(locationBuf); |
---|
| 344 | + locationBuf.set(lookAtBuf); |
---|
| 345 | + lookAtBuf.set(cStatic.point1); |
---|
321 | 346 | // UP.mul(-1); |
---|
322 | 347 | |
---|
323 | 348 | RotatePosition(dx,-dy); |
---|
324 | 349 | |
---|
325 | 350 | // UP.mul(-1); |
---|
326 | 351 | right.mul(-1); |
---|
| 352 | + |
---|
327 | 353 | cStatic.point1.set(location); |
---|
328 | 354 | location.set(lookAt); |
---|
329 | 355 | lookAt.set(cStatic.point1); |
---|
| 356 | + |
---|
| 357 | + cStatic.point1.set(locationBuf); |
---|
| 358 | + locationBuf.set(lookAtBuf); |
---|
| 359 | + lookAtBuf.set(cStatic.point1); |
---|
330 | 360 | |
---|
331 | 361 | computeTransform(); |
---|
332 | 362 | } |
---|
.. | .. |
---|
341 | 371 | fromScreen = LA.newMatrix(); |
---|
342 | 372 | } |
---|
343 | 373 | |
---|
| 374 | + if (locationBuf == null) |
---|
| 375 | + { |
---|
| 376 | + locationBuf = new cVector(); |
---|
| 377 | + locationBuf.set(location); |
---|
| 378 | + lookAtBuf = new cVector(); |
---|
| 379 | + lookAtBuf.set(lookAt); |
---|
| 380 | + upBuf = new cVector(); |
---|
| 381 | + upBuf.set(UP); |
---|
| 382 | +// up2Buf = new cVector(); |
---|
| 383 | +// up2Buf.set(UP2); |
---|
| 384 | + } |
---|
| 385 | + else |
---|
| 386 | + { |
---|
| 387 | + double K = 0.25; |
---|
| 388 | + |
---|
| 389 | + locationBuf.y = location.y * K + locationBuf.y * (1 - K); |
---|
| 390 | + lookAtBuf.y = lookAt.y * K + lookAtBuf.y * (1 - K); |
---|
| 391 | + |
---|
| 392 | + upBuf.x = UP.x * K + upBuf.x * (1 - K); |
---|
| 393 | + upBuf.y = UP.y * K + upBuf.y * (1 - K); |
---|
| 394 | + upBuf.z = UP.z * K + upBuf.z * (1 - K); |
---|
| 395 | + upBuf.normalize(); |
---|
| 396 | +// up2Buf.x = UP2.x * K + up2Buf.x * (1 - K); |
---|
| 397 | +// up2Buf.y = UP2.y * K + up2Buf.y * (1 - K); |
---|
| 398 | +// up2Buf.z = UP2.z * K + up2Buf.z * (1 - K); |
---|
| 399 | + |
---|
| 400 | + K = 1; |
---|
| 401 | + |
---|
| 402 | + locationBuf.x = location.x * K + locationBuf.x * (1 - K); |
---|
| 403 | + locationBuf.z = location.z * K + locationBuf.z * (1 - K); |
---|
| 404 | + lookAtBuf.x = lookAt.x * K + lookAtBuf.x * (1 - K); |
---|
| 405 | + lookAtBuf.z = lookAt.z * K + lookAtBuf.z * (1 - K); |
---|
| 406 | + } |
---|
| 407 | + |
---|
344 | 408 | cVector up2 = up; |
---|
345 | 409 | cVector right2 = right; |
---|
346 | 410 | |
---|
347 | | - up2.x = UP.x; |
---|
348 | | - up2.y = UP.y; |
---|
349 | | - up2.z = UP.z; |
---|
350 | | - LA.vecSub(lookAt, location, away); |
---|
| 411 | + up2.x = upBuf.x; |
---|
| 412 | + up2.y = upBuf.y; |
---|
| 413 | + up2.z = upBuf.z; |
---|
| 414 | + LA.vecSub(lookAtBuf, locationBuf, away); |
---|
351 | 415 | LA.vecNormalize(away); |
---|
352 | 416 | LA.vecCross(away, up2, right2); |
---|
353 | 417 | if (right2.length2() < 0.0001) |
---|
354 | 418 | { |
---|
| 419 | + //System.out.println("right2.length2() < 0.0001"); |
---|
355 | 420 | // UP failed |
---|
356 | 421 | up2.x = UP2.x; |
---|
357 | 422 | up2.y = UP2.y; |
---|
.. | .. |
---|
361 | 426 | LA.vecCross(away, up2, right2); |
---|
362 | 427 | if (!(right2.length2() > 0)) |
---|
363 | 428 | { |
---|
| 429 | + System.exit(0); |
---|
364 | 430 | // old problem... |
---|
365 | 431 | assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever |
---|
366 | 432 | up2.x = UP.x = 0; |
---|
.. | .. |
---|
390 | 456 | } |
---|
391 | 457 | |
---|
392 | 458 | for (int i=0; i < 3; i++) |
---|
393 | | - fromScreen[3][i] = location.get(i); |
---|
| 459 | + fromScreen[3][i] = locationBuf.get(i); |
---|
394 | 460 | |
---|
395 | 461 | for (int i=0; i < 3; i++) |
---|
396 | | - temp[3][i] = -location.get(i); |
---|
| 462 | + temp[3][i] = -locationBuf.get(i); |
---|
397 | 463 | |
---|
398 | 464 | LA.matConcat(temp, toScreen, toScreen); |
---|
399 | 465 | |
---|
.. | .. |
---|
405 | 471 | LA.matConcat(fromScreen, rotate, fromScreen); |
---|
406 | 472 | //LA.matConcat(toScreen, rotate_1, toScreen); |
---|
407 | 473 | } |
---|
| 474 | + |
---|
| 475 | + if (CameraPane.IMAGEFLIP) |
---|
| 476 | + { |
---|
| 477 | + double[][] flip = { { -1,0,0,0 }, { 0,1,0,0}, { 0,0,1,0}, { 0,0,0,1 } }; |
---|
| 478 | + |
---|
| 479 | + LA.matConcat(fromScreen, flip, fromScreen); |
---|
| 480 | + } |
---|
| 481 | + |
---|
408 | 482 | //if (this == CameraPane.lightCamera) |
---|
409 | 483 | //CameraPane.lighttouched = true; |
---|
410 | | - |
---|
411 | 484 | LA.matInvert(fromScreen, toScreen); |
---|
412 | 485 | } |
---|
413 | 486 | |
---|
.. | .. |
---|
473 | 546 | static final int viewFront = 2; |
---|
474 | 547 | static final int viewSide = 3; |
---|
475 | 548 | int viewCode; |
---|
| 549 | + |
---|
476 | 550 | cVector location; |
---|
477 | 551 | cVector lookAt; |
---|
| 552 | + |
---|
| 553 | + transient cVector locationBuf; |
---|
| 554 | + transient cVector lookAtBuf; |
---|
| 555 | + transient cVector upBuf; |
---|
| 556 | + //transient cVector up2Buf; |
---|
| 557 | + |
---|
478 | 558 | cVector direction; |
---|
| 559 | + |
---|
479 | 560 | double[][] toScreen; |
---|
480 | 561 | double[][] fromScreen; |
---|
| 562 | + |
---|
481 | 563 | boolean perspective; |
---|
482 | 564 | int hAspect = 0; // Free camera |
---|
483 | 565 | int vAspect; |
---|