Physics Simulation & Visualization Tool 0.1
A C++ physics simulation engine with real-time 3D visualization
Loading...
Searching...
No Matches
PhysicsInspectorWidget.cpp
Go to the documentation of this file.
2#include <QCheckBox>
5#include "ui/Vector3Widget.h"
6
8 layout = new QFormLayout(this);
9 layout->setContentsMargins(6, 6, 6, 6);
10 layout->setSpacing(4);
11 setLayout(layout);
12
13 createUiComponents();
14}
15
16Physics::PhysicsBody* PhysicsInspectorWidget::getBody() const {
17 if (!selectedObject) return nullptr;
18 return selectedObject->getPhysicsBody();
19}
20
21void PhysicsInspectorWidget::createUiComponents() {
22 {
23 QCheckBox* unknownBox = nullptr;
24 Vector3Widget* velWidget = nullptr;
25
26 InspectorRow row("Velocity", this);
27
28 row.addCheckbox(
29 [this]() {
30 auto* b = getBody();
31 return b ? b->isUnknown("v0", BodyLock::NOLOCK) : false;
32 },
33 [this](bool val) {
34 if (auto* b = getBody()) b->setUnknown("v0", val, BodyLock::NOLOCK);
35 },
36 [&](QCheckBox* cb) { unknownBox = cb; }
37 );
38
39 row.addVec3(
40 [this]() {
41 auto* b = getBody();
42 return b ? b->getVelocity(BodyLock::NOLOCK) : glm::vec3(0.0f);
43 },
44 [this](glm::vec3 v) {
45 if (auto* b = getBody()) b->setVelocity(v, BodyLock::NOLOCK);
46 },
47 "m/s",
48 [&](Vector3Widget* v) { velWidget = v; }
49 );
50
51 if (unknownBox && velWidget) {
52 connect(unknownBox, &QCheckBox::toggled, velWidget, &QWidget::setDisabled);
53 velWidget->setEnabled(!unknownBox->isChecked());
54 }
55
56 layout->addRow(row.getLabel(), row.getEditor());
57 rows.push_back(std::move(row));
58 }
59
60 {
61 InspectorRow row("Mass", this);
62 row.addScalar(
63 [this]() {
64 auto* b = getBody();
65 return b ? b->getMass(BodyLock::NOLOCK) : 0.0f;
66 },
67 [this](float m) {
68 if (auto* b = getBody()) b->setMass(m, BodyLock::NOLOCK);
69 },
70 "kg"
71 );
72
73 layout->addRow(row.getLabel(), row.getEditor());
74 rows.push_back(std::move(row));
75 }
76}
77
79 selectedObject = object;
80
81 if (getBody()) {
82 this->setVisible(true);
83 this->setEnabled(true);
84 refresh();
85 } else {
86 this->setVisible(false);
87 }
88}
89
91 selectedObject = nullptr;
92 this->setVisible(false);
93}
94
96 if (!getBody()) {
97 this->setVisible(false);
98 return;
99 }
100
101 for (auto& row : rows) {
102 row.refresh();
103 }
104}
Abstract base class for inspector panel sections.
PhysicsInspectorWidget(QWidget *parent=nullptr)
void refresh() override
Updates UI widgets from the current object's state.
void load(SceneObject *object) override
Loads and binds this section to a scene object.
void unload() override
Unloads the current object and clears section state.
Physics::PhysicsBody * getPhysicsBody() const
Definition SceneObject.h:39