i6engine  1.0
VelocityComponent.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_API_VELOCITYCOMPONENT_H__
26 #define __I6ENGINE_API_VELOCITYCOMPONENT_H__
27 
29 
30 namespace i6e {
31 namespace api {
32 
46  public:
47  enum class MaxSpeedHandling {
48  KeepSpeed,
49  StopAcceleration
50  };
51  enum class DecelerationHandling {
52  Backward,
53  StopDeceleration
54  };
55 
56  VelocityComponent(const int64_t id, const attributeMap & params);
57 
59 
60  attributeMap synchronize() const override;
61 
62  std::string getTemplateName() const override {
63  return "Velocity";
64  }
65 
66  std::vector<componentOptions> getComponentOptions() override {
67  return {};
68  }
69 
74  void accelerate(const Vec3 & acceleration, MaxSpeedHandling handling, const std::function<void(void)> & callback);
75  void accelerate(const std::function<void(void)> & callback) {
76  accelerate(_acceleration, _handling, callback);
77  }
78 
83  void decelerate(const Vec3 & deceleration, DecelerationHandling handling, const std::function<void(void)> & callback);
84  void decelerate(const std::function<void(void)> & callback) {
85  decelerate(_deceleration, _decelerationHandling, callback);
86  }
87 
91  void stopAcceleration() const;
92 
96  void setMaxSpeed(double maxSpeed);
97 
101  void setResistanceCoefficient(double coeff);
102 
106  void setWindage(double windage);
107 
112  _decelerationHandling = handling;
113  }
114 
115  private:
116  Vec3 _acceleration;
117  Vec3 _deceleration;
118  double _maxSpeed;
119  double _resistanceCoefficient;
120  double _windage;
121  MaxSpeedHandling _handling;
122  DecelerationHandling _decelerationHandling;
123 
124  void Init() override;
125 
126  void Finalize() override;
127  };
128 
129 } /* namespace api */
130 } /* namespace i6e */
131 
132 #endif /* __I6ENGINE_API_VELOCITYCOMPONENT_H__ */
133 
std::string getTemplateName() const override
returns the name this template was registered with
#define ISIXE_MODULES_API
void accelerate(const std::function< void(void)> &callback)
std::map< std::string, std::string > attributeMap
Definition: attributeMap.h:42
Component for objects with more complex velocity handling than just setting an impulse, e.g. a car For creating a VelocityComponent, these keys are possible: Name Required Type Description Public acceleration yes double acceleration of this GameObject, in m / sē yes deceleration no double breaking acceleration of this GameObject, in m / sē yes maxSpeed yes double maximum speed this GameObject can reach, in m / s yes resistanceCoefficient no double resistance coefficient, default: 0.6 yes windage no double windage of this GameObject, default: 0.8 mē yes handling no int handling for reaching maximum speed, keep maximum speed or stop acceleration to roll out, default: 0 (= KeepSpeed) yes
Implements 3-dimensional vectors.
Definition: i6eVector.h:48
void setDecelerationHandling(DecelerationHandling handling)
sets the deceleration handling
void decelerate(const std::function< void(void)> &callback)
Component Base Class. All Components must derive from Component.
Definition: Component.h:97
std::vector< componentOptions > getComponentOptions() override
returns a vector containing all options of the Component being readable and writeable in the editor ...