Fixed some bugs with serialisation

This commit is contained in:
Diren D Bharwani 2023-02-03 18:40:45 +08:00
parent c73275f2d3
commit 36de32447d
10 changed files with 35 additions and 56 deletions

View File

@ -1,16 +1,2 @@
0 1 3
1 2 65535
2 3 65534
3 4 65534
4 5 65534
5 6 65534
6 7 65534
7 8 65534
8 9 65534
9 10 65534
10 11 65534
11 12 65534
12 13 65534
13 14 65534
14 15 65534
15 16 65534
0 1 65535
1 2 65415

View File

@ -135,20 +135,20 @@ Collapsed=0
Column 0 Weight=0.9945
Column 1 Weight=0.9945
Column 2 Weight=0.9945
Column 3 Weight=0.9945
Column 4 Weight=0.9945
Column 3 Weight=1.0320
Column 4 Weight=0.9570
Column 5 Weight=0.9945
Column 6 Weight=0.9945
Column 7 Weight=0.9945
Column 8 Weight=0.9945
Column 9 Weight=0.9945
Column 10 Weight=0.9945
Column 11 Weight=0.9945
Column 12 Weight=1.0132
Column 9 Weight=1.0320
Column 10 Weight=0.9570
Column 11 Weight=1.0133
Column 12 Weight=0.9945
Column 13 Weight=0.8444
Column 14 Weight=0.9945
Column 15 Weight=1.2009
Column 16 Weight=1.0132
Column 16 Weight=1.0133
[Docking][Data]
DockSpace ID=0xC5C9B8AB Window=0xBE4044E9 Pos=0,71 Size=1920,941 Split=X

View File

@ -13,7 +13,7 @@
Drag: 0.00999999978
Angular Drag: 0.100000001
Use Gravity: false
Interpolate: true
Interpolate: false
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: false
@ -25,7 +25,7 @@
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Collision Tag: 2
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
@ -52,7 +52,7 @@
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Collision Tag: 5
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006
@ -161,7 +161,7 @@
Collider Component:
Colliders:
- Is Trigger: false
Collision Tag: 1
Collision Tag: 7
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Friction: 0.400000006

View File

@ -82,7 +82,7 @@ public class PhysicsTestObj : Script
{
Ray colliderRay = new Ray();
colliderRay.Direction = Vector3.Right;
Physics.ColliderRaycast(collider.Owner, colliderRay, false, 8);
Physics.ColliderRaycast(collider.Owner, colliderRay, false, (ushort)64);
for (int i = 0; i < 6; ++i)
{

View File

@ -5,6 +5,7 @@
//#define SHEDITOR
#ifdef SHEDITOR
#include "Editor/SHEditor.h"
#include "Physics/System/SHPhysicsDebugDrawSystem.h"
//#include "Scenes/SBEditorScene.h"
#endif // SHEDITOR
@ -31,7 +32,6 @@
#include "Input/SHInputManager.h"
#include "Math/Transform/SHTransformSystem.h"
#include "Physics/System/SHPhysicsSystem.h"
#include "Physics/System/SHPhysicsDebugDrawSystem.h"
#include "Scripting/SHScriptEngine.h"
#include "UI/SHUISystem.h"
#include "Animation/SHAnimationSystem.h"

View File

@ -144,7 +144,13 @@ namespace SHADE
material.SetDensity(density);
if (rp3dCollider)
{
rp3dCollider->getMaterial().setMassDensity(material.GetDensity());
// Recompute the bodies' mass
dynamic_cast<rp3d::RigidBody*>(collider->collisionBody)->updateMassPropertiesFromColliders();
}
}
void SHCollisionShape::SetMaterial(const SHPhysicsMaterial& newMaterial) noexcept
@ -157,6 +163,9 @@ namespace SHADE
rp3dMaterial.setFrictionCoefficient(material.GetFriction());
rp3dMaterial.setBounciness(material.GetBounciness());
rp3dMaterial.setMassDensity(material.GetDensity());
// Recompute the bodies' mass
dynamic_cast<rp3d::RigidBody*>(collider->collisionBody)->updateMassPropertiesFromColliders();
}
}
@ -180,7 +189,13 @@ namespace SHADE
isTrigger ? flags |= FLAG_VALUE : flags &= ~FLAG_VALUE;
if (rp3dCollider)
{
rp3dCollider->setIsTrigger(isTrigger);
// Recompute the bodies' mass
dynamic_cast<rp3d::RigidBody*>(collider->collisionBody)->updateMassPropertiesFromColliders();
}
}
/*-----------------------------------------------------------------------------------*/

