-
Notifications
You must be signed in to change notification settings - Fork 1
/
LightDialog.cpp
executable file
·156 lines (120 loc) · 4.98 KB
/
LightDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// LightDialog.cpp : implementation file
//
#include "stdafx.h"
#include "CGWork.h"
#include "LightDialog.h"
// CLightDialog dialog
IMPLEMENT_DYNAMIC(CLightDialog, CDialog)
CLightDialog::CLightDialog(CWnd* pParent /*=NULL*/)
: CDialog(CLightDialog::IDD, pParent)
{
m_currentLightIdx = 0;
}
CLightDialog::~CLightDialog()
{
}
void CLightDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//ambient light
DDX_Text(pDX, IDC_AMBL_COLOR_R, m_ambiant.colorR);
DDX_Text(pDX, IDC_AMBL_COLOR_G, m_ambiant.colorG);
DDX_Text(pDX, IDC_AMBL_COLOR_B, m_ambiant.colorB);
//update light parameters for the currently selected light
DDX_Text(pDX, IDC_LIGHT_COLOR_R, m_lights[m_currentLightIdx].colorR);
DDX_Text(pDX, IDC_LIGHT_COLOR_G, m_lights[m_currentLightIdx].colorG);
DDX_Text(pDX, IDC_LIGHT_COLOR_B, m_lights[m_currentLightIdx].colorB);
DDX_Text(pDX, IDC_LIGHT_POS_X, m_lights[m_currentLightIdx].posX);
DDX_Text(pDX, IDC_LIGHT_POS_Y, m_lights[m_currentLightIdx].posY);
DDX_Text(pDX, IDC_LIGHT_POS_Z, m_lights[m_currentLightIdx].posZ);
DDX_Text(pDX, IDC_LIGHT_DIR_X, m_lights[m_currentLightIdx].dirX);
DDX_Text(pDX, IDC_LIGHT_DIR_Y, m_lights[m_currentLightIdx].dirY);
DDX_Text(pDX, IDC_LIGHT_DIR_Z, m_lights[m_currentLightIdx].dirZ);
//update lighting constants
DDX_Text(pDX, IDC_AMBIENT_MOD, m_ambient_mod);
DDV_MinMaxDouble(pDX, m_ambient_mod, 0, 1);
DDX_Text(pDX, IDC_DIFFUSE_MOD, m_diffuse_mod);
DDV_MinMaxDouble(pDX, m_diffuse_mod, 0, 1);
DDX_Text(pDX, IDC_SPECULAR_MOD, m_specular_mod);
DDV_MinMaxDouble(pDX, m_specular_mod, 0, 1);
DDX_Text(pDX, IDC_SPECULAR_N, m_specular_n);
//the following class members can't be updated directly through DDX
//using a helper variable for type-casting to solve the compilation error
int helper=m_lights[m_currentLightIdx].enabled;
DDX_Check(pDX,IDC_LIGHT_ENABLED,helper);
m_lights[m_currentLightIdx].enabled = (bool)helper;
helper = m_lights[m_currentLightIdx].type;
DDX_CBIndex(pDX,IDC_LIGHT_TYPE,helper);
m_lights[m_currentLightIdx].type = (LightType)helper;
helper = m_lights[m_currentLightIdx].space;
DDX_CBIndex(pDX,IDC_LIGHT_SPACE,helper);
m_lights[m_currentLightIdx].space = (LightSpace)helper;
}
BEGIN_MESSAGE_MAP(CLightDialog, CDialog)
ON_BN_CLICKED(IDC_RADIO_LIGHT1, &CLightDialog::OnBnClickedRadioLight)
ON_BN_CLICKED(IDC_RADIO_LIGHT2, &CLightDialog::OnBnClickedRadioLight)
ON_BN_CLICKED(IDC_RADIO_LIGHT3, &CLightDialog::OnBnClickedRadioLight)
ON_BN_CLICKED(IDC_RADIO_LIGHT4, &CLightDialog::OnBnClickedRadioLight)
ON_BN_CLICKED(IDC_RADIO_LIGHT5, &CLightDialog::OnBnClickedRadioLight)
ON_BN_CLICKED(IDC_RADIO_LIGHT6, &CLightDialog::OnBnClickedRadioLight)
ON_BN_CLICKED(IDC_RADIO_LIGHT7, &CLightDialog::OnBnClickedRadioLight)
ON_BN_CLICKED(IDC_RADIO_LIGHT8, &CLightDialog::OnBnClickedRadioLight)
ON_BN_CLICKED(IDC_LIGHT_ENABLED, &CLightDialog::OnBnClickedLightEnabled)
ON_CBN_SELCHANGE(IDC_LIGHT_TYPE, &CLightDialog::OnCbnSelchangeLightType)
ON_EN_CHANGE(IDC_LIGHT_COLOR_R, &CLightDialog::OnEnChangeLightColorR)
END_MESSAGE_MAP()
void CLightDialog::SetDialogData( LightID id,const LightParams& light )
{
if (id<=LIGHT_ID_AMBIENT)
m_ambiant = light;
else
m_lights[id]=light;
}
void CLightDialog::SetLightConstants(double ambient_mod, double diffuse_mod, double spcular_mod, double spcular_n)
{
m_ambient_mod = ambient_mod;
m_diffuse_mod = diffuse_mod;
m_specular_mod = spcular_mod;
m_specular_n = spcular_n;
}
LightParams CLightDialog::GetDialogData( LightID id )
{
if (id==LIGHT_ID_AMBIENT)
return m_ambiant;
else
return m_lights[id];
}
// CLightDialog message handlers
//this callback function is called when each of the radio buttons on the dialog is clicked
void CLightDialog::OnBnClickedRadioLight()
{
//save the dialog state into the data variables
UpdateData(TRUE);
//get the newly selected light index from the radio buttons
m_currentLightIdx=GetCheckedRadioButton(IDC_RADIO_LIGHT1,IDC_RADIO_LIGHT8)-IDC_RADIO_LIGHT1;
//Update all dialog fields according to the new light index
UpdateData(FALSE);
Invalidate();
}
BOOL CLightDialog::OnInitDialog()
{
CDialog::OnInitDialog();
//Set the radio button of the current light to be selected
CheckRadioButton(IDC_RADIO_LIGHT1,IDC_RADIO_LIGHT8,m_currentLightIdx+IDC_RADIO_LIGHT1);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CLightDialog::OnBnClickedLightEnabled()
{
}
void CLightDialog::OnCbnSelchangeLightType()
{
}
void CLightDialog::OnEnChangeLightColorR()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}