Flatland
joint.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name joint.h
11  * @brief Defines Joint
12  * @author Chunshang Li
13  *
14  * Software License Agreement (BSD License)
15  *
16  * Copyright (c) 2017, Avidbots Corp.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  * * Neither the name of the Avidbots Corp. nor the names of its
30  * contributors may be used to endorse or promote products derived
31  * from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #ifndef FLATLAND_SERVER_JOINT_H
48 #define FLATLAND_SERVER_JOINT_H
49 
50 #include <flatland_server/model.h>
51 #include <flatland_server/types.h>
52 #include <flatland_server/yaml_reader.h>
53 #include <yaml-cpp/yaml.h>
54 
55 namespace flatland_server {
56 
57 class Model;
58 
63 class Joint {
64  public:
66  std::string name_;
67  b2World *physics_world_;
69  b2Joint *physics_joint_;
70 
79  Joint(b2World *physics_world, Model *model, const std::string &name,
80  const Color &color, const b2JointDef &joint_def);
81  ~Joint();
82 
84  Joint(const Joint &) = delete;
85  Joint &operator=(const Joint &) = delete;
86 
90  void DebugOutput() const;
91 
95  Model *GetModel();
96 
100  const std::string &GetName() const;
101 
105  const Color &GetColor() const;
106 
110  void SetColor(const Color &color);
111 
115  b2Joint *GetPhysicsJoint();
116 
120  b2World *GetphysicsWorld();
121 
130  static Joint *MakeJoint(b2World *physics_world, Model *model,
131  YamlReader &joint_reader);
132 
150  static Joint *MakeRevoluteJoint(b2World *physics_world, Model *model,
151  YamlReader &joint_reader,
152  const std::string &name, const Color &color,
153  b2Body *body_A, b2Vec2 anchor_A,
154  b2Body *body_B, b2Vec2 anchor_B,
155  bool collide_connected);
156 
174  static Joint *MakeWeldJoint(b2World *physics_world, Model *model,
175  YamlReader &joint_reader, const std::string &name,
176  const Color &color, b2Body *body_A,
177  b2Vec2 anchor_A, b2Body *body_B, b2Vec2 anchor_B,
178  bool collide_connected);
179 };
180 }; // namespace flatland_server
181 #endif // FLATLAND_MODEL_JOINT_H
b2Joint * GetPhysicsJoint()
Definition: joint.cpp:70
void DebugOutput() const
logs the debugging information for the joint
Definition: joint.cpp:189
void SetColor(const Color &color)
Definition: joint.cpp:68
Definition: body.h:55
static Joint * MakeRevoluteJoint(b2World *physics_world, Model *model, YamlReader &joint_reader, const std::string &name, const Color &color, b2Body *body_A, b2Vec2 anchor_A, b2Body *body_B, b2Vec2 anchor_B, bool collide_connected)
Creates a revolute joint for the given params, throws exceptions upon failure.
Definition: joint.cpp:134
Definition: model.h:67
Definition: joint.h:63
b2World * physics_world_
Box2D physics world.
Definition: joint.h:67
const Color & GetColor() const
Definition: joint.cpp:66
Definition: types.h:110
Model * model_
Model the joint belongs to.
Definition: joint.h:65
b2World * GetphysicsWorld()
Definition: joint.cpp:72
b2Joint * physics_joint_
Box2D physics joint.
Definition: joint.h:69
static Joint * MakeWeldJoint(b2World *physics_world, Model *model, YamlReader &joint_reader, const std::string &name, const Color &color, b2Body *body_A, b2Vec2 anchor_A, b2Body *body_B, b2Vec2 anchor_B, bool collide_connected)
Creates a weld joint for the given params, throws exceptions upon failure.
Definition: joint.cpp:167
Definition: yaml_reader.h:76
Color color_
Color for visualization.
Definition: joint.h:68
static Joint * MakeJoint(b2World *physics_world, Model *model, YamlReader &joint_reader)
Creates a joint for the given params, throws exceptions upon failure.
Definition: joint.cpp:74
Model * GetModel()
Definition: joint.cpp:62
std::string name_
Name of the joint.
Definition: joint.h:66
Joint(b2World *physics_world, Model *model, const std::string &name, const Color &color, const b2JointDef &joint_def)
Constructor for the joint.
Definition: joint.cpp:53
const std::string & GetName() const
Definition: joint.cpp:64