forked from gameprogcpp/code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplineCamera.h
More file actions
48 lines (43 loc) · 1.3 KB
/
SplineCamera.h
File metadata and controls
48 lines (43 loc) · 1.3 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
// ----------------------------------------------------------------
// From Game Programming in C++ by Sanjay Madhav
// Copyright (C) 2017 Sanjay Madhav. All rights reserved.
//
// Released under the BSD License
// See LICENSE in root directory for full details.
// ----------------------------------------------------------------
#pragma once
#include "CameraComponent.h"
#include <vector>
struct Spline
{
// Control points for spline
// (Requires n+2 points where n is number
// of points in segment)
std::vector<Vector3> mControlPoints;
// Given spline segment where startIdx = P1,
// compute position based on t value
Vector3 Compute(size_t startIdx, float t) const;
// Returns number of control points
size_t GetNumPoints() const { return mControlPoints.size(); }
};
class SplineCamera : public CameraComponent
{
public:
SplineCamera(class Actor* owner);
void Update(float deltaTime) override;
// Restart the spline
void Restart();
void SetSpeed(float speed) { mSpeed = speed; }
void SetSpline(const Spline& spline) { mPath = spline; }
void SetPaused(bool pause) { mPaused = pause; }
private:
// Spline path camera follows
Spline mPath;
// Current control point index and t
size_t mIndex;
float mT;
// Amount t changes/sec
float mSpeed;
// Whether to move the camera long the path
bool mPaused;
};