Changeset 9

User picture

Author: machiel.sleeuwaert

(2008/11/10 20:07) Over 3 years ago


  

Affected files

Updated 3Xine/3Xine/3Xine.vcproj Download diff

89
171
			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
171
			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
172
			>
172
			>
173
			<File
173
			<File
174
				RelativePath=".\Game.cpp"
174
				RelativePath=".\Camera.cpp"
175
				>
175
				>
176
			</File>
176
			</File>
177
			<File
177
			<File
178
				RelativePath=".\Game.h"
178
				RelativePath=".\Camera.h"
179
				>
179
				>
180
			</File>
180
			</File>
181
		</Filter>
182
		<Filter
183
			Name="Header Files"
184
			Filter="h;hpp;hxx;hm;inl;inc;xsd"
185
			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
186
			>
187
			<File
181
			<File
188
				RelativePath=".\AbstractGame.cpp"
182
				RelativePath=".\Game.cpp"
189
				>
183
				>
190
			</File>
184
			</File>
191
			<File
185
			<File
192
				RelativePath=".\AbstractGame.h"
186
				RelativePath=".\Game.h"
193
				>
187
				>
194
			</File>
188
			</File>
195
			<File
189
			<File
196
				RelativePath=".\DirectInput.cpp"
190
				RelativePath=".\Game2.cpp"
197
				>
191
				>
198
			</File>
192
			</File>
199
			<File
193
			<File
200
				RelativePath=".\DirectInput.h"
194
				RelativePath=".\Game2.h"
201
				>
195
				>
202
			</File>
196
			</File>
203
			<File
197
		</Filter>
204
				RelativePath=".\IncAndDef.h"
198
		<Filter
199
			Name="Header Files"
200
			Filter="h;hpp;hxx;hm;inl;inc;xsd"
201
			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
202
			>
203
			<Filter
204
				Name="windows"
205
				>
205
				>
206
			</File>
206
				<File
207
			<File
207
					RelativePath=".\WinMain.cpp"
208
				RelativePath=".\util.h"
208
					>
209
				</File>
210
				<File
211
					RelativePath=".\WinMain.h"
212
					>
213
				</File>
214
			</Filter>
215
			<Filter
216
				Name="DirectInput"
209
				>
217
				>
210
			</File>
218
				<File
211
			<File
219
					RelativePath=".\DirectInput.cpp"
212
				RelativePath=".\XineEngine.cpp"
220
					>
221
				</File>
222
				<File
223
					RelativePath=".\DirectInput.h"
224
					>
225
				</File>
226
			</Filter>
227
			<Filter
228
				Name="Engine"
213
				>
229
				>
214
			</File>
230
				<File
215
			<File
231
					RelativePath=".\XineEngine.cpp"
216
				RelativePath=".\XineEngine.h"
232
					>
233
				</File>
234
				<File
235
					RelativePath=".\XineEngine.h"
236
					>
237
				</File>
238
			</Filter>
239
			<Filter
240
				Name="AbstractGame"
217
				>
241
				>
218
			</File>
242
				<File
243
					RelativePath=".\AbstractGame.cpp"
244
					>
245
				</File>
246
				<File
247
					RelativePath=".\AbstractGame.h"
248
					>
249
				</File>
250
			</Filter>
219
			<Filter
251
			<Filter
220
				Name="windows"
252
				Name="various headers"
221
				>
253
				>
222
				<File
254
				<File
223
					RelativePath=".\WinMain.cpp"
255
					RelativePath=".\IncAndDef.h"
224
					>
256
					>
225
				</File>
257
				</File>
226
				<File
258
				<File
227
					RelativePath=".\WinMain.h"
259
					RelativePath=".\util.h"
228
					>
260
					>
229
				</File>
261
				</File>
230
			</Filter>
262
			</Filter>

Updated 3Xine/3Xine/AbstractGame.h Download diff

