void CStructure::SetPhysicsTransform(const Matrix4x4& m)
{
	CPlanet* pPlanet = GameData().GetPlanet();
	if (!pPlanet)
	{
		SetLocalTransform(TMatrix(m));
		return;
	}

	if (!pPlanet->GetChunkManager()->HasGroupCenter())
	{
		SetLocalTransform(TMatrix(m));
		return;
	}

	GameData().SetGroupTransform(m);

	TMatrix mLocalTransform(pPlanet->GetChunkManager()->GetGroupCenterToPlanetTransform() * m);

	CBaseEntity* pMoveParent = GetMoveParent();
	TAssert(pMoveParent);
	if (pMoveParent)
	{
		while (pMoveParent != pPlanet)
		{
			mLocalTransform = pMoveParent->GetLocalTransform().InvertedRT() * mLocalTransform;
			pMoveParent = pMoveParent->GetMoveParent();
		}
	}

	SetLocalTransform(mLocalTransform);
}
void SceneNode::RestoreOriginalTransforms()
{
    SetLocalTransform(GetDefaultLocalTransform());
	
	uint32 size = (uint32)childs.size();
	for (uint32 c = 0; c < size; ++c)
		childs[c]->RestoreOriginalTransforms();
}
TrackedSceneObject::TrackedSceneObject()
{
    m_hardwareModule = 0;
    m_transform = vtkTransform::New();
    m_calibrationTransform = vtkTransform::New();
    vtkTransform * localTransform = vtkTransform::New();
    localTransform->Concatenate( m_transform );
    localTransform->Concatenate( m_calibrationTransform );
    SetLocalTransform( localTransform );
    localTransform->Delete();

    m_uncalibratedWorldTransform = vtkTransform::New();
    m_uncalibratedWorldTransform->Concatenate( m_transform );
}
ArbitraryAI::ArbitraryAI(const std::string& name, Camera* cameraInstance, const int& radius) : SimpleMeshObject(name) {

	camera = cameraInstance; //i kept in the camera pointer as i imagine most of our AI's will use camera position eventually 

	//Next lines create the physical and graphical representation of the object you want your AI to be (just like for any other GameObject

	SetMesh(AssetsManager::Sphere(), false);
	SetLocalTransform(Matrix4::Scale(Vector3(0.3f, 0.3f, 0.3f)));
	SetColour(Vector4(1.0f, 0.0f, 0.0f, 1.0f));
	SetBoundingRadius(1.0f);
	Physics()->SetInverseMass(1.0f);
	Physics()->SetForce(Vector3(0.0f, 9.81f, 0.0f));
	Physics()->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
	Physics()->SetCollisionShape(new SphereCollisionShape(0.3f));
	Physics()->SetInverseInertia(Physics()->GetCollisionShape()->BuildInverseInertia(1.0f));

	//1 == home state, 2 == guard state

	currentState = new OffState(); //sets the initial current state for the first frame (actually instantiates the state when the state is changed, so you dont have inactive states instantiated and sitting in memory doing nothing, ie rather than creating all states at startup and just changing the pointed, create and delkete states as they are used
}