Skip to content

Commit 67a7221

Browse files
committed
fixup cscamera
1 parent 3daa219 commit 67a7221

3 files changed

Lines changed: 44 additions & 36 deletions

File tree

game/camera.cpp

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -178,25 +178,41 @@ void Camera::moveRight(uint64_t dt) {
178178
implMove(KeyEvent::K_D,dt);
179179
}
180180

181-
void Camera::setMode(Camera::Mode m) {
181+
void Camera::setMode(const Camera::Mode m) {
182182
if(camMod==m)
183183
return;
184184

185-
const bool reset = true; //(m==Inventory || camMod==Inventory || camMod==Dialog || camMod==Dive || m==Fall || camMod==Fall);
185+
auto isRegular = [](const Camera::Mode m){
186+
return m==Normal || m==Inventory || m==Melee || m==Ranged || m==Magic;
187+
};
188+
189+
const auto prev = camMod;
186190
camMod = m;
187191

188-
if(camMarvinMod==M_Freeze)
192+
//const bool reset = true; //(m==Inventory || camMod==Inventory || camMod==Dialog || camMod==Dive || m==Fall || camMod==Fall);
193+
const bool reset = !(isRegular(prev) && isRegular(m));
194+
195+
if(prev==Mode::Cutscene) {
196+
state.spin = angles;
197+
state.target = origin;
198+
inter.target = origin;
199+
}
200+
201+
if(camMarvinMod==M_Free || camMarvinMod==M_Freeze)
189202
return;
190203

204+
const auto& def = cameraDef();
205+
191206
if(reset) {
192-
resetDst();
207+
state.range = def.best_range;
208+
state.spin = Vec3(0);
209+
//userRange = (def.best_range - def.min_range)/(def.max_range - def.min_range);
193210
}
194211

195212
if(auto pl = Gothic::inst().player()) {
196213
state.spin = Vec3(0, pl->rotation(), 0);
197214
}
198215

199-
const auto& def = cameraDef();
200216
auto rotBest = Vec3(def.best_elevation,
201217
def.best_azimuth,
202218
def.best_rot_z);
@@ -270,7 +286,6 @@ void Camera::setLookBack(bool lb) {
270286
if(lbEnable==lb)
271287
return;
272288
lbEnable = lb;
273-
resetDst();
274289
}
275290

276291
void Camera::toggleDebug() {
@@ -285,6 +300,18 @@ void Camera::setTarget(const Tempest::Vec3& pos) {
285300
state.target = pos;
286301
}
287302

303+
void Camera::setAngles(const Tempest::PointF& p) {
304+
angles = /*angleMod*/(Vec3(p.x,p.y,0));
305+
}
306+
307+
void Camera::setPosition(const Tempest::Vec3& pos) {
308+
origin = pos;
309+
}
310+
311+
void Camera::setDialogDistance(float d) {
312+
dlgDist = d;
313+
}
314+
288315
void Camera::onRotateMouse(const PointF& dpos) {
289316
state.spin.x += dpos.x;
290317
state.spin.y += dpos.y;
@@ -565,14 +592,6 @@ void Camera::implMove(Tempest::Event::KeyType key, uint64_t dt) {
565592
state.spin.y -= dRot;
566593
}
567594

568-
void Camera::setPosition(const Tempest::Vec3& pos) {
569-
origin = pos;
570-
}
571-
572-
void Camera::setDialogDistance(float d) {
573-
dlgDist = d;
574-
}
575-
576595
Vec3 Camera::followTarget(Vec3 pos, Vec3 dest, float dtF) {
577596
auto dp = (dest-pos);
578597
auto len = dp.length();
@@ -663,6 +682,10 @@ void Camera::tick(uint64_t dt) {
663682
if(Gothic::inst().isPause() || (camMarvinMod==M_Freeze && camMod!=Dialog))
664683
return;
665684

685+
if(isCutscene()) {
686+
return; // handle pass thru water ?
687+
}
688+
666689
const float dtF = float(dt)/1000.f;
667690

668691
{
@@ -678,10 +701,7 @@ void Camera::tick(uint64_t dt) {
678701

679702
switch (camMarvinMod) {
680703
case M_Normal: {
681-
if(isCutscene()) {
682-
// nop
683-
}
684-
else if(fpEnable && camMod!=Dialog) {
704+
if(fpEnable && camMod!=Dialog) {
685705
tickFirstPerson(dtF);
686706
}
687707
else {
@@ -901,17 +921,6 @@ Vec3 Camera::clampRotation(Tempest::Vec3 spin) {
901921
return (spin + plSpin);
902922
}
903923

904-
void Camera::resetDst() {
905-
if(isMarvin())
906-
return;
907-
const auto& def = cameraDef();
908-
909-
state.range = def.best_range;
910-
state.spin = Vec3(0);
911-
912-
//userRange = (def.best_range - def.min_range)/(def.max_range - def.min_range);
913-
}
914-
915924
Matrix4x4 Camera::mkView(const Vec3& pos, const Vec3& spin) const {
916925
Matrix4x4 view;
917926
view.identity();

game/camera.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Camera final {
6262
void moveLeft(uint64_t dt);
6363
void moveRight(uint64_t dt);
6464

65-
void setMode(Mode m);
65+
void setMode(const Mode m);
6666
void setMarvinMode(MarvinMode m);
6767
bool isMarvin() const;
6868
bool isFree() const;
@@ -90,6 +90,8 @@ class Camera final {
9090

9191
void setSpin(const Tempest::PointF& p);
9292
void setTarget(const Tempest::Vec3& pos);
93+
94+
void setAngles(const Tempest::PointF& pos);
9395
void setPosition(const Tempest::Vec3& pos);
9496
void setDialogDistance(float d);
9597

@@ -173,8 +175,6 @@ class Camera final {
173175
Tempest::Vec3 calcLookAtAngles(const Tempest::Vec3& origin, const Tempest::Vec3& target,
174176
const Tempest::Vec3& rotOffset, const Tempest::Vec3& defSpin) const;
175177

176-
void resetDst();
177-
178178
void implMove(Tempest::KeyEvent::KeyType t, uint64_t dt);
179179

180180
Tempest::Matrix4x4 mkView (const Tempest::Vec3& pos, const Tempest::Vec3& spin) const;

game/world/triggers/cscamera.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void CsCamera::onTrigger(const TriggerEvent& evt) {
166166
auto cPos = position();
167167
camera.setMode(Camera::Mode::Cutscene);
168168
camera.setPosition(cPos);
169-
camera.setSpin(spin(cPos));
169+
camera.setAngles(spin(cPos));
170170
}
171171
}
172172

@@ -207,7 +207,7 @@ void CsCamera::tick(uint64_t /*dt*/) {
207207
if(camera.isCutscene()) {
208208
auto cPos = position();
209209
camera.setPosition(cPos);
210-
camera.setSpin(spin(cPos));
210+
camera.setAngles(spin(cPos));
211211
}
212212
}
213213

@@ -238,6 +238,5 @@ PointF CsCamera::spin(Tempest::Vec3& d) {
238238
if(d.x!=0.f || d.z!=0.f)
239239
spinY = 90 + k * std::atan2(d.z,d.x);
240240

241-
auto& def = Gothic::cameraDef().stdCam();
242-
return {-spinX + def.rot_offset_x, spinY + def.rot_offset_y};
241+
return {-spinX, spinY};
243242
}

0 commit comments

Comments
 (0)