Flatland
body.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name body.h
11  * @brief Defines Body
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_BODY_H
48 #define FLATLAND_BODY_H
49 
50 #include <flatland_server/entity.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 
61 class Body {
62  public:
64  std::string name_;
65  b2Body *physics_body_;
67  YAML::Node properties_;
68 
81  Body(b2World *physics_world, Entity *entity, const std::string &name,
82  const Color &color, const Pose &pose, b2BodyType body_type,
83  const YAML::Node &properties, double linear_damping = 0,
84  double angular_damping = 0);
85 
89  void DebugOutput() const;
90 
94  Entity *GetEntity();
95 
99  const std::string &GetName() const;
100 
106  b2Body *GetPhysicsBody();
107 
112  int GetFixturesCount() const;
113 
117  const Color &GetColor() const;
118 
122  void SetColor(const Color &color);
123 
127  virtual ~Body();
128 
133  Body(const Body &) = delete;
134  Body &operator=(const Body &) = delete;
135 };
136 }; // namespace flatland_server
137 #endif // FLATLAND_MODEL_BODY_H
Entity * entity_
The entity the body belongs to.
Definition: body.h:63
const std::string & GetName() const
Definition: body.cpp:85
Definition: entity.h:61
Definition: body.h:55
Body(b2World *physics_world, Entity *entity, const std::string &name, const Color &color, const Pose &pose, b2BodyType body_type, const YAML::Node &properties, double linear_damping=0, double angular_damping=0)
constructor for body, takes in all the required parameters
Definition: body.cpp:52
void SetColor(const Color &color)
Set of the color of the body.
Definition: body.cpp:91
std::string name_
name of the body, unique within a model
Definition: body.h:64
b2Body * physics_body_
Box2D physics body.
Definition: body.h:65
Definition: types.h:84
int GetFixturesCount() const
Count the number of fixtures.
Definition: body.cpp:74
Definition: types.h:110
b2Body * GetPhysicsBody()
Get the Box2D body, use this to manipulate the body in physics through the Box2D methods.
Definition: body.cpp:87
const Color & GetColor() const
Definition: body.cpp:89
Definition: body.h:61
void DebugOutput() const
logs the debugging information for the body
Definition: body.cpp:93
Color color_
color, for visualization
Definition: body.h:66
virtual ~Body()
Definition: body.cpp:68
YAML::Node properties_
Properties document for plugins to use.
Definition: body.h:67
Entity * GetEntity()
Definition: body.cpp:83