VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Box2dUtil.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 BOX2DUTIL_H
18 #define BOX2DUTIL_H
19 
20 #include <Box2D/Box2D.h>
21 #include <QColor>
22 #include <QPointF>
23 #include <QRectF>
24 
29 namespace Box2dUtil {
30 
36 static inline float dotProduct(const b2Vec2& v1, const b2Vec2& v2) {
37  return v1.x * v2.x + v1.y * v2.y;
38 }
39 
44 static inline QPointF toQPointF(const b2Vec2& vec) {
45  return QPointF(vec.x, vec.y);
46 }
47 
52 static inline b2Vec2 toB2Vec2(const QPointF& vec) {
53  return b2Vec2(vec.x(), vec.y());
54 }
55 
60 static inline QRectF toQRectF(const b2AABB& aabb) {
61  return QRectF(toQPointF(aabb.lowerBound), toQPointF(aabb.upperBound));
62 }
63 
68 static inline b2AABB toB2AABB(const QRectF& rect) {
69  return { toB2Vec2(rect.topLeft()), toB2Vec2(rect.bottomRight()) };
70 }
71 
76 static inline QColor toQColor(const b2ParticleColor& color) {
77  return QColor::fromRgbF(color.r, color.g, color.b, color.a);
78 }
79 
84 static inline b2ParticleColor toB2ParticleColor(const QColor& color) {
85  return b2ParticleColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
86 }
87 
88 }
89 
90 #endif // BOX2DUTIL_H
qreal alphaF() const
qreal redF() const
qreal blueF() const
static QPointF toQPointF(const b2Vec2 &vec)
Returns a b2Vec2 converted to a QPointF.
Definition: Box2dUtil.h:44
static QColor toQColor(const b2ParticleColor &color)
Returns a b2ParticleColor converted to a QColor.
Definition: Box2dUtil.h:76
qreal x() const
qreal y() const
QPointF topLeft() const
qreal greenF() const
static b2ParticleColor toB2ParticleColor(const QColor &color)
Returns a QColor converted to a b2ParticleColor.
Definition: Box2dUtil.h:84
QColor fromRgbF(qreal r, qreal g, qreal b, qreal a)
static b2AABB toB2AABB(const QRectF &rect)
Returns a QRectF converted to a b2AABB.
Definition: Box2dUtil.h:68
QPointF bottomRight() const
static float dotProduct(const b2Vec2 &v1, const b2Vec2 &v2)
Returns the computed inner product between two Box2D vectors.
Definition: Box2dUtil.h:36
static b2Vec2 toB2Vec2(const QPointF &vec)
Returns a QPointF converted to a b2Vec2.
Definition: Box2dUtil.h:52
static QRectF toQRectF(const b2AABB &aabb)
Returns a b2AABB converted to a QRectF.
Definition: Box2dUtil.h:60