text: #include "PhysBody3D.h"
  #include "Bullet\include\btBulletDynamicsCommon.h"
  
  // =================================================
  PhysBody3D::PhysBody3D(btRigidBody* body) : body(body)
  {
  	body->setUserPointer(this);
  }
  
  // ---------------------------------------------------------
  PhysBody3D::~PhysBody3D()
  {
  	delete body;
  }
  
  // ---------------------------------------------------------
  void PhysBody3D::Push(float x, float y, float z)
  {
  	body->applyCentralImpulse(btVector3(x, y, z));
  }
  
  // ---------------------------------------------------------
  void PhysBody3D::GetTransform(float* matrix) const
  {
  	if(body != nullptr && matrix != NULL)
  	{
  		body->getWorldTransform().getOpenGLMatrix(matrix);
  	}
  }
  
  // ---------------------------------------------------------
  void PhysBody3D::SetTransform(const float* matrix) const
  {
  	if(body != nullptr && matrix != NULL)
  	{
  		btTransform t;
  		t.setFromOpenGLMatrix(matrix);
  		body->setWorldTransform(t);
  	}
  }
  
  // ---------------------------------------------------------
  void PhysBody3D::SetPos(float x, float y, float z)
  {
  	btTransform t = body->getWorldTransform();
  	t.setOrigin(btVector3(x, y, z));
  	body->setWorldTransform(t);
  }
  
  void PhysBody3D::GetPos(float* x, float* y, float* z)
  {
  	btTransform t = body->getWorldTransform();
  	btVector3 pos = t.getOrigin();
  	btVector3FloatData posFloat;
  	pos.serializeFloat(posFloat);
  	*x = posFloat.m_floats[0];
  	*y = posFloat.m_floats[1];
  	*z = posFloat.m_floats[2];
  }
  
  // ---------------------------------------------------------
  void PhysBody3D::SetAsSensor(bool is_sensor)
  {
  	if(this->is_sensor != is_sensor)
  	{
  		this->is_sensor = is_sensor;
  		if(is_sensor == true)
  			body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
  		else
  			body->setCollisionFlags(body->getCollisionFlags() &~ btCollisionObject::CF_NO_CONTACT_RESPONSE);
  	}
  }
  
  // ---------------------------------------------------------
  bool PhysBody3D::IsSensor() const
  {
  	return is_sensor;
  }
  
  bool PhysBody3D::isResting()
  {
  	return !body->isActive();
  }
  
  void PhysBody3D::SetInactive()
  {
  	body->setActivationState(WANTS_DEACTIVATION);
  }