Latest view frustum work
Showing the changes to interface/src/main.cpp (1 of 5 files). Show all
Unified · Split
| @@ -79,6 +79,9 @@ · 78 unmodified lines | |||
| 79 | 79 | ||
| 80 | using namespace std; | 80 | using namespace std; |
| 81 | 81 | ||
| 82 | void reshape(int width, int height); // will be defined below | ||
| 83 | |||
| 84 | |||
| 82 | pthread_t networkReceiveThread; | 85 | pthread_t networkReceiveThread; |
| 83 | bool stopNetworkReceiveThread = false; | 86 | bool stopNetworkReceiveThread = false; |
| 84 | 87 | ||
| @@ -97,10 +100,13 @@ bool wantColorRandomizer = true; // for addSphere and load file · 12 unmodified lines | |||
| 97 | 100 | ||
| 98 | Oscilloscope audioScope(256,200,true); | 101 | Oscilloscope audioScope(256,200,true); |
| 99 | 102 | ||
| 100 | Head myAvatar; // The rendered avatar of oneself | 103 | ViewFrustum viewFrustum; // current state of view frustum, perspective, orientation, etc. |
| 101 | Camera myCamera; // My view onto the world (sometimes on myself :) | 104 | |
| 105 | Head myAvatar; // The rendered avatar of oneself | ||
| 106 | Camera myCamera; // My view onto the world (sometimes on myself :) | ||
| 107 | Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode | ||
| 102 | 108 | ||
| 103 | // Starfield information | 109 | // Starfield information |
| 104 | char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; | 110 | char starFile[] = "https://s3-us-west-1.amazonaws.com/highfidelity/stars.txt"; |
| 105 | FieldOfView fov; | 111 | FieldOfView fov; |
| 106 | Stars stars; | 112 | Stars stars; |
| @@ -528,39 +534,57 @@ float viewFrustumOffsetUp = 0.0; · 421 unmodified lines | |||
| 528 | 534 | ||
| 529 | void render_view_frustum() { | 535 | void render_view_frustum() { |
| 530 | 536 | ||
| 531 | glm::vec3 cameraPosition = ::myCamera.getPosition(); | ||
| 532 | glm::vec3 headPosition = ::myAvatar.getHeadPosition(); | ||
| 533 | |||
| 534 | glm::vec3 cameraDirection = ::myCamera.getOrientation().getFront() * glm::vec3(1,1,-1); | ||
| 535 | glm::vec3 headDirection = myAvatar.getHeadLookatDirection(); // direction still backwards | ||
| 536 | |||
| 537 | glm::vec3 cameraUp = myCamera.getOrientation().getUp() * glm::vec3(1,1,1); | ||
| 538 | glm::vec3 headUp = myAvatar.getHeadLookatDirectionUp(); | ||
| 539 | |||
| 540 | glm::vec3 cameraRight = myCamera.getOrientation().getRight() * glm::vec3(1,1,-1); | ||
| 541 | glm::vec3 headRight = myAvatar.getHeadLookatDirectionRight() * glm::vec3(-1,1,-1); // z is flipped! | ||
| 542 | |||
| 543 | // We will use these below, from either the camera or head vectors calculated above | 537 | // We will use these below, from either the camera or head vectors calculated above |
| 544 | glm::vec3 position; | 538 | glm::vec3 position; |
| 545 | glm::vec3 direction; | 539 | glm::vec3 direction; |
| 546 | glm::vec3 up; | 540 | glm::vec3 up; |
| 547 | glm::vec3 right; | 541 | glm::vec3 right; |
| 542 | float fov, nearClip, farClip; | ||
| 548 | 543 | ||
| 549 | // Camera or Head? | 544 | // Camera or Head? |
| 550 | if (::cameraFrustum) { | 545 | if (::cameraFrustum) { |
| 551 | position = cameraPosition; | 546 | position = ::myCamera.getPosition(); |
| 552 | direction = cameraDirection; | 547 | direction = ::myCamera.getOrientation().getFront() * glm::vec3(1,1,-1); |
| 553 | up = cameraUp; | 548 | up = ::myCamera.getOrientation().getUp() * glm::vec3(1,1,1); |
| 554 | right = cameraRight; | 549 | right = ::myCamera.getOrientation().getRight() * glm::vec3(1,1,-1); |
| 550 | fov = ::myCamera.getFieldOfView(); | ||
| 551 | nearClip = ::myCamera.getNearClip(); | ||
| 552 | farClip = ::myCamera.getFarClip(); | ||
| 555 | } else { | 553 | } else { |
| 556 | position = headPosition; | 554 | position = ::myAvatar.getHeadPosition(); |
| 557 | direction = headDirection; | 555 | direction = ::myAvatar.getHeadLookatDirection(); |
| 558 | up = headUp; | 556 | up = ::myAvatar.getHeadLookatDirectionUp(); |
| 559 | right = headRight; | 557 | right = ::myAvatar.getHeadLookatDirectionRight() * glm::vec3(-1,1,-1); |
| 558 | |||
| 559 | // NOTE: we use the same lens details if we draw from the head | ||
| 560 | fov = ::myCamera.getFieldOfView(); | ||
| 561 | nearClip = ::myCamera.getNearClip(); | ||
| 562 | farClip = ::myCamera.getFarClip(); | ||
| 560 | } | 563 | } |
| 561 | 564 | ||
| 565 | /* | ||
| 566 | printf("position.x=%f, position.y=%f, position.z=%f\n", position.x, position.y, position.z); | ||
| 567 | printf("direction.x=%f, direction.y=%f, direction.z=%f\n", direction.x, direction.y, direction.z); | ||
| 568 | printf("up.x=%f, up.y=%f, up.z=%f\n", up.x, up.y, up.z); | ||
| 569 | printf("right.x=%f, right.y=%f, right.z=%f\n", right.x, right.y, right.z); | ||
| 570 | printf("fov=%f\n", fov); | ||
| 571 | printf("nearClip=%f\n", nearClip); | ||
| 572 | printf("farClip=%f\n", farClip); | ||
| 573 | */ | ||
| 574 | |||
| 575 | // Set the viewFrustum up with the correct position and orientation of the camera | ||
| 576 | viewFrustum.setPosition(position); | ||
| 577 | viewFrustum.setOrientation(direction,up,right); | ||
| 578 | |||
| 579 | // Also make sure it's got the correct lens details from the camera | ||
| 580 | viewFrustum.setFieldOfView(fov); | ||
| 581 | viewFrustum.setNearClip(nearClip); | ||
| 582 | viewFrustum.setFarClip(farClip); | ||
| 583 | |||
| 562 | // Ask the ViewFrustum class to calculate our corners | 584 | // Ask the ViewFrustum class to calculate our corners |
| 563 | ViewFrustum vf(position,direction,up,right,::WIDTH,::HEIGHT); | 585 | viewFrustum.calculate(); |
| 586 | |||
| 587 | //viewFrustum.dump(); | ||
| 564 | 588 | ||
| 565 | // Get ready to draw some lines | 589 | // Get ready to draw some lines |
| 566 | glDisable(GL_LIGHTING); | 590 | glDisable(GL_LIGHTING); |
| @@ -593,64 +617,64 @@ void render_view_frustum() { · 26 unmodified lines | |||
| 593 | if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES | 617 | if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES |
| 594 | || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_NEAR_PLANE) { | 618 | || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_NEAR_PLANE) { |
| 595 | // Drawing the bounds of the frustum | 619 | // Drawing the bounds of the frustum |
| 596 | // vf.getNear plane - bottom edge | 620 | // viewFrustum.getNear plane - bottom edge |
| 597 | glColor3f(1,0,0); | 621 | glColor3f(1,0,0); |
| 598 | glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); | 622 | glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); |
| 599 | glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); | 623 | glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); |
| 600 | 624 | ||
| 601 | // vf.getNear plane - top edge | 625 | // viewFrustum.getNear plane - top edge |
| 602 | glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); | 626 | glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); |
| 603 | glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); | 627 | glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); |
| 604 | 628 | ||
| 605 | // vf.getNear plane - right edge | 629 | // viewFrustum.getNear plane - right edge |
| 606 | glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); | 630 | glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); |
| 607 | glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); | 631 | glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); |
| 608 | 632 | ||
| 609 | // vf.getNear plane - left edge | 633 | // viewFrustum.getNear plane - left edge |
| 610 | glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); | 634 | glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); |
| 611 | glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); | 635 | glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); |
| 612 | } | 636 | } |
| 613 | 637 | ||
| 614 | if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES | 638 | if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES |
| 615 | || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_FAR_PLANE) { | 639 | || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_FAR_PLANE) { |
| 616 | // vf.getFar plane - bottom edge | 640 | // viewFrustum.getFar plane - bottom edge |
| 617 | glColor3f(0,1,0); // GREEN!!! | 641 | glColor3f(0,1,0); // GREEN!!! |
| 618 | glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); | 642 | glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); |
| 619 | glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); | 643 | glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); |
| 620 | 644 | ||
| 621 | // vf.getFar plane - top edge | 645 | // viewFrustum.getFar plane - top edge |
| 622 | glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); | 646 | glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); |
| 623 | glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); | 647 | glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); |
| 624 | 648 | ||
| 625 | // vf.getFar plane - right edge | 649 | // viewFrustum.getFar plane - right edge |
| 626 | glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); | 650 | glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); |
| 627 | glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); | 651 | glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); |
| 628 | 652 | ||
| 629 | // vf.getFar plane - left edge | 653 | // viewFrustum.getFar plane - left edge |
| 630 | glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); | 654 | glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); |
| 631 | glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); | 655 | glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); |
| 632 | } | 656 | } |
| 633 | 657 | ||
| 634 | if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES) { | 658 | if (::frustumDrawingMode == FRUSTUM_DRAW_MODE_ALL || ::frustumDrawingMode == FRUSTUM_DRAW_MODE_PLANES) { |
| 635 | // RIGHT PLANE IS CYAN | 659 | // RIGHT PLANE IS CYAN |
| 636 | // right plane - bottom edge - vf.getNear to distant | 660 | // right plane - bottom edge - viewFrustum.getNear to distant |
| 637 | glColor3f(0,1,1); | 661 | glColor3f(0,1,1); |
| 638 | glVertex3f(vf.getNearBottomRight().x, vf.getNearBottomRight().y, vf.getNearBottomRight().z); | 662 | glVertex3f(viewFrustum.getNearBottomRight().x, viewFrustum.getNearBottomRight().y, viewFrustum.getNearBottomRight().z); |
| 639 | glVertex3f(vf.getFarBottomRight().x, vf.getFarBottomRight().y, vf.getFarBottomRight().z); | 663 | glVertex3f(viewFrustum.getFarBottomRight().x, viewFrustum.getFarBottomRight().y, viewFrustum.getFarBottomRight().z); |
| 640 | 664 | ||
| 641 | // right plane - top edge - vf.getNear to distant | 665 | // right plane - top edge - viewFrustum.getNear to distant |
| 642 | glVertex3f(vf.getNearTopRight().x, vf.getNearTopRight().y, vf.getNearTopRight().z); | 666 | glVertex3f(viewFrustum.getNearTopRight().x, viewFrustum.getNearTopRight().y, viewFrustum.getNearTopRight().z); |
| 643 | glVertex3f(vf.getFarTopRight().x, vf.getFarTopRight().y, vf.getFarTopRight().z); | 667 | glVertex3f(viewFrustum.getFarTopRight().x, viewFrustum.getFarTopRight().y, viewFrustum.getFarTopRight().z); |
| 644 | 668 | ||
| 645 | // LEFT PLANE IS BLUE | 669 | // LEFT PLANE IS BLUE |
| 646 | // left plane - bottom edge - vf.getNear to distant | 670 | // left plane - bottom edge - viewFrustum.getNear to distant |
| 647 | glColor3f(0,0,1); | 671 | glColor3f(0,0,1); |
| 648 | glVertex3f(vf.getNearBottomLeft().x, vf.getNearBottomLeft().y, vf.getNearBottomLeft().z); | 672 | glVertex3f(viewFrustum.getNearBottomLeft().x, viewFrustum.getNearBottomLeft().y, viewFrustum.getNearBottomLeft().z); |
| 649 | glVertex3f(vf.getFarBottomLeft().x, vf.getFarBottomLeft().y, vf.getFarBottomLeft().z); | 673 | glVertex3f(viewFrustum.getFarBottomLeft().x, viewFrustum.getFarBottomLeft().y, viewFrustum.getFarBottomLeft().z); |
| 650 | 674 | ||
| 651 | // left plane - top edge - vf.getNear to distant | 675 | // left plane - top edge - viewFrustum.getNear to distant |
| 652 | glVertex3f(vf.getNearTopLeft().x, vf.getNearTopLeft().y, vf.getNearTopLeft().z); | 676 | glVertex3f(viewFrustum.getNearTopLeft().x, viewFrustum.getNearTopLeft().y, viewFrustum.getNearTopLeft().z); |
| 653 | glVertex3f(vf.getFarTopLeft().x, vf.getFarTopLeft().y, vf.getFarTopLeft().z); | 677 | glVertex3f(viewFrustum.getFarTopLeft().x, viewFrustum.getFarTopLeft().y, viewFrustum.getFarTopLeft().z); |
| 654 | } | 678 | } |
| 655 | 679 | ||
| 656 | glEnd(); | 680 | glEnd(); |
| @@ -660,8 +684,6 @@ void render_view_frustum() { · 3 unmodified lines | |||
| 660 | 684 | ||
| 661 | void display(void) | 685 | void display(void) |
| 662 | { | 686 | { |
| 663 | //printf( "avatar head lookat = %f, %f, %f\n", myAvatar.getAvatarHeadLookatDirection().x, myAvatar.getAvatarHeadLookatDirection().y, myAvatar.getAvatarHeadLookatDirection().z ); | ||
| 664 | |||
| 665 | PerfStat("display"); | 687 | PerfStat("display"); |
| 666 | 688 | ||
| 667 | glEnable(GL_LINE_SMOOTH); | 689 | glEnable(GL_LINE_SMOOTH); |
| @@ -708,13 +730,14 @@ void display(void) · 40 unmodified lines | |||
| 708 | //---------------------------------------------------- | 730 | //---------------------------------------------------- |
| 709 | myCamera.setTargetPosition ( myAvatar.getPos() ); | 731 | myCamera.setTargetPosition ( myAvatar.getPos() ); |
| 710 | myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); | 732 | myCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() ); |
| 711 | myCamera.setPitch ( 10.0 ); | 733 | myCamera.setPitch ( 0.0 ); // temporarily, this must be 0.0 or else bad juju |
| 712 | myCamera.setRoll ( 0.0 ); | 734 | myCamera.setRoll ( 0.0 ); |
| 713 | myCamera.setUp ( 0.45 ); | 735 | myCamera.setUp ( 0.45 ); |
| 714 | myCamera.setDistance ( 0.5 ); | 736 | myCamera.setDistance ( 0.5 ); |
| 715 | myCamera.setTightness ( 10.0f ); | 737 | myCamera.setTightness ( 10.0f ); |
| 716 | myCamera.update ( 1.f/FPS ); | 738 | myCamera.update ( 1.f/FPS ); |
| 717 | } | 739 | } |
| 740 | |||
| 718 | // Note: whichCamera is used to pick between the normal camera myCamera for our | 741 | // Note: whichCamera is used to pick between the normal camera myCamera for our |
| 719 | // main camera, vs, an alternate camera. The alternate camera we support right now | 742 | // main camera, vs, an alternate camera. The alternate camera we support right now |
| 720 | // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism | 743 | // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism |
| @@ -725,21 +748,20 @@ void display(void) · 4 unmodified lines | |||
| 725 | // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera | 748 | // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera |
| 726 | Camera whichCamera = myCamera; | 749 | Camera whichCamera = myCamera; |
| 727 | Camera viewFrustumOffsetCamera = myCamera; | 750 | Camera viewFrustumOffsetCamera = myCamera; |
| 728 | 751 | ||
| 729 | if (::viewFrustumFromOffset && ::frustumOn) { | 752 | if (::viewFrustumFromOffset && ::frustumOn) { |
| 730 | //---------------------------------------------------- | 753 | //---------------------------------------------------- |
| 731 | // set the camera to third-person view but offset so we can see the frustum | 754 | // set the camera to third-person view but offset so we can see the frustum |
| 732 | //---------------------------------------------------- | 755 | //---------------------------------------------------- |
| 733 | viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); | 756 | viewFrustumOffsetCamera.setYaw ( 180.0 - myAvatar.getBodyYaw() + ::viewFrustumOffsetYaw ); |
| 734 | viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); | 757 | viewFrustumOffsetCamera.setPitch ( 0.0 + ::viewFrustumOffsetPitch ); |
| 735 | viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); | 758 | viewFrustumOffsetCamera.setRoll ( 0.0 + ::viewFrustumOffsetRoll ); |
| 736 | viewFrustumOffsetCamera.setUp ( 0.2 + 0.2 ); | 759 | viewFrustumOffsetCamera.setUp ( 0.2 + ::viewFrustumOffsetUp ); |
| 737 | viewFrustumOffsetCamera.setDistance( 0.5 + 0.2 ); | 760 | viewFrustumOffsetCamera.setDistance ( 0.5 + ::viewFrustumOffsetDistance ); |
| 738 | viewFrustumOffsetCamera.update( 1.f/FPS ); | 761 | viewFrustumOffsetCamera.update(1.f/FPS); |
| 739 | |||
| 740 | whichCamera = viewFrustumOffsetCamera; | 762 | whichCamera = viewFrustumOffsetCamera; |
| 741 | } | 763 | } |
| 742 | 764 | ||
| 743 | //--------------------------------------------- | 765 | //--------------------------------------------- |
| 744 | // transform view according to whichCamera | 766 | // transform view according to whichCamera |
| 745 | // could be myCamera (if in normal mode) | 767 | // could be myCamera (if in normal mode) |
| @@ -750,6 +772,8 @@ void display(void) · 4 unmodified lines | |||
| 750 | glRotatef ( whichCamera.getRoll(), 0, 0, 1 ); | 772 | glRotatef ( whichCamera.getRoll(), 0, 0, 1 ); |
| 751 | glTranslatef( -whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z ); | 773 | glTranslatef( -whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z ); |
| 752 | 774 | ||
| 775 | |||
| 776 | |||
| 753 | if (::starsOn) { | 777 | if (::starsOn) { |
| 754 | // should be the first rendering pass - w/o depth buffer / lighting | 778 | // should be the first rendering pass - w/o depth buffer / lighting |
| 755 | stars.render(fov); | 779 | stars.render(fov); |
| @@ -966,7 +990,14 @@ int setDisplayFrustum(int state) { · 210 unmodified lines | |||
| 966 | } | 990 | } |
| 967 | 991 | ||
| 968 | int setFrustumOffset(int state) { | 992 | int setFrustumOffset(int state) { |
| 969 | return setValue(state, &::viewFrustumFromOffset); | 993 | int value = setValue(state, &::viewFrustumFromOffset); |
| 994 | |||
| 995 | // reshape so that OpenGL will get the right lens details for the camera of choice | ||
| 996 | if (state == MENU_ROW_PICKED) { | ||
| 997 | reshape(::WIDTH,::HEIGHT); | ||
| 998 | } | ||
| 999 | |||
| 1000 | return value; | ||
| 970 | } | 1001 | } |
| 971 | 1002 | ||
| 972 | int setFrustumOrigin(int state) { | 1003 | int setFrustumOrigin(int state) { |
| @@ -1026,12 +1057,13 @@ void initMenu() { · 53 unmodified lines | |||
| 1026 | menuColumnOptions->addRow("(V)oxels", setVoxels); | 1057 | menuColumnOptions->addRow("(V)oxels", setVoxels); |
| 1027 | menuColumnOptions->addRow("Stars (*)", setStars); | 1058 | menuColumnOptions->addRow("Stars (*)", setStars); |
| 1028 | menuColumnOptions->addRow("(Q)uit", quitApp); | 1059 | menuColumnOptions->addRow("(Q)uit", quitApp); |
| 1060 | |||
| 1029 | // Tools | 1061 | // Tools |
| 1030 | menuColumnTools = menu.addColumn("Tools"); | 1062 | menuColumnTools = menu.addColumn("Tools"); |
| 1031 | menuColumnTools->addRow("Stats (/)", setStats); | 1063 | menuColumnTools->addRow("Stats (/)", setStats); |
| 1032 | menuColumnTools->addRow("(M)enu", setMenu); | 1064 | menuColumnTools->addRow("(M)enu", setMenu); |
| 1033 | 1065 | ||
| 1034 | // Debug | 1066 | // Frustum Options |
| 1035 | menuColumnFrustum = menu.addColumn("Frustum"); | 1067 | menuColumnFrustum = menu.addColumn("Frustum"); |
| 1036 | menuColumnFrustum->addRow("Display (F)rustum", setDisplayFrustum); | 1068 | menuColumnFrustum->addRow("Display (F)rustum", setDisplayFrustum); |
| 1037 | menuColumnFrustum->addRow("Use (O)ffset Camera", setFrustumOffset); | 1069 | menuColumnFrustum->addRow("Use (O)ffset Camera", setFrustumOffset); |
| @@ -1187,7 +1219,7 @@ void key(unsigned char k, int x, int y) · 149 unmodified lines | |||
| 1187 | if (k == 'V' || k == 'v') ::showingVoxels = !::showingVoxels; // toggle voxels | 1219 | if (k == 'V' || k == 'v') ::showingVoxels = !::showingVoxels; // toggle voxels |
| 1188 | if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging | 1220 | if (k == 'F') ::frustumOn = !::frustumOn; // toggle view frustum debugging |
| 1189 | if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at | 1221 | if (k == 'C') ::cameraFrustum = !::cameraFrustum; // toggle which frustum to look at |
| 1190 | if (k == 'O' || k == 'G') ::viewFrustumFromOffset = !::viewFrustumFromOffset; // toggle view frustum offset debugging | 1222 | if (k == 'O' || k == 'G') setFrustumOffset(MENU_ROW_PICKED); // toggle view frustum offset debugging |
| 1191 | 1223 | ||
| 1192 | if (k == '[') ::viewFrustumOffsetYaw -= 0.5; | 1224 | if (k == '[') ::viewFrustumOffsetYaw -= 0.5; |
| 1193 | if (k == ']') ::viewFrustumOffsetYaw += 0.5; | 1225 | if (k == ']') ::viewFrustumOffsetYaw += 0.5; |
| @@ -1199,8 +1231,10 @@ void key(unsigned char k, int x, int y) · 5 unmodified lines | |||
| 1199 | if (k == '>') ::viewFrustumOffsetDistance += 0.5; | 1231 | if (k == '>') ::viewFrustumOffsetDistance += 0.5; |
| 1200 | if (k == ',') ::viewFrustumOffsetUp -= 0.05; | 1232 | if (k == ',') ::viewFrustumOffsetUp -= 0.05; |
| 1201 | if (k == '.') ::viewFrustumOffsetUp += 0.05; | 1233 | if (k == '.') ::viewFrustumOffsetUp += 0.05; |
| 1202 | if (k == '|') ViewFrustum::fovAngleAdust -= 0.05; | 1234 | |
| 1203 | if (k == '\\') ViewFrustum::fovAngleAdust += 0.05; | 1235 | // if (k == '|') ViewFrustum::fovAngleAdust -= 0.05; |
| 1236 | // if (k == '\\') ViewFrustum::fovAngleAdust += 0.05; | ||
| 1237 | |||
| 1204 | if (k == 'R') setFrustumRenderMode(MENU_ROW_PICKED); | 1238 | if (k == 'R') setFrustumRenderMode(MENU_ROW_PICKED); |
| 1205 | 1239 | ||
| 1206 | if (k == '&') { | 1240 | if (k == '&') { |
| @@ -1359,27 +1393,66 @@ void idle(void) { · 152 unmodified lines | |||
| 1359 | } | 1393 | } |
| 1360 | 1394 | ||
| 1361 | 1395 | ||
| 1362 | |||
| 1363 | void reshape(int width, int height) | 1396 | void reshape(int width, int height) |
| 1364 | { | 1397 | { |
| 1365 | WIDTH = width; | 1398 | WIDTH = width; |
| 1366 | HEIGHT = height; | 1399 | HEIGHT = height; |
| 1400 | float aspectRatio = ((float)width/(float)height); // based on screen resize | ||
| 1401 | |||
| 1402 | float fov; | ||
| 1403 | float nearClip; | ||
| 1404 | float farClip; | ||
| 1405 | |||
| 1406 | // get the lens details from the current camera | ||
| 1407 | if (::viewFrustumFromOffset) { | ||
| 1408 | fov = ::viewFrustumOffsetCamera.getFieldOfView(); | ||
| 1409 | nearClip = ::viewFrustumOffsetCamera.getNearClip(); | ||
| 1410 | farClip = ::viewFrustumOffsetCamera.getFarClip(); | ||
| 1411 | } else { | ||
| 1412 | fov = ::myCamera.getFieldOfView(); | ||
| 1413 | nearClip = ::myCamera.getNearClip(); | ||
| 1414 | farClip = ::myCamera.getFarClip(); | ||
| 1415 | } | ||
| 1367 | 1416 | ||
| 1417 | //printf("reshape() width=%d, height=%d, aspectRatio=%f fov=%f near=%f far=%f \n", | ||
| 1418 | // width,height,aspectRatio,fov,nearClip,farClip); | ||
| 1419 | |||
| 1420 | // Tell our viewFrustum about this change | ||
| 1421 | ::viewFrustum.setAspectRatio(aspectRatio); | ||
| 1422 | |||
| 1423 | |||
| 1424 | glViewport(0, 0, width, height); // shouldn't this account for the menu??? | ||
| 1368 | 1425 | ||
| 1369 | glMatrixMode(GL_PROJECTION); //hello | 1426 | glMatrixMode(GL_PROJECTION); //hello |
| 1370 | fov.setResolution(width, height) | ||
| 1371 | .setBounds(glm::vec3(-0.5f,-0.5f,-500.0f), glm::vec3(0.5f, 0.5f, 0.1f) ) | ||
| 1372 | .setPerspective(0.7854f); | ||
| 1373 | glLoadMatrixf(glm::value_ptr(fov.getViewerScreenXform())); | ||
| 1374 | 1427 | ||
| 1428 | // XXXBHG - Note: this is Tobias's code for loading the perspective matrix. At Philip's suggestion, I'm removing | ||
| 1429 | // it and putting back our old code that simply loaded the fov, ratio, and near/far clips. But I'm keeping this here | ||
| 1430 | // for reference for now. | ||
| 1431 | //fov.setResolution(width, height) | ||
| 1432 | // .setBounds(glm::vec3(-0.5f,-0.5f,-500.0f), glm::vec3(0.5f, 0.5f, 0.1f) ) | ||
| 1433 | // .setPerspective(0.7854f); | ||
| 1434 | //glLoadMatrixf(glm::value_ptr(fov.getViewerScreenXform())); | ||
| 1435 | |||
| 1436 | glLoadIdentity(); | ||
| 1437 | |||
| 1438 | // XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that | ||
| 1439 | // OpenGL won't clip our frustum rendering lines. This is a debug hack for sure! Basically, this makes | ||
| 1440 | // the near clip a little bit closer (therefor you see more) and the far clip a little bit farther (also, | ||
| 1441 | // to see more.) | ||
| 1442 | if (::frustumOn) { | ||
| 1443 | nearClip -= 0.01f; | ||
| 1444 | farClip += 0.01f; | ||
| 1445 | } | ||
| 1446 | |||
| 1447 | // On window reshape, we need to tell OpenGL about our new setting | ||
| 1448 | gluPerspective(fov,aspectRatio,nearClip,farClip); | ||
| 1449 | |||
| 1375 | glMatrixMode(GL_MODELVIEW); | 1450 | glMatrixMode(GL_MODELVIEW); |
| 1376 | glLoadIdentity(); | 1451 | glLoadIdentity(); |
| 1377 | 1452 | ||
| 1378 | glViewport(0, 0, width, height); | 1453 | |
| 1379 | } | 1454 | } |
| 1380 | 1455 | ||
| 1381 | |||
| 1382 | |||
| 1383 | void mouseFunc( int button, int state, int x, int y ) | 1456 | void mouseFunc( int button, int state, int x, int y ) |
| 1384 | { | 1457 | { |
| 1385 | if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) | 1458 | if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) |
| @@ -1469,6 +1542,12 @@ int main(int argc, const char * argv[]) · 83 unmodified lines | |||
| 1469 | #ifdef _WIN32 | 1542 | #ifdef _WIN32 |
| 1470 | glewInit(); | 1543 | glewInit(); |
| 1471 | #endif | 1544 | #endif |
| 1545 | |||
| 1546 | // Before we render anything, let's set up our viewFrustumOffsetCamera with a sufficiently large | ||
| 1547 | // field of view and near and far clip to make it interesting. | ||
| 1548 | //viewFrustumOffsetCamera.setFieldOfView(90.0); | ||
| 1549 | viewFrustumOffsetCamera.setNearClip(0.1); | ||
| 1550 | viewFrustumOffsetCamera.setFarClip(500.0); | ||
| 1472 | 1551 | ||
| 1473 | printf( "Created Display Window.\n" ); | 1552 | printf( "Created Display Window.\n" ); |
| 1474 | 1553 | ||