89
1
#pragma once
1
#pragma once
2
2
3
#include "XineEngine.h"
3
#include "XineEngine.h"
4
4
#include "DirectInput.h"
5
class AbstractGame
5
class AbstractGame
6
{
6
{
7
public:
7
public:

Added 3Xine/3Xine/Camera.cpp

Show contents

Added 3Xine/3Xine/Camera.h

Show contents

Updated 3Xine/3Xine/DirectInput.cpp Download diff

89
19
DirectInput::DirectInput():
19
DirectInput::DirectInput():
20
KeyboardCoopFlags(DISCL_NONEXCLUSIVE|DISCL_FOREGROUND), 
20
KeyboardCoopFlags(DISCL_NONEXCLUSIVE|DISCL_FOREGROUND), 
21
MouseCoopFlags(DISCL_NONEXCLUSIVE|DISCL_FOREGROUND),
21
MouseCoopFlags(DISCL_NONEXCLUSIVE|DISCL_FOREGROUND),
22
m_pDIinterface(0),m_pKeyboard(0),m_pMouse(0),AbsMousePos(0,0,0)
22
m_pDIinterface(0),m_pKeyboard(0),m_pMouse(0),AbsMousePos(0,0,0),RelMousePos(0,0,0),m_Sensivity(0.002f)
23
{
23
{
24
	ZeroMemory(m_KeyboardState, sizeof(m_KeyboardState));
24
	InitAbsMouse();
25
	ZeroMemory(&m_MouseState, sizeof(m_MouseState));
26
25
27
	HR(DirectInput8Create(XE->m_hInstance, DIRECTINPUT_VERSION, 
28
		IID_IDirectInput8, (void**)&m_pDIinterface, 0));
29
26
27
	HR(DirectInput8Create(XE->m_hInstance, DIRECTINPUT_VERSION,IID_IDirectInput8, (void**)&m_pDIinterface, 0));
28
30
	HR(m_pDIinterface->CreateDevice(GUID_SysKeyboard, &m_pKeyboard, 0));
29
	HR(m_pDIinterface->CreateDevice(GUID_SysKeyboard, &m_pKeyboard, 0));
31
	HR(m_pKeyboard->SetDataFormat(&c_dfDIKeyboard));
30
	HR(m_pKeyboard->SetDataFormat(&c_dfDIKeyboard));
32
	HR(m_pKeyboard->SetCooperativeLevel(XE->m_hwnd, KeyboardCoopFlags));
31
	HR(m_pKeyboard->SetCooperativeLevel(XE->m_hwnd, KeyboardCoopFlags));
...
...
38
	HR(m_pMouse->Acquire());
37
	HR(m_pMouse->Acquire());
39
}
38
}
40
39
40
void DirectInput::InitAbsMouse(){
41
	POINT P;
42
	P.y=0;
43
	P.x=0;
44
	ClientToScreen(XE->m_hwnd,&P);
45
	SetCursorPos(P.x,P.y);
46
	AbsMousePos = MOUSE(0,0,0);
41
47
48
// 	 POINT P;
49
// 	 bool m = ScreenToClient(XE->m_hwnd,&P);
50
// 	 AbsMousePos = MOUSE(P.x,P.y,0);
51
}
52
42
DirectInput::~DirectInput()
53
DirectInput::~DirectInput()
43
{
54
{
44
	m_pDIinterface->Release();
55
	m_pDIinterface->Release();
...
...
55
	
66
	
56
	if( FAILED(m_pKeyboard->GetDeviceState(sizeof(m_KeyboardState), (void**)&m_KeyboardState)) )
67
	if( FAILED(m_pKeyboard->GetDeviceState(sizeof(m_KeyboardState), (void**)&m_KeyboardState)) )
57
	{
68
	{
58
		// Keyboard lost, zero out keyboard data structure.
59
		ZeroMemory(m_KeyboardState, sizeof(m_KeyboardState));
60
69
61
		// Try to acquire for next time we poll.
70
		// Try to acquire for next time we poll.
62
		m_pKeyboard->Acquire();
71
		m_pKeyboard->Acquire();
63
		
72
		return;
64
	}
73
	}
65
74
66
	
75
	
67
76
68
	if( FAILED(m_pMouse->GetDeviceState(sizeof(DIMOUSESTATE2), (void**)&m_MouseState)) )
77
	if( FAILED(m_pMouse->GetDeviceState(sizeof(DIMOUSESTATE2), (void**)&m_MouseState)) )
69
	{
78
	{
70
		// Mouse lost, zero out mouse data structure.
79
		
71
		ZeroMemory(&m_MouseState, sizeof(m_MouseState));
72
73
		// Try to acquire for next time we poll.
80
		// Try to acquire for next time we poll.
74
		m_pMouse->Acquire(); 
81
		m_pMouse->Acquire();
82
		return;
75
		
83
		
76
	}
84
	}
77
	RelMousePos.x = m_MouseState.lX;
78
	RelMousePos.y = m_MouseState.lY;
79
	RelMousePos.z = m_MouseState.lZ;
80
85
81
	AbsMousePos+=RelMousePos;
86
	if(m_MouseState.lZ != 0)
87
	{
88
		RelMousePos.z = (float)m_MouseState.lZ;
89
90
		if (RelMousePos.z>0)
91
			AbsMousePos.z = 1;
92
		else 
93
			AbsMousePos.z = -1;
94
		return;
95
	}
96
		
97
98
	RelMousePos.x = (float)m_MouseState.lX*m_Sensivity;
99
	RelMousePos.y = (float)m_MouseState.lY*m_Sensivity;
100
101
	AbsMousePos.x+=(int)m_MouseState.lX;
102
	AbsMousePos.y+=(int)m_MouseState.lY;
103
104
// 	if(AbsMousePos.x<0)
105
// 		AbsMousePos.x=0;
106
// 	if(AbsMousePos.x>XE->m_ClientRect.right)
107
// 		AbsMousePos.x=XE->m_ClientRect.right;
108
		
109
	
110
	AbsMousePos.z = 0;
111
112
113
	
82
}
114
}
83
115
84
116
...
...
94
}
126
}
95
127
96
128
97
	D3DXVECTOR3 DirectInput::GetAbsMousePos()
