#ifndef RIGIDBODYCOMPONENT_H
#define RIGIDBODYCOMPONENT_H

#include "engine/physics/bullet_private.h"
#include "engine/physics/physicsworld.h"

class PhysicsManager;
class PhysicsWorld;
class ShapeComponent;


//! Rigid body
class RigidBody
{
public:
	RigidBody();
	~RigidBody();

	void UpdateEntityTranslationDirty();
	void UpdateBodyTranslationDirty();

	// Setter's and getter's
	const float GetMass() { return m_mass; }
	void SetMass(float value) { m_mass = value; }

	const bool IsStatic() { return m_static; }

	btRigidBody* GetSDKBody() { return m_rigidBody; }
	btCompoundShape* GetCompoundShape() { return m_compoundShape; }
	PhysicsWorld* GetPhysicsWorld() { return m_physicsWorld; }

	//void getWorldTransform(btTransform& worldTrans) const override;
	//void setWorldTransform(const btTransform& worldTrans) override;

	void DisableBodyOrientUpdate();

	void DisableBody();

	void DisableCollide();
	void EnableCollide();

	void AttachShape(ShapeComponent* shape);
	void DettachShape(ShapeComponent* shape);

	void ApplyImpulse(const glm::vec3& impulse);

	void SetLinearVelocity(const glm::vec3& velocity);
	glm::vec3 GetLinearVelocity();

private:
	void CreateBody();
	void DestroyBody();
	void UpdateBodyProperties();

private:
	btRigidBody* m_rigidBody;
	btCompoundShape* m_compoundShape;

	PhysicsWorld* m_physicsWorld;

	// Body mass
	float m_mass;
	bool m_isEnable;
	bool m_static;
	bool m_isKinematic;
	bool m_isTrigger;
	bool m_inWorld;

	// engine properties
	bool m_disableBodyOrientUpdate;
};


#endif // !RIGIDBODYCOMPONENT_H
