3dPageLight.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:12k
源码类别:
OpenGL
开发平台:
Visual C++
- /////////////////////////////////////////////////////////////////////////////
- // 3dPageLight.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 "MyColorPaletteWnd.h"
- #include "EditColorDlg.h"
- #include "3dObjectDialog.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dPageLight
- IMPLEMENT_DYNCREATE(C3dPageLight, CPropertyPage)
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageLight dialog construction
- C3dPageLight::C3dPageLight()
- :CPropertyPage(C3dPageLight::IDD)
- {
- m_pWorld = NULL;
- m_pLight = NULL;
- //{{AFX_DATA_INIT(C3dPageLight)
- m_szName = _T("");
- m_fSpotAngle = 0.0f;
- m_fRadius = 0.0f;
- m_iAttnConstant = -1;
- m_fAttnFactor = 0.0f;
- m_iDirectional = -1;
- //}}AFX_DATA_INIT
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageLight Destructor
- C3dPageLight::~C3dPageLight()
- {
- }
- void C3dPageLight::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(C3dPageLight)
- DDX_Control(pDX, IDC_LIGHT_TYPE_COMBO, m_ComboType);
- DDX_Control(pDX, IDC_LIGHT_DISPLAY_COMBO, m_ComboDisplayAs);
- DDX_Control(pDX, IDC_SLIDER_ATTN_FACTOR, m_SliderAttnFactor);
- DDX_Text(pDX, IDC_NAME, m_szName);
- DDV_MaxChars(pDX, m_szName, 40);
- DDX_Text(pDX, IDC_CUTOFF, m_fSpotAngle);
- DDX_Text(pDX, IDC_RADIUS, m_fRadius);
- DDX_Radio(pDX, IDC_ATTN_CONSTANT, m_iAttnConstant);
- DDX_Text(pDX, IDC_ATTN_FACTOR, m_fAttnFactor);
- DDX_Radio(pDX, IDC_W_DIRECTIONAL, m_iDirectional);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(C3dPageLight, CPropertyPage)
- //{{AFX_MSG_MAP(C3dPageLight)
- ON_CBN_SELCHANGE(IDC_LIGHT_TYPE_COMBO, OnSelchangeTypeCombo)
- ON_CBN_SELCHANGE(IDC_LIGHT_DISPLAY_COMBO, OnSelchangeDisplayCombo)
- ON_BN_CLICKED(IDC_ATTN_CONSTANT, OnAttnConstant)
- ON_BN_CLICKED(IDC_ATTN_LINEAR, OnAttnLinear)
- ON_BN_CLICKED(IDC_ATTN_QUADRATIC, OnAttnQuadratic)
- ON_EN_KILLFOCUS(IDC_ATTN_FACTOR, OnKillfocusAttnFactor)
- ON_BN_CLICKED(IDC_W_DIRECTIONAL, OnWDirectional)
- ON_BN_CLICKED(IDC_W_POSITIONAL, OnWPositional)
- ON_NOTIFY(NM_SETFOCUS, IDC_SLIDER_ATTN_FACTOR, OnSetfocusSliderAttnFactor)
- ON_NOTIFY(NM_RETURN, IDC_SLIDER_ATTN_FACTOR, OnReturnSliderAttnFactor)
- ON_WM_HSCROLL()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageLight Methods / Implementation
- void C3dPageLight::SetWindowsState()
- {
- switch(m_pLight->m_iLightType)
- {
- case LIGHT_AMBIENT:
- // Disable all windows except Name and Type
- GetDlgItem(IDC_LIGHT_DISPLAY_COMBO)->EnableWindow(FALSE);
- GetDlgItem(IDC_CUTOFF)->EnableWindow(FALSE);
- GetDlgItem(IDC_RADIUS)->EnableWindow(FALSE);
- GetDlgItem(IDC_W_DIRECTIONAL)->EnableWindow(FALSE);
- GetDlgItem(IDC_W_POSITIONAL)->EnableWindow(FALSE);
- break;
- case LIGHT_POINT:
- // Disable all windows except Name and Type
- GetDlgItem(IDC_LIGHT_DISPLAY_COMBO)->EnableWindow(TRUE);
- GetDlgItem(IDC_RADIUS)->EnableWindow(TRUE);
- GetDlgItem(IDC_W_DIRECTIONAL)->EnableWindow(TRUE);
- GetDlgItem(IDC_W_POSITIONAL)->EnableWindow(TRUE);
- GetDlgItem(IDC_CUTOFF)->EnableWindow(FALSE);
- break;
- case LIGHT_SPOT:
- // Disable all windows except Name and Type
- GetDlgItem(IDC_LIGHT_DISPLAY_COMBO)->EnableWindow(TRUE);
- GetDlgItem(IDC_RADIUS)->EnableWindow(TRUE);
- GetDlgItem(IDC_W_DIRECTIONAL)->EnableWindow(TRUE);
- GetDlgItem(IDC_W_POSITIONAL)->EnableWindow(TRUE);
- GetDlgItem(IDC_CUTOFF)->EnableWindow(TRUE);
- break;
- }
- // Set light Positional/Directional radio buttons
- if(m_iDirectional == 0 || m_pLight->m_iLightType == LIGHT_AMBIENT)
- {
- // Disable the radio button and data windows
- GetDlgItem(IDC_ATTN_CONSTANT)->EnableWindow(FALSE);
- GetDlgItem(IDC_ATTN_LINEAR)->EnableWindow(FALSE);
- GetDlgItem(IDC_ATTN_QUADRATIC)->EnableWindow(FALSE);
- GetDlgItem(IDC_ATTN_FACTOR)->EnableWindow(FALSE);
- GetDlgItem(IDC_SLIDER_ATTN_FACTOR)->EnableWindow(FALSE);
- }
- else
- {
- // Disable the radio button and data windows
- GetDlgItem(IDC_ATTN_CONSTANT)->EnableWindow(TRUE);
- GetDlgItem(IDC_ATTN_LINEAR)->EnableWindow(TRUE);
- GetDlgItem(IDC_ATTN_QUADRATIC)->EnableWindow(TRUE);
- GetDlgItem(IDC_ATTN_FACTOR)->EnableWindow(TRUE);
- GetDlgItem(IDC_SLIDER_ATTN_FACTOR)->EnableWindow(TRUE);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dPageLight message handlers
- BOOL C3dPageLight::OnInitDialog()
- {
- float k, l, q;
- int count;
- // let the base class do the default work
- CPropertyPage::OnInitDialog();
- // Ensure that we have valid pointers
- if(!m_pWorld || !m_pLight)
- return FALSE;
- // Get the Directional lights' properties and set the dialog data
- m_szName.Format("%s", m_pLight->m_szName);
- m_pLight->GetSpotAngle(&m_fSpotAngle);
- m_pLight->GetRadius(&m_fRadius);
- // Fill our combo boxes and set the default selections:
- // Reset or clear the contents of the light Type combo box
- m_ComboType.ResetContent();
- // Load the light type selections
- m_ComboType.AddString("Ambient background");
- count = m_ComboType.GetCount() - 1; // zero based
- m_ComboType.SetItemData(count, NULL);
- m_ComboType.AddString("Point Light");
- count = m_ComboType.GetCount() - 1; // zero based
- m_ComboType.SetItemData(count, NULL);
- m_ComboType.AddString("Spot Light");
- count = m_ComboType.GetCount() - 1; // zero based
- m_ComboType.SetItemData(count, NULL);
- // Set a default selection
- m_ComboType.SetCurSel(m_pLight->m_iLightType);
- // Reset or clear the contents of the Display As combo box
- m_ComboDisplayAs.ResetContent();
- // Load the light type selections
- m_ComboDisplayAs.AddString("None");
- count = m_ComboDisplayAs.GetCount() - 1; // zero based
- m_ComboDisplayAs.SetItemData(count, NULL);
- m_ComboDisplayAs.AddString("Sphere");
- count = m_ComboDisplayAs.GetCount() - 1; // zero based
- m_ComboDisplayAs.SetItemData(count, NULL);
- m_ComboDisplayAs.AddString("Cylinder");
- count = m_ComboDisplayAs.GetCount() - 1; // zero based
- m_ComboDisplayAs.SetItemData(count, NULL);
- m_ComboDisplayAs.AddString("Rectangle");
- count = m_ComboDisplayAs.GetCount() - 1; // zero based
- m_ComboDisplayAs.SetItemData(count, NULL);
- // Set a default selection
- m_ComboDisplayAs.SetCurSel(m_pLight->m_iDisplayAs);
- // Set light Positional/Directional radio buttons
- if(m_pLight->m_fOrigin[3] == 0.0f)
- m_iDirectional = 0;
- else
- m_iDirectional = 1;
- // Get the lights' attenuation factor
- m_pLight->GetAttenuation(&k, &l, &q);
- // Get a pointer to our attenuation slider
- CSliderCtrl* pSlider = (CSliderCtrl*)GetDlgItem(IDC_SLIDER_ATTN_FACTOR);
- pSlider->SetRange(0, 100, TRUE);
- // Set the dialog's radio buttons, the value in the
- // attenuation data box and the initial position of
- // the attenuation slider control
- if(k > 0.0f)
- {
- m_iAttnConstant = 0;
- m_fAttnFactor = k;
- pSlider->SetPos((int)(k*100));
- }
- if(l > 0.0f)
- {
- m_iAttnConstant = 1;
- m_fAttnFactor = l;
- pSlider->SetPos((int)(l*100));
- }
- if(q > 0.0f)
- {
- m_iAttnConstant = 2;
- m_fAttnFactor = q;
- pSlider->SetPos((int)(q*100));
- }
- // Enable or Disable selected windows
- SetWindowsState();
- // 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 C3dPageLight::OnOK()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- // Get the dialog data and set the Directional lights' properties
- m_pLight->m_szName = m_szName;
- m_pLight->SetSpotAngle(m_fSpotAngle);
- m_pLight->SetRadius(m_fRadius);
- if(m_iAttnConstant == 0)
- m_pLight->SetAttenuation(m_fAttnFactor, 0.0f, 0.0f);
- if(m_iAttnConstant == 1)
- m_pLight->SetAttenuation(0.0f, m_fAttnFactor, 0.0f);
- if(m_iAttnConstant == 2)
- m_pLight->SetAttenuation(0.0f, 0.0f, m_fAttnFactor);
- // Force the light to rebuild its' display list
- m_pLight->m_bBuildLists = TRUE;
- CPropertyPage::OnOK();
- }
- void C3dPageLight::OnSelchangeTypeCombo()
- {
- // Get the zero-based index of the item selected
- m_pLight->m_iLightType = m_ComboType.GetCurSel();
- // Enable or Disable selected windows
- SetWindowsState();
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageLight::OnSelchangeDisplayCombo()
- {
- // Get the zero-based index of the item selected
- m_pLight->m_iDisplayAs = m_ComboDisplayAs.GetCurSel();
- // Enable or Disable selected windows
- SetWindowsState();
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageLight::OnWDirectional()
- {
- // Set the radio button
- m_iDirectional = 0;
- // Set the light's 'W' component
- m_pLight->m_fOrigin[W] = 0.0f;
- // Enable or Disable selected windows
- SetWindowsState();
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageLight::OnWPositional()
- {
- // Set the radio button
- m_iDirectional = 1;
- // Set the light's 'W' component
- m_pLight->m_fOrigin[W] = 1.0f;
- // Enable or Disable selected windows
- SetWindowsState();
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageLight::OnAttnConstant()
- {
- // Set the radio button
- m_iAttnConstant = 0;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageLight::OnAttnLinear()
- {
- // Set the radio button
- m_iAttnConstant = 1;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageLight::OnAttnQuadratic()
- {
- // Set the radio button
- m_iAttnConstant = 2;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void C3dPageLight::OnKillfocusAttnFactor()
- {
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(TRUE);
- }
- void C3dPageLight::OnSetfocusSliderAttnFactor(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- *pResult = 0;
- }
- void C3dPageLight::OnReturnSliderAttnFactor(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- *pResult = 0;
- }
- void C3dPageLight::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // Note: MFC maps vertically oriented CSliderCtrl to WM_VSCROLL
- // and horizontally oriented CSliderCtrl to WM_HSCROLL
- // Get the position of our color slider and calculate the
- // difference in position to our initial position
- int posn = m_SliderAttnFactor.GetPos();
- if(nSBCode == SB_LINELEFT) // nSBCode = 0
- {
- }
- if(nSBCode == SB_LINERIGHT) // nSBCode = 1
- {
- }
- if(nSBCode == SB_PAGELEFT) // nSBCode = 2
- {
- }
- if(nSBCode == SB_PAGERIGHT) // nSBCode = 3
- {
- }
- if(nSBCode == SB_THUMBPOSITION) // nSBCode = 4
- {
- m_fAttnFactor = posn/100.0f;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- if(nSBCode == SB_THUMBTRACK) // nSBCode = 5
- {
- m_fAttnFactor = posn/100.0f;
- // Dialog box is being initialized (FALSE)
- // or data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
- }