-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathCamera.c
106 lines (86 loc) · 2.08 KB
/
Camera.c
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
/*
* Copyright (c) scott.cgi All Rights Reserved.
*
* This source code belongs to project Mojoc, which is a pure C Game Engine hosted on GitHub.
* The Mojoc Game Engine is licensed under the MIT License, and will continue to be iterated with coding passion.
*
* License : https://github.com/scottcgi/Mojoc/blob/master/LICENSE
* GitHub : https://github.com/scottcgi/Mojoc
* CodeStyle: https://github.com/scottcgi/Mojoc/blob/master/Docs/CodeStyle.md
*
* Since : 2013-1-10
* Update : 2019-1-24
* Author : scott.cgi
*/
#include "Engine/Graphics/OpenGL/Camera.h"
static void SetOrthographic()
{
// near and far is distance of eye position to look up direction
AMatrix->Orthographic
(
ACamera->left,
ACamera->right,
ACamera->bottom,
ACamera->top,
ACamera->near,
ACamera->far,
ACamera->projection
);
AMatrix->MultiplyMM(ACamera->projection, ACamera->view, ACamera->vp);
}
static void SetFrustum()
{
// near and far is distance of eye position to look up direction
AMatrix->Frustum
(
ACamera->left,
ACamera->right,
ACamera->bottom,
ACamera->top,
ACamera->near,
ACamera->far,
ACamera->projection
);
AMatrix->MultiplyMM(ACamera->projection, ACamera->view, ACamera->vp);
}
static void SetLookAt()
{
AMatrix->LookAt
(
ACamera->eyeX,
ACamera->eyeY,
ACamera->eyeZ,
ACamera->lookX,
ACamera->lookY,
ACamera->lookZ,
ACamera->upX,
ACamera->upY,
ACamera->upZ,
ACamera->view
);
AMatrix->MultiplyMM(ACamera->projection, ACamera->view, ACamera->vp);
}
static float GetNearZOrder()
{
return ACamera->eyeZ - ACamera->near;
}
static float GetFarZOrder()
{
return GetNearZOrder() - ACamera->far;
}
struct ACamera ACamera[1] =
{{
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
MATRIX4_IDENTITY,
MATRIX4_IDENTITY,
MATRIX4_IDENTITY,
SetOrthographic,
SetFrustum,
SetLookAt,
GetNearZOrder,
GetFarZOrder,
}};