-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.cpp
81 lines (67 loc) · 1.8 KB
/
camera.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
#include <stdlib.h>
#include "camera.h"
#include "vector.h"
#include "consts.h"
#include <assert.h>
Camera::Camera(vect3d &pCtrPos, vect3d &pUpVec, vect3d &pViewVec, float fNtoF, float fPlaneRatio)
: _fN2F(fNtoF), _fPlaneRatio(fPlaneRatio), _pSampler(NULL)
{
assert((fNtoF > 0) && (fPlaneRatio > 0));
// viewing direction
_dir[0] = pViewVec[0];
_dir[1] = pViewVec[1];
_dir[2] = pViewVec[2];
normalize(_dir);
// Center point of the view plane
_ctrPos[0] = pCtrPos[0];
_ctrPos[1] = pCtrPos[1];
_ctrPos[2] = pCtrPos[2];
// Up vec of the view plane, with vec-len as 1/2 of view plane height
_upVec[0] = pUpVec[0];
_upVec[1] = pUpVec[1];
_upVec[2] = pUpVec[2];
normalize(_upVec);
vecScale(_upVec, WinHeight * _fPlaneRatio * 0.5, _upVec);
// right vec of the view plane, with vec-len as 1/2 of view plane width
cross_product(_dir, _upVec, _rightVec);
normalize(_rightVec);
vecScale(_rightVec, WinWidth * _fPlaneRatio * 0.5, _rightVec);
// default: no multi-sampling
_nMultiSamplingCount = 1;
}
void Camera::setSampler(SamplingType eType)
{
if(_pSampler)
{
delete _pSampler;
}
switch(eType)
{
case STRATIFIED:
_pSampler = new StratifiedSampler;
break;
case LOW_DISC:
_pSampler = new LowDiscrepancySampler;
break;
case BEST_CANDID:
_pSampler = new BestCandidateSampler;
break;
}
}
///
///
///
OrthoCamera::OrthoCamera(vect3d &pCtrPos, vect3d &pUpVec, vect3d &pViewVec, float fNtoF, float fPlaneRatio)
: Camera(pCtrPos, pUpVec, pViewVec, fNtoF, fPlaneRatio)
{ }
///
///
PerpCamera::PerpCamera(float fEye2Near, vect3d &pCtrPos, vect3d &pUpVec, vect3d &pViewVec, float fNtoF, float fPlaneRatio)
: Camera(pCtrPos, pUpVec, pViewVec, fNtoF, fPlaneRatio)
{
assert(fEye2Near > 0);
//
vect3d vInverseVec;
vecScale(_dir, -fEye2Near, vInverseVec);
point2point(_ctrPos, vInverseVec, _eyePos);
}