externals
box2d
testbed
tests
tumbler.cpp
Go to the documentation of this file.
1
// MIT License
2
3
// Copyright (c) 2019 Erin Catto
4
5
// Permission is hereby granted, free of charge, to any person obtaining a copy
6
// of this software and associated documentation files (the "Software"), to deal
7
// in the Software without restriction, including without limitation the rights
8
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the Software is
10
// furnished to do so, subject to the following conditions:
11
12
// The above copyright notice and this permission notice shall be included in all
13
// copies or substantial portions of the Software.
14
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
// SOFTWARE.
22
23
#include "test.h"
24
25
class
Tumbler
:
public
Test
26
{
27
public
:
28
29
enum
30
{
31
e_count
= 800
32
};
33
34
Tumbler
()
35
{
36
b2Body
* ground = NULL;
37
{
38
b2BodyDef
bd;
39
ground =
m_world
->
CreateBody
(&bd);
40
}
41
42
{
43
b2BodyDef
bd;
44
bd.
type
=
b2_dynamicBody
;
45
bd.
allowSleep
=
false
;
46
bd.
position
.
Set
(0.0
f
, 10.0
f
);
47
b2Body
* body =
m_world
->
CreateBody
(&bd);
48
49
b2PolygonShape
shape;
50
shape.
SetAsBox
(0.5
f
, 10.0
f
,
b2Vec2
( 10.0
f
, 0.0
f
), 0.0);
51
body->
CreateFixture
(&shape, 5.0
f
);
52
shape.
SetAsBox
(0.5
f
, 10.0
f
,
b2Vec2
(-10.0
f
, 0.0
f
), 0.0);
53
body->
CreateFixture
(&shape, 5.0
f
);
54
shape.
SetAsBox
(10.0
f
, 0.5
f
,
b2Vec2
(0.0
f
, 10.0
f
), 0.0);
55
body->
CreateFixture
(&shape, 5.0
f
);
56
shape.
SetAsBox
(10.0
f
, 0.5
f
,
b2Vec2
(0.0
f
, -10.0
f
), 0.0);
57
body->
CreateFixture
(&shape, 5.0
f
);
58
59
b2RevoluteJointDef
jd;
60
jd.
bodyA
= ground;
61
jd.
bodyB
= body;
62
jd.
localAnchorA
.
Set
(0.0
f
, 10.0
f
);
63
jd.
localAnchorB
.
Set
(0.0
f
, 0.0
f
);
64
jd.
referenceAngle
= 0.0f;
65
jd.
motorSpeed
= 0.05f *
b2_pi
;
66
jd.
maxMotorTorque
= 1e8f;
67
jd.
enableMotor
=
true
;
68
m_joint
= (
b2RevoluteJoint
*)
m_world
->
CreateJoint
(&jd);
69
}
70
71
m_count
= 0;
72
}
73
74
void
Step
(
Settings
& settings)
override
75
{
76
Test::Step
(settings);
77
78
if
(
m_count
<
e_count
)
79
{
80
b2BodyDef
bd;
81
bd.
type
=
b2_dynamicBody
;
82
bd.
position
.
Set
(0.0
f
, 10.0
f
);
83
b2Body
* body =
m_world
->
CreateBody
(&bd);
84
85
b2PolygonShape
shape;
86
shape.
SetAsBox
(0.125
f
, 0.125
f
);
87
body->
CreateFixture
(&shape, 1.0
f
);
88
89
++
m_count
;
90
}
91
}
92
93
static
Test
*
Create
()
94
{
95
return
new
Tumbler
;
96
}
97
98
b2RevoluteJoint
*
m_joint
;
99
int32
m_count
;
100
};
101
102
static
int
testIndex
=
RegisterTest
(
"Benchmark"
,
"Tumbler"
,
Tumbler::Create
);
b2RevoluteJoint
Definition:
b2_revolute_joint.h:94
b2Body::CreateFixture
b2Fixture * CreateFixture(const b2FixtureDef *def)
Definition:
b2_body.cpp:165
b2RevoluteJointDef::localAnchorB
b2Vec2 localAnchorB
The local anchor point relative to bodyB's origin.
Definition:
b2_revolute_joint.h:63
f
f
b2BodyDef
Definition:
b2_body.h:52
Test
Definition:
test.h:80
b2Vec2
A 2D column vector.
Definition:
b2_math.h:41
int32
signed int int32
Definition:
b2_types.h:28
b2PolygonShape
Definition:
b2_polygon_shape.h:32
b2PolygonShape::SetAsBox
void SetAsBox(float hx, float hy)
Definition:
b2_polygon_shape.cpp:36
b2BodyDef::type
b2BodyType type
Definition:
b2_body.h:74
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition:
b2_body.h:128
Tumbler::Create
static Test * Create()
Definition:
tumbler.cpp:93
Tumbler::Tumbler
Tumbler()
Definition:
tumbler.cpp:34
b2World::CreateJoint
b2Joint * CreateJoint(const b2JointDef *def)
Definition:
b2_world.cpp:220
Tumbler::m_count
int32 m_count
Definition:
tumbler.cpp:99
b2RevoluteJointDef::localAnchorA
b2Vec2 localAnchorA
The local anchor point relative to bodyA's origin.
Definition:
b2_revolute_joint.h:60
b2Vec2::Set
void Set(float x_, float y_)
Set this vector to some specified coordinates.
Definition:
b2_math.h:53
b2RevoluteJointDef::referenceAngle
float referenceAngle
The bodyB angle minus bodyA angle in the reference state (radians).
Definition:
b2_revolute_joint.h:66
Settings
Definition:
settings.h:25
b2RevoluteJointDef::enableMotor
bool enableMotor
A flag to enable the joint motor.
Definition:
b2_revolute_joint.h:78
Test::m_world
b2World * m_world
Definition:
test.h:128
b2_pi
#define b2_pi
Definition:
b2_common.h:41
b2BodyDef::position
b2Vec2 position
Definition:
b2_body.h:78
b2RevoluteJointDef::motorSpeed
float motorSpeed
The desired motor speed. Usually in radians per second.
Definition:
b2_revolute_joint.h:81
Tumbler
Definition:
tumbler.cpp:25
testIndex
static int testIndex
Definition:
tumbler.cpp:102
Tumbler::e_count
Definition:
tumbler.cpp:31
RegisterTest
int RegisterTest(const char *category, const char *name, TestCreateFcn *fcn)
Definition:
test.cpp:458
b2RevoluteJointDef
Definition:
b2_revolute_joint.h:39
b2BodyDef::allowSleep
bool allowSleep
Definition:
b2_body.h:103
Test::Step
virtual void Step(Settings &settings)
Definition:
test.cpp:278
Tumbler::Step
void Step(Settings &settings) override
Definition:
tumbler.cpp:74
b2RevoluteJointDef::maxMotorTorque
float maxMotorTorque
Definition:
b2_revolute_joint.h:85
b2JointDef::bodyA
b2Body * bodyA
The first attached body.
Definition:
b2_joint.h:89
b2World::CreateBody
b2Body * CreateBody(const b2BodyDef *def)
Definition:
b2_world.cpp:115
b2JointDef::bodyB
b2Body * bodyB
The second attached body.
Definition:
b2_joint.h:92
b2_dynamicBody
Definition:
b2_body.h:47
Tumbler::m_joint
b2RevoluteJoint * m_joint
Definition:
tumbler.cpp:98
mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21