Skip to content

Commit c0f77f5

Browse files
committed
About window + small fixes
- Fix rendering breaking when approaching pole singularities - Fill world center gap if cursor3D isn't at (0,0,0)
1 parent 43afc1e commit c0f77f5

7 files changed

Lines changed: 204 additions & 41 deletions

File tree

3DRadSpace/3DRadSpace_Editor_WindowsDX11/Editor/RenderWindow.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ void RenderWindow::Initialize()
4848
dLines.push_back(VertexPositionColor{Vector3(-halfNumLines, 0, float(i)), Colors::Gray});
4949
}
5050

51+
auto centerLines = std::initializer_list<VertexPositionColor>{
52+
VertexPositionColor{ Vector3(0,0,halfNumLines), Colors::Gray },
53+
VertexPositionColor{ Vector3(0,0,-halfNumLines), Colors::Gray },
54+
VertexPositionColor{ Vector3(halfNumLines, 0, 0), Colors::Gray },
55+
VertexPositionColor{ Vector3(-halfNumLines, 0, 0), Colors::Gray }
56+
};
57+
5158
axis = std::make_unique<Primitives::LineList>(Device.get(), axisLines);
59+
grid_center = std::make_unique<Primitives::LineList>(Device.get(), centerLines);
5260
grid = std::make_unique<Primitives::LineList>(Device.get(), dLines);
5361

5462
Camera.InternalInitialize(this);
@@ -162,10 +170,11 @@ void RenderWindow::_controlCamera()
162170
auto mouseDelta = (Vector2)(screenCenter - mousePos) * float(Update_dt) / 100.0f;
163171
cameraPos -= mouseDelta * Settings::CameraSensitivity.Value;
164172

173+
constexpr float poleLimit = 0.01f;
165174
cameraPos.Y = std::clamp<float>(
166175
cameraPos.Y,
167-
-std::numbers::pi_v<float> / 2.f + std::numeric_limits<float>::epsilon(),
168-
std::numbers::pi_v<float> / 2.f - std::numeric_limits<float>::epsilon()
176+
-std::numbers::pi_v<float> / 2.f + poleLimit,
177+
std::numbers::pi_v<float> / 2.f - poleLimit
169178
);
170179

171180
Window->SetMouseVisibility(false);
@@ -397,6 +406,13 @@ void RenderWindow::Draw3D()
397406
grid->View = View;
398407
grid->Projection = Projection;
399408
grid->Draw3D();
409+
410+
if (!Math::WithinEpsilon(cursor3D.X, 0) && !Math::WithinEpsilon(cursor3D.Y, 0) && !Math::WithinEpsilon(cursor3D.Z, 0))
411+
{
412+
grid_center->View = View;
413+
grid_center->Projection = Projection;
414+
grid_center->Draw3D();
415+
}
400416
}
401417

402418
auto drawAllObjects = [this]()

3DRadSpace/3DRadSpace_Editor_WindowsDX11/Editor/RenderWindow.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class RenderWindow : public Engine3DRadSpace::Game
3232
Camera Camera;
3333
std::unique_ptr<LineList> axis;
3434
std::unique_ptr<LineList> grid;
35+
std::unique_ptr<LineList> grid_center;
3536

3637
float zoom = 5.0f;
3738
float timer = 0;

3DRadSpace/3DRadSpace_Editor_WindowsDX11/Editor/SkinmeshPreviewer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ void SkinmeshPreviewer::Update()
4747
Vector2 mouseDelta = static_cast<Vector2>(pd) * float(Draw_dt);
4848
_camCoords -= mouseDelta * Settings::CameraSensitivity.Value;
4949

50+
constexpr float poleLimit = 0.01f;
5051
_camCoords.Y = std::clamp<float>(
5152
_camCoords.Y,
52-
-std::numbers::pi_v<float> / 2.0f + std::numeric_limits<float>::epsilon(),
53-
std::numbers::pi_v<float> / 2.0f - std::numeric_limits<float>::epsilon()
53+
-std::numbers::pi_v<float> / 2.f + poleLimit,
54+
std::numbers::pi_v<float> / 2.f - poleLimit
5455
);
5556

