Problem with Virtual keys

Ok so here's the deal. I have been working with directX and I am trying to get the geometry to move with the keyboard. It is successfully working to a point.
the problem arises when I press say left and right the model stops spinning as expected. but it also locks the up and down movement( well its not really up and down movement but the up and down keys are set to another rotation matrix). This is not desirable can someone direct me to a fix or perhaps some resources I can study. Here is the problem code anyway.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
XMMATRIX MatrixManipulation ( int number )
{
	// Variables /////////////////////////////////////////////////////////////////////////////
	unsigned short int left = GetKeyState(VK_LEFT);
	unsigned short int right = GetKeyState(VK_RIGHT);
	unsigned short int up = GetKeyState(VK_UP);
	unsigned short int down = GetKeyState(VK_DOWN);
	static float time = 0.0f;
	static float time2 = 0.0f;

	if (left & 0x8000)
	{
		time += 0.0001f;
	}
	if  (right & 0x8000)
	{
		time -= 0.0001f;
	}
	if (up & 0x8000)
	{
		time2 += 0.0001f;
	}
	if (down & 0x8000)
	{
		time2 -= 0.0001f;
	}
	
	
	//////////////////////////////////////////////////////////////////////////////////////////


	// Create Final Matrix ///////////////////////////////////////////////////////////////////
	XMMATRIX rotmatrix [ 11 ];

	rotmatrix [ 0 ] = XMMatrixRotationY ( XMConvertToRadians ( 45.0f ) );
	rotmatrix [ 1 ] = XMMatrixRotationY ( XMConvertToRadians ( 90.0f ) );
	rotmatrix [ 2 ] = XMMatrixRotationY ( XMConvertToRadians ( 135.0f ) );
	rotmatrix [ 3 ] = XMMatrixRotationY ( XMConvertToRadians ( 180.0f ) );
	rotmatrix [ 4 ] = XMMatrixRotationY ( XMConvertToRadians ( 225.0f ) );
	rotmatrix [ 5 ] = XMMatrixRotationY ( XMConvertToRadians ( 270.0f ) );
	rotmatrix [ 6 ] = XMMatrixRotationY ( XMConvertToRadians ( 315.0f ) );
	rotmatrix [ 7 ] = XMMatrixRotationY ( XMConvertToRadians ( 360.0f ) );
	rotmatrix [ 8 ] = XMMatrixRotationX ( XMConvertToRadians ( 90.0f ) );
	rotmatrix [ 9 ] = XMMatrixRotationZ ( time );
	rotmatrix [ 10 ] = XMMatrixRotationY ( time2 );
	
	XMMATRIX transmatrix = XMMatrixTranslation ( 0.0f , 0.0f , 2.0f );

	XMMATRIX scalematrix = XMMatrixScaling ( 1.5f , 1.5f , 1.5f );

	XMMATRIX viewmatrix = XMMatrixLookAtLH ( XMVectorSet ( 0.0f , 4.0f , 8.0f , 0 ) , XMVectorSet ( 0.0f , 0.0f , 0.0f , 0 ) , XMVectorSet ( 0.0f , 1.0f , 0.0f , 0 ) );
	XMMATRIX projmatrix = XMMatrixPerspectiveFovLH ( XMConvertToRadians ( 45.0f ) , ( FLOAT ) SCREENWIDTH / ( FLOAT ) SCREENHEIGHT , 1.0f , 100.0f );
	
	XMMATRIX finalmatrix [ 9 ];

	finalmatrix [ 0 ] = rotmatrix [ 9 ] * transmatrix * rotmatrix [ 0 ] * rotmatrix [ 10 ] * viewmatrix * projmatrix;
	finalmatrix [ 1 ] = rotmatrix [ 9 ] * transmatrix * rotmatrix [ 1 ] * rotmatrix [ 10 ] * viewmatrix * projmatrix;
	finalmatrix [ 2 ] = rotmatrix [ 9 ] * transmatrix * rotmatrix [ 2 ] * rotmatrix [ 10 ] * viewmatrix * projmatrix;
	finalmatrix [ 3 ] = rotmatrix [ 9 ] * transmatrix * rotmatrix [ 3 ] * rotmatrix [ 10 ] * viewmatrix * projmatrix;
	finalmatrix [ 4 ] = rotmatrix [ 9 ] * transmatrix * rotmatrix [ 4 ] * rotmatrix [ 10 ] * viewmatrix * projmatrix;
	finalmatrix [ 5 ] = rotmatrix [ 9 ] * transmatrix * rotmatrix [ 5 ] * rotmatrix [ 10 ] * viewmatrix * projmatrix;
	finalmatrix [ 6 ] = rotmatrix [ 9 ] * transmatrix * rotmatrix [ 6 ] * rotmatrix [ 10 ] * viewmatrix * projmatrix;
	finalmatrix [ 7 ] = rotmatrix [ 9 ] * transmatrix * rotmatrix [ 7 ] * rotmatrix [ 10 ] * viewmatrix * projmatrix;
	finalmatrix [ 8 ] = rotmatrix [ 9 ] * rotmatrix [ 8 ] * scalematrix * viewmatrix * projmatrix;

	//////////////////////////////////////////////////////////////////////////////////////////
	return finalmatrix [ number ];

bump
Last edited on
Topic archived. No new replies allowed.