heavy2.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 Heavy2 : public Test
26 {
27 public:
28 
30  {
31  {
32  b2BodyDef bd;
33  b2Body* ground = m_world->CreateBody(&bd);
34 
35  b2EdgeShape shape;
36  shape.SetTwoSided(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
37  ground->CreateFixture(&shape, 0.0f);
38  }
39 
40  b2BodyDef bd;
41  bd.type = b2_dynamicBody;
42  bd.position.Set(0.0f, 2.5f);
43  b2Body* body = m_world->CreateBody(&bd);
44 
45  b2CircleShape shape;
46  shape.m_radius = 0.5f;
47  body->CreateFixture(&shape, 10.0f);
48 
49  bd.position.Set(0.0f, 3.5f);
50  body = m_world->CreateBody(&bd);
51  body->CreateFixture(&shape, 10.0f);
52 
53  m_heavy = NULL;
54  }
55 
56  void ToggleHeavy()
57  {
58  if (m_heavy)
59  {
61  m_heavy = NULL;
62  }
63  else
64  {
65  b2BodyDef bd;
66  bd.type = b2_dynamicBody;
67  bd.position.Set(0.0f, 9.0f);
68  m_heavy = m_world->CreateBody(&bd);
69 
70  b2CircleShape shape;
71  shape.m_radius = 5.0f;
72  m_heavy->CreateFixture(&shape, 10.0f);
73  }
74  }
75 
76  void Keyboard(int key) override
77  {
78  switch (key)
79  {
80  case GLFW_KEY_H:
81  ToggleHeavy();
82  break;
83  }
84  }
85 
86  static Test* Create()
87  {
88  return new Heavy2;
89  }
90 
92 };
93 
94 static int testIndex = RegisterTest("Solver", "Heavy 2", Heavy2::Create);
static int testIndex
Definition: heavy2.cpp:94
b2Fixture * CreateFixture(const b2FixtureDef *def)
Definition: b2_body.cpp:165
void ToggleHeavy()
Definition: heavy2.cpp:56
b2Body * m_heavy
Definition: heavy2.cpp:91
f
void Keyboard(int key) override
Definition: heavy2.cpp:76
static Test * Create()
Definition: heavy2.cpp:86
Definition: test.h:80
#define GLFW_KEY_H
Definition: glfw3.h:385
A solid circle shape.
A 2D column vector.
Definition: b2_math.h:41
void SetTwoSided(const b2Vec2 &v1, const b2Vec2 &v2)
Set this as an isolated edge. Collision is two-sided.
b2BodyType type
Definition: b2_body.h:74
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:128
float m_radius
Definition: b2_shape.h:102
void Set(float x_, float y_)
Set this vector to some specified coordinates.
Definition: b2_math.h:53
Heavy2()
Definition: heavy2.cpp:29
b2World * m_world
Definition: test.h:128
b2Vec2 position
Definition: b2_body.h:78
void DestroyBody(b2Body *body)
Definition: b2_world.cpp:139
int RegisterTest(const char *category, const char *name, TestCreateFcn *fcn)
Definition: test.cpp:458
b2Body * CreateBody(const b2BodyDef *def)
Definition: b2_world.cpp:115


mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:20