Compare commits
No commits in common. "ead9c883fee29d31c5df98ad3911e0d956fa8697" and "efa08063c0cfd63cd65e5522867dbcaaa4acdc13" have entirely different histories.
ead9c883fe
...
efa08063c0
4
Makefile
4
Makefile
@ -24,11 +24,10 @@ CFLAGS += -Wno-unknown-pragmas
|
|||||||
CFLAGS += -I./include
|
CFLAGS += -I./include
|
||||||
CFLAGS += -municode
|
CFLAGS += -municode
|
||||||
LDFLAGS += -municode
|
LDFLAGS += -municode
|
||||||
|
LIBS += -ld3d10
|
||||||
|
|
||||||
CXXFLAGS += -fno-exceptions
|
CXXFLAGS += -fno-exceptions
|
||||||
|
|
||||||
LIBS = -ld3d10
|
|
||||||
|
|
||||||
all: $(BUILD_TYPE)/d3d10.exe
|
all: $(BUILD_TYPE)/d3d10.exe
|
||||||
|
|
||||||
$(BUILD_TYPE)/%.fxo: src/%.fx
|
$(BUILD_TYPE)/%.fxo: src/%.fx
|
||||||
@ -61,7 +60,6 @@ OBJS = \
|
|||||||
$(BUILD_TYPE)/main.obj \
|
$(BUILD_TYPE)/main.obj \
|
||||||
$(BUILD_TYPE)/print.obj \
|
$(BUILD_TYPE)/print.obj \
|
||||||
$(BUILD_TYPE)/render_state.obj \
|
$(BUILD_TYPE)/render_state.obj \
|
||||||
$(BUILD_TYPE)/input.obj \
|
|
||||||
$(BUILD_TYPE)/main.res
|
$(BUILD_TYPE)/main.res
|
||||||
|
|
||||||
$(BUILD_TYPE)/d3d10.exe: $(OBJS)
|
$(BUILD_TYPE)/d3d10.exe: $(OBJS)
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#ifndef _INPUT_HPP_
|
|
||||||
#define _INPUT_HPP_
|
|
||||||
|
|
||||||
HRESULT InitInput(HINSTANCE hInstance);
|
|
||||||
void UpdateInput();
|
|
||||||
|
|
||||||
struct Joystate {
|
|
||||||
int buttons;
|
|
||||||
float triggerL;
|
|
||||||
float triggerR;
|
|
||||||
float thumbLX;
|
|
||||||
float thumbLY;
|
|
||||||
float thumbRX;
|
|
||||||
float thumbRY;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern Joystate g_Joystate;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -67,7 +67,7 @@ PS_INPUT VSInstanced(VS_INPUT_INSTANCED input)
|
|||||||
{
|
{
|
||||||
VS_INPUT input_vs = (VS_INPUT)0;
|
VS_INPUT input_vs = (VS_INPUT)0;
|
||||||
|
|
||||||
input_vs.Pos = mul(float4(input.Pos.xyz * 0.3f, 1), input.mTransform);
|
input_vs.Pos = mul(float4(input.Pos.xyz, 1), input.mTransform);
|
||||||
//input_vs.Pos = float4(input.Pos.xyz, 1) + float4(0, input.InstanceID * 3, 0, 0);
|
//input_vs.Pos = float4(input.Pos.xyz, 1) + float4(0, input.InstanceID * 3, 0, 0);
|
||||||
input_vs.Normal = input.Normal;
|
input_vs.Normal = input.Normal;
|
||||||
input_vs.Tex = input.Tex;
|
input_vs.Tex = input.Tex;
|
||||||
|
|||||||
@ -1,68 +0,0 @@
|
|||||||
#include <windows.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <XInput.h>
|
|
||||||
|
|
||||||
#include "print.hpp"
|
|
||||||
#include "input.hpp"
|
|
||||||
|
|
||||||
Joystate g_Joystate;
|
|
||||||
|
|
||||||
typedef DWORD (WINAPI * lpXInputGetCapabilities)(DWORD, DWORD, XINPUT_CAPABILITIES *);
|
|
||||||
typedef DWORD (WINAPI * lpXInputGetState)(DWORD, XINPUT_STATE *);
|
|
||||||
|
|
||||||
//lpXInputGetCapabilities g_XInputGetCapabilities;
|
|
||||||
lpXInputGetState g_XInputGetState;
|
|
||||||
|
|
||||||
HRESULT InitInput(HINSTANCE hInstance)
|
|
||||||
{
|
|
||||||
const char * libs[] = {
|
|
||||||
"xinput1_4.dll",
|
|
||||||
"xinput1_3.dll",
|
|
||||||
"xinput9_1_0.dll",
|
|
||||||
"xinput1_2.dll",
|
|
||||||
"xinput1_1.dll",
|
|
||||||
};
|
|
||||||
const int libs_length = (sizeof (libs)) / (sizeof (libs[0]));
|
|
||||||
|
|
||||||
HMODULE hLib;
|
|
||||||
for (int i = 0; i < libs_length; i++) {
|
|
||||||
hLib = LoadLibraryA(libs[i]);
|
|
||||||
if (hLib != NULL) {
|
|
||||||
//print("using xinput: %s\n", libs[i]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hLib == NULL) {
|
|
||||||
print("no xinput module found\n");
|
|
||||||
return E_FAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//g_XInputGetCapabilities = (lpXInputGetCapabilities)GetProcAddress(hLib, "XInputGetCapabilities");
|
|
||||||
//assert(g_XInputGetCapabilities != NULL);
|
|
||||||
g_XInputGetState = (lpXInputGetState)GetProcAddress(hLib, "XInputGetState");
|
|
||||||
assert(g_XInputGetState != NULL);
|
|
||||||
|
|
||||||
return S_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateInput()
|
|
||||||
{
|
|
||||||
XINPUT_STATE state;
|
|
||||||
for (DWORD i = 0; i < 4; i++) {
|
|
||||||
DWORD ret = g_XInputGetState(i, &state);
|
|
||||||
if (ret != ERROR_SUCCESS) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float trigger = 1.0f / 255.0f;
|
|
||||||
const float thumb = 1.0f / 32768.0f;
|
|
||||||
g_Joystate.buttons = state.Gamepad.wButtons;
|
|
||||||
g_Joystate.triggerL = ((float)state.Gamepad.bLeftTrigger) * trigger;
|
|
||||||
g_Joystate.triggerR = ((float)state.Gamepad.bRightTrigger) * trigger;
|
|
||||||
g_Joystate.thumbLX = ((float)state.Gamepad.sThumbLX) * thumb;
|
|
||||||
g_Joystate.thumbLY = ((float)state.Gamepad.sThumbLY) * thumb;
|
|
||||||
g_Joystate.thumbRX = ((float)state.Gamepad.sThumbRX) * thumb;
|
|
||||||
g_Joystate.thumbRY = ((float)state.Gamepad.sThumbRY) * thumb;
|
|
||||||
}
|
|
||||||
91
src/main.cpp
91
src/main.cpp
@ -8,7 +8,6 @@
|
|||||||
#include "globals.hpp"
|
#include "globals.hpp"
|
||||||
#include "print.hpp"
|
#include "print.hpp"
|
||||||
#include "render_state.hpp"
|
#include "render_state.hpp"
|
||||||
#include "input.hpp"
|
|
||||||
|
|
||||||
#include "gltf.hpp"
|
#include "gltf.hpp"
|
||||||
#include "gltf_instance.hpp"
|
#include "gltf_instance.hpp"
|
||||||
@ -120,18 +119,12 @@ XMFLOAT4 g_vLightColors[2] = {
|
|||||||
XMFLOAT4(0.9f, 0.0f, 0.0f, 1.0f)
|
XMFLOAT4(0.9f, 0.0f, 0.0f, 1.0f)
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
XMVECTOR g_Eye = XMVectorSet(0.0f, 0.0f, -2.0f, 1.0f);
|
|
||||||
XMVECTOR g_At = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f);
|
|
||||||
|
|
||||||
// forward declarations
|
// forward declarations
|
||||||
|
|
||||||
HRESULT InitWindow(HINSTANCE hInstance, int nCmdShow);
|
HRESULT InitWindow(HINSTANCE hInstance, int nCmdShow);
|
||||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||||
HRESULT InitDirect3DDevice();
|
HRESULT InitDirect3DDevice();
|
||||||
void Render(float t);
|
void Render();
|
||||||
void Update(float t);
|
|
||||||
BOOL Resize();
|
BOOL Resize();
|
||||||
void InitializeNodeInstances();
|
void InitializeNodeInstances();
|
||||||
|
|
||||||
@ -158,17 +151,6 @@ const FontSize g_FontSize = {
|
|||||||
|
|
||||||
WindowSize g_ViewportSize;
|
WindowSize g_ViewportSize;
|
||||||
|
|
||||||
float GetTime()
|
|
||||||
{
|
|
||||||
static DWORD dwTimeStart = 0;
|
|
||||||
DWORD dwTimeCur = GetTickCount();
|
|
||||||
if (dwTimeStart == 0)
|
|
||||||
dwTimeStart = dwTimeCur;
|
|
||||||
float t = (dwTimeCur - dwTimeStart) / 1000.0f;
|
|
||||||
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
|
||||||
{
|
{
|
||||||
//FreeConsole();
|
//FreeConsole();
|
||||||
@ -186,11 +168,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
|
|||||||
|
|
||||||
InitializeNodeInstances();
|
InitializeNodeInstances();
|
||||||
|
|
||||||
if (FAILED(InitInput(hInstance))) {
|
|
||||||
print("InitInput\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MSG msg = {};
|
MSG msg = {};
|
||||||
while (msg.message != WM_QUIT) {
|
while (msg.message != WM_QUIT) {
|
||||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||||
@ -212,12 +189,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
|
|||||||
TranslateMessage(&msg);
|
TranslateMessage(&msg);
|
||||||
DispatchMessage(&msg);
|
DispatchMessage(&msg);
|
||||||
} else {
|
} else {
|
||||||
if (Resize()) {
|
if (Resize())
|
||||||
UpdateInput();
|
Render();
|
||||||
float t = GetTime();
|
|
||||||
Update(t);
|
|
||||||
Render(t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1156,6 +1129,11 @@ HRESULT InitDirect3DDevice()
|
|||||||
g_World1 = XMMatrixIdentity();
|
g_World1 = XMMatrixIdentity();
|
||||||
g_World2 = XMMatrixIdentity();
|
g_World2 = XMMatrixIdentity();
|
||||||
|
|
||||||
|
XMVECTOR Eye = XMVectorSet(0.0f, 0.0f, -2.0f, 0.0f);
|
||||||
|
XMVECTOR At = XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
XMVECTOR Up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
|
||||||
|
g_View = XMMatrixLookAtLH(Eye, At, Up);
|
||||||
|
|
||||||
float fFov = XM_PI * 0.5f;
|
float fFov = XM_PI * 0.5f;
|
||||||
float fAspect = width / (float)height;
|
float fAspect = width / (float)height;
|
||||||
float fNear = 0.1f;
|
float fNear = 0.1f;
|
||||||
@ -1461,22 +1439,10 @@ void RenderFont()
|
|||||||
print("g_pVertexBuffersFont->Map");
|
print("g_pVertexBuffersFont->Map");
|
||||||
}
|
}
|
||||||
|
|
||||||
sprint("bloomPasses: %d\n"
|
int length = sprint("bloomPasses: %d\n"
|
||||||
" exposure: %f\n\n"
|
" exposure: %f",
|
||||||
"triggerL: % 5.3f\n"
|
|
||||||
"triggerR: % 5.3f\n"
|
|
||||||
" thumbLX: % 5.3f\n"
|
|
||||||
" thumbLY: % 5.3f\n"
|
|
||||||
" thumbRX: % 5.3f\n"
|
|
||||||
" thumbRY: % 5.3f",
|
|
||||||
g_bloomPasses,
|
g_bloomPasses,
|
||||||
g_exposure,
|
g_exposure);
|
||||||
g_Joystate.triggerL,
|
|
||||||
g_Joystate.triggerR,
|
|
||||||
g_Joystate.thumbLX,
|
|
||||||
g_Joystate.thumbLY,
|
|
||||||
g_Joystate.thumbRX,
|
|
||||||
g_Joystate.thumbRY);
|
|
||||||
|
|
||||||
const char start_advance = 10;
|
const char start_advance = 10;
|
||||||
int hadvance = start_advance;
|
int hadvance = start_advance;
|
||||||
@ -1543,7 +1509,7 @@ void RenderFont()
|
|||||||
|
|
||||||
for (UINT p = 0; p < techDesc.Passes; p++) {
|
for (UINT p = 0; p < techDesc.Passes; p++) {
|
||||||
g_pTechniqueFont->GetPassByIndex(p)->Apply(0);
|
g_pTechniqueFont->GetPassByIndex(p)->Apply(0);
|
||||||
g_pd3dDevice->Draw(ix, 0);
|
g_pd3dDevice->Draw(length, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1626,16 +1592,6 @@ void RenderBloom()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float deadzone(float f)
|
|
||||||
{
|
|
||||||
const float threshold = 0.25f;
|
|
||||||
if (fabsf(f) <= threshold)
|
|
||||||
return 0.0f;
|
|
||||||
else {
|
|
||||||
return copysignf(fabsf(f) - threshold, f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update(float t)
|
void Update(float t)
|
||||||
{
|
{
|
||||||
XMVECTOR vLightDirs[2] = {
|
XMVECTOR vLightDirs[2] = {
|
||||||
@ -1650,19 +1606,6 @@ void Update(float t)
|
|||||||
XMMATRIX mRotate0 = XMMatrixRotationY(0.4f * t);
|
XMMATRIX mRotate0 = XMMatrixRotationY(0.4f * t);
|
||||||
XMVECTOR lightDir0 = XMVector4Transform(vLightDirs[0], mRotate0);
|
XMVECTOR lightDir0 = XMVector4Transform(vLightDirs[0], mRotate0);
|
||||||
XMStoreFloat4(&g_vLightDirs[0], lightDir0);
|
XMStoreFloat4(&g_vLightDirs[0], lightDir0);
|
||||||
|
|
||||||
// view
|
|
||||||
XMMATRIX mRotateView = XMMatrixRotationY(deadzone(g_Joystate.thumbLX) * 0.002f);
|
|
||||||
|
|
||||||
XMMATRIX mTranslateView = XMMatrixTranslation(deadzone(g_Joystate.thumbRX) * 0.002f,
|
|
||||||
0.0f,
|
|
||||||
deadzone(g_Joystate.thumbRY) * 0.002f);
|
|
||||||
|
|
||||||
g_Eye = XMVector4Transform(g_Eye, mTranslateView * mRotateView);
|
|
||||||
XMVECTOR Up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
g_View = XMMatrixLookAtLH(g_Eye, g_At, Up);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderVolume(float t)
|
void RenderVolume(float t)
|
||||||
@ -1738,8 +1681,16 @@ void RenderVolumeMesh()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render(float t)
|
void Render()
|
||||||
{
|
{
|
||||||
|
static DWORD dwTimeStart = 0;
|
||||||
|
DWORD dwTimeCur = GetTickCount();
|
||||||
|
if (dwTimeStart == 0)
|
||||||
|
dwTimeStart = dwTimeCur;
|
||||||
|
float t = (dwTimeCur - dwTimeStart) / 1000.0f;
|
||||||
|
|
||||||
|
Update(t);
|
||||||
|
|
||||||
// clear
|
// clear
|
||||||
|
|
||||||
const float ClearColor[4] = { 0.2f, 0.125f, 0.2f, 1.0f };
|
const float ClearColor[4] = { 0.2f, 0.125f, 0.2f, 1.0f };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user