-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointLight.cpp
175 lines (145 loc) · 3.47 KB
/
PointLight.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "PointLight.h"
//RwRaster* PointLight::mShadowRaster[60];
PointLight::PointLight()
{
//mShadowRaster = nullptr;
}
PointLight::PointLight(int width, int height)
{
//mShadowRaster = RwD3D9RasterCreate(width, height, D3DFMT_G32R32F, rwRASTERTYPECAMERATEXTURE);
// rwD3D9CubeRasterCreate(mShadowRaster, D3DFMT_G32R32F, 1);
}
PointLight::~PointLight()
{
//if (mShadowRaster == nullptr)
// return;
//RwRasterDestroy(mShadowRaster);
//std::ofstream myfile;
//myfile.open("example2.txt");
//myfile << "Writing this to a file.\n";
//myfile << "Writing this to a file.\n";
//myfile << "Writing this to a file.\n";
//myfile << "Writing this to a file.\n";
//myfile.close();
}
void PointLight::SetMatrix(XMMATRIX matrix)
{
}
void PointLight::SetColor(XMFLOAT3 color)
{
mColor = color;
}
void PointLight::SetPosition(XMFLOAT3 position)
{
mPosition = XMLoadFloat3(&position);
}
void PointLight::SetDirection(XMFLOAT3 direction)
{
mDirection = XMLoadFloat3(&direction);
}
void PointLight::SetIntensity(float intensity)
{
mIntensity = intensity;
}
void PointLight::SetRadius(float radius)
{
mRadius = max(1.0f, radius);
}
void PointLight::CastShadow(bool cast)
{
mCastShadow = cast;
}
Math::Frustum PointLight::GetFrustum(int i)
{
return mFrustum[i];
}
XMMATRIX PointLight::GetViewMatrix(int i)
{
return mView[i];
}
XMMATRIX PointLight::GetProjection()
{
return mProjection;
}
XMFLOAT3 PointLight::GetColor()
{
return mColor;
}
XMFLOAT3 PointLight::GetDirection()
{
XMFLOAT3 direction;
XMStoreFloat3(&direction, mDirection);
return direction;
}
XMFLOAT3 PointLight::GetPosition()
{
XMFLOAT3 position;
XMStoreFloat3(&position, mPosition);
return position;
}
float PointLight::GetIntensity()
{
return mIntensity;
}
float PointLight::GetRadius()
{
return mRadius;
}
XMMATRIX PointLight::GetWorld()
{
return mWorld;
}
const XMVECTOR DXCubeForward[6] =
{
{1, 0, 0, 0},
{-1, 0, 0, 0 },
{0, 1, 0, 0},
{0, -1, 0, 0},
{0, 0, 1, 0},
{0, 0, -1, 0},
};
const XMVECTOR DXCubeUp[6] =
{
{0, 1, 0, 0 },
{0, 1, 0, 0},
{0, 0, -1, 0 },
{0, 0, 1, 0 },
{0, 1, 0, 0 },
{0, 1, 0, 0 },
};
void PointLight::Update()
{
XMStoreFloat3(&mSphere.Center, mPosition);
mSphere.Radius = mRadius;
XMMATRIX scaling = XMMatrixScaling(1/mRadius, 1 / mRadius, 1 / mRadius);
XMMATRIX translation = XMMatrixTranslationFromVector(mPosition);
mWorld = scaling*translation;
mProjection = XMMatrixPerspectiveFovLH(XMConvertToRadians(90.0f), 1.0f, 0.01f, mRadius);
for (size_t i = 0; i < 6; i++)
{
/*switch (static_cast<D3DCUBEMAP_FACES>(i))
{
case D3DCUBEMAP_FACE_POSITIVE_X:
mView[i] = XMMatrixLookAtLH(mPosition, mPosition + -g_XMIdentityR0, -g_XMIdentityR1);
break;
case D3DCUBEMAP_FACE_NEGATIVE_X:
mView[i] = XMMatrixLookAtLH(mPosition, mPosition + g_XMIdentityR0, -g_XMIdentityR1);
break;
case D3DCUBEMAP_FACE_POSITIVE_Y:
mView[i] = XMMatrixLookAtLH(mPosition, mPosition + g_XMIdentityR1, -g_XMIdentityR2);
break;
case D3DCUBEMAP_FACE_NEGATIVE_Y:
mView[i] = XMMatrixLookAtLH(mPosition, mPosition + -g_XMIdentityR1, g_XMIdentityR2);
break;
case D3DCUBEMAP_FACE_POSITIVE_Z:
mView[i] = XMMatrixLookAtLH(mPosition, mPosition + -g_XMIdentityR2, -g_XMIdentityR1);
break;
case D3DCUBEMAP_FACE_NEGATIVE_Z:
mView[i] = XMMatrixLookAtLH(mPosition, mPosition + -g_XMIdentityR2, -g_XMIdentityR1);
break;
}*/
mView[i] = XMMatrixLookAtLH(mPosition, mPosition + DXCubeForward[i], DXCubeUp[i]);
mMatrix[i] = mView[i] * mProjection;
mFrustum[i].SetMatrix(mMatrix[i]);
}
}