-
Notifications
You must be signed in to change notification settings - Fork 1
/
soft3dapp.cpp
201 lines (170 loc) · 4.59 KB
/
soft3dapp.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/******************************************************
g-Matrix3D Neo Engine
Copyright (c)2003 Kim Seong Wan (kaswan, Â𻧱ͽÅ)
E-mail: [email protected]
http://www.g-matrix.pe.kr
*******************************************************/
#include "stdafx.h"
#include "soft3dapp.h"
#include "resource.h"
#include "graphics.h"
static Soft3DApp* g_pSoft3DApp = NULL;
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return g_pSoft3DApp->AppProc(hWnd, uMsg, wParam, lParam);
}
Soft3DApp::Soft3DApp()
{
g_pSoft3DApp = this;
m_bIsActive = false;
// Default value
m_ClientWidth = 640;
m_ClientHeight = 480;
}
int Soft3DApp::Create(HINSTANCE hInst, int width, int height)
{
WNDCLASS wc;
m_ClientWidth = width;
m_ClientHeight = height;
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(hInst, (LPCTSTR)IDI_ICON1);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wc.lpszClassName = "ray3d";
m_hInst = hInst;
RegisterClass(&wc);
RECT rect;
rect.left = 0;
rect.top = 0;
rect.right = m_ClientWidth - 1;
rect.bottom = m_ClientHeight - 1;
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW/*|WS_SYSMENU|WS_MINIMIZEBOX*/, true);
m_WindowWidth = rect.right - rect.left + 1;
m_WindowHeight = rect.bottom - rect.top + 1;
m_hWnd = CreateWindow("Ray3d",
"Ray3d <g-Matrix3d Ray>",
WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX,
(GetSystemMetrics(SM_CXFULLSCREEN) - m_WindowWidth) / 2,
(GetSystemMetrics(SM_CYFULLSCREEN) - m_WindowHeight)/ 2,
m_WindowWidth,
m_WindowHeight,
NULL,
NULL,
hInst,
NULL);
ShowWindow(m_hWnd, SW_SHOW);
UpdateWindow(m_hWnd);
return 0;
}
int Soft3DApp::Run()
{
MSG msg;
while (1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else return msg.wParam;
}
else if(IsActive())
{
UpdateFrame();
}
else
{
WaitMessage();
}
}
return msg.wParam;
}
LRESULT Soft3DApp::AppProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//RECT rect;
// Mouse
short int xPos, yPos;
static bool bMouseOn = false;
static int numThreads;
switch (uMsg)
{
case WM_CREATE:
InitGraphics(hWnd, m_ClientWidth, m_ClientHeight);
break;
case WM_CLOSE:
DeinitGraphics(hWnd);
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_ABOUT:
MessageBox(hWnd,
"g-Matrix3d Ray v0.60\n\n(c)2008, 2019, 2023 Kim Seong Wan(kaswan) \n\n\[email protected]\n\thttps://github.com/idgmatrix/Ray3d",
"About Ray3d", MB_OK);
return 0;
case IDC_OPEN:
OnOpen(hWnd);
return 0;
case IDC_EXIT:
DeinitGraphics(hWnd);
PostQuitMessage(0);
return 0;
case ID_THREADS_1THREAD:
case ID_THREADS_2THREADS:
case ID_THREADS_3THREADS:
case ID_THREADS_4THREADS:
case ID_THREADS_5THREADS:
case ID_THREADS_6THREADS:
case ID_THREADS_7THREADS:
case ID_THREADS_8THREADS:
case ID_THREADS_9THREADS:
case ID_THREADS_10THREADS:
case ID_THREADS_11THREADS:
case ID_THREADS_12THREADS:
case ID_THREADS_13THREADS:
case ID_THREADS_14THREADS:
case ID_THREADS_15THREADS:
case ID_THREADS_16THREADS:
numThreads = GetNumThreads();
CheckMenuItem(GetMenu(hWnd), ID_THREADS_1THREAD + numThreads - 1, MF_UNCHECKED);
numThreads = LOWORD(wParam) - ID_THREADS_1THREAD + 1;
SetNumThreads(numThreads);
CheckMenuItem(GetMenu(hWnd), ID_THREADS_1THREAD + numThreads - 1, MF_CHECKED);
return 0;
}
break;
case WM_LBUTTONDOWN:
bMouseOn = true;
SetCapture(hWnd);
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor
//OnPicking(xPos, yPos);
OnMouseLButtonDown(xPos, yPos);
break;
case WM_LBUTTONUP:
bMouseOn = false;
ReleaseCapture();
break;
case WM_MOUSEMOVE:
if (bMouseOn)
{
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor
//PutPixel(xPos, yPos);
//UpdateFrame();
OnMouseMove(xPos, yPos);
}
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}