[Change] Some further work on new dynamics.

[Fix] Load/Save works again.
[Meh] Collision test ok, but no response.
This commit is contained in:
Rtch90 2018-04-08 17:18:07 +01:00
parent 88f4b7e6a7
commit 7c8204f02d
4 changed files with 31 additions and 14 deletions

View File

@ -43,18 +43,31 @@ void DynamicBody::AddRelTorque(const vector3d t) {
} }
void DynamicBody::Save(void) { void DynamicBody::Save(void) {
assert(0); /* Add new dynamics stuff. */
using namespace Serializer::Write; using namespace Serializer::Write;
ModelBody::Save(); ModelBody::Save();
wr_vector3d(GetAngVelocity()); for(int i = 0; i < 16; i++) wr_double(m_orient[i]);
wr_vector3d(GetVelocity()); wr_vector3d(m_force);
wr_vector3d(m_torque);
wr_vector3d(m_vel);
wr_vector3d(m_angVel);
wr_double(m_mass);
wr_double(m_massRadius);
wr_double(m_angInertia);
wr_bool(m_enabled);
} }
void DynamicBody::Load(void) { void DynamicBody::Load(void) {
using namespace Serializer::Read; using namespace Serializer::Read;
ModelBody::Load(); ModelBody::Load();
SetAngVelocity(rd_vector3d()); for(int i = 0; i < 16; i++) m_orient[i] = rd_double();
SetVelocity(rd_vector3d()); m_force = rd_vector3d();
m_torque = rd_vector3d();
m_vel = rd_vector3d();
m_angVel = rd_vector3d();
m_mass = rd_double();
m_massRadius = rd_double();
m_angInertia = rd_double();
m_enabled = rd_bool();
} }
void DynamicBody::SetTorque(const vector3d t) { void DynamicBody::SetTorque(const vector3d t) {
@ -84,7 +97,7 @@ void DynamicBody::TimeStepUpdate(const float timeStep) {
m_vel += timeStep * m_force * (1.0/m_mass); m_vel += timeStep * m_force * (1.0/m_mass);
m_angVel += timeStep * m_torque * (1.0 / m_angInertia); m_angVel += timeStep * m_torque * (1.0 / m_angInertia);
const vector3d pos = GetPosition(); vector3d pos = GetPosition();
/* Applying angular velocity :/ */ /* Applying angular velocity :/ */
{ {
double len = m_angVel.Length(); double len = m_angVel.Length();
@ -96,22 +109,25 @@ void DynamicBody::TimeStepUpdate(const float timeStep) {
} }
} }
SetPosition(pos + m_vel * timeStep); pos += m_vel * timeStep;
m_orient[12] = pos.x;
m_orient[13] = pos.y;
m_orient[14] = pos.z;
TriMeshUpdateLastPos(m_orient);
m_force = vector3d(0.0); m_force = vector3d(0.0);
m_torque = vector3d(0.0); m_torque = vector3d(0.0);
TriMeshUpdateLastPos(m_orient);
} }
} }
void DynamicBody::Enable(void) { void DynamicBody::Enable(void) {
ModelBody::Enable(); ModelBody::Enable();
//dBodyEnable(m_body); m_enabled = true;
} }
void DynamicBody::Disable(void) { void DynamicBody::Disable(void) {
ModelBody::Disable(); ModelBody::Disable();
//dBodyDisable(m_body); m_enabled = false;
} }
void DynamicBody::SetRotMatrix(const matrix4x4d& r) { void DynamicBody::SetRotMatrix(const matrix4x4d& r) {

View File

@ -98,7 +98,7 @@ void ModelBody::SetFrame(Frame* f) {
} }
} }
void ModelBody::TriMeshUpdateLastPos(matrix4x4d currentTransform) { void ModelBody::TriMeshUpdateLastPos(const matrix4x4d& currentTransform) {
m_geom->MoveTo(currentTransform); m_geom->MoveTo(currentTransform);
} }

View File

@ -26,7 +26,7 @@ public:
virtual void Enable(void); virtual void Enable(void);
void GetAabb(Aabb& aabb); void GetAabb(Aabb& aabb);
void TriMeshUpdateLastPos(matrix4x4d currentTransform); void TriMeshUpdateLastPos(const matrix4x4d& currentTransform);
void SetModel(int sbreModel); void SetModel(int sbreModel);
void RenderSbreModel(const Frame* camFrame, int model, ObjParams* params); void RenderSbreModel(const Frame* camFrame, int model, ObjParams* params);

View File

@ -333,10 +333,11 @@ static bool _OnCollision2(Object* o1, Object* o2, CollisionContact* c) {
} }
#define MAX_CONTACTS 1 #define MAX_CONTACTS 1
/* XXX SO REESTED!! 1 CONTACT PER PHYSICS TICK?! WTH?! */
static int contact_num; static int contact_num;
static void hitCallback(CollisionContact* c) { static void hitCallback(CollisionContact* c) {
if(contact_num++ >= MAX_CONTACTS) return; if(contact_num++ >= MAX_CONTACTS) return;
printf("AUCH!! %x\n", SDL_GetTicks()); printf("AUCH!! %x (depth %f)\n", SDL_GetTicks(), c->depth);
#if 0 #if 0
dContact contact; dContact contact;