| 186 | | switch (_currentMode) |
|---|
| 187 | | { |
|---|
| 188 | | case NONE: |
|---|
| 189 | | _currentState = IDLE; |
|---|
| 190 | | break; |
|---|
| 191 | | |
|---|
| 192 | | case TRACKBALL: |
|---|
| 193 | | |
|---|
| 194 | | switch (button) |
|---|
| 195 | | { |
|---|
| 196 | | case LEFT_MOUSE : _currentState = ROTATING; |
|---|
| 197 | | break; |
|---|
| 198 | | |
|---|
| 199 | | case RIGHT_MOUSE : _currentState = TRANSLATING_Z; |
|---|
| 200 | | break; |
|---|
| 201 | | |
|---|
| 202 | | case MIDDLE_MOUSE: _currentState = TRANSLATING_XY; |
|---|
| 203 | | getIntersectionPoint(x,y); |
|---|
| 204 | | break; |
|---|
| 205 | | |
|---|
| 206 | | case UP_MOUSE : _currentState = IDLE; |
|---|
| 207 | | _trackball.translateZ(-_rMotionFactor); |
|---|
| 208 | | break; |
|---|
| 209 | | |
|---|
| 210 | | case DOWN_MOUSE : _currentState = IDLE; |
|---|
| 211 | | _trackball.translateZ(_rMotionFactor); |
|---|
| 212 | | break; |
|---|
| 213 | | |
|---|
| 214 | | default: FNOTICE(("Navigator: buttonPress, unknown button\n")); |
|---|
| 215 | | break; |
|---|
| 216 | | } |
|---|
| 217 | | break; |
|---|
| 218 | | |
|---|
| 219 | | case FLY: |
|---|
| 220 | | |
|---|
| 221 | | switch (button) |
|---|
| 222 | | { |
|---|
| 223 | | case LEFT_MOUSE : _currentState = TRANSLATING_ZPLUS; |
|---|
| 224 | | break; |
|---|
| 225 | | |
|---|
| 226 | | case MIDDLE_MOUSE: _currentState = ROTATING; |
|---|
| 227 | | break; |
|---|
| 228 | | |
|---|
| 229 | | case RIGHT_MOUSE : _currentState = TRANSLATING_ZMINUS; |
|---|
| 230 | | break; |
|---|
| 231 | | |
|---|
| 232 | | case UP_MOUSE : _currentState = IDLE; |
|---|
| 233 | | _flyer.forward(-_rMotionFactor); |
|---|
| 234 | | break; |
|---|
| 235 | | |
|---|
| 236 | | case DOWN_MOUSE : _currentState = IDLE; |
|---|
| 237 | | _flyer.forward(_rMotionFactor); |
|---|
| 238 | | break; |
|---|
| 239 | | |
|---|
| 240 | | default: FNOTICE(("Navigator: buttonPress, unknown button\n")); |
|---|
| 241 | | break; |
|---|
| 242 | | } |
|---|
| 243 | | break; |
|---|
| 244 | | |
|---|
| 245 | | case WALK: |
|---|
| 246 | | |
|---|
| 247 | | switch (button) |
|---|
| 248 | | { |
|---|
| 249 | | case LEFT_MOUSE : _currentState = TRANSLATING_ZPLUS; |
|---|
| 250 | | break; |
|---|
| 251 | | |
|---|
| 252 | | case MIDDLE_MOUSE: _currentState = ROTATING; |
|---|
| 253 | | break; |
|---|
| 254 | | |
|---|
| 255 | | case RIGHT_MOUSE : _currentState = TRANSLATING_ZMINUS; |
|---|
| 256 | | break; |
|---|
| 257 | | |
|---|
| 258 | | case UP_MOUSE : _currentState = IDLE; |
|---|
| 259 | | _walker.forward(-_rMotionFactor); |
|---|
| 260 | | break; |
|---|
| 261 | | |
|---|
| 262 | | case DOWN_MOUSE : _currentState = IDLE; |
|---|
| 263 | | _walker.forward(_rMotionFactor); |
|---|
| 264 | | break; |
|---|
| 265 | | |
|---|
| 266 | | default: FNOTICE(("Navigator: buttonPress, unknown button\n")); |
|---|
| 267 | | break; |
|---|
| 268 | | } |
|---|
| 269 | | break; |
|---|
| 270 | | |
|---|
| 271 | | default: |
|---|
| 272 | | |
|---|
| 273 | | FNOTICE(("Navigator: buttonPress, unknown mode\n")); |
|---|
| 274 | | break; |
|---|
| 275 | | } |
|---|
| | 201 | _engine->buttonPress(button, x, y, this); |
|---|
| 280 | | void Navigator::buttonRelease(Int16 , Int16 x, Int16 y) |
|---|
| 281 | | { |
|---|
| 282 | | switch (_currentMode) |
|---|
| 283 | | { |
|---|
| 284 | | case NONE: break; |
|---|
| 285 | | |
|---|
| 286 | | case TRACKBALL: if (!_moved && _clickCenter) |
|---|
| 287 | | { |
|---|
| 288 | | IntersectAction * act = IntersectAction::create(); |
|---|
| 289 | | Line line; |
|---|
| 290 | | _vp->getCamera()->calcViewRay(line, x, y, *_vp); |
|---|
| 291 | | |
|---|
| 292 | | Pnt3f lp1 = line.getPosition(); |
|---|
| 293 | | Vec3f ld1 = line.getDirection(); |
|---|
| 294 | | |
|---|
| 295 | | act->setLine(line); |
|---|
| 296 | | act->apply(_vp->getRoot()); |
|---|
| 297 | | if (act->didHit()) |
|---|
| 298 | | { |
|---|
| 299 | | Pnt3f p1 = act->getHitPoint(); |
|---|
| 300 | | _trackball.setAt(p1); |
|---|
| 301 | | } |
|---|
| 302 | | |
|---|
| 303 | | delete act; |
|---|
| 304 | | } |
|---|
| 305 | | break; |
|---|
| 306 | | |
|---|
| 307 | | case FLY: break; |
|---|
| 308 | | case WALK: break; |
|---|
| 309 | | |
|---|
| 310 | | default: FNOTICE(("Navigator: buttonRelease, unknown mode\n")); |
|---|
| 311 | | break; |
|---|
| 312 | | } |
|---|
| 313 | | _currentState=IDLE; |
|---|
| | 206 | void Navigator::buttonRelease(Int16 button, Int16 x, Int16 y) |
|---|
| | 207 | { |
|---|
| | 208 | _engine->buttonRelease(button, x, y, this); |
|---|
| 318 | | void Navigator::keyPress(Int16 key, Int16 , Int16 ) |
|---|
| 319 | | { |
|---|
| 320 | | switch (_currentMode) |
|---|
| 321 | | { |
|---|
| 322 | | case NONE: |
|---|
| 323 | | break; |
|---|
| 324 | | |
|---|
| 325 | | case TRACKBALL: |
|---|
| 326 | | |
|---|
| 327 | | switch (key) |
|---|
| 328 | | { |
|---|
| 329 | | case LEFT : /*undefined*/ break; |
|---|
| 330 | | case RIGHT : /*undefined*/ break; |
|---|
| 331 | | case FORWARDS : _trackball.translateZ(-_rMotionFactor); break; |
|---|
| 332 | | case BACKWARDS : _trackball.translateZ(_rMotionFactor); break; |
|---|
| 333 | | default : FNOTICE(("Navigator: keyPress, unknown key\n")); |
|---|
| 334 | | } |
|---|
| 335 | | break; |
|---|
| 336 | | |
|---|
| 337 | | case FLY: |
|---|
| 338 | | |
|---|
| 339 | | switch (key) |
|---|
| 340 | | { |
|---|
| 341 | | case LEFTROT : _flyer.rotate(-_rRotationAngle, 0); break; |
|---|
| 342 | | case RIGHTROT : _flyer.rotate( _rRotationAngle, 0); break; |
|---|
| 343 | | case LEFT : _flyer.right( _rMotionFactor); break; |
|---|
| 344 | | case RIGHT : _flyer.right(-_rMotionFactor); break; |
|---|
| 345 | | case FORWARDS : _flyer.forward(-_rMotionFactor); break; |
|---|
| 346 | | case BACKWARDS : _flyer.forward( _rMotionFactor); break; |
|---|
| 347 | | default : FNOTICE(("Navigator: keyPress, unknown key\n")); |
|---|
| 348 | | } |
|---|
| 349 | | break; |
|---|
| 350 | | |
|---|
| 351 | | case WALK: |
|---|
| 352 | | |
|---|
| 353 | | switch (key) |
|---|
| 354 | | { |
|---|
| 355 | | case LEFTROT : _walker.rotate(-_rRotationAngle, 0); break; |
|---|
| 356 | | case RIGHTROT : _walker.rotate( _rRotationAngle, 0); break; |
|---|
| 357 | | case LEFT : _walker.right( _rMotionFactor); break; |
|---|
| 358 | | case RIGHT : _walker.right(-_rMotionFactor); break; |
|---|
| 359 | | case FORWARDS : _walker.forward(-_rMotionFactor); break; |
|---|
| 360 | | case BACKWARDS : _walker.forward( _rMotionFactor); break; |
|---|
| 361 | | default : FNOTICE(("Navigator: keyPress, unknown key\n")); |
|---|
| 362 | | } |
|---|
| 363 | | break; |
|---|
| 364 | | |
|---|
| 365 | | default: |
|---|
| 366 | | |
|---|
| 367 | | FNOTICE(("Navigator: keyPress, unknown mode\n")); |
|---|
| 368 | | break; |
|---|
| 369 | | } |
|---|
| | 213 | void Navigator::keyPress(Int16 key, Int16 x, Int16 y) |
|---|
| | 214 | { |
|---|
| | 215 | _engine->keyPress(key, x, y, this); |
|---|
| 378 | | Real32 width = Real32(_vp->getPixelWidth()); |
|---|
| 379 | | Real32 height = Real32(_vp->getPixelHeight()); |
|---|
| 380 | | |
|---|
| 381 | | if(width <= 0 || height <= 0) |
|---|
| 382 | | return; |
|---|
| 383 | | |
|---|
| 384 | | WindowPtr par = _vp->getParent(); |
|---|
| 385 | | Real32 winHeight; |
|---|
| 386 | | |
|---|
| 387 | | if(par != NullFC) |
|---|
| 388 | | winHeight = (Real32)par->getHeight(); |
|---|
| 389 | | else |
|---|
| 390 | | winHeight = height; |
|---|
| 391 | | |
|---|
| 392 | | Real32 fromX = (2.0f * (_lastX - _vp->getPixelLeft())- width)/ width; |
|---|
| 393 | | Real32 fromY = (2.0f * (winHeight - _lastY - _vp->getPixelBottom()) |
|---|
| 394 | | - height) / height; |
|---|
| 395 | | Real32 toX = (2.0f * (x - _vp->getPixelLeft()) - width) / width; |
|---|
| 396 | | Real32 toY = (2.0f * (winHeight - y - _vp->getPixelBottom()) |
|---|
| 397 | | - height)/height; |
|---|
| 398 | | switch (_currentMode) |
|---|
| 399 | | { |
|---|
| 400 | | case NONE: |
|---|
| 401 | | FNOTICE(("Navigator: moveTo NONE mode\n")); |
|---|
| 402 | | break; |
|---|
| 403 | | |
|---|
| 404 | | case TRACKBALL: |
|---|
| 405 | | |
|---|
| 406 | | switch (_currentState) |
|---|
| 407 | | { |
|---|
| 408 | | case ROTATING :_trackball.rotate(fromX, fromY, toX, toY); |
|---|
| 409 | | break; |
|---|
| 410 | | |
|---|
| 411 | | case TRANSLATING_XY:{ |
|---|
| 412 | | Real32 distanceX = 0,distanceY = 0; |
|---|
| 413 | | calcDeltas(Int16(_lastX), Int16(_lastY), x, y, |
|---|
| 414 | | distanceX, distanceY); |
|---|
| 415 | | _trackball.translateXY(distanceX, distanceY); |
|---|
| 416 | | } |
|---|
| 417 | | break; |
|---|
| 418 | | |
|---|
| 419 | | case TRANSLATING_Z: { |
|---|
| 420 | | Real32 distance = osgSgn(toY-fromY)* |
|---|
| 421 | | 100.f * |
|---|
| 422 | | osgPow(osgAbs(toY-fromY),2.f); |
|---|
| 423 | | _trackball.translateZ(distance * _rMotionFactor); |
|---|
| 424 | | } |
|---|
| 425 | | break; |
|---|
| 426 | | |
|---|
| 427 | | default :;//IDLE |
|---|
| 428 | | } |
|---|
| 429 | | |
|---|
| 430 | | break; |
|---|
| 431 | | |
|---|
| 432 | | case FLY: |
|---|
| 433 | | |
|---|
| 434 | | { |
|---|
| 435 | | Real32 distanceX = -(fromX-toX); |
|---|
| 436 | | Real32 distanceY = (fromY-toY); |
|---|
| 437 | | _flyer.rotate(distanceX, distanceY); |
|---|
| 438 | | |
|---|
| 439 | | switch (_currentState) |
|---|
| 440 | | { |
|---|
| 441 | | case TRANSLATING_ZPLUS: _flyer.forward(-_rMotionFactor); |
|---|
| 442 | | break; |
|---|
| 443 | | |
|---|
| 444 | | case TRANSLATING_ZMINUS: _flyer.forward(_rMotionFactor); |
|---|
| 445 | | break; |
|---|
| 446 | | |
|---|
| 447 | | case ROTATING: break; |
|---|
| 448 | | |
|---|
| 449 | | default: ;//IDLE |
|---|
| 450 | | } |
|---|
| 451 | | } |
|---|
| 452 | | break; |
|---|
| 453 | | |
|---|
| 454 | | case WALK: |
|---|
| 455 | | |
|---|
| 456 | | { |
|---|
| 457 | | Real32 distanceX = -(fromX-toX); |
|---|
| 458 | | Real32 distanceY = (fromY-toY); |
|---|
| 459 | | _walker.rotate(distanceX, distanceY); |
|---|
| 460 | | |
|---|
| 461 | | switch (_currentState) |
|---|
| 462 | | { |
|---|
| 463 | | case TRANSLATING_ZPLUS: _walker.forward(-_rMotionFactor); |
|---|
| 464 | | break; |
|---|
| 465 | | |
|---|
| 466 | | case TRANSLATING_ZMINUS: _walker.forward(_rMotionFactor); |
|---|
| 467 | | break; |
|---|
| 468 | | |
|---|
| 469 | | case ROTATING: break; |
|---|
| 470 | | |
|---|
| 471 | | default: ;//IDLE |
|---|
| 472 | | } |
|---|
| 473 | | } |
|---|
| 474 | | break; |
|---|
| 475 | | |
|---|
| 476 | | default: |
|---|
| 477 | | |
|---|
| 478 | | FNOTICE(("Navigator: moveTo, unknown mode\n")); |
|---|
| 479 | | break; |
|---|
| 480 | | } |
|---|
| | 224 | Real32 fromX, fromY, toX, toY; |
|---|
| | 225 | if (!calcFromTo(x, y, fromX, fromY, toX, toY)) return; |
|---|
| | 226 | |
|---|
| | 227 | _engine->moveTo(x, y, this); |
|---|
| | 228 | |
|---|
| 575 | | _walker.setGround(_vp->getRoot()); |
|---|
| 576 | | _walker.setWorld (_vp->getRoot()); |
|---|
| 577 | | } |
|---|
| 578 | | |
|---|
| 579 | | /*! Set the navigation parameters in case of NONE mode |
|---|
| 580 | | */ |
|---|
| 581 | | void Navigator::setNoneMatrix(Pnt3f new_from, Pnt3f new_at, Vec3f new_up) |
|---|
| 582 | | { |
|---|
| 583 | | bool b = MatrixLookAt(_NoneMatrix, new_at, new_at+(new_at-new_from), new_up); |
|---|
| 584 | | |
|---|
| 585 | | if (b) FNOTICE(("Navigator: set(.,.,.) failed\n")); |
|---|
| | 321 | _engine->onViewportChanged(_vp); |
|---|
| 677 | | switch (_currentMode) |
|---|
| 678 | | { |
|---|
| 679 | | case NONE: setNoneMatrix(new_from, new_at, new_up); |
|---|
| 680 | | break; |
|---|
| 681 | | |
|---|
| 682 | | case TRACKBALL: _trackball.set(new_from, new_at, new_up); |
|---|
| 683 | | break; |
|---|
| 684 | | |
|---|
| 685 | | case FLY: _flyer.set(new_from, new_at, new_up); |
|---|
| 686 | | break; |
|---|
| 687 | | |
|---|
| 688 | | case WALK: _walker.set(new_from, new_at, new_up); |
|---|
| 689 | | break; |
|---|
| 690 | | |
|---|
| 691 | | default: FNOTICE(("Navigator: set, unknown mode")); |
|---|
| 692 | | break; |
|---|
| 693 | | } |
|---|
| | 357 | _engine->set(new_from, new_at, new_up); |
|---|
| 700 | | switch (_currentMode) |
|---|
| 701 | | { |
|---|
| 702 | | case NONE: //setNoneMatrix((Pnt3f) new_matrix[3], |
|---|
| 703 | | // (Pnt3f)(new_matrix[3]-new_matrix[2]), |
|---|
| 704 | | // (Vec3f) new_matrix[1]); |
|---|
| 705 | | _NoneMatrix = new_matrix; |
|---|
| 706 | | break; |
|---|
| 707 | | |
|---|
| 708 | | case TRACKBALL: _trackball.set(new_matrix); |
|---|
| 709 | | break; |
|---|
| 710 | | |
|---|
| 711 | | case FLY: _flyer.set(new_matrix); |
|---|
| 712 | | break; |
|---|
| 713 | | |
|---|
| 714 | | case WALK: _walker.set(new_matrix); |
|---|
| 715 | | break; |
|---|
| 716 | | |
|---|
| 717 | | default: FNOTICE(("Navigator: set(Matrix), unknown mode")); |
|---|
| 718 | | break; |
|---|
| 719 | | } |
|---|
| | 364 | _engine->set(new_matrix); |
|---|
| 758 | | static Pnt3f returnValue(0.f, 0.f, 0.f); |
|---|
| 759 | | returnValue = (Pnt3f)_NoneMatrix[3]; |
|---|
| 760 | | |
|---|
| 761 | | switch (_currentMode) |
|---|
| 762 | | { |
|---|
| 763 | | case NONE: return returnValue; |
|---|
| 764 | | case TRACKBALL: return _trackball.getFrom(); |
|---|
| 765 | | case FLY: return _flyer .getFrom(); |
|---|
| 766 | | case WALK: return _walker .getFrom(); |
|---|
| 767 | | default: FNOTICE(("Navigator: getFrom, unknown mode")); |
|---|
| 768 | | break; |
|---|
| 769 | | } |
|---|
| 770 | | |
|---|
| 771 | | return returnValue; |
|---|
| | 393 | return _engine->getFrom(); |
|---|
| | 471 | |
|---|
| | 472 | |
|---|
| | 473 | bool Navigator::getMoved(void) |
|---|
| | 474 | { |
|---|
| | 475 | return _moved; |
|---|
| | 476 | } |
|---|
| | 477 | |
|---|
| | 478 | ViewportPtr Navigator::getViewport(void) |
|---|
| | 479 | { |
|---|
| | 480 | return _vp; |
|---|
| | 481 | } |
|---|
| | 482 | |
|---|
| | 483 | Real32 Navigator::getLastX(void) |
|---|
| | 484 | { |
|---|
| | 485 | return _lastX; |
|---|
| | 486 | } |
|---|
| | 487 | |
|---|
| | 488 | Real32 Navigator::getLastY(void) |
|---|
| | 489 | { |
|---|
| | 490 | return _lastY; |
|---|
| | 491 | } |
|---|
| | 492 | |
|---|
| | 493 | TrackballEngine* Navigator::getTrackballNavigator(void) |
|---|
| | 494 | { |
|---|
| | 495 | return _trackballEngine; |
|---|
| | 496 | } |
|---|
| | 497 | |
|---|
| | 498 | FlyEngine* Navigator::getFlyNavigator(void) |
|---|
| | 499 | { |
|---|
| | 500 | return _flyEngine; |
|---|
| | 501 | } |
|---|
| | 502 | |
|---|
| | 503 | WalkEngine* Navigator::getWalkNavigator() |
|---|
| | 504 | { |
|---|
| | 505 | return _walkEngine; |
|---|
| | 506 | } |
|---|
| | 507 | |
|---|
| | 508 | NavigatorEngine* Navigator::getUserNavigator(void) |
|---|
| | 509 | { |
|---|
| | 510 | return _userEngine; |
|---|
| | 511 | } |
|---|
| | 512 | |
|---|
| | 513 | void Navigator::setUserEngine(NavigatorEngine* userEngine) |
|---|
| | 514 | { |
|---|
| | 515 | if (userEngine == NULL) return; |
|---|
| | 516 | |
|---|
| | 517 | if (userEngine != _userEngine) { |
|---|
| | 518 | subRef(_userEngine); |
|---|
| | 519 | _userEngine = userEngine; |
|---|
| | 520 | addRef(_userEngine); |
|---|
| | 521 | } |
|---|
| | 522 | } |
|---|
| | 523 | |
|---|
| 917 | | /*! Calculates the transformation matrix from CC to WC using the actual view |
|---|
| 918 | | matrix. |
|---|
| 919 | | */ |
|---|
| 920 | | static void calcCCtoWCMatrix(Matrix &cctowc, const Matrix &view, |
|---|
| 921 | | const ViewportPtr port) |
|---|
| 922 | | { |
|---|
| 923 | | Matrix proj, projtrans; |
|---|
| 924 | | |
|---|
| 925 | | port->getCamera()->getProjection( proj, port->getPixelWidth(), |
|---|
| 926 | | port->getPixelHeight()); |
|---|
| 927 | | port->getCamera()->getProjectionTranslation( projtrans, |
|---|
| 928 | | port->getPixelWidth(), |
|---|
| 929 | | port->getPixelHeight()); |
|---|
| 930 | | |
|---|
| 931 | | Matrix wctocc = proj; |
|---|
| 932 | | wctocc.mult( projtrans ); |
|---|
| 933 | | wctocc.mult( view ); |
|---|
| 934 | | |
|---|
| 935 | | cctowc.invertFrom( wctocc ); |
|---|
| 936 | | } |
|---|
| 937 | | |
|---|
| 938 | | /*! Calculates the intersection point of a ray that starts at from and goes |
|---|
| 939 | | through the position on the screen given by x,y with the world, if no |
|---|
| 940 | | intersection point exists the intersection is set to (0,0,0) |
|---|
| 941 | | */ |
|---|
| 942 | | void Navigator::getIntersectionPoint(Int16 x, Int16 y) |
|---|
| 943 | | { |
|---|
| 944 | | IntersectAction * act = IntersectAction::create(); |
|---|
| 945 | | Line line; |
|---|
| | 555 | bool Navigator::calcFromTo(Int16 x, Int16 y, |
|---|
| | 556 | Real32& fromX, Real32& fromY, |
|---|
| | 557 | Real32& toX, Real32& toY) |
|---|
| | 558 | { |
|---|
| | 559 | Real32 width = Real32(_vp->getPixelWidth()); |
|---|
| | 560 | Real32 height = Real32(_vp->getPixelHeight()); |
|---|
| | 561 | |
|---|
| | 562 | if(width <= 0 || height <= 0) return false; |
|---|
| | 563 | |
|---|
| | 564 | WindowPtr par = _vp->getParent(); |
|---|
| | 565 | Real32 winHeight; |
|---|
| 947 | | _vp->getCamera()->calcViewRay(line, x, y, *_vp); |
|---|
| 948 | | |
|---|
| 949 | | if(_clickNoIntersect) |
|---|
| 950 | | { |
|---|
| 951 | | Real32 u = (_dir.dot(Pnt3f(0.0f, 0.0f, 0.0f) - line.getPosition())) / |
|---|
| 952 | | (_dir.dot(line.getDirection())); |
|---|
| 953 | | _ip = line.getPosition() + u * line.getDirection(); |
|---|
| 954 | | return; |
|---|
| 955 | | } |
|---|
| 956 | | |
|---|
| 957 | | act->setLine(line); |
|---|
| 958 | | act->apply(_vp->getRoot()); |
|---|
| 959 | | |
|---|
| 960 | | Matrix cctowc,view; |
|---|
| 961 | | Int16 width = _vp->getPixelWidth(); |
|---|
| 962 | | Int16 height = _vp->getPixelHeight(); |
|---|
| 963 | | |
|---|
| 964 | | _vp->getCamera()->getViewing(view, width, height); |
|---|
| 965 | | |
|---|
| 966 | | calcCCtoWCMatrix(cctowc, view, _vp); |
|---|
| 967 | | |
|---|
| 968 | | Pnt3f at,to; |
|---|
| 969 | | |
|---|
| 970 | | cctowc.multFullMatrixPnt( Pnt3f( 0, 0, 0.5f ), to ); |
|---|
| 971 | | cctowc.multFullMatrixPnt( Pnt3f( 0, 0, 1 ), at ); |
|---|
| 972 | | |
|---|
| 973 | | _dir = to - at; |
|---|
| 974 | | |
|---|
| 975 | | if (act->didHit()) |
|---|
| 976 | | { |
|---|
| 977 | | _ip = act->getHitPoint(); |
|---|
| 978 | | } |
|---|
| | 567 | if(par != NullFC) |
|---|
| | 568 | winHeight = (Real32)par->getHeight(); |
|---|
| 980 | | { |
|---|
| 981 | | Real32 u = (_dir.dot(Pnt3f(0.0f, 0.0f, 0.0f) - line.getPosition())) / |
|---|
| 982 | | (_dir.dot(line.getDirection())); |
|---|
| 983 | | _ip = line.getPosition() + u * line.getDirection(); |
|---|
| 984 | | } |
|---|
| 985 | | |
|---|
| 986 | | delete act; |
|---|
| 987 | | } |
|---|
| 988 | | |
|---|
| 989 | | /*! Calculate the real translation that has to be done, so that the |
|---|
| 990 | | trackball can actually drag the object in the plane parallel to the |
|---|
| 991 | | screen. |
|---|
| 992 | | */ |
|---|
| 993 | | void Navigator::calcDeltas(Int16 , Int16 , Int16 toX, Int16 toY, |
|---|
| 994 | | Real32 &distanceX, Real32 &distanceY) |
|---|
| 995 | | { |
|---|
| 996 | | Matrix view; |
|---|
| 997 | | |
|---|
| 998 | | view=_trackball.getMatrix(); |
|---|
| 999 | | |
|---|
| 1000 | | Pnt3f from( view[3][0], view[3][1], view[3][2] ); |
|---|
| 1001 | | |
|---|
| 1002 | | view.invert(); |
|---|
| 1003 | | Matrix cctowc; |
|---|
| 1004 | | calcCCtoWCMatrix(cctowc, view, _vp); |
|---|
| 1005 | | |
|---|
| 1006 | | Real32 rx = ( toX / (Real32) _vp->getPixelWidth() ) * 2.f - 1.f, |
|---|
| 1007 | | ry = 1.f - ( toY / (Real32) _vp->getPixelHeight() ) * 2.f; |
|---|
| 1008 | | |
|---|
| 1009 | | Pnt3f at; |
|---|
| 1010 | | cctowc.multFullMatrixPnt( Pnt3f( rx, ry, 1 ), at ); |
|---|
| 1011 | | |
|---|
| 1012 | | Line line2; |
|---|
| 1013 | | line2.setValue(from, at-from); |
|---|
| 1014 | | |
|---|
| 1015 | | Real32 u = (_dir.dot(_ip-line2.getPosition())) / |
|---|
| 1016 | | (_dir.dot(line2.getDirection())); |
|---|
| 1017 | | |
|---|
| 1018 | | Pnt3f p2 = line2.getPosition() + u * line2.getDirection(); |
|---|
| 1019 | | |
|---|
| 1020 | | Vec3f transl; |
|---|
| 1021 | | transl[0] = -p2[0] + _ip[0]; |
|---|
| 1022 | | transl[1] = -p2[1] + _ip[1]; |
|---|
| 1023 | | transl[2] = -p2[2] + _ip[2]; |
|---|
| 1024 | | |
|---|
| 1025 | | view.multMatrixVec(transl); |
|---|
| 1026 | | |
|---|
| 1027 | | distanceX = transl[0]; |
|---|
| 1028 | | distanceY = transl[1]; |
|---|
| 1029 | | } |
|---|
| | 570 | winHeight = height; |
|---|
| | 571 | |
|---|
| | 572 | fromX = (2.0f * (_lastX - _vp->getPixelLeft())- width) / width; |
|---|
| | 573 | fromY = (2.0f * (winHeight-_lastY-_vp->getPixelBottom())-height) / height; |
|---|
| | 574 | |
|---|
| | 575 | toX = (2.0f * (x - _vp->getPixelLeft()) - width) / width; |
|---|
| | 576 | toY = (2.0f * (winHeight - y - _vp->getPixelBottom()) - height) / height; |
|---|
| | 577 | |
|---|
| | 578 | return true; |
|---|
| | 579 | } |
|---|
| | 580 | |
|---|