Line | |
---|
1 | #include "common.h"
|
---|
2 | #include "Camera.h"
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 | namespace CHCDemo
|
---|
7 | {
|
---|
8 |
|
---|
9 |
|
---|
10 | Camera::Camera()
|
---|
11 | {
|
---|
12 | mWidth = 100;
|
---|
13 | mHeight = 100;
|
---|
14 | mFovy = 90.0f * M_PI/180.0f;
|
---|
15 | }
|
---|
16 |
|
---|
17 |
|
---|
18 | Camera::Camera(int width, int height, float fieldOfView)
|
---|
19 | {
|
---|
20 | mWidth = width;
|
---|
21 | mHeight = height;
|
---|
22 |
|
---|
23 | mFovy = fieldOfView * M_PI/180.0f;
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | void Camera::Precompute()
|
---|
28 | {
|
---|
29 | mDirection.Normalize();
|
---|
30 |
|
---|
31 | Vector3 side = CrossProd(Vector3(0,1,0), mDirection);
|
---|
32 | mUp = Normalize(CrossProd(side, mDirection));
|
---|
33 | mRight = Normalize(CrossProd(mDirection, mUp));
|
---|
34 |
|
---|
35 | float k = tan(mFovy/2);
|
---|
36 | mUp *= k;
|
---|
37 | mRight *= k*mWidth/mHeight;
|
---|
38 | }
|
---|
39 |
|
---|
40 |
|
---|
41 | void Camera::SetPosition(const Vector3 &pos)
|
---|
42 | {
|
---|
43 | mPosition = pos;
|
---|
44 | Precompute();
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | void Camera::SetDirection(const Vector3 &dir)
|
---|
49 | {
|
---|
50 | mDirection = dir;
|
---|
51 | Precompute();
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | void Camera::LookInBox(const AxisAlignedBox3 &box)
|
---|
56 | {
|
---|
57 | mDirection = Vector3(0,0,1);
|
---|
58 | mPosition = box.Center();
|
---|
59 |
|
---|
60 | Precompute();
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | void Camera::LookAtBox(const AxisAlignedBox3 &box)
|
---|
65 | {
|
---|
66 | mDirection = box.Max() - box.Min();
|
---|
67 | mPosition = box.Min() - mDirection;
|
---|
68 |
|
---|
69 | Precompute();
|
---|
70 | }
|
---|
71 |
|
---|
72 | }
|
---|
73 |
|
---|
Note: See
TracBrowser
for help on using the repository browser.