.. | .. |
---|
52 | 52 | perspective = true; |
---|
53 | 53 | break; |
---|
54 | 54 | case 1: // '\001' |
---|
55 | | - location = LA.newVector(4, 0, 0); |
---|
| 55 | + location = LA.newVector(0, 0, 4); // Needed for translation direction |
---|
56 | 56 | perspective = false; |
---|
57 | 57 | break; |
---|
58 | 58 | case 2: // '\002' |
---|
.. | .. |
---|
63 | 63 | //LA.matXRotate(fromScreen, LA.toRadians(90)); |
---|
64 | 64 | break; |
---|
65 | 65 | case 3: // '\003' |
---|
66 | | - location = LA.newVector(0, 0, 4); |
---|
| 66 | + location = LA.newVector(4, 0, 0); // Needed for translation direction |
---|
67 | 67 | //LA.matZRotate(toScreen, LA.toRadians(-90)); |
---|
68 | 68 | //LA.matXRotate(toScreen, LA.toRadians(-90)); |
---|
69 | 69 | //LA.matXRotate(fromScreen, LA.toRadians(90)); |
---|
.. | .. |
---|
71 | 71 | perspective = false; |
---|
72 | 72 | break; |
---|
73 | 73 | case 4: // Default light |
---|
74 | | - location = LA.newVector(-5, 20, 10); |
---|
| 74 | + location = LA.newVector(-5, 15, 10); |
---|
75 | 75 | perspective = false; |
---|
76 | 76 | break; |
---|
77 | 77 | } |
---|
.. | .. |
---|
104 | 104 | focalLength = 1; |
---|
105 | 105 | setAspect(4, 3); |
---|
106 | 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; |
---|
107 | 116 | } |
---|
108 | 117 | |
---|
109 | 118 | void setAspect(int width, int height) |
---|
.. | .. |
---|
150 | 159 | void RotatePosition(float dx, float dy) |
---|
151 | 160 | { |
---|
152 | 161 | if(hAspect != 0) return; |
---|
| 162 | + |
---|
| 163 | + if (CameraPane.IMAGEFLIP) |
---|
| 164 | + { |
---|
| 165 | + dx = -dx; |
---|
| 166 | + } |
---|
153 | 167 | |
---|
154 | 168 | if (CameraPane.ROTATECAMERA) |
---|
155 | 169 | { |
---|
.. | .. |
---|
207 | 221 | void Translate(float dx, float dy, float scale) |
---|
208 | 222 | { |
---|
209 | 223 | if(hAspect != 0) return; |
---|
| 224 | + |
---|
| 225 | + if (CameraPane.IMAGEFLIP) |
---|
| 226 | + { |
---|
| 227 | + dx = -dx; |
---|
| 228 | + } |
---|
210 | 229 | |
---|
211 | 230 | if (CameraPane.ROTATECAMERA) |
---|
212 | 231 | { |
---|
.. | .. |
---|
267 | 286 | if (scale == 0) |
---|
268 | 287 | { |
---|
269 | 288 | // Zoom |
---|
270 | | - LA.vecSub(location, lookAt, location); |
---|
271 | | - |
---|
272 | | - cVector p = location; |
---|
273 | | - |
---|
274 | 289 | double factor = Math.exp(-dy/300.0); // (1 + dy/100); |
---|
275 | 290 | |
---|
276 | | - p.x *= factor; |
---|
277 | | - p.y *= factor; |
---|
278 | | - p.z *= factor; |
---|
| 291 | + if (viewCode != 0) |
---|
| 292 | + { |
---|
| 293 | + LA.vecSub(location, lookAt, location); |
---|
279 | 294 | |
---|
280 | | - 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 | + } |
---|
281 | 310 | } |
---|
282 | 311 | else |
---|
283 | 312 | { |
---|
284 | 313 | LA.vecSub(location, lookAt, direction); |
---|
285 | 314 | |
---|
286 | 315 | //scale /= Distance(); |
---|
287 | | - scale /= shaper_fovy/20; |
---|
| 316 | + // scale /= shaper_fovy/20; |
---|
288 | 317 | |
---|
289 | 318 | location.x -= dy * direction.x / scale; |
---|
290 | 319 | //location.y -= dy * direction.y / scale; |
---|
.. | .. |
---|
305 | 334 | |
---|
306 | 335 | void RotateInterest(float dx, float dy) |
---|
307 | 336 | { |
---|
| 337 | + right.mul(-1); |
---|
| 338 | + |
---|
308 | 339 | cStatic.point1.set(location); |
---|
309 | 340 | location.set(lookAt); |
---|
310 | 341 | lookAt.set(cStatic.point1); |
---|
311 | | - right.mul(-1); |
---|
| 342 | + |
---|
| 343 | + cStatic.point1.set(locationBuf); |
---|
| 344 | + locationBuf.set(lookAtBuf); |
---|
| 345 | + lookAtBuf.set(cStatic.point1); |
---|
312 | 346 | // UP.mul(-1); |
---|
313 | 347 | |
---|
314 | 348 | RotatePosition(dx,-dy); |
---|
315 | 349 | |
---|
316 | 350 | // UP.mul(-1); |
---|
317 | 351 | right.mul(-1); |
---|
| 352 | + |
---|
318 | 353 | cStatic.point1.set(location); |
---|
319 | 354 | location.set(lookAt); |
---|
320 | 355 | lookAt.set(cStatic.point1); |
---|
321 | 356 | |
---|
322 | | - //computeTransform(); |
---|
| 357 | + cStatic.point1.set(locationBuf); |
---|
| 358 | + locationBuf.set(lookAtBuf); |
---|
| 359 | + lookAtBuf.set(cStatic.point1); |
---|
| 360 | + |
---|
| 361 | + computeTransform(); |
---|
323 | 362 | } |
---|
324 | 363 | |
---|
325 | 364 | //synchronized // june 2014 |
---|
.. | .. |
---|
332 | 371 | fromScreen = LA.newMatrix(); |
---|
333 | 372 | } |
---|
334 | 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 | + |
---|
335 | 408 | cVector up2 = up; |
---|
336 | 409 | cVector right2 = right; |
---|
337 | 410 | |
---|
338 | | - up2.x = UP.x; |
---|
339 | | - up2.y = UP.y; |
---|
340 | | - up2.z = UP.z; |
---|
341 | | - 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); |
---|
342 | 415 | LA.vecNormalize(away); |
---|
343 | 416 | LA.vecCross(away, up2, right2); |
---|
344 | 417 | if (right2.length2() < 0.0001) |
---|
345 | 418 | { |
---|
| 419 | + //System.out.println("right2.length2() < 0.0001"); |
---|
346 | 420 | // UP failed |
---|
347 | 421 | up2.x = UP2.x; |
---|
348 | 422 | up2.y = UP2.y; |
---|
.. | .. |
---|
352 | 426 | LA.vecCross(away, up2, right2); |
---|
353 | 427 | if (!(right2.length2() > 0)) |
---|
354 | 428 | { |
---|
| 429 | + System.exit(0); |
---|
355 | 430 | // old problem... |
---|
356 | 431 | assert (right2.length2() <= 0 || right2.length2() > 0); // weirdest thing ever |
---|
357 | 432 | up2.x = UP.x = 0; |
---|
.. | .. |
---|
381 | 456 | } |
---|
382 | 457 | |
---|
383 | 458 | for (int i=0; i < 3; i++) |
---|
384 | | - fromScreen[3][i] = location.get(i); |
---|
| 459 | + fromScreen[3][i] = locationBuf.get(i); |
---|
385 | 460 | |
---|
386 | 461 | for (int i=0; i < 3; i++) |
---|
387 | | - temp[3][i] = -location.get(i); |
---|
| 462 | + temp[3][i] = -locationBuf.get(i); |
---|
388 | 463 | |
---|
389 | 464 | LA.matConcat(temp, toScreen, toScreen); |
---|
390 | 465 | |
---|
.. | .. |
---|
396 | 471 | LA.matConcat(fromScreen, rotate, fromScreen); |
---|
397 | 472 | //LA.matConcat(toScreen, rotate_1, toScreen); |
---|
398 | 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 | + |
---|
399 | 482 | //if (this == CameraPane.lightCamera) |
---|
400 | 483 | //CameraPane.lighttouched = true; |
---|
401 | | - |
---|
402 | 484 | LA.matInvert(fromScreen, toScreen); |
---|
403 | 485 | } |
---|
404 | 486 | |
---|
.. | .. |
---|
464 | 546 | static final int viewFront = 2; |
---|
465 | 547 | static final int viewSide = 3; |
---|
466 | 548 | int viewCode; |
---|
| 549 | + |
---|
467 | 550 | cVector location; |
---|
468 | 551 | cVector lookAt; |
---|
| 552 | + |
---|
| 553 | + transient cVector locationBuf; |
---|
| 554 | + transient cVector lookAtBuf; |
---|
| 555 | + transient cVector upBuf; |
---|
| 556 | + //transient cVector up2Buf; |
---|
| 557 | + |
---|
469 | 558 | cVector direction; |
---|
470 | | - double toScreen[][]; |
---|
471 | | - double fromScreen[][]; |
---|
| 559 | + |
---|
| 560 | + double[][] toScreen; |
---|
| 561 | + double[][] fromScreen; |
---|
| 562 | + |
---|
472 | 563 | boolean perspective; |
---|
473 | 564 | int hAspect = 0; // Free camera |
---|
474 | 565 | int vAspect; |
---|