Changeset 608 for trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
- Timestamp:
- 02/08/06 20:32:42 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
r599 r608 13 13 #include <Cg/cgGL.h> 14 14 15 #include <QVBoxLayout> 16 15 17 static CGcontext sCgContext = NULL; 16 18 static CGprogram sCgFragmentProgram = NULL; … … 43 45 mViewPoint = mSceneGraph->GetBox().Center(); 44 46 mViewDirection = Vector3(0,0,1); 47 45 48 // timerId = startTimer(10); 46 49 // debug coords for atlanta 47 mViewPoint = Vector3(3473, 6.778, -1699);48 mViewDirection = Vector3(-0.2432, 0, 0.97);50 // mViewPoint = Vector3(3473, 6.778, -1699); 51 // mViewDirection = Vector3(-0.2432, 0, 0.97); 49 52 50 53 mFrame = 0; … … 205 208 { 206 209 QString s; 207 s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)", 210 int vc = 0; 211 if (mViewCellsManager) 212 vc = mViewCellsManager->GetViewCells().size(); 213 s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d", 208 214 mFrame, 209 215 mViewPoint.x, … … 212 218 mViewDirection.x, 213 219 mViewDirection.y, 214 mViewDirection.z 215 220 mViewDirection.z, 221 vc 216 222 ); 217 223 renderText(0,20,s); … … 433 439 434 440 441 void 442 GlRendererWidget::SetupProjection(const int w, const int h) 443 { 444 if (!mTopView) 445 GlRenderer::SetupProjection(w, h); 446 else { 447 glViewport(0, 0, w, h); 448 glMatrixMode(GL_PROJECTION); 449 glLoadIdentity(); 450 gluPerspective(50.0, 1.0, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 451 glMatrixMode(GL_MODELVIEW); 452 } 453 } 454 435 455 float 436 456 GlRendererWidget::RenderErrors() … … 444 464 SetupCamera(); 445 465 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 446 447 466 467 double eq[4]; 468 eq[0] = mSceneCutPlane.mNormal.x; 469 eq[1] = mSceneCutPlane.mNormal.y; 470 eq[2] = mSceneCutPlane.mNormal.z; 471 eq[3] = mSceneCutPlane.mD; 472 473 if (mCutScene) { 474 glClipPlane(GL_CLIP_PLANE0, eq); 475 glEnable(GL_CLIP_PLANE0); 476 } 477 448 478 if (mDetectEmptyViewSpace) 449 479 glEnable( GL_CULL_FACE ); … … 553 583 } 554 584 585 glDisable(GL_CLIP_PLANE0); 586 555 587 return pErrorPixels; 556 588 } … … 697 729 GlRendererWidget::paintGL() 698 730 { 699 if (mRenderViewCells) 731 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 732 733 734 RenderErrors(); 735 RenderInfo(); 736 737 if (mRenderViewCells) 700 738 RenderViewCells(); 701 else { 702 RenderErrors(); 703 RenderInfo(); 704 } 705 739 706 740 mFrame++; 707 741 } … … 714 748 GlRenderer::SetupCamera(); 715 749 else { 716 float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05; 717 Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x, 718 -1, 719 mViewDirection.y); 720 721 Vector3 target = mViewPoint + dist*mViewDirection; 722 Vector3 up(0,1,0); 723 724 glLoadIdentity(); 725 gluLookAt(pos.x, pos.y, pos.z, 726 target.x, target.y, target.z, 727 up.x, up.y, up.z); 750 if (0) { 751 float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05; 752 Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x, 753 -1, 754 mViewDirection.y); 755 756 Vector3 target = mViewPoint + dist*mViewDirection; 757 Vector3 up(0,1,0); 758 759 glLoadIdentity(); 760 gluLookAt(pos.x, pos.y, pos.z, 761 target.x, target.y, target.z, 762 up.x, up.y, up.z); 763 } else { 764 float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*mTopDistance; 765 Vector3 pos = mViewPoint + dist*Vector3(0, 766 1, 767 0); 768 769 Vector3 target = mViewPoint; 770 Vector3 up(mViewDirection.x, 0, mViewDirection.z); 771 772 glLoadIdentity(); 773 gluLookAt(pos.x, pos.y, pos.z, 774 target.x, target.y, target.z, 775 up.x, up.y, up.z); 776 777 } 728 778 } 729 779 … … 736 786 case Qt::Key_T: 737 787 mTopView = !mTopView; 788 SetupProjection(width(), height()); 738 789 updateGL(); 739 790 break; … … 746 797 break; 747 798 } 748 799 } 800 801 802 RendererControlWidget::RendererControlWidget(QWidget * parent, Qt::WFlags f): 803 QWidget(parent, f) 804 { 805 806 QVBoxLayout *vl = new QVBoxLayout; 807 setLayout(vl); 808 809 QWidget *vbox = new QGroupBox("ViewCells", this); 810 layout()->addWidget(vbox); 811 812 vl = new QVBoxLayout; 813 vbox->setLayout(vl); 814 815 QSlider *slider = new QSlider(Qt::Horizontal, vbox); 816 vl->addWidget(slider); 817 slider->show(); 818 slider->setRange(1, 10000); 819 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 820 slider->setValue(500); 821 822 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int))); 823 824 825 826 QWidget *hbox = new QWidget(vbox); 827 vl->addWidget(hbox); 828 QHBoxLayout *hlayout = new QHBoxLayout; 829 hbox->setLayout(hlayout); 830 831 QCheckBox *cb = new QCheckBox("Show viewcells", hbox); 832 hlayout->addWidget(cb); 833 cb->setChecked(false); 834 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); 835 836 vbox->resize(800,100); 837 838 839 vbox = new QGroupBox("Rendering", this); 840 layout()->addWidget(vbox); 841 842 vl = new QVBoxLayout; 843 vbox->setLayout(vl); 844 845 slider = new QSlider(Qt::Horizontal, vbox); 846 vbox->layout()->addWidget(slider); 847 slider->show(); 848 slider->setRange(0, 1000); 849 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 850 slider->setValue(1000); 851 852 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); 853 854 855 cb = new QCheckBox("Cut view cells", vbox); 856 vbox->layout()->addWidget(cb); 857 cb->setChecked(false); 858 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool))); 859 860 cb = new QCheckBox("Cut scene", vbox); 861 vbox->layout()->addWidget(cb); 862 cb->setChecked(false); 863 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool))); 864 865 866 slider = new QSlider(Qt::Horizontal, vbox); 867 vbox->layout()->addWidget(slider); 868 slider->show(); 869 slider->setRange(1, 1000); 870 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 871 slider->setValue(500); 872 873 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int))); 874 875 cb = new QCheckBox("Top View", vbox); 876 vbox->layout()->addWidget(cb); 877 cb->setChecked(false); 878 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); 879 880 881 adjustSize(); 749 882 } 750 883 … … 761 894 mTopView = false; 762 895 mRenderViewCells = false; 763 764 QSlider *slider = new QSlider(this); 765 slider->show(); 766 slider->setRange(1, 10000); 767 768 connect(slider, SIGNAL(valueChanged(int)), this, SLOT(SetViewcellGranularity(int))); 769 } 770 771 void 772 GlRendererWidget::SetViewcellGranularity(int number) 896 mTopDistance = 1.0f; 897 mCutViewCells = false; 898 mCutScene = false; 899 900 RendererControlWidget *cw = new RendererControlWidget(NULL); 901 connect(cw, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 902 connect(cw, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 903 connect(cw, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 904 connect(cw, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); 905 connect(cw, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); 906 connect(cw, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); 907 connect(cw, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 908 909 cw->show(); 910 } 911 912 void 913 GlRendererWidget::SetViewCellGranularity(int number) 773 914 { 774 915 mViewCellsManager->CollectViewCells(number); … … 777 918 778 919 void 920 GlRendererWidget::SetSceneCut(int number) 921 { 922 // assume the cut plane can only be aligned with xz plane 923 // shift it along y according to number, which is percentage of the bounding 924 // box position 925 if (mViewCellsManager) { 926 AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 927 Vector3 p = box.Min() + (number/1000.0f)*box.Max(); 928 mSceneCutPlane.mNormal = Vector3(0,-1,0); 929 mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p); 930 updateGL(); 931 } 932 } 933 934 void 935 GlRendererWidget::SetTopDistance(int number) 936 { 937 mTopDistance = number/1000.0f; 938 updateGL(); 939 } 940 941 void 779 942 GlRendererWidget::RenderViewCells() 780 943 { … … 782 945 783 946 SetupCamera(); 784 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 785 947 glEnable(GL_CULL_FACE); 948 glCullFace(GL_FRONT); 949 double eq[4]; 950 eq[0] = mSceneCutPlane.mNormal.x; 951 eq[1] = mSceneCutPlane.mNormal.y; 952 eq[2] = mSceneCutPlane.mNormal.z; 953 eq[3] = mSceneCutPlane.mD; 954 955 if (mCutViewCells) { 956 glClipPlane(GL_CLIP_PLANE0, eq); 957 glEnable(GL_CLIP_PLANE0); 958 } 959 786 960 int i; 787 961 ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 788 962 for (i=0; i < viewcells.size(); i++) { 789 963 ViewCell *vc = viewcells[i]; 790 Mesh *m = vc->GetMesh(); 791 float r = RandomValue(0.5, 1.0); 792 float g = RandomValue(0.5, 1.0); 793 float b = RandomValue(0.5, 1.0); 794 795 glColor3f(r, g, b); 796 //SetupMaterial(m->mMaterial); 797 964 // Mesh *m = vc->GetMesh(); 965 RgbColor c = vc->GetColor(); 966 glColor3f(c.r, c.g, c.b); 798 967 RenderViewCell(vc); 799 968 } 969 970 glDisable(GL_CLIP_PLANE0); 800 971 801 972 }
Note: See TracChangeset
for help on using the changeset viewer.