add_pair.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 AddPair : public Test
26 {
27 public:
28 
30  {
31  m_world->SetGravity(b2Vec2(0.0f,0.0f));
32  {
33  b2CircleShape shape;
34  shape.m_p.SetZero();
35  shape.m_radius = 0.1f;
36 
37  float minX = -6.0f;
38  float maxX = 0.0f;
39  float minY = 4.0f;
40  float maxY = 6.0f;
41 
42  for (int32 i = 0; i < 400; ++i)
43  {
44  b2BodyDef bd;
45  bd.type = b2_dynamicBody;
46  bd.position = b2Vec2(RandomFloat(minX,maxX),RandomFloat(minY,maxY));
47  b2Body* body = m_world->CreateBody(&bd);
48  body->CreateFixture(&shape, 0.01f);
49  }
50  }
51 
52  {
53  b2PolygonShape shape;
54  shape.SetAsBox(1.5f, 1.5f);
55  b2BodyDef bd;
56  bd.type = b2_dynamicBody;
57  bd.position.Set(-40.0f,5.0f);
58  bd.bullet = true;
59  b2Body* body = m_world->CreateBody(&bd);
60  body->CreateFixture(&shape, 1.0f);
61  body->SetLinearVelocity(b2Vec2(10.0f, 0.0f));
62  }
63  }
64 
65  static Test* Create()
66  {
67  return new AddPair;
68  }
69 };
70 
71 static int testIndex = RegisterTest("Benchmark", "Add Pair", AddPair::Create);
b2World::SetGravity
void SetGravity(const b2Vec2 &gravity)
Change the global gravity vector.
Definition: b2_world.h:309
b2BodyDef::bullet
bool bullet
Definition: b2_body.h:115
b2Body
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:128
b2CircleShape
A solid circle shape.
Definition: b2_circle_shape.h:30
b2Vec2::SetZero
void SetZero()
Set this vector to all zeros.
Definition: b2_math.h:50
b2Vec2::Set
void Set(float x_, float y_)
Set this vector to some specified coordinates.
Definition: b2_math.h:53
b2Vec2
A 2D column vector.
Definition: b2_math.h:41
b2Body::SetLinearVelocity
void SetLinearVelocity(const b2Vec2 &v)
Definition: b2_body.h:504
f
f
AddPair
Definition: add_pair.cpp:25
b2BodyDef::type
b2BodyType type
Definition: b2_body.h:74
b2_dynamicBody
@ b2_dynamicBody
Definition: b2_body.h:47
b2Shape::m_radius
float m_radius
Definition: b2_shape.h:102
RandomFloat
float RandomFloat()
Random number in range [-1,1].
Definition: test.h:37
b2PolygonShape::SetAsBox
void SetAsBox(float hx, float hy)
Definition: b2_polygon_shape.cpp:36
AddPair::AddPair
AddPair()
Definition: add_pair.cpp:29
b2BodyDef
Definition: b2_body.h:52
testIndex
static int testIndex
Definition: add_pair.cpp:71
b2World::CreateBody
b2Body * CreateBody(const b2BodyDef *def)
Definition: b2_world.cpp:115
b2PolygonShape
Definition: b2_polygon_shape.h:32
RegisterTest
int RegisterTest(const char *category, const char *name, TestCreateFcn *fcn)
Definition: test.cpp:458
int32
signed int int32
Definition: b2_types.h:28
Test
Definition: test.h:80
AddPair::Create
static Test * Create()
Definition: add_pair.cpp:65
b2BodyDef::position
b2Vec2 position
Definition: b2_body.h:78
b2CircleShape::m_p
b2Vec2 m_p
Position.
Definition: b2_circle_shape.h:57
Test::m_world
b2World * m_world
Definition: test.h:128
b2Body::CreateFixture
b2Fixture * CreateFixture(const b2FixtureDef *def)
Definition: b2_body.cpp:165


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:06