VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
CameraMovementLogic.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CAMERAMOVEMENTLOGIC_H
18 #define CAMERAMOVEMENTLOGIC_H
19 
20 #include <Engine/Logic.h>
21 #include <QMap>
22 
23 class Camera;
24 class QRectF;
25 
37 class CameraMovementLogic : public Logic {
38  Q_OBJECT
39 
43  Q_PROPERTY(float minFov READ getMinFov WRITE setMinFov NOTIFY minFovChanged)
47  Q_PROPERTY(float xPullFactor READ getXPullFactor WRITE setXPullFactor NOTIFY xPullFactorChanged)
51  Q_PROPERTY(float yPullFactor READ getYPullFactor WRITE setYPullFactor NOTIFY yPullFactorChanged)
56  Q_PROPERTY(float towedXPullFactor READ getTowedXPullFactor WRITE setTowedXPullFactor NOTIFY
62  Q_PROPERTY(float towedYPullFactor READ getTowedYPullFactor WRITE setTowedYPullFactor NOTIFY
67  Q_PROPERTY(float lookaheadScale READ getLookaheadScale WRITE setLookaheadScale NOTIFY
72  Q_PROPERTY(float fovPullFactor READ getFovPullFactor WRITE setFovPullFactor NOTIFY
77  Q_PROPERTY(float xFovBorder READ getXFovBorder WRITE setXFovBorder NOTIFY xFovBorderChanged)
81  Q_PROPERTY(float yFovBorder READ getYFovBorder WRITE setYFovBorder NOTIFY yFovBorderChanged)
82 
83 public:
87  float getMinFov() const { return mMinFov; }
92  void setMinFov(float value);
96  float getXPullFactor() const { return mXPullFactor; }
101  void setXPullFactor(float value);
105  float getYPullFactor() const { return mYPullFactor; }
110  void setYPullFactor(float value);
114  float getTowedXPullFactor() const { return mTowedXPullFactor; }
119  void setTowedXPullFactor(float value);
123  float getTowedYPullFactor() const { return mTowedYPullFactor; }
128  void setTowedYPullFactor(float value);
132  float getLookaheadScale() const { return mLookaheadScale; }
137  void setLookaheadScale(float value);
141  float getFovPullFactor() const { return mFovPullFactor; }
146  void setFovPullFactor(float value);
150  float getXFovBorder() const { return mXFovBorder; }
155  void setXFovBorder(float value);
159  float getYFovBorder() const { return mYFovBorder; }
164  void setYFovBorder(float value);
168  virtual void init() override;
173  virtual void update() override;
174 
175 signals:
179  void minFovChanged();
183  void xPullFactorChanged();
187  void yPullFactorChanged();
199  void lookaheadScaleChanged();
203  void fovPullFactorChanged();
207  void xFovBorderChanged();
211  void yFovBorderChanged();
212 
213 private:
218  QRectF getExpandedBBoxOfPlayerActors() const;
219  QPointF getExtrapolatedPosition(Actor* actor) const;
220  QPointF computeLookAt(const QRectF& actorsBBox) const;
221  float computeFov(const QRectF& actorsBBox) const;
222  void boundCameraViewport(QPointF* lookAt, float* fov) const;
223  void fillCameraViewport(QPointF* lookAt, float* fov) const;
224 
225  // Camera whose fov and lookAt is controlled by this logic
226  Camera* mCamera = nullptr;
227  float mMinFov = 16.0f;
228  float mXPullFactor = 0.08f;
229  float mYPullFactor = 0.08f;
230  float mTowedXPullFactor = 0.04f;
231  float mTowedYPullFactor = 0.04f;
232  float mLookaheadScale = 1.0f;
233  float mFovPullFactor = 1.0f;
234  float mXFovBorder = 0.1f;
235  float mYFovBorder = 0.1f;
236  // Map of points which trail behind camera tracked actors
237  QMap<Actor*, QPointF> mTowedControlPoints;
238 };
239 Q_DECLARE_METATYPE(CameraMovementLogic*)
240 
241 #endif // CAMERAMOVEMENTLOGIC_H
void setXPullFactor(float value)
Sets xPullFactor.
float fovPullFactor
Speed of adjusting to the correct fov width.
Definition: CameraMovementLogic.h:73
void setLookaheadScale(float value)
Sets lookaheadScale.
void setMinFov(float value)
Sets minFov.
float getMinFov() const
Returns minFov.
Definition: CameraMovementLogic.h:87
float getXFovBorder() const
Returns xFovBorder.
Definition: CameraMovementLogic.h:150
void yPullFactorChanged()
Emitted when yPullFactor changes.
void setXFovBorder(float value)
Sets xFovBorder.
float getTowedYPullFactor() const
Returns towedYPullFactor.
Definition: CameraMovementLogic.h:123
float xFovBorder
Extra width added to the bounding box of Actor::PlayerActors.
Definition: CameraMovementLogic.h:77
void setTowedXPullFactor(float value)
Sets towedXPullFactor.
float xPullFactor
Strength of horizontal force that pull the camera to the center of the bounding box.
Definition: CameraMovementLogic.h:47
float getYFovBorder() const
Returns yFovBorder.
Definition: CameraMovementLogic.h:159
float getXPullFactor() const
Returns xPullFactor.
Definition: CameraMovementLogic.h:96
Actor actor
Parent actor that is affected by this Logic's behavior.
Definition: Logic.h:36
void lookaheadScaleChanged()
Emitted when lookaheadScale changes.
void fovPullFactorChanged()
Emitted when fovPullFactor changes.
float getLookaheadScale() const
Returns lookaheadScale.
Definition: CameraMovementLogic.h:132
void setYFovBorder(float value)
Sets yFovBorder.
float minFov
Minimum field of view the Camera will adjust to.
Definition: CameraMovementLogic.h:43
Logic to make the camera follow the bounding box of all Actor::PlayerActors.
Definition: CameraMovementLogic.h:37
virtual void update() override
Updates the parent actor Camera's properties to follow the constraints from the scene.
void towedXPullFactorChanged()
Emitted when towedXPullFactor changes.
Non-visual entities in the QML item tree that define behavior for their parent Actor.
Definition: Logic.h:31
float getFovPullFactor() const
Returns fovPullFactor.
Definition: CameraMovementLogic.h:141
void setYPullFactor(float value)
Sets yPullFactor.
float getTowedXPullFactor() const
Returns towedXPullFactor.
Definition: CameraMovementLogic.h:114
virtual void init() override
Initializes the parent actor Camera with parameters for the current scene.
float towedXPullFactor
Strength of horizontal towing forces that slowly pull the camera to the center of the bounding box...
Definition: CameraMovementLogic.h:57
void xFovBorderChanged()
Emitted when xFovBorder changes.
float lookaheadScale
Extra distance that the camera leads the PlayerActors.
Definition: CameraMovementLogic.h:68
void towedYPullFactorChanged()
Emitted when towedYPullFactor changes.
Representation of an entity within the Game scene.
Definition: Actor.h:40
float towedYPullFactor
Strength of vertical towing forces that slowly pull the camera to the center of the bounding box...
Definition: CameraMovementLogic.h:63
void setTowedYPullFactor(float value)
Sets towedYPullFactor.
QQuickItem which represents the Camera into the game world.
Definition: Camera.h:42
void setFovPullFactor(float value)
Sets fovPullFactor.
void minFovChanged()
Emitted when minFov changes.
float yFovBorder
Extra height added to the bounding box of Actor::PlayerActors.
Definition: CameraMovementLogic.h:81
void yFovBorderChanged()
Emitted when yFovBorder changes.
void xPullFactorChanged()
Emitted when xPullFactor changes.
float getYPullFactor() const
Returns yPullFactor.
Definition: CameraMovementLogic.h:105
float yPullFactor
Strength of vertical force that pull the camera to the center of the bounding box.
Definition: CameraMovementLogic.h:51