DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
camerafollow.cpp
1#pragma helper_mask_fpr 0x1000
2
3#include "camerafollow.hpp"
4
5#include <libvu0.h>
6
7#include <cmath>
8
9#include "mathutil.hpp"
10
11void CCameraFollow::Step(int steps) {
13 return;
14 }
15
16 // A step count below zero turns the eye onto its angle without any of the
17 // steps in between.
18 if (steps < 0) {
19 if (this->follow_on) {
20 this->angle = this->next_angle;
21 this->SetNextPos(NULL, this->follow[0] + this->distance * sinf(this->angle), this->follow[1] + this->height, this->follow[2] + this->distance * cosf(this->angle));
22 this->SetNextRef(NULL, this->follow[0], this->follow[1], this->follow[2]);
23 }
24
25 this->CCamera::Step(steps);
26 } else {
27 int i;
28
29 // The angle that the eye turns to stays inside one turn.
30 if (this->next_angle > TWO_PI_D) {
31 this->next_angle -= TWO_PI;
32 }
33
34 if (this->next_angle < 0.0f) {
35 this->next_angle += TWO_PI;
36 }
37
38 for (i = 0; i < steps; i++) {
39 if (this->follow_on) {
40 float turn = this->speed / 2.0f;
41
42 if (turn < 1.0f) {
43 turn = 1.0f;
44 }
45
46 this->angle = AngleInterpolate(this->angle, this->next_angle, turn, INTERPOLATE_FRACTION);
47
48 // An eye that reaches its position in about one step turns at
49 // once as well.
50 if (this->speed < 1.1f) {
51 this->angle = this->next_angle;
52 }
53
54 this->SetNextPos(NULL, this->follow[0] + this->distance * sinf(this->angle), this->follow[1] + this->height, this->follow[2] + this->distance * cosf(this->angle));
55 this->SetNextRef(NULL, this->follow[0], this->follow[1], this->follow[2]);
56 }
57
58 this->CCamera::Step(1);
59 }
60
61 // An eye that no longer circles the position takes the angle that the
62 // base camera measured for it.
63 if (!this->follow_on) {
64 this->next_angle = this->angle_h;
65 this->angle = this->angle_h;
66 }
67 }
68}
69
71 this->CCamera::Stay();
72
73 if (this->follow_on) {
74 sceVu0CopyVector(this->follow, this->next_ref);
75 this->next_angle = this->angle;
76 }
77}
78
80 this->follow[0] = src.follow[0];
81 this->follow[1] = src.follow[1];
82 this->follow[2] = src.follow[2];
83 this->follow[3] = src.follow[3];
84 this->distance = src.distance;
85 this->height = src.height;
86 return *this;
87}
88
89void CCameraFollow::SetFollow(float x, float y, float z) {
90 this->follow[0] = x;
91 this->follow[1] = y;
92 this->follow[2] = z;
93}
94
96 this->follow_on = 1;
97}
98
100 this->follow_on = 0;
101}
102
103void CCameraFollow::SetAngle(float angle) {
104 this->next_angle = angle;
105}
106
108 this->next_angle = angle;
109 this->angle = angle;
110}
111
113 return this->angle;
114}
115
116void CCameraFollow::AddAngle(float delta) {
117 this->next_angle += delta;
118}
119
120void CCameraFollow::SetDistance(float distance) {
121 this->distance = distance;
122}
123
125 return this->distance;
126}
127
128void CCameraFollow::AddDistance(float delta) {
129 this->distance += delta;
130}
131
132void CCameraFollow::SetHeight(float height) {
133 this->height = height;
134}
135
137 return this->height;
138}
139
140void CCameraFollow::AddHeight(float delta) {
141 this->height += delta;
142}
143
144CCameraFollow::CCameraFollow(float distance, float height, float angle, float speed) : CCamera(speed) {
145 this->follow[0] = 0.0f;
146 this->follow[1] = 0.0f;
147 this->follow[2] = 0.0f;
148 this->next_angle = angle;
149 this->angle = angle;
150 this->distance = distance;
151 this->height = height;
152 this->follow_on = 1;
153}
154
void SetHeight(float height)
void AddDistance(float delta)
void SetFollow(float x, float y, float z)
CCameraFollow(float distance, float height, float angle, float speed)
CCameraFollow & operator=(const CCameraFollow &src)
void SetAngleSoon(float angle)
void AddAngle(float delta)
void SetDistance(float distance)
virtual void Step(int steps)
void SetAngle(float angle)
virtual void Stay()
virtual ~CCameraFollow()
void AddHeight(float delta)
float speed
Definition camera.hpp:26
virtual void Step(int steps)
Definition camera.cpp:13
void SetNextRef(CFrame *parent, float x, float y, float z)
Definition camera.cpp:141
static s32 StopCamera
Definition camera.hpp:38
float next_ref[4]
Definition camera.hpp:23
float angle_h
Definition camera.hpp:27
virtual void Stay()
Definition camera.cpp:98
void SetNextPos(CFrame *parent, float x, float y, float z)
Definition camera.cpp:118
@ INTERPOLATE_FRACTION
Definition mathutil.hpp:16