-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLights.cpp
66 lines (51 loc) · 1.5 KB
/
CLights.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
#include "CLights.h"
CLights::CLights() {
Light = new CModel;
SpotlightConeAngle = 90.0f;
}
CLights::~CLights()
{
delete Light;
}
// Get "camera-like" view matrix for a spot light
D3DXMATRIXA16 CLights::CalculateLightViewMatrix()
{
D3DXMATRIXA16 viewMatrix;
// Get the world matrix of the light model and invert it to get the view matrix (that is more-or-less the definition of a view matrix)
// We don't always have a physical model for a light, in which case we would need to store this data along with the light colour etc.
D3DXMATRIXA16 worldMatrix = Light->GetWorldMatrix();
D3DXMatrixInverse(&viewMatrix, NULL, &worldMatrix);
return viewMatrix;
}
// Get "camera-like" projection matrix for a spot light
D3DXMATRIXA16 CLights::CalculateLightProjMatrix()
{
D3DXMATRIXA16 projMatrix;
// Create a projection matrix for the light. Use the spotlight cone angle as an FOV, just set default values for everything else.
D3DXMatrixPerspectiveFovLH(&projMatrix, ToRadians(SpotlightConeAngle), 1, 0.1f, 1000.0f);
return projMatrix;
}
bool CLights::Load(std::string xFile, ID3D10EffectTechnique* technique)
{
if (!Light->Load(xFile, technique)) return false;
}
void CLights::SetPosition(D3DXVECTOR3 pos)
{
Light->SetPosition(pos);
}
void CLights::SetScale(float scale)
{
Light->SetScale(scale);
}
void CLights::SetFacePoint(D3DXVECTOR3 point)
{
Light->FacePoint(point);
}
void CLights::Update()
{
Light->UpdateMatrix();
}
void CLights::Render(ID3D10EffectTechnique* technique)
{
Light->Render(technique);
}