5657
Window->SetMouseVisibility(false);
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include "AboutWindow.hpp"
2+
#include "../../resource.h"
3+
4+
INT_PTR WINAPI AboutWindow_DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5+
{
6+
static AboutWindow* wndAbout = nullptr;
7+
8+
switch (msg)
9+
{
10+
case WM_INITDIALOG:
11+
{
12+
wndAbout = reinterpret_cast<AboutWindow*>(lParam);
13+
wndAbout->window = hwnd;
14+
wndAbout->_createControls();
15+
return 1;
16+
}
17+
case WM_COMMAND:
18+
switch (LOWORD(wParam))
19+
{
20+
case IDOK:
21+
EndDialog(hwnd, IDOK);
22+
return TRUE;
23+
case IDCANCEL:
24+
EndDialog(hwnd, IDCANCEL);
25+
return TRUE;
26+
default:
27+
break;
28+
}
29+
if (HIWORD(wParam) == BN_CLICKED && reinterpret_cast<HWND>(lParam) == wndAbout->_okButton)
30+
{
31+
EndDialog(hwnd, IDOK);
32+
return TRUE;
33+
}
34+
break;
35+
default:
36+
break;
37+
}
38+
return FALSE;
39+
}
40+
41+
AboutWindow::AboutWindow(HWND owner, HINSTANCE hInstance) : Dialog(owner, hInstance, AboutWindow_DlgProc, "About 3DRadSpace", 260, 130)
42+
{
43+
}
44+
45+
void AboutWindow::_createControls()
46+
{
47+
_iconPictureBox = CreateWindowExA(
48+
0,
49+
"Static",
50+
"",
51+
WS_VISIBLE | WS_CHILD | SS_ICON,
52+
10, 10, 200, 200,
53+
window,
54+
nullptr,
55+
hInstance,
56+
nullptr
57+
);
58+
59+
HICON hIcon = (HICON)LoadImageA(
60+
hInstance,
61+
MAKEINTRESOURCEA(IDI_ICON1),
62+
IMAGE_ICON,
63+
200, 200,
64+
LR_DEFAULTCOLOR
65+
);
66+
if (hIcon == nullptr)
67+
{
68+
MessageBoxA(window, "Failed to load the icon for the about window!", "Error", MB_ICONERROR);
69+
}
70+
else
71+
{
72+
SendMessageA(_iconPictureBox, STM_SETICON, reinterpret_cast<WPARAM>(hIcon), 0);
73+
}
74+
75+
_label = CreateWindowExA(
76+
0,
77+
"Static",
78+
"3DRadSpace Editor\nVersion 0.1.0Alpha\n\nhttps:\\3dradspace.github.io\n\n\n\nThis software is licensed under MIT.",
79+
WS_VISIBLE | WS_CHILD | SS_CENTER,
80+
220, 10, 200, 200,
81+
window,
82+
nullptr,
83+
hInstance,
84+
nullptr
85+
);
86+
87+
_okButton = CreateWindowExA(
88+
0,
89+
"Button",
90+
"OK",
91+
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
92+
390, 220, 100, 30,
93+
window,
94+
reinterpret_cast<HMENU>(IDOK),
95+
hInstance,
96+
nullptr
97+
);
98+
}
99+
100+
void AboutWindow::ShowDialog()
101+
{
102+
Dialog::ShowDialog(static_cast<void*>(this));
103+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include "../Controls/Dialog.hpp"
3+
4+
class AboutWindow : public Dialog
5+
{
6+
HWND _label = nullptr;
7+
HWND _iconPictureBox = nullptr;
8+
HWND _okButton = nullptr;
9+
10+
void _createControls();
11+
public:
12+
AboutWindow(HWND owner, HINSTANCE hInstance);
13+
14+
void ShowDialog();
15+
16+
friend INT_PTR WINAPI AboutWindow_DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
17+
};

0 commit comments

Comments
 (0)