コード例 #1
0
void SbWaxGraph::Update()
{
    MtMatrix4 m4Transform = MtMatrix4( ExWAX9::GetTransform() );

    if( UiKeyboard::pInstance()->IsHeld( UiKeyCode_Z ) )
    {
        MtMatrix4 m4Temp;
        m4Temp.SetRotationY( MtDegreesToRadians( 1.0f ) );
        m4Rotate = m4Temp * m4Rotate;
    }

    if( UiKeyboard::pInstance()->IsHeld( UiKeyCode_X ) )
    {
        MtMatrix4 m4Temp;
        m4Temp.SetRotationY(MtDegreesToRadians(-1.0f));
        m4Rotate = m4Temp * m4Rotate;
    }
    m4Transform = m4Rotate * m4Transform;

    m_pWaxModel->SetLocalTransform( m4Transform );
    m_pWaxModel->Update();
}
コード例 #2
0
RsCamera::RsCamera()
{
	m_nearPlane   = 0.1f;
	m_farPlane    = 1000.0f;
	m_fieldOfView = MtDegreesToRadians( 60.0f );

	m_v3Position = MtVector3(0, 0, 0);	
	m_m3Orientation.SetIdentity();

	m_viewport = RsViewport( 0, 0, 0, 0 );
	m_aspect = 0;
	m_isPerspective = BtTrue;

	m_width = 0;
	m_height = 0;
}
コード例 #3
0
BtBool pgModel::Update( BtU32 screenIndex, BtBool isPressed, BtBool isReleased )
{
    if( ApConfig::IsWin() )
    {
        if( UiKeyboard::pInstance()->IsPressed( UiKeyCode_1 ) )
        {
            ShowShape = 1;
        }
        if( UiKeyboard::pInstance()->IsPressed( UiKeyCode_2 ) )
        {
            ShowShape = 2;
        }

        // Rotate the model
        BtFloat speed = 0.1f;
        if( UiKeyboard::pInstance()->IsHeld( UiKeyCode_UP ) )
        {
            MtMatrix3 m3Rotate;
            m3Rotate.SetRotationX( -speed );
            m_m3Rotation = m_m3Rotation * m3Rotate;
        }
        if( UiKeyboard::pInstance()->IsHeld( UiKeyCode_DOWN ) )
        {
            MtMatrix3 m3Rotate;
            m3Rotate.SetRotationX( speed );
            m_m3Rotation = m_m3Rotation * m3Rotate;
        }
        if( UiKeyboard::pInstance()->IsHeld( UiKeyCode_RIGHT ) )
        {
            MtMatrix3 m3Rotate;
            m3Rotate.SetRotationY( -speed );
            m_m3Rotation = m3Rotate * m_m3Rotation;
        }
        if( UiKeyboard::pInstance()->IsHeld( UiKeyCode_LEFT ) )
        {
            MtMatrix3 m3Rotate;
            m3Rotate.SetRotationY( speed );
            m_m3Rotation = m3Rotate * m_m3Rotation;
        }
    }
    
	/*
	MtMatrix4 m4Translation;
	m4Translation.SetTranslation( MtVector3( 0, -4.5f, 13.0f ) );

	// Set the rotation
	MtMatrix4 m4Transform;
    MtMatrix4 Y;
    Y.SetRotationX(MtDegreesToRadians(-20.0f));
    m4Transform = Y * m_m3Rotation * m4Translation;
	*/
	MtMatrix4 m4Rotate;
	m4Rotate.SetRotationX(MtDegreesToRadians(90.0f));
	MtMatrix4 m4Transform;
	m4Transform.SetTranslation(MtVector3(-5, 0, 10.0f));
	m_pModel->SetLocalTransform(m_m3Rotation * m4Rotate * m4Transform);
	m_pModel->Update();
    
	if( ( screenIndex == 20 ) || ( screenIndex == 21 ) )
    {
        m4Transform =  m4Transform;
		scaleTime = 0;
        m_elapsedTime = BtTime::GetElapsedTimeInSeconds();
    }
         
    const BtFloat MaxTime = 1.5f;
    
    if( ( screenIndex == 22 ) || ( screenIndex == 23 ) )
    {
		if( isPressed )
		{
            if( m_isContracting )
            {
                scaleTime -= BtTime::GetTick();
            }
            else
            {
                scaleTime += BtTime::GetTick();
            }
            
            if( scaleTime < 0 )
            {
                scaleTime = 0;
                m_isContracting = BtFalse;
                return BtTrue;
            }
            if( scaleTime > MaxTime )
            {
                scaleTime = MaxTime;
                m_isContracting = BtTrue;
            }
		}
        if( isReleased )
        {
            scaleTime = 0;
            m_isContracting = BtFalse;
		}
		m_scale = scaleTime / MaxTime;
    }
	return BtFalse;
}
コード例 #4
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();
		}
	}
}
コード例 #5
0
void pgCamera::Init()
{
	BtFloat width = (BtFloat)RsUtil::GetWidth();
	BtFloat height = (BtFloat)RsUtil::GetHeight();

	m_camera = RsCamera(0.1f, 10000.0f, width / height, RsViewport(0, 0, (BtU32)width, (BtU32)height), MtDegreesToRadians(60.0f));
	m_camera.SetDimension(RsUtil::GetDimension());
	m_camera.SetPerspective(BtTrue);

	m_cameraData.m_v3Position = MtVector3(0, 0, 0);
	m_cameraData.m_m3Rotation.SetIdentity();

	m_speed = 100.0f;
	m_cameraData.m_pitch = 0;
	m_cameraData.m_yaw = 0;
	m_isFlyCam = BtTrue;
}