chain_problem.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 ChainProblem : public Test
26 {
27 public:
28 
30  {
31  {
32  b2Vec2 g(0.0f, -10.0f);
33  m_world->SetGravity(g);
34  b2Body** bodies = (b2Body**)b2Alloc(2 * sizeof(b2Body*));
35  b2Joint** joints = (b2Joint**)b2Alloc(0 * sizeof(b2Joint*));
36  {
37  b2BodyDef bd;
38  bd.type = b2BodyType(0);
39  bodies[0] = m_world->CreateBody(&bd);
40 
41  {
42  b2FixtureDef fd;
43 
44  b2Vec2 v1(0.0f, 1.0f);
45  b2Vec2 v2(0.0f, 0.0f);
46  b2Vec2 v3(4.0f, 0.0f);
47 
48  b2EdgeShape shape;
49  shape.SetTwoSided(v1, v2);
50  bodies[0]->CreateFixture(&shape, 0.0f);
51 
52  shape.SetTwoSided(v2, v3);
53  bodies[0]->CreateFixture(&shape, 0.0f);
54  }
55  }
56  {
57  b2BodyDef bd;
58  bd.type = b2BodyType(2);
59  //bd.position.Set(6.033980250358582e-01f, 3.028350114822388e+00f);
60  bd.position.Set(1.0f, 3.0f);
61  bodies[1] = m_world->CreateBody(&bd);
62 
63  {
64  b2FixtureDef fd;
65  fd.friction = 0.2f;
66  fd.density = 10.0f;
67  b2PolygonShape shape;
68  b2Vec2 vs[8];
69  vs[0].Set(0.5f, -3.0f);
70  vs[1].Set(0.5f, 3.0f);
71  vs[2].Set(-0.5f, 3.0f);
72  vs[3].Set(-0.5f, -3.0f);
73  shape.Set(vs, 4);
74 
75  fd.shape = &shape;
76 
77  bodies[1]->CreateFixture(&fd);
78  }
79  }
80  b2Free(joints);
81  b2Free(bodies);
82  joints = NULL;
83  bodies = NULL;
84  }
85  }
86 
87  static Test* Create()
88  {
89  return new ChainProblem;
90  }
91 
92 };
93 
94 static int testIndex = RegisterTest("Bugs", "Chain Problem", ChainProblem::Create);
const b2Shape * shape
Definition: b2_fixture.h:76
void * b2Alloc(int32 size)
Implement this function to use your own memory allocator.
Definition: b2_settings.h:100
b2Fixture * CreateFixture(const b2FixtureDef *def)
Definition: b2_body.cpp:165
float density
The density, usually in kg/m^2.
Definition: b2_fixture.h:92
f
b2BodyType
Definition: b2_body.h:43
void SetGravity(const b2Vec2 &gravity)
Change the global gravity vector.
Definition: b2_world.h:309
Definition: test.h:80
static int testIndex
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
static Test * Create()
A rigid body. These are created via b2World::CreateBody.
Definition: b2_body.h:128
void Set(float x_, float y_)
Set this vector to some specified coordinates.
Definition: b2_math.h:53
b2World * m_world
Definition: test.h:128
b2Vec2 position
Definition: b2_body.h:78
void Set(const b2Vec2 *points, int32 count)
void b2Free(void *mem)
If you implement b2Alloc, you should also implement this function.
Definition: b2_settings.h:106
int RegisterTest(const char *category, const char *name, TestCreateFcn *fcn)
Definition: test.cpp:458
b2Body * CreateBody(const b2BodyDef *def)
Definition: b2_world.cpp:115
float friction
The friction coefficient, usually in the range [0,1].
Definition: b2_fixture.h:82


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