feat(joints): added parameters for motor joint
This commit is contained in:
parent
47d720f438
commit
590ecbe5ec
6 changed files with 60 additions and 8 deletions
|
@ -10,6 +10,7 @@ std::map<std::string, std::string> CATEGORY_STR = {
|
|||
{ "BEHAVIOR", "PROP_CATEGORY_BEHAVIOR" },
|
||||
{ "PART", "PROP_CATEGORY_PART" },
|
||||
{ "SURFACE", "PROP_CATEGORY_SURFACE" },
|
||||
{ "SURFACE_INPUT", "PROP_CATEGORY_SURFACE_INPUT" },
|
||||
};
|
||||
|
||||
std::map<std::string, std::string> MAPPED_TYPE = {
|
||||
|
|
|
@ -56,9 +56,10 @@ enum PropertyCategory {
|
|||
PROP_CATEGORY_BEHAVIOR,
|
||||
PROP_CATEGORY_PART,
|
||||
PROP_CATEGORY_SURFACE,
|
||||
PROP_CATEGORY_SURFACE_INPUT,
|
||||
};
|
||||
|
||||
const int PROPERTY_CATEGORY_MAX = PROP_CATEGORY_SURFACE;
|
||||
const int PROPERTY_CATEGORY_MAX = PROP_CATEGORY_SURFACE_INPUT;
|
||||
|
||||
struct PropertyMeta {
|
||||
const Data::TypeInfo* type;
|
||||
|
|
|
@ -94,7 +94,8 @@ void Part::onUpdated(std::string property) {
|
|||
workspace().value()->SyncPartPhysics(std::dynamic_pointer_cast<Part>(this->shared_from_this()));
|
||||
|
||||
// When position/rotation/size is manually edited, break all joints, they don't apply anymore
|
||||
BreakJoints();
|
||||
if (property != "Anchored")
|
||||
BreakJoints();
|
||||
}
|
||||
|
||||
// Expands provided extents to fit point
|
||||
|
@ -158,6 +159,32 @@ SurfaceType Part::surfaceFromFace(NormalId face) {
|
|||
return SurfaceSmooth; // Unreachable
|
||||
}
|
||||
|
||||
float Part::GetSurfaceParamA(Vector3 face) {
|
||||
// printVec(face);
|
||||
// printf("Enum: %d\n", faceFromNormal(face));
|
||||
switch (faceFromNormal(face)) {
|
||||
case Top: return topParamA;
|
||||
case Bottom: return bottomParamA;
|
||||
case Right: return rightParamA;
|
||||
case Left: return leftParamA;
|
||||
case Front: return frontParamA;
|
||||
case Back: return backParamA;
|
||||
}
|
||||
return 0; // Unreachable
|
||||
}
|
||||
|
||||
float Part::GetSurfaceParamB(Vector3 face) {
|
||||
switch (faceFromNormal(face)) {
|
||||
case Top: return topParamB;
|
||||
case Bottom: return bottomParamB;
|
||||
case Right: return rightParamB;
|
||||
case Left: return leftParamB;
|
||||
case Front: return frontParamB;
|
||||
case Back: return backParamB;
|
||||
}
|
||||
return 0; // Unreachable
|
||||
}
|
||||
|
||||
bool Part::checkJointContinuity(std::shared_ptr<Part> otherPart) {
|
||||
// Make sure that the two parts don't depend on one another
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
bool selected = false;
|
||||
|
||||
DEF_PROP_CATEGORY(BEHAVIOR)
|
||||
DEF_PROP bool anchored = false;
|
||||
DEF_PROP_(on_update=onUpdated) bool anchored = false;
|
||||
DEF_PROP bool locked = false;
|
||||
|
||||
DEF_PROP_CATEGORY(SURFACE)
|
||||
|
@ -76,10 +76,27 @@ public:
|
|||
DEF_PROP SurfaceType frontSurface = SurfaceType::SurfaceSmooth;
|
||||
DEF_PROP SurfaceType backSurface = SurfaceType::SurfaceSmooth;
|
||||
|
||||
DEF_PROP_CATEGORY(SURFACE_INPUT)
|
||||
DEF_PROP float topParamA = -0.5;
|
||||
DEF_PROP float bottomParamA = -0.5;
|
||||
DEF_PROP float leftParamA = -0.5;
|
||||
DEF_PROP float rightParamA = -0.5;
|
||||
DEF_PROP float frontParamA = -0.5;
|
||||
DEF_PROP float backParamA = -0.5;
|
||||
|
||||
DEF_PROP float topParamB = 0.5;
|
||||
DEF_PROP float bottomParamB = 0.5;
|
||||
DEF_PROP float leftParamB = 0.5;
|
||||
DEF_PROP float rightParamB = 0.5;
|
||||
DEF_PROP float frontParamB = 0.5;
|
||||
DEF_PROP float backParamB = 0.5;
|
||||
|
||||
|
||||
rp::RigidBody* rigidBody = nullptr;
|
||||
|
||||
inline SurfaceType GetSurfaceFromFace(NormalId face) { return surfaceFromFace(face); }
|
||||
float GetSurfaceParamA(Vector3 face);
|
||||
float GetSurfaceParamB(Vector3 face);
|
||||
|
||||
Part();
|
||||
Part(PartConstructParams params);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "workspace.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include "objects/base/instance.h"
|
||||
#include "objects/jointsservice.h"
|
||||
#include "objects/joint/jointinstance.h"
|
||||
|
@ -104,13 +105,14 @@ void Workspace::PhysicsStep(float deltaTime) {
|
|||
part->cframe = CFrame(transform);
|
||||
part->velocity = part->rigidBody->getLinearVelocity();
|
||||
|
||||
part->rigidBody->enableGravity(true);
|
||||
// part->rigidBody->enableGravity(true);
|
||||
for (auto& joint : part->secondaryJoints) {
|
||||
if (joint.expired() || !joint.lock()->IsA("RotateV")) continue;
|
||||
|
||||
|
||||
std::shared_ptr<JointInstance> motor = joint.lock()->CastTo<JointInstance>().expect();
|
||||
part->rigidBody->enableGravity(false);
|
||||
part->rigidBody->setAngularVelocity((motor->part0.lock()->cframe * motor->c0).LookVector() * 10.f);
|
||||
float rate = motor->part0.lock()->GetSurfaceParamB(motor->c0.LookVector().Unit()) * 30;
|
||||
// part->rigidBody->enableGravity(false);
|
||||
part->rigidBody->setAngularVelocity(-(motor->part0.lock()->cframe * motor->c0).LookVector() * rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,7 +249,8 @@ QStringList PROPERTY_CATEGORY_NAMES {
|
|||
"Data",
|
||||
"Behavior",
|
||||
"Part",
|
||||
"Surface"
|
||||
"Surface",
|
||||
"Surface Inputs",
|
||||
};
|
||||
|
||||
QModelIndex PropertiesView::indexAt(const QPoint &point) const {
|
||||
|
@ -330,6 +331,9 @@ void PropertiesView::setSelected(std::optional<InstanceRef> instance) {
|
|||
|
||||
// Remove child-less categories
|
||||
for (int i = 0; i <= PROPERTY_CATEGORY_MAX; i++) {
|
||||
if (i == PROP_CATEGORY_SURFACE_INPUT)
|
||||
propertyCategories[(PropertyCategory)i]->setExpanded(false);
|
||||
|
||||
if (propertyCategories[(PropertyCategory)i]->childCount() > 0) continue;
|
||||
int idx = indexOfTopLevelItem(propertyCategories[(PropertyCategory)i]);
|
||||
delete takeTopLevelItem(idx);
|
||||
|
|
Loading…
Add table
Reference in a new issue