|
|
@@ -1,7 +1,7 @@
|
|
|
#include "anki/physics/RigidBody.h"
|
|
|
#include "anki/physics/PhysicsWorld.h"
|
|
|
#include "anki/scene/SceneGraph.h"
|
|
|
-#include "anki/physics/MotionState.h"
|
|
|
+#include "anki/scene/MoveComponent.h"
|
|
|
|
|
|
namespace anki {
|
|
|
|
|
|
@@ -26,7 +26,7 @@ RigidBody::RigidBody(PhysicsWorld* world, const Initializer& init)
|
|
|
localInertia = btVector3(0.0, 0.0, 0.0);
|
|
|
}
|
|
|
|
|
|
- motionState = MotionState(init.startTrf, init.movable);
|
|
|
+ motionState = MotionState(toBt(init.startTrf));
|
|
|
|
|
|
btRigidBody::btRigidBodyConstructionInfo cInfo(
|
|
|
init.mass, &motionState, init.shape, localInertia);
|
|
|
@@ -36,6 +36,11 @@ RigidBody::RigidBody(PhysicsWorld* world, const Initializer& init)
|
|
|
setContactProcessingThreshold(
|
|
|
getPhysicsWorld().defaultContactProcessingThreshold);
|
|
|
|
|
|
+ if(init.kinematic)
|
|
|
+ {
|
|
|
+ // XXX
|
|
|
+ }
|
|
|
+
|
|
|
//forceActivationState(ISLAND_SLEEPING);
|
|
|
|
|
|
// register
|
|
|
@@ -56,4 +61,50 @@ RigidBody::~RigidBody()
|
|
|
getPhysicsWorld().dynamicsWorld->removeRigidBody(this);
|
|
|
}
|
|
|
|
|
|
+//==============================================================================
|
|
|
+void RigidBody::syncUpdate(SceneNode& node, F32 prevTime, F32 crntTime)
|
|
|
+{
|
|
|
+ MoveComponent* move = node.getMoveComponent();
|
|
|
+ if(ANKI_UNLIKELY(move == nullptr))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Bool updated = move->bitsEnabled(MoveComponent::MF_MARKED_FOR_UPDATE);
|
|
|
+ Transform oldTrf = move->getLocalTransform();
|
|
|
+
|
|
|
+ // Sync from motion state to move component
|
|
|
+ if(motionState.getUpdated())
|
|
|
+ {
|
|
|
+ // Set local transform and preserve scale
|
|
|
+ Transform newTrf;
|
|
|
+ F32 originalScale = move->getLocalTransform().getScale();
|
|
|
+ newTrf = toAnki(motionState.getWorldTransform2());
|
|
|
+ newTrf.setScale(originalScale);
|
|
|
+ std::cout << newTrf.getOrigin().toString() << std::endl;
|
|
|
+ move->setLocalTransform(newTrf);
|
|
|
+
|
|
|
+ // Set the flag
|
|
|
+ motionState.setUpdated(false);
|
|
|
+
|
|
|
+ std::cout << "From motion state to move component" << std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Sync from move component to motion state
|
|
|
+ if(updated)
|
|
|
+ {
|
|
|
+ std::cout << "Activating again " << oldTrf.getOrigin().toString() << std::endl;
|
|
|
+
|
|
|
+ setWorldTransform(toBt(oldTrf));
|
|
|
+ //motionState.setWorldTransform(toBt(oldTrf));
|
|
|
+ //forceActivationState(ACTIVE_TAG);
|
|
|
+ activate();
|
|
|
+ //clearForces();
|
|
|
+ //setLinearVelocity(btVector3(0.0, 0.0, 0.0));
|
|
|
+ //setAngularVelocity(btVector3(0.0, 0.0, 0.0));
|
|
|
+
|
|
|
+ //setGravity(getPhysicsWorld().dynamicsWorld->getGravity());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
} // end namespace anki
|