#ifndef CPHYSICS_CUSTOM_H
#define CPHYSICS_CUSTOM_H

#include "PhysicsGlobal.h"
#include "SPhysicsStructs.h"
#include "IPhysicsJoint.h"

class IPhysicsCustom : public IPhysicsJoint
{
public:
	IPhysicsCustom();
	~IPhysicsCustom();

	void init(NewtonWorld* world, SPhysicsCustomJoint* jnt);
	void addLinearRow(vector3df pivot1, vector3df pivot2, vector3df direction);
	void addAngularRow(f32 relativeAngleError, vector3df pin);
	void addGeneralRow(vector3df linear1, vector3df angular1, vector3df linear2, vector3df angular2);
	void setRowMinFriction(f32 friction);
	void setRowMaxFriction(f32 friction);
	void setRowAcceleration(f32 acceleration);
	void setRowStiffness(f32 stiffness);
	void setRowSpringDamperAcceleration(f32 springStiffness, f32 springDamper);
	f32 getRowForce(int row);

	void pinAndDirToLocal( const vector3df& pinpt, const vector3df& pindir, 
								   vector3df& localOrient0, vector3df& localPos0 ,vector3df& localOrient1, vector3df& localPos1 );

	matrix4 grammSchmidt( const vector3df& pin );

	virtual void submitConstraint() = 0;

private:
	static void _cdecl customJointCallback(const NewtonJoint* userJoint);
	
	IPhysicsBaseEntity* m_child;
	IPhysicsBaseEntity* m_parent;
};

#endif