View File

@ -210,9 +210,6 @@ namespace SHADE
{
.entityID = rigidBody->GetEID()
, .bodyType = rigidBody->type
, .interpolate = rigidBody->interpolate
, .drag = rigidBody->drag
, .angularDrag = rigidBody->angularDrag
};
rigidBodyQueue.push(RIGID_BODY_DEF);
@ -232,22 +229,8 @@ namespace SHADE
SHColliderDef::ShapeDef shapeDef
{
.type = shape->GetType()
, .posOffset = shape->GetPositionOffset()
, .rotOffset = shape->GetRotationOffset()
};
switch (shape->GetType())
{
case SHCollisionShape::Type::SPHERE:
shapeDef.size.x = dynamic_cast<const SHSphere*>(shape)->GetWorldRadius();
break;
case SHCollisionShape::Type::BOX:
shapeDef.size = dynamic_cast<const SHBox*>(shape)->GetWorldExtents();
break;
default:
break;
}
colliderDef.shapes.emplace_back(shapeDef);
}
@ -311,9 +294,9 @@ namespace SHADE
rigidBodyComponent->SetFreezeRotationY (rigidBodyComponent->GetFreezeRotationY());
rigidBodyComponent->SetFreezeRotationZ (rigidBodyComponent->GetFreezeRotationZ());
rigidBodyComponent->SetInterpolate (DEF.interpolate);
rigidBodyComponent->SetDrag (DEF.drag);
rigidBodyComponent->SetAngularDrag (DEF.angularDrag);
rigidBodyComponent->SetInterpolate (rigidBodyComponent->IsInterpolating());
rigidBodyComponent->SetDrag (rigidBodyComponent->GetDrag());
rigidBodyComponent->SetAngularDrag (rigidBodyComponent->GetAngularDrag());
rigidBodyQueue.pop();
}

View File

@ -47,9 +47,6 @@ namespace SHADE
{
EntityID entityID = MAX_EID;
SHRigidBodyComponent::Type bodyType = SHRigidBodyComponent::Type::STATIC;
bool interpolate = true;
float drag = 0.0f;
float angularDrag = 0.0f;
};
struct SHColliderDef
@ -57,9 +54,6 @@ namespace SHADE
struct ShapeDef
{
SHCollisionShape::Type type = SHCollisionShape::Type::SPHERE;
SHVec3 posOffset = SHVec3::Zero;
SHVec3 rotOffset = SHVec3::Zero;
SHVec3 size = SHVec3::Zero; // x for sphere radius, all 3 for box extents
};
EntityID entityID = MAX_EID;

View File

@ -42,6 +42,7 @@ namespace SHADE
/* Friends */
/*---------------------------------------------------------------------------------*/
friend class SHCollisionShape;
friend class SHPhysicsSystem;
friend class SHPhysicsObjectManager;

View File

@ -155,7 +155,7 @@ namespace SHADE
// Load start and end points into the container for debug drawing
#ifdef SHEDITOR
SHVec3 endPos = info.ray.position + info.ray.direction * SHRay::MAX_RAYCAST_DIST;
SHVec3 endPos = info.ray.position + info.ray.direction * std::clamp(info.distance, 0.0f, SHRay::MAX_RAYCAST_DIST);
if (!results.empty())
endPos = results.back().position;