Example #1
0
MtMatrix3 MtMatrix3::GetTranspose() const
{
    return MtMatrix3( _00,_10,_20,
                      _01,_11,_21,
                      _02,_12,_22
                    );
}
Example #2
0
MtMatrix3 operator*(MtMatrix3 &m, BtFloat s)
{
    return MtMatrix3(	m._00*s,
                        m._01*s,
                        m._02*s,
                        m._10*s,
                        m._11*s,
                        m._12*s,
                        m._20*s,
                        m._21*s,
                        m._22*s);
}
Example #3
0
MtMatrix3 operator/(MtMatrix3 &m, BtFloat s)
{
    return	MtMatrix3(	m._00/s,
                        m._01/s,
                        m._02/s,
                        m._10/s,
                        m._11/s,
                        m._12/s,
                        m._20/s,
                        m._21/s,
                        m._22/s);
}
Example #4
0
MtMatrix3 operator-(MtMatrix3 &m1, MtMatrix3 &m2)
{
    return MtMatrix3(	m1._00-m2._00,
                        m1._01-m2._01,
                        m1._02-m2._02,
                        m1._10-m2._10,
                        m1._11-m2._11,
                        m1._12-m2._12,
                        m1._20-m2._20,
                        m1._21-m2._21,
                        m1._22-m2._22);
}
Example #5
0
MtMatrix3 operator+(MtMatrix3 &m1, MtMatrix3 &m2)
{
    return MtMatrix3(	m1._00+m2._00,
                        m1._01+m2._01,
                        m1._02+m2._02,
                        m1._10+m2._10,
                        m1._11+m2._11,
                        m1._12+m2._12,
                        m1._20+m2._20,
                        m1._21+m2._21,
                        m1._22+m2._22);
}
Example #6
0
MtMatrix3 MtMatrix3::operator * ( const MtMatrix3& m2) const
{
    return MtMatrix3(	_00*m2._00 + _01*m2._10 + _02*m2._20 ,
                        _00*m2._01 + _01*m2._11 + _02*m2._21 ,
                        _00*m2._02 + _01*m2._12 + _02*m2._22 ,

                        _10*m2._00 + _11*m2._10 + _12*m2._20 ,
                        _10*m2._01 + _11*m2._11 + _12*m2._21 ,
                        _10*m2._02 + _11*m2._12 + _12*m2._22 ,

                        _20*m2._00 + _21*m2._10 + _22*m2._20 ,
                        _20*m2._01 + _21*m2._11 + _22*m2._21 ,
                        _20*m2._02 + _21*m2._12 + _22*m2._22 );
}
Example #7
0
MtMatrix3 MtMatrix3::GetInverse() const
{
    BtFloat d = _00*_11*_22 -
                _00*_21*_12 +
                _10*_21*_02 -
                _10*_01*_22 +
                _20*_01*_12 -
                _20*_11*_02;

    if (d == 0) d = 1;

    return MtMatrix3(	(_11*_22-_12*_21)/d,
                        -(_01*_22-_02*_21)/d,
                        (_01*_12-_02*_11)/d,
                        -(_10*_22-_12*_20)/d,
                        (_00*_22-_02*_20)/d,
                        -(_00*_12-_02*_10)/d,
                        (_10*_21-_11*_20)/d,
                        -(_00*_21-_01*_20)/d,
                        (_00*_11-_01*_10)/d );
}
Example #8
0
// Public functions ///////////////////////////////////////////////////////////
MtMatrix3 Quaternion2Matrix(MtQuaternion &q)
{
    return MtMatrix3(q);
}
Example #9
0
void pgCamera::Update()
{
	if (ApConfig::IsWin())
	{
		static BtBool isLoaded = BtFalse;
		if (isLoaded == BtFalse)
		{
			// If we have a previously saved version of the camera then load
			FsFile file;
			BtChar filename[64];
			sprintf(filename, "%s%s", ApConfig::GetDocuments(), "camera.txt");
			file.Open(filename, FsMode_Read);
			if (file.IsOpen())
			{
				file.Read(m_cameraData);
				file.Close();
			}
			isLoaded = BtTrue;
		}
	}

	if (UiKeyboard::pInstance()->IsPressed(UiKeyCode_F3))
	{
		m_isFlyCam = !m_isFlyCam;
	}


	for (BtU32 i = 1; i < MaxTouches; i += 2)
	{
		if (ShTouch::IsHeld(i) || m_isFlyCam)
		{
			BtFloat speed = BtTime::GetTick() * 10.0f;

			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LSHIFT))
			{
				speed = speed * 10.0f;
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_W))
			{
				MoveForward(speed);
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_S))
			{
				MoveBackward(speed);
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_D))
			{
				MoveRight(speed);
			}
			if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_A))
			{
				MoveLeft(speed);
			}
		}
	}


	if (ShTouch::IsHeld(1))
	{
        BtBool onScreen = BtTrue;//ShTouch::OnScreen(1);
		if (onScreen)
		{
			for (BtU32 i = 0; i < MaxTouches; i += 2)
			{
				// Rotate the camera
				MtVector2 v2MouseDirection = ShTouch::GetMovement(i);
				BtFloat speed = BtTime::GetTick() * 0.1f;
				MtMatrix3 m3Rotate;
				m3Rotate.SetRotationY(v2MouseDirection.x * -speed);
				m_cameraData.m_m3Rotation = m3Rotate * m_cameraData.m_m3Rotation;
				m3Rotate.SetRotationX(v2MouseDirection.y * speed);
				m_cameraData.m_m3Rotation = m_cameraData.m_m3Rotation * m3Rotate;
			}
		}
	}

	static BtBool isCursorKeys = BtFalse;

	// Rotate the camera
	BtFloat speed = BtTime::GetTick();

	if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LSHIFT))
	{
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_LEFT))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_yaw += speed;
		}
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_RIGHT))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_yaw -= speed;
		}
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_UP))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_pitch -= speed;
		}
		if (UiKeyboard::pInstance()->IsHeld(UiKeyCode_DOWN))
		{
			isCursorKeys = BtTrue;
			m_cameraData.m_pitch += speed;
		}
	}

	if (!ApConfig::IsWin())
	{
		// Support a landscape quaternion
		MtMatrix3 m_m3Rotation;
		MtQuaternion quaternion = ShIMU::GetQuaternion(0);
		quaternion.x = quaternion.x;
		quaternion.y = quaternion.y;
		quaternion.z = -quaternion.z;

		m_m3Rotation = MtMatrix3(quaternion);
		//m_m3Rotation = m_m3Rotation.GetInverse();

		MtMatrix3 m3RotateY;
		m3RotateY.SetRotationY(MtDegreesToRadians(90.0f));

		MtMatrix3 m3RotateZ;
		m3RotateZ.SetRotationZ(MtDegreesToRadians(-90.0f));

		m_m3Rotation = m3RotateY * m_m3Rotation;
		m_m3Rotation = m3RotateZ * m_m3Rotation;
		m_m3Rotation = m_m3Rotation * m3RotateZ;

		m_camera.SetRotation(m_m3Rotation);

	}
	else if (ShHMD::IsHMD())
	{
		MtMatrix3 m3RotateY;
		m3RotateY.SetRotationX(m_cameraData.m_pitch);
		MtMatrix3 m3RotateX;
		m3RotateX.SetRotationY(m_cameraData.m_yaw);
		m_cameraData.m_m3Rotation = m3RotateX * m3RotateY;

		// Cache the ShHMD rotation
		MtQuaternion quaternion = ShHMD::GetQuaternion();

		// Set the IMU rotation
		MtMatrix4 m4FinalRotation = m_cameraData.m_m3Rotation * MtMatrix3(quaternion);

		// Set the rotation
		m_camera.SetRotation(m4FinalRotation);
	}
	else
	{
		if (isCursorKeys)
		{
			MtMatrix3 m3RotateY;
			m3RotateY.SetRotationX(m_cameraData.m_pitch);
			MtMatrix3 m3RotateX;
			m3RotateX.SetRotationY(m_cameraData.m_yaw);
			m_cameraData.m_m3Rotation = m3RotateX * m3RotateY;
		}

		// Set the rotation
		m_camera.SetRotation(m_cameraData.m_m3Rotation);
	}

	// Set the position
	m_camera.SetPosition(m_cameraData.m_v3Position);

	// Update the camera
	m_camera.Update();

	if (UiKeyboard::pInstance()->IsPressed(SaveCameraKey))
	{
		FsFile file;
		BtChar filename[64];
		sprintf(filename, "%s%s", ApConfig::GetDocuments(), "camera.txt");
		file.Open(filename, FsMode_Write);
		if (file.IsOpen())
		{
			file.Write(m_cameraData);
			file.Close();
		}
	}
}