Esempio n. 1
0
	/** TODO: avoid recalculating when nothing changed */
	Matrix44 Entity2D::GetCenterTransformationMatrix()
	{
		Matrix44 matrix = Matrix44::Identity;
		matrix.Scale(Vector3::Create(m_vScale.X, m_vScale.Y, 1.0f));
		matrix.Rotate(Vector3::Create(0.0f, 0.0f, m_fRotation*Math::DegToRadFactor));		
		matrix.Translate(Vector3::Create(m_vPosition.X, m_vPosition.Y, 0.0f));

		// TODO: use type checking at initialization time in AddChild() and only use static_cast here		
		if(Entity2D* pEntity2D = GetAncestor<Entity2D>())
		{
			matrix *= pEntity2D->GetTransformationMatrix();
		}
		
		return matrix;
	}
Esempio n. 2
0
	//! returns true if the button is touched
	bool Button::IsTouched() const
	{
		Matrix44 transformation = Matrix44::Identity;
		transformation.Translate(-Vector3::Create(m_vCenter.X, m_vCenter.Y, 0.0f));
		transformation.Scale(Vector3::Create(m_vScale.X, m_vScale.Y, 1.0f));
		transformation.Rotate(Vector3::Create(0.0f, 0.0f, m_fRotation*Math::DegToRadFactor));		
		transformation.Translate(Vector3::Create(m_vOriginalPosition.X, m_vOriginalPosition.Y, 0.0f));
		if(Entity2D* p2DEntity = GetAncestor<Entity2D>())
		{
			transformation *= p2DEntity->GetTransformationMatrix();
		}

		Matrix44 inverse;
		if(transformation.GetInverse(inverse))
		{
			Vector2 vTouchPos = InputManager::Instance()->GetTouchState().vPosition;
			Vector3 invTouchPos3D = inverse.TransformVect(Vector3::Create(vTouchPos.X, vTouchPos.Y, 0.0f));
			Vector2 vInvTouchPos(invTouchPos3D.X, invTouchPos3D.Y);
			return GetBoundingBox().Contains(vInvTouchPos);
		}

		return false;
	}