Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose 'angular_velocity ' as a public attribute in 'PropNode' for modding #771

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@
### Loup Garou
- Added sphinx documentation generation
- Added docker build system
- Various CI/CD improvements
- Various CI/CD improvements

### Dhextras
- Added Small feature for modders
10 changes: 10 additions & 0 deletions src/ballistica/scene_v1/node/prop_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,16 @@ void PropNode::Step() {
}
}

// adding new attribute as angularvel for angular velocity which is actually rotation force
if (body_.exists()) {
if (angular_velocity_.size() != 3) {
throw Exception("Expected float array of size 3 for velocity",
PyExcType::kValue);
} else {
dBodySetAngularVel(body_->body(), angular_velocity_[0], angular_velocity_[1], angular_velocity_[2]);
}
}

// apply damping force
float rotationalDampingX = 0.02f;
float rotationalDampingY = 0.02f;
Expand Down
5 changes: 5 additions & 0 deletions src/ballistica/scene_v1/node/prop_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class PropNode : public Node {
void set_damping(float val) { damping_ = val; }
auto max_speed() const -> float { return max_speed_; }
void set_max_speed(float val) { max_speed_ = val; }
auto angular_velocity() const -> std::vector<float> { return angular_velocity_; }
void set_angular_velocity(const std::vector<float>& vals) { angular_velocity_ = vals; }
auto gravity_scale() const -> float { return gravity_scale_; }
void set_gravity_scale(float val) { gravity_scale_ = val; }

Expand Down Expand Up @@ -101,6 +103,7 @@ class PropNode : public Node {
float max_speed_{20.0f};
std::vector<float> velocity_{0.0f, 0.0f, 0.0f};
std::vector<float> position_{0.0f, 0.0f, 0.0f};
std::vector<float> angular_velocity_{0.0f, 0.0f, 0.0f};
std::vector<float> extra_acceleration_{0.0, 0.0, 0.0};
float extra_mesh_scale_{1.0f}; // For use by subclasses.
bool sticky_{};
Expand Down Expand Up @@ -149,6 +152,7 @@ class PropNodeType : public NodeType {
BA_FLOAT_ATTR(damping, damping, set_damping);
BA_FLOAT_ATTR(body_scale, body_scale, SetBodyScale);
BA_FLOAT_ATTR(max_speed, max_speed, set_max_speed);
BA_FLOAT_ARRAY_ATTR(angular_velocity, angular_velocity, set_angular_velocity);
BA_FLOAT_ARRAY_ATTR(extra_acceleration, extra_acceleration,
SetExtraAcceleration);
BA_FLOAT_ATTR(gravity_scale, gravity_scale, set_gravity_scale);
Expand Down Expand Up @@ -177,6 +181,7 @@ class PropNodeType : public NodeType {
density(this),
damping(this),
max_speed(this),
angular_velocity(this),
body_scale(this),
body(this),
extra_acceleration(this),
Expand Down