VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
PolygonBody.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 POLYGONBODY_H
18 #define POLYGONBODY_H
19 
20 #include <QPolygonF>
21 #include "Body.h"
22 
27 class PolygonBody : public Body {
28  Q_OBJECT
29 
33  Q_PROPERTY(QVariantList vertices READ getVerticesAsVariantList
35 
36 public:
37 
41  explicit PolygonBody(QObject* parent = nullptr);
42 
46  const QList<QPointF>& getVertices() const;
47 
51  QVariantList getVerticesAsVariantList() const;
52 
57  void setVertices(const QList<QPointF>& value);
58 
63  void setVerticesFromVariantList(const QVariantList& value);
64 
70 
71 signals:
75  void verticesChanged();
76 
77 protected:
82  virtual void forEachShape(const std::function<void(b2Shape*)>& func) override;
83 
84 private:
85  void triangulate();
86 
87  QList<QPointF> mVertices = {
88  QPointF(-1.0f, -1.0f), QPointF(1.0f, -1.0f), QPointF(1.0f, 1.0f), QPointF(-1.0f, 1.0f) };
89  QList<QPolygonF> mTriangles;
90  bool mTrianglesDirty = true;
91 
92  static const float WELD_TOLERANCE;
93 };
94 Q_DECLARE_METATYPE(PolygonBody*)
95 
96 #endif // POLYGONBODY_H
A QObject container for a Box2D b2Body.
Definition: Body.h:57
const QList< QPointF > & getVertices() const
Returns vertices as a QList.
QVariantList vertices
The vertices defining the PolygonBody.
Definition: PolygonBody.h:34
void setVerticesFromVariantList(const QVariantList &value)
Sets vertices.
A QObject container for a Box2D b2Body that represents a polygon.
Definition: PolygonBody.h:27
void verticesChanged()
Emitted when vertices changes.
QVariantList getVerticesAsVariantList() const
Returns vertices as a QVariantList.
PolygonBody(QObject *parent=nullptr)
Constructs a PolygonBody.
virtual void forEachShape(const std::function< void(b2Shape *)> &func) override
Calls func on the b2Shapes that represents this PolygonBody.
QObject * parent() const
const QList< QPolygonF > & getTriangles()
Returns a QList of this PolygonBody's triangles.
void setVertices(const QList< QPointF > &value)
Sets vertices.