3dPageTerrain.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:9k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPageTerrain.cpp : implementation file
- //
- // glOOP (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1998
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- // This program is -not- in the public domain.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "glOOP.h"
- #include "3dObjectDialog.h"
- #include <math.h>
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dPageTerrain
- IMPLEMENT_DYNCREATE(C3dPageTerrain, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrain dialog construction
- C3dPageTerrain::C3dPageTerrain()
- : CPropertyPage(C3dPageTerrain::IDD)
- {
- m_bInitVertices = FALSE;
- //{{AFX_DATA_INIT(C3dPageTerrain)
- m_fDepth = 0.0f;
- m_fWidth = 0.0f;
- m_szName = _T("");
- m_iTile = 0;
- m_iHeightSeed = 0;
- m_bRandomSeed = FALSE;
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrain Destructor
- C3dPageTerrain::~C3dPageTerrain()
- {
- }
- void C3dPageTerrain::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageTerrain)
- DDX_Control(pDX, IDC_SLIDER_SEALEVEL, m_SliderSeaLevel);
- DDX_Control(pDX, IDC_SLIDER_HEIGHT, m_SliderHeight);
- DDX_Control(pDX, IDC_COMBO_GRIDSIZE, m_ComboGridSize);
- DDX_Text(pDX, IDC_DEPTH, m_fDepth);
- DDX_Text(pDX, IDC_WIDTH, m_fWidth);
- DDX_Text(pDX, IDC_NAME, m_szName);
- DDV_MaxChars(pDX, m_szName, 40);
- DDX_Text(pDX, IDC_TILE, m_iTile);
- DDV_MinMaxInt(pDX, m_iTile, 1, 10000);
- DDX_Text(pDX, IDC_HEIGHT_SEED, m_iHeightSeed);
- DDX_Check(pDX, IDC_RANDOM_SEED, m_bRandomSeed);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageTerrain, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageTerrain)
- ON_EN_CHANGE(IDC_DEPTH, OnChangeDepth)
- ON_EN_CHANGE(IDC_WIDTH, OnChangeWidth)
- ON_CBN_SELCHANGE(IDC_COMBO_GRIDSIZE, OnSelchangeComboGridsize)
- ON_WM_VSCROLL()
- ON_EN_CHANGE(IDC_HEIGHT_SEED, OnChangeHeightSeed)
- ON_BN_CLICKED(IDC_RANDOM_SEED, OnRandomHeight)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageTerrain message handlers
- BOOL C3dPageTerrain::OnInitDialog()
- {
- // let the base class do the default work
- CPropertyPage::OnInitDialog();
- // Set our local values to the Objects' values
- m_szName = m_pObject->m_szName;
- m_fDepth = m_pObject->m_fDepth;
- m_fWidth = m_pObject->m_fWidth;
- m_fHeight = m_pObject->m_fHeight;
- m_iHeightSeed = m_pObject->m_iHeightSeed;
- m_fSeaLevel = m_pObject->m_fSeaLevel;
- m_iTile = m_pObject->m_iTile;
- // Fill our combo boxes and set the default selections:
- // Reset or clear the contents of the light Type combo box
- m_ComboGridSize.ResetContent();
- // Load the light type selections
- m_ComboGridSize.AddString("2 x 2 Grid");
- m_ComboGridSize.AddString("4 x 4 Grid");
- m_ComboGridSize.AddString("8 x 8 Grid");
- m_ComboGridSize.AddString("16 x 16 Grid");
- m_ComboGridSize.AddString("32 x 32 Grid");
- m_ComboGridSize.AddString("64 x 64 Grid");
- m_ComboGridSize.AddString("128 x 128 Grid");
- m_ComboGridSize.AddString("256 x 256 Grid");
- // Set a default selection (brute force method..)
- // (I'm sure there is some algorthium, but I'm
- // anxious..)
- if(m_pObject->m_iSize == 2)
- m_ComboGridSize.SetCurSel(0);
- if(m_pObject->m_iSize == 4)
- m_ComboGridSize.SetCurSel(1);
- if(m_pObject->m_iSize == 8)
- m_ComboGridSize.SetCurSel(2);
- if(m_pObject->m_iSize == 16)
- m_ComboGridSize.SetCurSel(3);
- if(m_pObject->m_iSize == 32)
- m_ComboGridSize.SetCurSel(4);
- if(m_pObject->m_iSize == 64)
- m_ComboGridSize.SetCurSel(5);
- if(m_pObject->m_iSize == 128)
- m_ComboGridSize.SetCurSel(6);
- if(m_pObject->m_iSize == 256)
- m_ComboGridSize.SetCurSel(7);
- // Set our Terrain Height slider. Scaled by 10.
- m_SliderHeight.SetRange(0, 50, TRUE);
- m_SliderHeight.SetPos((int)(m_fHeight*10));
- // Set our Sea Level slider
- m_SliderSeaLevel.SetRange(0, 100, TRUE);
- m_SliderSeaLevel.SetPos((int)((1-m_fSeaLevel)*100));
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void C3dPageTerrain::OnOK()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- if(m_bRandomSeed)
- m_pObject->m_iHeightSeed = -1;
- else
- m_pObject->m_iHeightSeed = m_iHeightSeed;
- // Set the Objects Origin..
- m_pObject->m_szName = m_szName;
- m_pObject->m_fDepth = m_fDepth;
- m_pObject->m_fWidth = m_fWidth;
- m_pObject->m_fHeight = m_fHeight;
- m_pObject->m_fSeaLevel = m_fSeaLevel;
- m_pObject->m_iTile = m_iTile;
- // Force the object to rebuild its' display list
- m_pObject->m_bBuildLists = TRUE;
- // Rebuild our objects vertices?
- if(m_bInitVertices)
- m_pObject->InitTerrain();
- CPropertyPage::OnOK();
- }
- void C3dPageTerrain::OnChangeDepth()
- {
- // User has modified the planes depth, so set our vertice
- // initialization flag
- m_bInitVertices = TRUE;
- }
- void C3dPageTerrain::OnChangeWidth()
- {
- // User has modified the planes width depth, so set our vertice
- // initialization flag
- m_bInitVertices = TRUE;
- }
- void C3dPageTerrain::OnChangeHeightSeed()
- {
- // User has modified the planes width depth, so set our vertice
- // initialization flag
- m_bInitVertices = TRUE;
- }
- void C3dPageTerrain::OnSelchangeComboGridsize()
- {
- int count;
- // User has modified the planes width depth, so set our vertice
- // initialization flag
- m_bInitVertices = TRUE;
- // Get the zero-based index of the item selected
- count = m_ComboGridSize.GetCurSel();
- if(count == 0)
- m_pObject->m_iSize = 2;
- if(count == 1)
- m_pObject->m_iSize = 4;
- if(count == 2)
- m_pObject->m_iSize = 8;
- if(count == 3)
- m_pObject->m_iSize = 16;
- if(count == 4)
- m_pObject->m_iSize = 32;
- if(count == 5)
- m_pObject->m_iSize = 64;
- if(count == 6)
- m_pObject->m_iSize = 128;
- if(count == 7)
- m_pObject->m_iSize = 256;
- }
- void C3dPageTerrain::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // Note: MFC maps vertically oriented CSliderCtrl to WM_VSCROLL
- // and horizontally oriented CSliderCtrl to WM_HSCROLL
- int posn;
- if((CSliderCtrl*)pScrollBar == &m_SliderHeight)
- {
- // Get the position of our slider since it's position
- // is not returned when paging up/down/left/right
- posn = m_SliderHeight.GetPos();
- if(nSBCode == SB_LINELEFT) // nSBCode = 0
- {
- }
- if(nSBCode == SB_LINERIGHT) // nSBCode = 1
- {
- }
- if(nSBCode == SB_PAGELEFT) // nSBCode = 2
- {
- m_fHeight = posn/10.0f; // Scale by 10
- }
- if(nSBCode == SB_PAGERIGHT) // nSBCode = 3
- {
- m_fHeight = posn/10.0f; // Scale by 10
- }
- if(nSBCode == SB_THUMBPOSITION) // nSBCode = 4
- {
- m_fHeight = posn/10.0f; // Scale by 10
- }
- if(nSBCode == SB_THUMBTRACK) // nSBCode = 5
- {
- }
- // User has modified the planes depth, so set our vertice
- // initialization flag
- m_bInitVertices = TRUE;
- }
- else if((CSliderCtrl*)pScrollBar == &m_SliderSeaLevel)
- {
- // Get the position of our slider since it's position
- // is not returned when paging up/down/left/right
- posn = m_SliderSeaLevel.GetPos();
- if(nSBCode == SB_LINELEFT) // nSBCode = 0
- {
- }
- if(nSBCode == SB_LINERIGHT) // nSBCode = 1
- {
- }
- if(nSBCode == SB_PAGELEFT) // nSBCode = 2
- {
- m_fSeaLevel = 1-(posn/100.0f);// Scale by 100
- }
- if(nSBCode == SB_PAGERIGHT) // nSBCode = 3
- {
- m_fSeaLevel = 1-(posn/100.0f);// Scale by 100
- }
- if(nSBCode == SB_THUMBPOSITION) // nSBCode = 4
- {
- m_fSeaLevel = 1-(posn/100.0f);// Scale by 100
- }
- if(nSBCode == SB_THUMBTRACK) // nSBCode = 5
- {
- }
- // User has modified the planes depth, so set our vertice
- // initialization flag
- m_bInitVertices = TRUE;
- }
- CPropertyPage::OnVScroll(nSBCode, nPos, pScrollBar);
- }
- void C3dPageTerrain::OnRandomHeight()
- {
- // User has modified the planes depth, so set our vertice
- // initialization flag
- m_bInitVertices = TRUE;
- }