refactor(physics): removed remnants of rp3d from datatypes and other code

This commit is contained in:
maelstrom 2025-08-22 17:46:54 +02:00
parent 5f57622466
commit 089fd02899
19 changed files with 176 additions and 139 deletions

View file

@ -1,12 +1,10 @@
#include "cframe.h"
#include "datatypes/vector.h"
#include "error/data.h"
#include "physics/util.h"
#include <glm/ext/matrix_transform.hpp>
#include <glm/gtc/matrix_inverse.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/matrix.hpp>
#include <reactphysics3d/mathematics/Transform.h>
#include "datatypes/variant.h"
#include <pugixml.hpp>
#define GLM_ENABLE_EXPERIMENTAL
@ -40,9 +38,6 @@ CFrame::CFrame(Vector3 position, glm::quat quat)
, rotation(quat) {
}
CFrame::CFrame(const rp::Transform& transform) : CFrame::CFrame(rpToGlm(transform.getPosition()), rpToGlm(transform.getOrientation())) {
}
glm::mat3 lookAt(Vector3 position, Vector3 lookAt, Vector3 up) {
// https://github.com/sgorsten/linalg/issues/29#issuecomment-743989030
Vector3 f = (lookAt - position).Unit(); // Forward/Look
@ -77,10 +72,6 @@ CFrame::operator glm::mat4() const {
return glm::translate(glm::mat4(1.0f), this->translation) * glm::mat4(this->rotation);
}
CFrame::operator rp::Transform() const {
return rp::Transform(glmToRp(translation), glmToRp(rotation));
}
Vector3 CFrame::ToEulerAnglesXYZ() {
float x;
float y;

View file

@ -8,8 +8,6 @@
#include <glm/gtc/matrix_access.hpp>
#include <glm/matrix.hpp>
namespace reactphysics3d { class Transform; };
class DEF_DATA_(name="CoordinateFrame") CFrame {
AUTOGEN_PREAMBLE_DATA
@ -24,7 +22,6 @@ public:
DEF_DATA_CTOR CFrame();
DEF_DATA_CTOR CFrame(float x, float y, float z, float R00, float R01, float R02, float R10, float R11, float R12, float R20, float R21, float R22);
DEF_DATA_CTOR CFrame(Vector3 , Vector3 lookAt, Vector3 up = Vector3(0, 1, 0));
CFrame(const reactphysics3d::Transform&);
CFrame(Vector3 position, glm::quat quat);
virtual ~CFrame();
@ -46,11 +43,11 @@ public:
static void PushLuaLibrary(lua_State*);
operator glm::mat4() const;
operator reactphysics3d::Transform() const;
//inline static CFrame identity() { }
DEF_DATA_PROP inline Vector3 Position() const { return translation; }
DEF_DATA_PROP inline CFrame Rotation() const { return CFrame { glm::vec3(0, 0, 0), rotation }; }
inline glm::mat3 RotMatrix() const { return rotation; }
DEF_DATA_METHOD CFrame Inverse() const;
DEF_DATA_PROP inline float X() const { return translation.x; }
DEF_DATA_PROP inline float Y() const { return translation.y; }

View file

@ -3,7 +3,6 @@
#include <cstdlib>
#include <glm/ext/quaternion_geometric.hpp>
#include <iomanip>
#include <reactphysics3d/mathematics/Vector3.h>
#include <string>
#include <pugixml.hpp>
#include "datatypes/base.h"
@ -11,11 +10,8 @@
#include "error/data.h"
#include <sstream>
namespace rp = reactphysics3d;
Vector3::Vector3() : vector(glm::vec3(0, 0, 0)) {};
Vector3::Vector3(const glm::vec3& src) : vector(src) {};
Vector3::Vector3(const rp::Vector3& src) : vector(glm::vec3(src.x, src.y, src.z)) {};
Vector3::Vector3(float x, const float y, float z) : vector(glm::vec3(x, y, z)) {};
Vector3::~Vector3() = default;
@ -31,7 +27,6 @@ const std::string Vector3::ToString() const {
}
Vector3::operator glm::vec3() const { return vector; };
Vector3::operator rp::Vector3() const { return rp::Vector3(X(), Y(), Z()); };
// Operators

View file

@ -5,9 +5,6 @@
#include "error/data.h"
#include <glm/ext/vector_float3.hpp>
#include <glm/geometric.hpp>
#include <reactphysics3d/mathematics/Vector3.h>
// namespace reactphysics3d { class Vector3; };
class DEF_DATA Vector3 {
AUTOGEN_PREAMBLE_DATA
@ -18,7 +15,6 @@ public:
DEF_DATA_CTOR Vector3(float x, float y, float z);
inline Vector3(float value) : Vector3(value, value, value) {}
Vector3(const glm::vec3&);
Vector3(const reactphysics3d::Vector3&);
virtual ~Vector3();
DEF_DATA_PROP static Vector3 ZERO;
@ -33,7 +29,6 @@ public:
static void PushLuaLibrary(lua_State*);
operator glm::vec3() const;
operator reactphysics3d::Vector3() const;
DEF_DATA_PROP inline float X() const { return vector.x; }
DEF_DATA_PROP inline float Y() const { return vector.y; }

View file

@ -1,15 +1,11 @@
#include "jointinstance.h"
#include "datatypes/cframe.h"
#include "datatypes/ref.h"
#include "objects/datamodel.h"
#include "objects/service/jointsservice.h"
#include "objects/part/part.h"
#include "objects/part/basepart.h"
#include "objects/service/workspace.h"
#include <memory>
#include <reactphysics3d/constraint/FixedJoint.h>
#include <reactphysics3d/engine/PhysicsWorld.h>
#include "ptr_helpers.h"
JointInstance::JointInstance(const InstanceType* type): Instance(type) {
}

View file

@ -3,7 +3,6 @@
#include "objects/part/part.h"
#include "objects/service/workspace.h"
#include "rendering/renderer.h"
#include <reactphysics3d/constraint/HingeJoint.h>
Rotate::Rotate(): JointInstance(&TYPE) {
}

View file

@ -5,8 +5,6 @@
#include "objects/joint/jointinstance.h"
#include <memory>
namespace reactphysics3d { class HingeJoint; }
class DEF_INST Rotate : public JointInstance {
AUTOGEN_PREAMBLE

View file

@ -3,7 +3,6 @@
#include "objects/part/part.h"
#include "objects/service/workspace.h"
#include "rendering/renderer.h"
#include <reactphysics3d/constraint/HingeJoint.h>
#define PI 3.14159

View file

@ -4,7 +4,6 @@
#include "objects/base/instance.h"
#include "objects/joint/jointinstance.h"
#include <memory>
namespace reactphysics3d { class HingeJoint; }
class DEF_INST RotateV : public JointInstance {
AUTOGEN_PREAMBLE

View file

@ -8,8 +8,6 @@
#include "objects/service/workspace.h"
#include "physics/world.h"
#include <memory>
#include <reactphysics3d/constraint/FixedJoint.h>
#include <reactphysics3d/engine/PhysicsWorld.h>
Snap::Snap(): JointInstance(&TYPE) {
}

View file

@ -5,8 +5,6 @@
#include "objects/joint/jointinstance.h"
#include <memory>
namespace reactphysics3d { class FixedJoint; }
class DEF_INST Snap : public JointInstance {
AUTOGEN_PREAMBLE

View file

@ -8,8 +8,6 @@
#include "objects/service/workspace.h"
#include "physics/world.h"
#include <memory>
#include <reactphysics3d/constraint/FixedJoint.h>
#include <reactphysics3d/engine/PhysicsWorld.h>
Weld::Weld(): JointInstance(&TYPE) {
}

View file

@ -5,8 +5,6 @@
#include "objects/joint/jointinstance.h"
#include <memory>
namespace reactphysics3d { class FixedJoint; }
class DEF_INST Weld : public JointInstance {
AUTOGEN_PREAMBLE

View file

@ -1,9 +1,9 @@
#include "wedgepart.h"
#include "physics/util.h"
#include <reactphysics3d/collision/ConvexMesh.h>
#include <reactphysics3d/collision/shapes/ConvexMeshShape.h>
// #include "physics/util.h"
// #include <reactphysics3d/collision/ConvexMesh.h>
// #include <reactphysics3d/collision/shapes/ConvexMeshShape.h>
rp::ConvexMesh* wedgePhysMesh;
// rp::ConvexMesh* wedgePhysMesh;
WedgePart::WedgePart(): BasePart(&TYPE) {
}
@ -28,65 +28,65 @@ WedgePart::WedgePart(PartConstructParams params): BasePart(&TYPE, params) {
// rigidBody->addCollider(shape, rp::Transform());
// }
void WedgePart::createWedgeShape(rp::PhysicsCommon* common) {
// https://www.reactphysics3d.com/documentation/index.html#creatingbody
float vertices[] = {
// X Y Z
/*0*/ -1, 1, 1, // 0
/*1*/ -1, -1, 1, // |
/*2*/ -1, -1, -1, // 1---2
// void WedgePart::createWedgeShape(rp::PhysicsCommon* common) {
// // https://www.reactphysics3d.com/documentation/index.html#creatingbody
// float vertices[] = {
// // X Y Z
// /*0*/ -1, 1, 1, // 0
// /*1*/ -1, -1, 1, // |
// /*2*/ -1, -1, -1, // 1---2
/*3*/ 1, 1, 1,
/*4*/ 1, -1, 1,
/*5*/ 1, -1, -1,
};
// /*3*/ 1, 1, 1,
// /*4*/ 1, -1, 1,
// /*5*/ 1, -1, -1,
// };
// -x +x
// +z 1----------4
// | bottom |
// -z 2----------5
// // -x +x
// // +z 1----------4
// // | bottom |
// // -z 2----------5
// -x +x
// +y 0----------3
// | front |
// -y 1----------4
// // -x +x
// // +y 0----------3
// // | front |
// // -y 1----------4
// -x +x
// +yz 0----------3
// | slope |
// -yz 2----------5
// // -x +x
// // +yz 0----------3
// // | slope |
// // -yz 2----------5
int indices[] = {
// Base
1, 2, 5, 4,
// int indices[] = {
// // Base
// 1, 2, 5, 4,
// Back-face
0, 1, 4, 3,
// 4, 1, 0, 3,
// // Back-face
// 0, 1, 4, 3,
// // 4, 1, 0, 3,
// Slope
0, 2, 5, 3,
// 3, 5, 2, 0,
// // Slope
// 0, 2, 5, 3,
// // 3, 5, 2, 0,
// Sides
0, 1, 2,
3, 4, 5,
};
// // Sides
// 0, 1, 2,
// 3, 4, 5,
// };
// Description of the six faces of the convex mesh
rp::PolygonVertexArray::PolygonFace* polygonFaces = new rp::PolygonVertexArray::PolygonFace[5];
polygonFaces[0] = { 4, 0 }; // Bottom
polygonFaces[1] = { 4, 4 }; // Front
polygonFaces[2] = { 4, 8 }; // Slope
polygonFaces[3] = { 3, 12 }; // Side
polygonFaces[4] = { 3, 15 }; // Side
// // Description of the six faces of the convex mesh
// rp::PolygonVertexArray::PolygonFace* polygonFaces = new rp::PolygonVertexArray::PolygonFace[5];
// polygonFaces[0] = { 4, 0 }; // Bottom
// polygonFaces[1] = { 4, 4 }; // Front
// polygonFaces[2] = { 4, 8 }; // Slope
// polygonFaces[3] = { 3, 12 }; // Side
// polygonFaces[4] = { 3, 15 }; // Side
// Create the polygon vertex array
rp::PolygonVertexArray polygonVertexArray(6, vertices, 3 * sizeof(float), indices, sizeof(int), 5, polygonFaces,
rp::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE,
rp::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
// // Create the polygon vertex array
// rp::PolygonVertexArray polygonVertexArray(6, vertices, 3 * sizeof(float), indices, sizeof(int), 5, polygonFaces,
// rp::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE,
// rp::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
// Create the convex mesh
std::vector<rp::Message> messages;
// wedgePhysMesh = common->createConvexMesh(polygonVertexArray, messages);
}
// // Create the convex mesh
// std::vector<rp::Message> messages;
// // wedgePhysMesh = common->createConvexMesh(polygonVertexArray, messages);
// }

View file

@ -7,7 +7,7 @@ class DEF_INST_(hidden) WedgePart : public BasePart {
AUTOGEN_PREAMBLE
protected:
static void createWedgeShape(rp::PhysicsCommon* common);
// static void createWedgeShape(rp::PhysicsCommon* common);
friend Workspace;
public:

View file

@ -0,0 +1,61 @@
#pragma once
#include "datatypes/cframe.h"
#include "datatypes/vector.h"
#include <glm/ext/vector_float3.hpp>
#include <reactphysics3d/body/Body.h>
#include <reactphysics3d/mathematics/Quaternion.h>
#include <reactphysics3d/mathematics/Vector3.h>
#include <glm/ext.hpp>
#define rp reactphysics3d
template <typename T, typename F>
T convert(F vec) = delete;
// Vector3
template <>
inline Vector3 convert<Vector3>(rp::Vector3 vec) {
return Vector3(vec.x, vec.y, vec.z);
}
template <>
inline rp::Vector3 convert<rp::Vector3>(Vector3 vec) {
return rp::Vector3(vec.X(), vec.Y(), vec.Z());
}
template <>
inline glm::vec3 convert<glm::vec3>(rp::Vector3 vec) {
return glm::vec3(vec.x, vec.y, vec.z);
}
template <>
inline rp::Vector3 convert<rp::Vector3>(glm::vec3 vec) {
return rp::Vector3(vec.x, vec.y, vec.z);
}
// Quaternion
template <>
inline glm::quat convert<glm::quat>(rp::Quaternion quat) {
return glm::quat(quat.w, quat.x, quat.y, quat.z);
}
template <>
inline rp::Quaternion convert<rp::Quaternion>(glm::quat quat) {
return rp::Quaternion(quat.w, rp::Vector3(quat.x, quat.y, quat.z));
}
// CFrame
template <>
inline rp::Transform convert<rp::Transform>(CFrame frame) {
return rp::Transform(convert<rp::Vector3>(frame.Position()), convert<rp::Quaternion>((glm::quat)frame.RotMatrix()));
}
template <>
inline CFrame convert<CFrame>(rp::Transform trans) {
return CFrame(convert<Vector3>(trans.getPosition()), convert<glm::quat>(trans.getOrientation()));
}
#undef rp

View file

@ -3,9 +3,11 @@
#include "datatypes/vector.h"
#include "objects/joint/jointinstance.h"
#include "objects/part/basepart.h"
#include "physics/convert.h"
#include "physics/util.h"
#include <reactphysics3d/constraint/FixedJoint.h>
#include <reactphysics3d/constraint/HingeJoint.h>
#include <reactphysics3d/body/RigidBody.h>
#include "timeutil.h"
#include <memory>
#include "objects/service/workspace.h"
@ -82,8 +84,8 @@ void PhysWorld::step(float deltaTime) {
// Sync properties
const rp::Transform& transform = part->rigidBody.rigidBody->getTransform();
part->cframe = CFrame(transform);
part->velocity = part->rigidBody.rigidBody->getLinearVelocity();
part->cframe = convert<CFrame>(transform);
part->velocity = convert<Vector3>(part->rigidBody.rigidBody->getLinearVelocity());
// part->rigidBody->enableGravity(true);
// RotateV/Motor joint
@ -93,7 +95,7 @@ void PhysWorld::step(float deltaTime) {
std::shared_ptr<JointInstance> motor = joint.lock()->CastTo<JointInstance>().expect();
float rate = motor->part0.lock()->GetSurfaceParamB(-motor->c0.LookVector().Unit()) * 30;
// part->rigidBody->enableGravity(false);
part->rigidBody.rigidBody->setAngularVelocity(-(motor->part0.lock()->cframe * motor->c0).LookVector() * rate);
part->rigidBody.rigidBody->setAngularVelocity(convert<rp::Vector3>(-(motor->part0.lock()->cframe * motor->c0).LookVector() * rate));
}
}
@ -110,7 +112,7 @@ void PhysWorld::removeBody(std::shared_ptr<BasePart> part) {
}
void PhysWorld::syncBodyProperties(std::shared_ptr<BasePart> part) {
rp::Transform transform = part->cframe;
rp::Transform transform = convert<rp::Transform>(part->cframe);
if (!part->rigidBody.rigidBody) {
part->rigidBody.rigidBody = worldImpl->createRigidBody(transform);
} else {
@ -133,7 +135,7 @@ void PhysWorld::syncBodyProperties(std::shared_ptr<BasePart> part) {
part->rigidBody.rigidBody->updateMassFromColliders();
part->rigidBody.rigidBody->updateLocalInertiaTensorFromColliders();
part->rigidBody.rigidBody->setLinearVelocity(part->velocity);
part->rigidBody.rigidBody->setLinearVelocity(convert<rp::Vector3>(part->velocity));
// part->rigidBody->setMass(density * part->size.x * part->size.y * part->size.z);
part->rigidBody.rigidBody->setUserData(&*part);
@ -143,12 +145,16 @@ void PhysWorld::syncBodyProperties(std::shared_ptr<BasePart> part) {
RaycastResult::RaycastResult(const rp::RaycastInfo& raycastInfo)
: worldPoint(raycastInfo.worldPoint)
, worldNormal(raycastInfo.worldNormal)
, hitFraction(raycastInfo.hitFraction)
: worldPoint(convert<Vector3>(raycastInfo.worldPoint))
, worldNormal(convert<Vector3>(raycastInfo.worldNormal))
// , hitFraction(raycastInfo.hitFraction)
, triangleIndex(raycastInfo.triangleIndex)
, body(raycastInfo.body)
, collider(raycastInfo.collider) {}
, body(dynamic_cast<rp::RigidBody*>(raycastInfo.body))
// , collider(raycastInfo.collider)
{
if (body.rigidBody && body.rigidBody->getUserData() != nullptr)
hitPart = reinterpret_cast<BasePart*>(body.rigidBody->getUserData())->shared<BasePart>();
}
class NearestRayHit : public rp::RaycastCallback {
rp::Vector3 startPos;
@ -191,8 +197,8 @@ public:
std::optional<const RaycastResult> PhysWorld::castRay(Vector3 point, Vector3 rotation, float maxLength, std::optional<RaycastFilter> filter, unsigned short categoryMaskBits) {
// std::scoped_lock lock(globalPhysicsLock);
rp::Ray ray(glmToRp(point), glmToRp(glm::normalize((glm::vec3)rotation)) * maxLength);
NearestRayHit rayHit(glmToRp(point), filter);
rp::Ray ray(convert<rp::Vector3>(point), convert<rp::Vector3>(glm::normalize((glm::vec3)rotation)) * maxLength);
NearestRayHit rayHit(convert<rp::Vector3>(point), filter);
worldImpl->raycast(ray, &rayHit, categoryMaskBits);
return rayHit.getNearestHit();
}
@ -208,15 +214,15 @@ PhysJoint PhysWorld::createJoint(PhysJointInfo& type, std::shared_ptr<BasePart>
) { Logger::fatalError("Failed to create joint between two parts due to the call being invalid"); panic(); };
if (PhysJointGlueInfo* info = dynamic_cast<PhysJointGlueInfo*>(&type)) {
return worldImpl->createJoint(rp::FixedJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, info->anchorPoint));
return worldImpl->createJoint(rp::FixedJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, convert<rp::Vector3>(info->anchorPoint)));
} else if (PhysJointWeldInfo* info = dynamic_cast<PhysJointWeldInfo*>(&type)) {
return worldImpl->createJoint(rp::FixedJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, info->anchorPoint));
return worldImpl->createJoint(rp::FixedJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, convert<rp::Vector3>(info->anchorPoint)));
} else if (PhysJointSnapInfo* info = dynamic_cast<PhysJointSnapInfo*>(&type)) {
return worldImpl->createJoint(rp::FixedJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, info->anchorPoint));
return worldImpl->createJoint(rp::FixedJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, convert<rp::Vector3>(info->anchorPoint)));
} else if (PhysJointHingeInfo* info = dynamic_cast<PhysJointHingeInfo*>(&type)) {
return worldImpl->createJoint(rp::HingeJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, info->anchorPoint, info->rotationAxis));
return worldImpl->createJoint(rp::HingeJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, convert<rp::Vector3>(info->anchorPoint), convert<rp::Vector3>(info->rotationAxis)));
} else if (PhysJointMotorInfo* info = dynamic_cast<PhysJointMotorInfo*>(&type)) {
auto implInfo = rp::HingeJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, info->anchorPoint, info->rotationAxis);
auto implInfo = rp::HingeJointInfo(part0->rigidBody.rigidBody, part1->rigidBody.rigidBody, convert<rp::Vector3>(info->anchorPoint), convert<rp::Vector3>((info->rotationAxis)));
implInfo.isCollisionEnabled = false;
return worldImpl->createJoint(implInfo);
@ -239,7 +245,7 @@ void PhysRigidBody::updateCollider(std::shared_ptr<BasePart> bPart) {
if (part->shape == PartType::Ball) {
physShape = physicsCommon.createSphereShape(glm::min(part->size.X(), part->size.Y(), part->size.Z()) * 0.5f);
} else if (part->shape == PartType::Block) {
physShape = physicsCommon.createBoxShape(glmToRp(part->size * glm::vec3(0.5f)));
physShape = physicsCommon.createBoxShape(convert<rp::Vector3>(part->size * glm::vec3(0.5f)));
}
// Recreate the rigidbody if the shape changes

View file

@ -3,6 +3,7 @@
#include "datatypes/vector.h"
#include "enum/part.h"
#include "reactphysics3d/body/RigidBody.h"
#include "utils.h"
#include <functional>
#include <list>
#include <memory>
@ -10,26 +11,7 @@
namespace rp = reactphysics3d;
struct RaycastResult {
rp::Vector3 worldPoint;
rp::Vector3 worldNormal;
rp::decimal hitFraction;
int triangleIndex;
rp::Body* body;
rp::Collider* collider;
RaycastResult(const rp::RaycastInfo& raycastInfo);
};
enum FilterResult {
TARGET, // The object is captured
BLOCK, // The object blocks any objects behind it, but is not captured
PASS, // The object is transparent, ignore it
};
class BasePart;
typedef std::function<FilterResult(std::shared_ptr<BasePart>)> RaycastFilter;
class PhysWorld;
class PhysicsEventListener : public rp::EventListener {
friend PhysWorld;
@ -57,6 +39,7 @@ public:
inline PhysJoint() {}
};
struct RaycastResult;
class PhysRigidBody {
rp::RigidBody* rigidBody = nullptr;
inline PhysRigidBody(rp::RigidBody* rigidBody) : rigidBody(rigidBody) {}
@ -64,6 +47,7 @@ class PhysRigidBody {
PartType _lastShape;
friend PhysWorld;
friend RaycastResult;
public:
inline PhysRigidBody() {}
@ -72,6 +56,31 @@ public:
void updateCollider(std::shared_ptr<BasePart>);
};
// // Provides internal implementation-specific values from the raycast result
// struct RaycastResultInternal {
// rp::decimal hitFraction;
// rp::Collider* collider;
// };
struct RaycastResult {
Vector3 worldPoint;
Vector3 worldNormal;
int triangleIndex;
PhysRigidBody body;
nullable std::shared_ptr<BasePart> hitPart;
RaycastResult(const rp::RaycastInfo& raycastInfo);
};
enum FilterResult {
TARGET, // The object is captured
BLOCK, // The object blocks any objects behind it, but is not captured
PASS, // The object is transparent, ignore it
};
class BasePart;
typedef std::function<FilterResult(std::shared_ptr<BasePart>)> RaycastFilter;
class PhysWorld : public std::enable_shared_from_this<PhysWorld> {
rp::PhysicsWorld* worldImpl;
PhysicsEventListener physicsEventListener;

View file

@ -148,10 +148,10 @@ void MainGLWidget::handleObjectDrag(QMouseEvent* evt) {
if (!rayHit) return;
CFrame targetFrame = partFromBody(rayHit->body)->cframe;
CFrame targetFrame = rayHit->hitPart->cframe;
Vector3 surfaceNormal = targetFrame.Inverse().Rotation() * rayHit->worldNormal;
Vector3 inverseSurfaceNormal = Vector3::ONE - surfaceNormal.Abs();
glm::vec3 partSize = partFromBody(rayHit->body)->size;
glm::vec3 partSize = rayHit->hitPart->size;
Vector3 tFormedHitPos = targetFrame * ((targetFrame.Inverse() * initialHitPos) * inverseSurfaceNormal);
Vector3 tFormedInitialPos = targetFrame * ((targetFrame.Inverse() * initialFrame.Position()) * inverseSurfaceNormal);
Vector3 vec = rayHit->worldPoint + (tFormedInitialPos - tFormedHitPos);
@ -338,7 +338,7 @@ void MainGLWidget::handleCursorChange(QMouseEvent* evt) {
};
std::optional<const RaycastResult> rayHit = gWorkspace()->CastRayNearest(camera.cameraPos, pointDir, 50000);
if (rayHit && !partFromBody(rayHit->body)->locked) {
if (rayHit && !rayHit->hitPart->locked) {
setCursor(Qt::OpenHandCursor);
return;
}
@ -404,8 +404,8 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
// raycast part
std::shared_ptr<Selection> selection = gDataModel->GetService<Selection>();
std::optional<const RaycastResult> rayHit = gWorkspace()->CastRayNearest(camera.cameraPos, pointDir, 50000);
if (!rayHit || !partFromBody(rayHit->body)) { selection->Set({}); return; }
std::shared_ptr<BasePart> part = partFromBody(rayHit->body);
if (!rayHit || !rayHit->hitPart) { selection->Set({}); return; }
std::shared_ptr<BasePart> part = rayHit->hitPart;
if (part->locked) { selection->Set({}); return; }
std::shared_ptr<PVInstance> selObject = part;