VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
RollingMovementLogic.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 ROLLINGMOVEMENTLOGIC_H
18 #define ROLLINGMOVEMENTLOGIC_H
19 
20 #include <Box2D/Box2D.h>
21 #include <Engine/Logic.h>
22 
48 class RollingMovementLogic : public Logic {
49  Q_OBJECT
50 
71  Q_PROPERTY(float speed READ getSpeed WRITE setSpeed NOTIFY speedChanged)
75  Q_PROPERTY(float proximityRadius READ getProximityRadius WRITE setProximityRadius
89  Q_PROPERTY(float turnBoost READ getTurnBoost WRITE setTurnBoost NOTIFY turnBoostChanged)
93  Q_PROPERTY(float torqueForceRatio READ getTorqueForceRatio WRITE setTorqueForceRatio
102 
103 public:
107  QPointF getDirection() const { return mDirection; }
112  void setDirection(const QPointF& value);
121  void setMagnetismInfluence(const QPointF& value);
125  float getSpeed() const { return mSpeed; }
130  void setSpeed(float value);
134  float getProximityRadius() const { return mProximityRadius; }
139  void setProximityRadius(float value);
143  float getAntiGravityAmount() const { return mAntiGravityAmount; }
148  void setAntiGravityAmount(float value);
152  float getTurnBoost() const { return mTurnBoost; }
157  void setTurnBoost(float value);
161  float getTorqueForceRatio() const { return mTorqueForceRatio; }
166  void setTorqueForceRatio(float value);
170  float getSpeedFalloffRatio() const { return mSpeedFalloffRatio; }
175  void setSpeedFalloffRatio(float value);
176 
183  Q_INVOKABLE QPointF getGroundNormal() const;
184 
188  virtual void update() override;
189 
190 signals:
194  void directionChanged();
202  void speedChanged();
206  void proximityRadiusChanged();
214  void turnBoostChanged();
223 
224 private:
225  struct Ray;
226  class RayCastCallbackHelper;
227 
228  QPointF mDirection;
229 
230  float mSpeed = 7.0f;
231  float mProximityRadius = 0.6f;
232  b2Vec2 mGroundNormal = b2Vec2(0.0f, 0.0f);
233  b2Vec2 mMagnetismInfluence = b2Vec2(0.0f, 0.0f);
234  float mAntiGravityAmount = 0.3f;
235  float mTurnBoost = 2.0f;
236  float mTorqueForceRatio = 2.0f;
237  float mSpeedFalloffRatio = 0.5f;
238 
239  static const Ray PROXIMITY_TEST_RAYS[];
240  static const int PROXIMITY_TEST_RAY_COUNT;
241 };
242 Q_DECLARE_METATYPE(RollingMovementLogic*)
243 
244 #endif // ROLLINGMOVEMENTLOGIC_H
QPointF magnetismInfluence
Direction to the magnetic object this actor is magnetizing to, or a zero vector if there is currently...
Definition: RollingMovementLogic.h:65
void setTorqueForceRatio(float value)
Sets torqueForceRatio.
QPointF getDirection() const
Returns direction.
Definition: RollingMovementLogic.h:107
float getTorqueForceRatio() const
Returns torqueForceRatio.
Definition: RollingMovementLogic.h:161
void setAntiGravityAmount(float value)
Sets antiGravityAmount.
Q_INVOKABLE QPointF getGroundNormal() const
Returns the current "up" direction used to orient movement.
void proximityRadiusChanged()
Emitted when proximityRadius changes.
void setDirection(const QPointF &value)
Sets direction.
void turnBoostChanged()
Emitted when turnBoost changes.
Logic which exerts force in a specified direction, causing the actor to roll in that direction...
Definition: RollingMovementLogic.h:48
void speedFalloffRatioChanged()
Emitted when speedFalloffRatio changes.
void setSpeedFalloffRatio(float value)
Sets speedFalloffRatio.
void setTurnBoost(float value)
Sets turnBoost.
float getAntiGravityAmount() const
Returns antiGravityAmount.
Definition: RollingMovementLogic.h:143
QPointF direction
Direction the actor should move in.
Definition: RollingMovementLogic.h:56
float torqueForceRatio
Balance of torque to linear force.
Definition: RollingMovementLogic.h:94
float getSpeed() const
Returns speed.
Definition: RollingMovementLogic.h:125
Non-visual entities in the QML item tree that define behavior for their parent Actor.
Definition: Logic.h:31
void torqueForceRatioChanged()
Emitted when torqueForceRatio changes.
QPointF getMagnetismInfluence() const
Returns magnetismInfluence.
float turnBoost
Extra force multiplier applied when turning.
Definition: RollingMovementLogic.h:89
float antiGravityAmount
Amount of force the actor can exert against gravity, as a percentage from 0.0f to 1...
Definition: RollingMovementLogic.h:85
float getTurnBoost() const
Returns turnBoost.
Definition: RollingMovementLogic.h:152
void magnetismInfluenceChanged()
Emitted when magnetismInfluence changes.
void speedChanged()
Emitted when speed changes.
float speed
Speed the actor accelerates at.
Definition: RollingMovementLogic.h:71
void setMagnetismInfluence(const QPointF &value)
Sets magnetismInfluence.
virtual void update() override
Computes and applys torque and linear forces on this actor's Body.
void directionChanged()
Emitted when direction changes.
float proximityRadius
Distance that the actor will sense other bodies to use as orientation references. ...
Definition: RollingMovementLogic.h:76
float getSpeedFalloffRatio() const
Returns speedFalloffRatio.
Definition: RollingMovementLogic.h:170
float getProximityRadius() const
Returns proximityRadius.
Definition: RollingMovementLogic.h:134
void antiGravityAmountChanged()
Emitted when antiGravityAmount changes.
void setProximityRadius(float value)
Sets proximityRadius.
float speedFalloffRatio
Amount of falloff at higher speeds.
Definition: RollingMovementLogic.h:101
void setSpeed(float value)
Sets speed.