Skip to content

Commit c7e1fc3

Browse files
committed
cleanup
1 parent 7d88e1b commit c7e1fc3

File tree

3 files changed

+34
-38
lines changed

3 files changed

+34
-38
lines changed

examples/loaders/urdf_loader.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int main(int argc, char** argv) {
7474
for (auto i = 0; i < robot->numDOF(); i++) {
7575
const auto type = info[i].type;
7676
const auto minmax = robot->getJointRange(i, true);
77-
bool isRevolute = type == JointType::Revolute;
77+
bool isRevolute = type == Robot::JointType::Revolute;
7878
float min = minmax.first > (isRevolute ? -360.f : -1.f) ? minmax.first : (isRevolute ? -360.f : -1.f);
7979
float max = minmax.second < (isRevolute ? 360.f : 1.f) ? minmax.second : (isRevolute ? 360.f : 1.f);
8080
if (ImGui::SliderFloat(labels[i].c_str(), &jointValues[i], min, max)) {
@@ -100,12 +100,11 @@ int main(int argc, char** argv) {
100100

101101
Clock clock;
102102
canvas.animate([&]() {
103-
const auto dt = clock.getDelta();
104103

105104
if (animate) {
106105
for (auto i = 0; i < robot->numDOF(); ++i) {
107106
jointValues[i] = robot->getJointValue(i, true);
108-
robot->setJointValue(i, std::sin(clock.elapsedTime) * 0.5f);
107+
robot->setJointValue(i, std::sin(clock.getElapsedTime()) * 0.5f);
109108
}
110109
}
111110

include/threepp/objects/Robot.hpp

+25-28
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@
99

1010
namespace threepp {
1111

12-
struct JointRange {
13-
float min;
14-
float max;
12+
class Robot: public Object3D {
1513

16-
[[nodiscard]] float clamp(float value) const {
17-
return std::clamp(value, min, max);
18-
}
19-
};
14+
public:
15+
struct JointRange {
16+
float min;
17+
float max;
2018

21-
enum class JointType {
22-
Revolute,
23-
Prismatic,
24-
Fixed
25-
};
19+
[[nodiscard]] float clamp(float value) const {
20+
return std::clamp(value, min, max);
21+
}
22+
};
2623

27-
struct JointInfo {
28-
Vector3 axis;
29-
JointType type;
30-
std::optional<JointRange> range;
24+
enum class JointType {
25+
Revolute,
26+
Prismatic,
27+
Fixed
28+
};
3129

32-
std::string parent;
33-
std::string child;
34-
};
30+
struct JointInfo {
31+
Vector3 axis;
32+
JointType type;
33+
std::optional<JointRange> range;
3534

36-
class Robot: public Object3D {
35+
std::string parent;
36+
std::string child;
37+
};
3738

38-
public:
3939
Robot() = default;
4040

4141
void showColliders(bool flag) {
@@ -56,7 +56,7 @@ namespace threepp {
5656
joints_.emplace_back(joint);
5757
jointInfos_.emplace_back(info);
5858
if (info.type != JointType::Fixed) {
59-
size_t idx = joints_.size() -1;
59+
size_t idx = joints_.size() - 1;
6060
articulatedJoints_.emplace(idx, std::make_pair(joint.get(), info));
6161
origPose_.emplace(idx, std::make_pair(joint->position.clone(), joint->quaternion.clone()));
6262
}
@@ -122,10 +122,7 @@ namespace threepp {
122122
}
123123
}
124124

125-
for (const auto& l : links_) {
126-
127-
if (!l->parent) add(*l);
128-
}
125+
add(links_.front());
129126

130127
jointValues_.resize(numDOF());
131128
}
@@ -223,14 +220,14 @@ namespace threepp {
223220
}
224221

225222
private:
223+
std::vector<float> jointValues_;
224+
226225
std::vector<JointInfo> jointInfos_;
227226
std::vector<std::shared_ptr<Object3D>> links_;
228227
std::vector<std::shared_ptr<Object3D>> colliders_;
229228
std::vector<std::shared_ptr<Object3D>> joints_;
230229
std::unordered_map<size_t, std::pair<Object3D*, JointInfo>> articulatedJoints_;
231230
std::unordered_map<size_t, std::pair<Vector3, Quaternion>> origPose_;
232-
233-
std::vector<float> jointValues_;
234231
};
235232

236233
}// namespace threepp

src/threepp/loaders/URDFLoader.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,27 @@ namespace {
5757
return mtl;
5858
}
5959

60-
JointType getType(const std::string& type) {
60+
Robot::JointType getType(const std::string& type) {
6161
if (type == "revolute" || type == "continuous") {
62-
return JointType::Revolute;
62+
return Robot::JointType::Revolute;
6363
}
6464
if (type == "prismatic") {
65-
return JointType::Prismatic;
65+
return Robot::JointType::Prismatic;
6666
}
67-
return JointType::Fixed;
67+
return Robot::JointType::Fixed;
6868
}
6969

70-
std::optional<JointRange> getRange(const pugi::xml_node& node) {
70+
std::optional<Robot::JointRange> getRange(const pugi::xml_node& node) {
7171
const auto limit = node.child("limit");
7272
if (!limit || !limit.attribute("lower") || !limit.attribute("upper")) return {};
7373
const auto min = utils::parseFloat(limit.attribute("lower").value());
7474
const auto max = utils::parseFloat(limit.attribute("upper").value());
75-
return JointRange{
75+
return Robot::JointRange{
7676
.min = min,
7777
.max = max};
7878
}
7979

80-
JointInfo parseInfo(const pugi::xml_node& node) {
80+
Robot::JointInfo parseInfo(const pugi::xml_node& node) {
8181

8282
auto axis = parseTupleString(node.child("axis")
8383
.attribute("xyz")

0 commit comments

Comments
 (0)