129
	MOUSE DirectInput::GetAbsMousePos()
98
	{
130
	{
99
		return AbsMousePos;
131
		return AbsMousePos;
100
	}
132
	}

Updated 3Xine/3Xine/DirectInput.h Download diff

89
20
	void Tick();
20
	void Tick();
21
	bool KeyDown(unsigned char key);
21
	bool KeyDown(unsigned char key);
22
	bool MouseButtonDown(int button);
22
	bool MouseButtonDown(int button);
23
	D3DXVECTOR3 GetAbsMousePos();
23
	MOUSE GetAbsMousePos();
24
	D3DXVECTOR3 GetRelMousePos();
24
	D3DXVECTOR3 GetRelMousePos();
25
	void InitAbsMouse();
25
26
26
27
27
28
...
...
38
39
39
	IDirectInputDevice8* m_pMouse;
40
	IDirectInputDevice8* m_pMouse;
40
	DIMOUSESTATE2        m_MouseState;
41
	DIMOUSESTATE2        m_MouseState;
41
	D3DXVECTOR3 AbsMousePos;
42
	
43
	MOUSE AbsMousePos;
42
	D3DXVECTOR3 RelMousePos;
44
	D3DXVECTOR3 RelMousePos;
45
	
46
	float m_Sensivity;
43
47
44
private:
48
45
	// -------------------------
49
	// -------------------------
46
	// Disabling default copy constructor and default assignment operator.
50
	// Disabling default copy constructor and default assignment operator.
47
	// If you get a linker error from one of these functions, your class is internally trying to use them. This is
51
	// If you get a linker error from one of these functions, your class is internally trying to use them. This is

Updated 3Xine/3Xine/Game.cpp Download diff

89
1
#include "Game.h"
1
#include "Game.h"
2
2
3
Game::Game():m_pFont(0)
3
Game::Game():m_pFont(0),color(0)
4
{
4
{
5
5
6
	//make font description
6
	//make font description
...
...
32
}
32
}
33
void Game::DrawScene(RECT rect)
33
void Game::DrawScene(RECT rect)
34
{
34
{
35
	//drawtext
35
	tstringstream temp;
36
	m_pFont->DrawText(0,_T("Xine Engine"),-1,&rect,DT_CENTER | DT_VCENTER,D3DCOLOR_XRGB(255,0,0));
36
	temp << DI->GetAbsMousePos().x << " " << DI->GetAbsMousePos().y;
37
	if (DI->GetAbsMousePos().z > 0)
38
		color+=20;
39
	else if (DI->GetAbsMousePos().z < 0)
40
		color-=20;
41
	m_pFont->DrawText(0,temp.str().c_str(),-1,&rect,DT_CENTER | DT_VCENTER,D3DCOLOR_XRGB(255,color,0));
37
}
42
}

Updated 3Xine/3Xine/Game.h Download diff

89
10
	void DrawScene(RECT rect);
10
	void DrawScene(RECT rect);
11
private:
11
private:
12
	ID3DXFont* m_pFont;
12
	ID3DXFont* m_pFont;
13
14
	int color;
13
};
15
};

Added 3Xine/3Xine/Game2.cpp

Show contents

Added 3Xine/3Xine/Game2.h

Show contents

Updated 3Xine/3Xine/IncAndDef.h Download diff

89
34
#define HEIGHT 600
34
#define HEIGHT 600
35
#define WIDTH 800
35
#define WIDTH 800
36
#define XE XineEngine::GetSingleton()
36
#define XE XineEngine::GetSingleton()
37
#define DI DirectInput::GetSingleton()
37
#define DI DirectInput::GetSingleton()
38
39
struct MOUSE {
40
	MOUSE( int x, int y, int z ):x(x),y(y),z(z)
41
	{}
42
	
43
	int x;
44
	int y;
45
	int z;
46
};

