-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.c
More file actions
65 lines (53 loc) · 1.55 KB
/
Copy pathcommon.c
File metadata and controls
65 lines (53 loc) · 1.55 KB
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
#include "common.h"
#define _USE_MATH_DEFINES
#include <math.h>
const float3_t float3_zero = {0.0, 0.0, 0.0};
const point_t point_zero = {0.0, 0.0, 0.0};
const direction_t direction_none = {0.0, 0.0, 0.0};
static
void project_camera_init
(
project_camera_t* camera, const point_t* eye, const direction_t* front,
float left_fov, float right_fov, float top_fov, float bottom_fov
)
{
camera->eye = *eye;
camera->front = *front;
camera->left_fov = left_fov;
camera->right_fov = right_fov;
camera->top_fov = top_fov;
camera->bottom_fov = bottom_fov;
camera->left_angle_tan = -tanf((left_fov / 180) * M_PI);
camera->right_angle_tan = tanf((right_fov / 180) * M_PI);
camera->top_angle_tan = tanf((top_fov / 180) * M_PI);
camera->bottom_angle_tan = -tanf((bottom_fov / 180) * M_PI);
return;
}
void setup_project_camera(project_camera_t *camera)
{
point_t eye = {320.0, 240.0, 180.0};
direction_t front = {0.0, 0.0, -1.0};
/* 为避免不能完全看到目标场景全貌,视角范围可以尽量大一些 */
project_camera_init(camera, &eye, &front, 80, 80, 80, 80);
return;
}
static
void sphere_init(sphere_t* sphere, const point_t* center, float radius)
{
sphere->center = *center;
sphere->radius = radius;
sphere->sqr_radius = radius * radius;
return;
}
void setup_sphere(sphere_t *sphere)
{
point_t center = {320.0, 240.0, -120.0};
sphere_init(sphere, ¢er, 210);
return;
}
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
uint64_t now_ms(void)
{
return GetTickCount();
}