Updated 3Xine/3Xine/XineEngine.cpp Download diff

89
1
#include "XineEngine.h"
1
#include "XineEngine.h"
2
#include "DirectInput.h"
2
#include "DirectInput.h"
3
#include "Game.h"
3
#include "Game2.h"
4
XineEngine* XineEngine::SINGLETONPOINTER = 0;
4
XineEngine* XineEngine::SINGLETONPOINTER = 0;
5
5
6
6
...
...
11
m_numframes(0),m_TimeElapsed(0.0f),
11
m_numframes(0),m_TimeElapsed(0.0f),
12
m_FPS(0),m_hInstance(0)
12
m_FPS(0),m_hInstance(0)
13
{
13
{
14
	
14
	m_ClientRect.left = 0;
15
	m_ClientRect.top = 0;
16
	m_ClientRect.right = m_Width;
17
	m_ClientRect.bottom = m_Height;
15
}
18
}
16
19
17
XineEngine::~XineEngine()
20
XineEngine::~XineEngine()
...
...
31
	QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
34
	QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
32
	float secondsincount = 1.0f/(float)freq;
35
	float secondsincount = 1.0f/(float)freq;
33
36
34
	
35
	QueryPerformanceCounter((LARGE_INTEGER*)&PrevCount);
37
	QueryPerformanceCounter((LARGE_INTEGER*)&PrevCount);
36
38
37
	// Default to a window with a client area rectangle of m_iWidth x m_iHeight
39
	 
38
	RECT R = {0, 0, m_Width, m_Height};
40
	AdjustWindowRect(&m_ClientRect, WS_OVERLAPPEDWINDOW, false); //make the right size (for backbuffer)
39
	AdjustWindowRect(&R, WS_OVERLAPPEDWINDOW, false); //make the right size (for backbuffer)
40
41
41
	// Create the window
42
	// Create the window
42
	if(!(m_hwnd = CreateWindow(GAMENAME,GAMENAME,WS_OVERLAPPEDWINDOW,(GetSystemMetrics(SM_CXSCREEN) - m_Width)/2,(GetSystemMetrics(SM_CYSCREEN) - m_Height)/2,R.right,R.bottom,	NULL, NULL,hInstance, NULL)))
43
	if(!(m_hwnd = CreateWindow(GAMENAME,GAMENAME,WS_OVERLAPPEDWINDOW,(GetSystemMetrics(SM_CXSCREEN) - m_Width)/2,(GetSystemMetrics(SM_CYSCREEN) - m_Height)/2,m_Width,m_Height,	NULL, NULL,hInstance, NULL)))
43
		return 0;
44
		return 0;
44
	
45
	
45
46
...
...
79
	
80
	
80
	InitializeDirect3D();
81
	InitializeDirect3D();
81
82
83
	//m_3D9Device->SetCursorProperties(GetSystemMetrics(SM_CXSCREEN)/2,GetSystemMetrics(SM_CYSCREEN),)
82
84
83
85
	m_pGame = new Game2();
84
	m_pGame = new Game();
85
}
86
}
86
87
87
void XineEngine::Resize(RECT R)
88
void XineEngine::Resize(RECT R)
...
...
273
		case SIZE_MAXIMIZED:
274
		case SIZE_MAXIMIZED:
274
			SetPaused(false);
275
			SetPaused(false);
275
			GetClientRect(m_hwnd,&clientrect);
276
			GetClientRect(m_hwnd,&clientrect);
276
				Resize(clientrect);
277
			Resize(clientrect);
277
			break;
278
			break;
278
		case SIZE_MAXSHOW:
279
		case SIZE_MAXSHOW:
279
			break;
280
			break;
...
...
287
		PostQuitMessage(0);
288
		PostQuitMessage(0);
288
		break;
289
		break;
289
290
291
// 	case WM_MOUSEMOVE:
292
// 
293
// 		P.x = LOWORD(lParam); 
294
// 		P.y = HIWORD(lParam); 
295
// 		P.y=0;
296
// 		P.x=0;
297
// 		ClientToScreen(m_hwnd,&P);
298
// 		SetCursorPos(P.x,P.y);
299
// 		break;
290
	default:  
300
	default:  
291
		return DefWindowProc(m_hwnd, msg, wParam, lParam);
301
		return DefWindowProc(m_hwnd, msg, wParam, lParam);
292
	}
302
	}