remove dependency on d3dx

This is mostly because it is not possible to statically link d3dx10.

Coincidentally, the directxmath API appears to be superior to d3dxmath in most
ways.
This commit is contained in:
Zack Buhman 2026-01-13 12:50:02 -06:00
parent 12e04e1f40
commit 7985ad3434
15 changed files with 44561 additions and 19647 deletions

View File

@ -10,6 +10,7 @@ CXXSTD += -std=gnu++14
CFLAGS += -Wall -Werror -Wfatal-errors CFLAGS += -Wall -Werror -Wfatal-errors
CFLAGS += -Wno-unused-but-set-variable CFLAGS += -Wno-unused-but-set-variable
CFLAGS += -Wno-unknown-pragmas
CXXFLAGS += -fno-exceptions CXXFLAGS += -fno-exceptions
CFLAGS += -municode CFLAGS += -municode
@ -47,4 +48,4 @@ OBJS = \
$(BUILD_TYPE)/main.res $(BUILD_TYPE)/main.res
$(BUILD_TYPE)/d3d10.exe: $(OBJS) $(BUILD_TYPE)/d3d10.exe: $(OBJS)
$(CXX) $(LDFLAGS) $(WOPT) -o $@ $(OBJS) -ld3dx10 -ld3d10 $(CXX) $(LDFLAGS) $(WOPT) -o $@ $(OBJS) -ld3d10

View File

@ -1,25 +1,26 @@
#pragma once
#ifndef _CUBE_HPP_ #ifndef _CUBE_HPP_
#define _CUBE_HPP_ #define _CUBE_HPP_
namespace cube { namespace cube {
extern const D3DXVECTOR3 accessor_0[]; extern const XMFLOAT3 accessor_0[];
const int accessor_0__length = 24; const int accessor_0__length = 24;
const int accessor_0__size = (sizeof (D3DXVECTOR3)) * 24; const int accessor_0__size = (sizeof (XMFLOAT3)) * 24;
extern const D3DXVECTOR3 accessor_1[]; extern const XMFLOAT3 accessor_1[];
const int accessor_1__length = 24; const int accessor_1__length = 24;
const int accessor_1__size = (sizeof (D3DXVECTOR3)) * 24; const int accessor_1__size = (sizeof (XMFLOAT3)) * 24;
extern const D3DXVECTOR2 accessor_2[]; extern const XMFLOAT2 accessor_2[];
const int accessor_2__length = 24; const int accessor_2__length = 24;
const int accessor_2__size = (sizeof (D3DXVECTOR2)) * 24; const int accessor_2__size = (sizeof (XMFLOAT2)) * 24;
extern const DWORD accessor_3[]; extern const int accessor_3[];
const int accessor_3__length = 36; const int accessor_3__length = 36;
const int accessor_3__size = (sizeof (DWORD)) * 36; const int accessor_3__size = (sizeof (int)) * 36;
extern const Node node_0; extern const Node node_0;
extern const Node * nodes[]; extern const Node * nodes[];

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,40 +2,40 @@
#define GLTF_HPP_ #define GLTF_HPP_
struct Mesh { struct Mesh {
const D3DXVECTOR3 * position; const XMFLOAT3 * position;
const DWORD position_size; const int position_size;
const D3DXVECTOR3 * normal; const XMFLOAT3 * normal;
const DWORD normal_size; const int normal_size;
const D3DXVECTOR2 * texcoord_0; const XMFLOAT2 * texcoord_0;
const DWORD texcoord_0_size; const int texcoord_0_size;
const D3DXVECTOR4 * weights_0; const XMFLOAT4 * weights_0;
const DWORD weights_0_size; const int weights_0_size;
const D3DXVECTOR4 * joints_0; const XMFLOAT4 * joints_0;
const DWORD joints_0_size; const int joints_0_size;
const DWORD * indices; const int * indices;
const DWORD indices_size; const int indices_size;
}; };
struct Skin; struct Skin;
struct Node { struct Node {
const DWORD parent_ix; const int parent_ix;
const Skin * skin; // skin index (global) const Skin * skin; // skin index (global)
const Mesh * mesh; // mesh index (global) const Mesh * mesh; // mesh index (global)
const D3DXVECTOR3 translation; const XMFLOAT3 translation;
const D3DXQUATERNION rotation; const XMFLOAT4 rotation;
const D3DXVECTOR3 scale; const XMFLOAT3 scale;
}; };
struct Skin { struct Skin {
const D3DXMATRIX * inverse_bind_matrices; // accessor const XMMATRIX * inverse_bind_matrices; // accessor
const int * joints; const int * joints;
DWORD joints_length; int joints_length;
}; };
enum AnimationChannelPath { enum AnimationChannelPath {

View File

@ -2,9 +2,9 @@
#define GLTF_INSTANCE_HPP_ #define GLTF_INSTANCE_HPP_
struct NodeInstance { struct NodeInstance {
D3DXVECTOR3 translation; XMVECTOR translation;
D3DXQUATERNION rotation; XMVECTOR rotation;
D3DXVECTOR3 scale; XMVECTOR scale;
}; };
#endif #endif

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -1,89 +1,89 @@
#include <d3dx9.h> #include "directxmath/directxmath.h"
#include "gltf.hpp" #include "gltf.hpp"
#include "cube.hpp" #include "cube.hpp"
namespace cube { namespace cube {
const D3DXVECTOR3 accessor_0[] = { const XMFLOAT3 accessor_0[] = {
D3DXVECTOR3(-1.0000000f, -1.0000000f, 1.0000000f), XMFLOAT3(-1.0000000f, -1.0000000f, 1.0000000f),
D3DXVECTOR3(-1.0000000f, -1.0000000f, 1.0000000f), XMFLOAT3(-1.0000000f, -1.0000000f, 1.0000000f),
D3DXVECTOR3(-1.0000000f, -1.0000000f, 1.0000000f), XMFLOAT3(-1.0000000f, -1.0000000f, 1.0000000f),
D3DXVECTOR3(-1.0000000f, 1.0000000f, 1.0000000f), XMFLOAT3(-1.0000000f, 1.0000000f, 1.0000000f),
D3DXVECTOR3(-1.0000000f, 1.0000000f, 1.0000000f), XMFLOAT3(-1.0000000f, 1.0000000f, 1.0000000f),
D3DXVECTOR3(-1.0000000f, 1.0000000f, 1.0000000f), XMFLOAT3(-1.0000000f, 1.0000000f, 1.0000000f),
D3DXVECTOR3(-1.0000000f, -1.0000000f, -1.0000000f), XMFLOAT3(-1.0000000f, -1.0000000f, -1.0000000f),
D3DXVECTOR3(-1.0000000f, -1.0000000f, -1.0000000f), XMFLOAT3(-1.0000000f, -1.0000000f, -1.0000000f),
D3DXVECTOR3(-1.0000000f, -1.0000000f, -1.0000000f), XMFLOAT3(-1.0000000f, -1.0000000f, -1.0000000f),
D3DXVECTOR3(-1.0000000f, 1.0000000f, -1.0000000f), XMFLOAT3(-1.0000000f, 1.0000000f, -1.0000000f),
D3DXVECTOR3(-1.0000000f, 1.0000000f, -1.0000000f), XMFLOAT3(-1.0000000f, 1.0000000f, -1.0000000f),
D3DXVECTOR3(-1.0000000f, 1.0000000f, -1.0000000f), XMFLOAT3(-1.0000000f, 1.0000000f, -1.0000000f),
D3DXVECTOR3( 1.0000000f, -1.0000000f, 1.0000000f), XMFLOAT3( 1.0000000f, -1.0000000f, 1.0000000f),
D3DXVECTOR3( 1.0000000f, -1.0000000f, 1.0000000f), XMFLOAT3( 1.0000000f, -1.0000000f, 1.0000000f),
D3DXVECTOR3( 1.0000000f, -1.0000000f, 1.0000000f), XMFLOAT3( 1.0000000f, -1.0000000f, 1.0000000f),
D3DXVECTOR3( 1.0000000f, 1.0000000f, 1.0000000f), XMFLOAT3( 1.0000000f, 1.0000000f, 1.0000000f),
D3DXVECTOR3( 1.0000000f, 1.0000000f, 1.0000000f), XMFLOAT3( 1.0000000f, 1.0000000f, 1.0000000f),
D3DXVECTOR3( 1.0000000f, 1.0000000f, 1.0000000f), XMFLOAT3( 1.0000000f, 1.0000000f, 1.0000000f),
D3DXVECTOR3( 1.0000000f, -1.0000000f, -1.0000000f), XMFLOAT3( 1.0000000f, -1.0000000f, -1.0000000f),
D3DXVECTOR3( 1.0000000f, -1.0000000f, -1.0000000f), XMFLOAT3( 1.0000000f, -1.0000000f, -1.0000000f),
D3DXVECTOR3( 1.0000000f, -1.0000000f, -1.0000000f), XMFLOAT3( 1.0000000f, -1.0000000f, -1.0000000f),
D3DXVECTOR3( 1.0000000f, 1.0000000f, -1.0000000f), XMFLOAT3( 1.0000000f, 1.0000000f, -1.0000000f),
D3DXVECTOR3( 1.0000000f, 1.0000000f, -1.0000000f), XMFLOAT3( 1.0000000f, 1.0000000f, -1.0000000f),
D3DXVECTOR3( 1.0000000f, 1.0000000f, -1.0000000f), XMFLOAT3( 1.0000000f, 1.0000000f, -1.0000000f),
}; };
const D3DXVECTOR3 accessor_1[] = { const XMFLOAT3 accessor_1[] = {
D3DXVECTOR3( 0.0000000f, 0.0000000f, 1.0000000f), XMFLOAT3( 0.0000000f, 0.0000000f, 1.0000000f),
D3DXVECTOR3( 0.0000000f, -1.0000000f, 0.0000000f), XMFLOAT3( 0.0000000f, -1.0000000f, 0.0000000f),
D3DXVECTOR3(-1.0000000f, 0.0000000f, 0.0000000f), XMFLOAT3(-1.0000000f, 0.0000000f, 0.0000000f),
D3DXVECTOR3( 0.0000000f, 0.0000000f, 1.0000000f), XMFLOAT3( 0.0000000f, 0.0000000f, 1.0000000f),
D3DXVECTOR3( 0.0000000f, 1.0000000f, 0.0000000f), XMFLOAT3( 0.0000000f, 1.0000000f, 0.0000000f),
D3DXVECTOR3(-1.0000000f, 0.0000000f, 0.0000000f), XMFLOAT3(-1.0000000f, 0.0000000f, 0.0000000f),
D3DXVECTOR3( 0.0000000f, 0.0000000f, -1.0000000f), XMFLOAT3( 0.0000000f, 0.0000000f, -1.0000000f),
D3DXVECTOR3( 0.0000000f, -1.0000000f, 0.0000000f), XMFLOAT3( 0.0000000f, -1.0000000f, 0.0000000f),
D3DXVECTOR3(-1.0000000f, 0.0000000f, 0.0000000f), XMFLOAT3(-1.0000000f, 0.0000000f, 0.0000000f),
D3DXVECTOR3( 0.0000000f, 0.0000000f, -1.0000000f), XMFLOAT3( 0.0000000f, 0.0000000f, -1.0000000f),
D3DXVECTOR3( 0.0000000f, 1.0000000f, 0.0000000f), XMFLOAT3( 0.0000000f, 1.0000000f, 0.0000000f),
D3DXVECTOR3(-1.0000000f, 0.0000000f, 0.0000000f), XMFLOAT3(-1.0000000f, 0.0000000f, 0.0000000f),
D3DXVECTOR3( 0.0000000f, 0.0000000f, 1.0000000f), XMFLOAT3( 0.0000000f, 0.0000000f, 1.0000000f),
D3DXVECTOR3( 0.0000000f, -1.0000000f, 0.0000000f), XMFLOAT3( 0.0000000f, -1.0000000f, 0.0000000f),
D3DXVECTOR3( 1.0000000f, 0.0000000f, 0.0000000f), XMFLOAT3( 1.0000000f, 0.0000000f, 0.0000000f),
D3DXVECTOR3( 0.0000000f, 0.0000000f, 1.0000000f), XMFLOAT3( 0.0000000f, 0.0000000f, 1.0000000f),
D3DXVECTOR3( 0.0000000f, 1.0000000f, 0.0000000f), XMFLOAT3( 0.0000000f, 1.0000000f, 0.0000000f),
D3DXVECTOR3( 1.0000000f, 0.0000000f, 0.0000000f), XMFLOAT3( 1.0000000f, 0.0000000f, 0.0000000f),
D3DXVECTOR3( 0.0000000f, 0.0000000f, -1.0000000f), XMFLOAT3( 0.0000000f, 0.0000000f, -1.0000000f),
D3DXVECTOR3( 0.0000000f, -1.0000000f, 0.0000000f), XMFLOAT3( 0.0000000f, -1.0000000f, 0.0000000f),
D3DXVECTOR3( 1.0000000f, 0.0000000f, 0.0000000f), XMFLOAT3( 1.0000000f, 0.0000000f, 0.0000000f),
D3DXVECTOR3( 0.0000000f, 0.0000000f, -1.0000000f), XMFLOAT3( 0.0000000f, 0.0000000f, -1.0000000f),
D3DXVECTOR3( 0.0000000f, 1.0000000f, 0.0000000f), XMFLOAT3( 0.0000000f, 1.0000000f, 0.0000000f),
D3DXVECTOR3( 1.0000000f, 0.0000000f, 0.0000000f), XMFLOAT3( 1.0000000f, 0.0000000f, 0.0000000f),
}; };
const D3DXVECTOR2 accessor_2[] = { const XMFLOAT2 accessor_2[] = {
D3DXVECTOR2( 0.3750000f, 0.0000000f), XMFLOAT2( 0.3750000f, 0.0000000f),
D3DXVECTOR2( 0.1250000f, 0.2500000f), XMFLOAT2( 0.1250000f, 0.2500000f),
D3DXVECTOR2( 0.3750000f, 1.0000000f), XMFLOAT2( 0.3750000f, 1.0000000f),
D3DXVECTOR2( 0.6250000f, 0.0000000f), XMFLOAT2( 0.6250000f, 0.0000000f),
D3DXVECTOR2( 0.8750000f, 0.2500000f), XMFLOAT2( 0.8750000f, 0.2500000f),
D3DXVECTOR2( 0.6250000f, 1.0000000f), XMFLOAT2( 0.6250000f, 1.0000000f),
D3DXVECTOR2( 0.3750000f, 0.7500000f), XMFLOAT2( 0.3750000f, 0.7500000f),
D3DXVECTOR2( 0.1250000f, 0.5000000f), XMFLOAT2( 0.1250000f, 0.5000000f),
D3DXVECTOR2( 0.3750000f, 0.7500000f), XMFLOAT2( 0.3750000f, 0.7500000f),
D3DXVECTOR2( 0.6250000f, 0.7500000f), XMFLOAT2( 0.6250000f, 0.7500000f),
D3DXVECTOR2( 0.8750000f, 0.5000000f), XMFLOAT2( 0.8750000f, 0.5000000f),
D3DXVECTOR2( 0.6250000f, 0.7500000f), XMFLOAT2( 0.6250000f, 0.7500000f),
D3DXVECTOR2( 0.3750000f, 0.2500000f), XMFLOAT2( 0.3750000f, 0.2500000f),
D3DXVECTOR2( 0.3750000f, 0.2500000f), XMFLOAT2( 0.3750000f, 0.2500000f),
D3DXVECTOR2( 0.3750000f, 0.2500000f), XMFLOAT2( 0.3750000f, 0.2500000f),
D3DXVECTOR2( 0.6250000f, 0.2500000f), XMFLOAT2( 0.6250000f, 0.2500000f),
D3DXVECTOR2( 0.6250000f, 0.2500000f), XMFLOAT2( 0.6250000f, 0.2500000f),
D3DXVECTOR2( 0.6250000f, 0.2500000f), XMFLOAT2( 0.6250000f, 0.2500000f),
D3DXVECTOR2( 0.3750000f, 0.5000000f), XMFLOAT2( 0.3750000f, 0.5000000f),
D3DXVECTOR2( 0.3750000f, 0.5000000f), XMFLOAT2( 0.3750000f, 0.5000000f),
D3DXVECTOR2( 0.3750000f, 0.5000000f), XMFLOAT2( 0.3750000f, 0.5000000f),
D3DXVECTOR2( 0.6250000f, 0.5000000f), XMFLOAT2( 0.6250000f, 0.5000000f),
D3DXVECTOR2( 0.6250000f, 0.5000000f), XMFLOAT2( 0.6250000f, 0.5000000f),
D3DXVECTOR2( 0.6250000f, 0.5000000f), XMFLOAT2( 0.6250000f, 0.5000000f),
}; };
const DWORD accessor_3[] = { const int accessor_3[] = {
2, 2,
5, 5,
11, 11,
@ -138,12 +138,12 @@ const Mesh mesh_0 = {
}; };
const Node node_0 = { const Node node_0 = {
(DWORD)-1, // parent_ix (int)-1, // parent_ix
NULL, // skin NULL, // skin
&mesh_0, // mesh &mesh_0, // mesh
D3DXVECTOR3( 0.0000000f, 0.0000000f, 0.0000000f), // translation XMFLOAT3( 0.0000000f, 0.0000000f, 0.0000000f), // translation
D3DXQUATERNION( 0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f), // rotation XMFLOAT4( 0.0000000f, 0.0000000f, 0.0000000f, 1.0000000f), // rotation
D3DXVECTOR3( 1.0000000f, 1.0000000f, 1.0000000f), // scale XMFLOAT3( 1.0000000f, 1.0000000f, 1.0000000f), // scale
}; };
const Node * nodes[] = { const Node * nodes[] = {

View File

@ -1,9 +1,10 @@
#include <windows.h> #include <windows.h>
#include <d3d10.h> #include <d3d10.h>
#include <d3dx9.h>
#include <assert.h> #include <assert.h>
#include <strsafe.h> #include <strsafe.h>
#include "directxmath/directxmath.h"
#include "globals.hpp" #include "globals.hpp"
#include "print.hpp" #include "print.hpp"
#include "render_state.hpp" #include "render_state.hpp"
@ -12,7 +13,7 @@
#include "gltf_instance.hpp" #include "gltf_instance.hpp"
#include "robot_player.hpp" #include "robot_player.hpp"
#define ROOT_MESH_NODE node_39 #define ROOT_MESH_NODE robot_player::node_39
#include "cube.hpp" #include "cube.hpp"
HINSTANCE g_hInstance = NULL; HINSTANCE g_hInstance = NULL;
@ -40,10 +41,10 @@ ID3D10EffectMatrixVariable * g_pJointVariable = NULL;
ID3D10EffectVectorVariable * g_pLightDirVariable = NULL; ID3D10EffectVectorVariable * g_pLightDirVariable = NULL;
ID3D10EffectVectorVariable * g_pLightColorVariable = NULL; ID3D10EffectVectorVariable * g_pLightColorVariable = NULL;
ID3D10EffectShaderResourceVariable * g_pDiffuseVariable = NULL; ID3D10EffectShaderResourceVariable * g_pDiffuseVariable = NULL;
D3DXMATRIX g_World1; XMMATRIX g_World1;
D3DXMATRIX g_World2; XMMATRIX g_World2;
D3DXMATRIX g_View; XMMATRIX g_View;
D3DXMATRIX g_Projection; XMMATRIX g_Projection;
// bloom // bloom
ID3D10RenderTargetView * g_pRenderTargetViewTexture[2] = { NULL, NULL }; ID3D10RenderTargetView * g_pRenderTargetViewTexture[2] = { NULL, NULL };
@ -67,7 +68,7 @@ int g_bloomPasses = 4;
float g_exposure = 3.4f; float g_exposure = 3.4f;
#endif #endif
typedef D3DXVECTOR2 BloomVertex; typedef XMFLOAT2 BloomVertex;
// font // font
ID3D10Effect * g_pEffectFont = NULL; ID3D10Effect * g_pEffectFont = NULL;
@ -82,7 +83,7 @@ ID3D10EffectVectorVariable * g_pTexScaleVariableFont = NULL;
ID3D10EffectShaderResourceVariable * g_pDiffuseVariableFont = NULL; ID3D10EffectShaderResourceVariable * g_pDiffuseVariableFont = NULL;
const int g_iFontBufferLength = 512; const int g_iFontBufferLength = 512;
typedef D3DXVECTOR4 FontVertex; typedef XMFLOAT4 FontVertex;
// perlin // perlin
ID3D10Effect * g_pEffectVolume = NULL; ID3D10Effect * g_pEffectVolume = NULL;
@ -112,10 +113,10 @@ ID3D10Buffer * g_pVertexBufferCube[g_dwVertexBufferCountCube];
ID3D10Buffer * g_pIndexBufferCube = NULL; ID3D10Buffer * g_pIndexBufferCube = NULL;
// lights // lights
D3DXVECTOR4 g_vLightDirs[2]; XMFLOAT4 g_vLightDirs[2];
D3DXVECTOR4 g_vLightColors[2] = { XMFLOAT4 g_vLightColors[2] = {
D3DXVECTOR4(0.0f, 0.9f, 0.9f, 1.0f), XMFLOAT4(0.0f, 0.9f, 0.9f, 1.0f),
D3DXVECTOR4(0.9f, 0.0f, 0.0f, 1.0f) XMFLOAT4(0.9f, 0.0f, 0.0f, 1.0f)
}; };
// forward declarations // forward declarations
@ -608,16 +609,16 @@ HRESULT InitVolumeBuffers()
D3D10_BUFFER_DESC bd; D3D10_BUFFER_DESC bd;
D3D10_SUBRESOURCE_DATA initData; D3D10_SUBRESOURCE_DATA initData;
const D3DXVECTOR2 position[] = { const XMFLOAT2 position[] = {
D3DXVECTOR2(-1, 1), XMFLOAT2(-1, 1),
D3DXVECTOR2( 1, 1), XMFLOAT2( 1, 1),
D3DXVECTOR2(-1, -1), XMFLOAT2(-1, -1),
D3DXVECTOR2( 1, -1), XMFLOAT2( 1, -1),
}; };
// position // position
bd.Usage = D3D10_USAGE_DEFAULT; bd.Usage = D3D10_USAGE_DEFAULT;
bd.ByteWidth = (sizeof (D3DXVECTOR2)) * 4; bd.ByteWidth = (sizeof (XMFLOAT2)) * 4;
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0; bd.CPUAccessFlags = 0;
bd.MiscFlags = 0; bd.MiscFlags = 0;
@ -632,11 +633,11 @@ HRESULT InitVolumeBuffers()
} }
// +Y is up // +Y is up
D3DXVECTOR2 vtxBloom[] = { XMFLOAT2 vtxBloom[] = {
D3DXVECTOR2(-1, -1), // top left XMFLOAT2(-1, -1), // top left
D3DXVECTOR2(-1, 1), // top right XMFLOAT2(-1, 1), // top right
D3DXVECTOR2( 1, -1), // bottom left XMFLOAT2( 1, -1), // bottom left
D3DXVECTOR2( 1, 1), // bottom right XMFLOAT2( 1, 1), // bottom right
}; };
HRESULT InitBloomBuffers() HRESULT InitBloomBuffers()
@ -1038,23 +1039,22 @@ HRESULT InitDirect3DDevice()
// transform matrices // transform matrices
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
D3DXMatrixIdentity(&g_World1); g_World1 = XMMatrixIdentity();
D3DXMatrixIdentity(&g_World2); g_World2 = XMMatrixIdentity();
D3DXVECTOR3 Eye(0.0f, 1.0f, -2.0f); XMVECTOR Eye = XMVectorSet(0.0f, 1.0f, -2.0f, 0.0f);
D3DXVECTOR3 At(0.0f, 1.0f, 0.0f); XMVECTOR At = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
D3DXVECTOR3 Up(0.0f, 1.0f, 0.0f); XMVECTOR Up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
D3DXMatrixLookAtLH(&g_View, &Eye, &At, &Up); g_View = XMMatrixLookAtLH(Eye, At, Up);
float fFov = (float)D3DX_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;
float fFar = 100.0f; float fFar = 100.0f;
D3DXMatrixPerspectiveFovLH(&g_Projection, g_Projection = XMMatrixPerspectiveFovLH(fFov,
fFov, fAspect,
fAspect, fNear,
fNear, fFar);
fFar);
return S_OK; return S_OK;
} }
@ -1086,31 +1086,27 @@ BOOL Resize()
InitDirect3DViews(); InitDirect3DViews();
float fFov = (float)D3DX_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;
float fFar = 100.0f; float fFar = 100.0f;
D3DXMatrixPerspectiveFovLH(&g_Projection, g_Projection = XMMatrixPerspectiveFovLH(fFov,
fFov, fAspect,
fAspect, fNear,
fNear, fFar);
fFar);
return true; return true;
} }
static inline D3DXMATRIX MatrixTRS(const D3DXVECTOR3 * translation, static inline XMMATRIX MatrixTRS(FXMVECTOR translation,
const D3DXQUATERNION * rotation, FXMVECTOR rotation,
const D3DXVECTOR3 * scaling) FXMVECTOR scaling)
{ {
D3DXMATRIX mTranslation; XMMATRIX mTranslation = XMMatrixTranslationFromVector(translation);
D3DXMatrixTranslation(&mTranslation, translation->x, translation->y, translation->z);
D3DXMATRIX mRotation; XMMATRIX mRotation = XMMatrixRotationQuaternion(rotation);
D3DXMatrixRotationQuaternion(&mRotation, rotation);
D3DXMATRIX mScaling; XMMATRIX mScaling = XMMatrixScalingFromVector(scaling);
D3DXMatrixScaling(&mScaling, scaling->x, scaling->y, scaling->z);
//return mScaling * mRotation * mTranslation; //return mScaling * mRotation * mTranslation;
return mScaling * mRotation * mTranslation; return mScaling * mRotation * mTranslation;
@ -1141,34 +1137,27 @@ static inline float Lerp(const float * frames, float t, int frame_ix)
return (t - frames[frame_ix]) / (frames[frame_ix + 1] - frames[frame_ix]); return (t - frames[frame_ix]) / (frames[frame_ix + 1] - frames[frame_ix]);
} }
const int joints_length = skin_0__joints__length; const int joints_length = robot_player::skin_0__joints__length;
D3DXMATRIX mJoints[joints_length]; XMMATRIX mJoints[joints_length];
NodeInstance node_inst[nodes__length]; NodeInstance node_inst[robot_player::nodes__length];
void InitializeNodeInstances() void InitializeNodeInstances()
{ {
for (int i = 0; i < nodes__length; i++) { const Node ** nodes = robot_player::nodes;
node_inst[i].translation = nodes[i]->translation; for (int i = 0; i < robot_player::nodes__length; i++) {
node_inst[i].rotation = nodes[i]->rotation; node_inst[i].translation = XMLoadFloat3((const XMFLOAT3 *)&nodes[i]->translation);
node_inst[i].scale = nodes[i]->scale; node_inst[i].rotation = XMLoadFloat4((const XMFLOAT4 *)&nodes[i]->rotation);
node_inst[i].scale = XMLoadFloat3((const XMFLOAT3 *)&nodes[i]->scale);
} }
} }
void VectorLerp(D3DXVECTOR3 * output, XMMATRIX GlobalTransform(int node_ix)
const D3DXVECTOR3 * a,
const D3DXVECTOR3 * b,
const float t)
{
*output = *a + t * (*b - *a);
}
D3DXMATRIX GlobalTransform(int node_ix)
{ {
const NodeInstance * instance = &node_inst[node_ix]; const NodeInstance * instance = &node_inst[node_ix];
const Node * node = nodes[node_ix]; const Node * node = robot_player::nodes[node_ix];
D3DXMATRIX local_transform = MatrixTRS(&instance->translation, XMMATRIX local_transform = MatrixTRS(XMLoadFloat3((const XMFLOAT3*)&instance->translation),
&instance->rotation, XMLoadFloat4((const XMFLOAT4*)&instance->rotation),
&instance->scale); XMLoadFloat3((const XMFLOAT3*)&instance->scale));
if (((int)node->parent_ix) != 40) { if (((int)node->parent_ix) != 40) {
return local_transform * GlobalTransform(node->parent_ix); return local_transform * GlobalTransform(node->parent_ix);
} else { } else {
@ -1178,8 +1167,8 @@ D3DXMATRIX GlobalTransform(int node_ix)
void Animate(float t) void Animate(float t)
{ {
const AnimationChannel * channels = animation_1__channels; const AnimationChannel * channels = robot_player::animation_1__channels;
const int channels_length = animation_1__channels__length; const int channels_length = robot_player::animation_1__channels__length;
t = loop(t, 3.75); t = loop(t, 3.75);
@ -1197,29 +1186,26 @@ void Animate(float t)
switch (channels[i].target.path) { switch (channels[i].target.path) {
case ACP__TRANSLATION: case ACP__TRANSLATION:
{ {
const D3DXVECTOR3 * output = (const D3DXVECTOR3 *)sampler->output; const XMFLOAT3 * output = (const XMFLOAT3 *)sampler->output;
VectorLerp(&instance->translation, instance->translation = XMVectorLerp(XMLoadFloat3(&output[frame_ix]),
&output[frame_ix], XMLoadFloat3(&output[frame_ix+1]),
&output[frame_ix+1], lerp);
lerp);
break; break;
} }
case ACP__ROTATION: case ACP__ROTATION:
{ {
const D3DXQUATERNION * output = (const D3DXQUATERNION *)sampler->output; const XMFLOAT4 * output = (const XMFLOAT4 *)sampler->output;
D3DXQuaternionSlerp(&instance->rotation, instance->rotation = XMQuaternionSlerp(XMLoadFloat4(&output[frame_ix]),
&output[frame_ix], XMLoadFloat4(&output[frame_ix+1]),
&output[frame_ix+1], lerp);
lerp);
break; break;
} }
case ACP__SCALE: case ACP__SCALE:
{ {
const D3DXVECTOR3 * output = (const D3DXVECTOR3 *)sampler->output; const XMFLOAT3 * output = (const XMFLOAT3 *)sampler->output;
VectorLerp(&instance->scale, instance->scale = XMVectorLerp(XMLoadFloat3(&output[frame_ix]),
&output[frame_ix], XMLoadFloat3(&output[frame_ix+1]),
&output[frame_ix+1], lerp);
lerp);
break; break;
} }
default: default:
@ -1230,11 +1216,11 @@ void Animate(float t)
// transform all joints // transform all joints
const Skin * skin = ROOT_MESH_NODE.skin; const Skin * skin = ROOT_MESH_NODE.skin;
for (DWORD i = 0; i < skin->joints_length; i++) { for (int i = 0; i < skin->joints_length; i++) {
const int joint_ix = skin->joints[i]; const int joint_ix = skin->joints[i];
assert(joint_ix >= 0); assert(joint_ix >= 0);
const D3DXMATRIX& inverse_bind_matrix = skin->inverse_bind_matrices[i]; const XMMATRIX inverse_bind_matrix = XMMATRIX((const float*)&skin->inverse_bind_matrices[i]);
mJoints[i] = inverse_bind_matrix * GlobalTransform(joint_ix); mJoints[i] = inverse_bind_matrix * GlobalTransform(joint_ix);
} }
} }
@ -1242,17 +1228,13 @@ void Animate(float t)
void RenderModel(float t) void RenderModel(float t)
{ {
for (int i = 0; i < joints_length; i++) { for (int i = 0; i < joints_length; i++) {
D3DXMatrixIdentity(&mJoints[i]); mJoints[i] = XMMatrixIdentity();
} }
Animate(t); Animate(t);
D3DXMATRIX rx; XMMATRIX rx = XMMatrixRotationX(XM_PI * -0.0f);
D3DXMATRIX ry; XMMATRIX ry = XMMatrixRotationY(XM_PI * -1.0f + t);
D3DXMatrixRotationY(&ry, (float)D3DX_PI * -1.0f + t); g_World1 = XMMatrixMultiply(rx, ry);
D3DXMatrixRotationX(&rx, (float)D3DX_PI * -0.0f);
D3DXMatrixMultiply(&g_World1,
&rx,
&ry);
// matrices // matrices
g_pViewVariable->SetMatrix((float *)&g_View); g_pViewVariable->SetMatrix((float *)&g_View);
@ -1313,20 +1295,18 @@ void RenderMeshStatic(const Mesh * mesh, float t)
int indices_length = mesh->indices_size / (sizeof (DWORD)); int indices_length = mesh->indices_size / (sizeof (DWORD));
for (int m = 0; m < 2; m++) { for (int m = 0; m < 2; m++) {
D3DXMATRIX mLight; XMVECTOR vDir = XMLoadFloat4(&g_vLightDirs[m]);
D3DXMATRIX mLightScale; XMVECTOR vLightPos = vDir * (1.25f * (m + 1));
D3DXVECTOR3 vDir = D3DXVECTOR3(g_vLightDirs[m]);
D3DXVECTOR3 vLightPos = vDir * (1.25f * (m + 1)); XMMATRIX mLightRotate = XMMatrixRotationX(t * (1 + -2 * m));
D3DXMATRIX mLightRotate; XMMATRIX mLightTranslation = XMMatrixTranslationFromVector(vLightPos);
D3DXMatrixRotationX(&mLightRotate, t * (1 + -2 * m)); XMMATRIX mLightScale = XMMatrixScaling(0.05f, 0.05f, 0.05f);
D3DXMatrixTranslation(&mLight, vLightPos.x, vLightPos.y, vLightPos.z);
D3DXMatrixScaling(&mLightScale, 0.05f, 0.05f, 0.05f); XMMATRIX mLight = mLightRotate * mLightScale * mLightTranslation;
mLight = mLightRotate * mLightScale * mLight;
g_pWorldVariableStatic->SetMatrix((float *)&mLight); g_pWorldVariableStatic->SetMatrix((float *)&mLight);
D3DXMATRIX mLightNormal; XMMATRIX mLightNormal = XMMatrixTranspose(XMMatrixInverse(NULL, mLight));
D3DXMatrixTranspose(&mLightNormal, D3DXMatrixInverse(&mLightNormal, NULL, &mLight));
g_pWorldNormalVariableStatic->SetMatrix((float *)&mLightNormal); g_pWorldNormalVariableStatic->SetMatrix((float *)&mLightNormal);
g_pOutputColorVariableStatic->SetFloatVector((float *)&g_vLightColors[m]); g_pOutputColorVariableStatic->SetFloatVector((float *)&g_vLightColors[m]);
@ -1412,16 +1392,14 @@ void RenderFont()
// effect variables // effect variables
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
D3DXVECTOR2 invScreenSize = D3DXVECTOR2(2.0f / (float)g_ViewportSize.Width, XMFLOAT2 invScreenSize = XMFLOAT2(2.0f / (float)g_ViewportSize.Width,
2.0f / (float)g_ViewportSize.Height); 2.0f / (float)g_ViewportSize.Height);
D3DXVECTOR2 position = D3DXVECTOR2(6, 0); XMFLOAT2 glyphScale = XMFLOAT2((float)g_FontSize.Glyph.Width,
D3DXVECTOR2 glyphScale = D3DXVECTOR2((float)g_FontSize.Glyph.Width, (float)g_FontSize.Glyph.Height);
(float)g_FontSize.Glyph.Height);
D3DXVECTOR2 charCoord = D3DXVECTOR2(16, 0); XMFLOAT2 texScale = XMFLOAT2(glyphScale.x / (float)g_FontSize.Texture.Width,
D3DXVECTOR2 texScale = D3DXVECTOR2(glyphScale.x / (float)g_FontSize.Texture.Width, glyphScale.y / (float)g_FontSize.Texture.Height);
glyphScale.y / (float)g_FontSize.Texture.Height);
g_pInvScreenSizeVariableFont->SetFloatVector((float *)&invScreenSize); g_pInvScreenSizeVariableFont->SetFloatVector((float *)&invScreenSize);
g_pGlyphScaleVariableFont->SetFloatVector((float *)&glyphScale); g_pGlyphScaleVariableFont->SetFloatVector((float *)&glyphScale);
@ -1453,8 +1431,8 @@ void RenderBloom()
// effect variables // effect variables
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
D3DXVECTOR2 invScreenSize = D3DXVECTOR2(1.0f / (float)g_ViewportSize.Width, XMFLOAT2 invScreenSize = XMFLOAT2(1.0f / (float)g_ViewportSize.Width,
1.0f / (float)g_ViewportSize.Height); 1.0f / (float)g_ViewportSize.Height);
g_pInvScreenSizeVariableBloom->SetFloatVector((float *)&invScreenSize); g_pInvScreenSizeVariableBloom->SetFloatVector((float *)&invScreenSize);
@ -1473,11 +1451,11 @@ void RenderBloom()
g_pExposureVariableBloom->SetFloat(g_exposure); g_pExposureVariableBloom->SetFloat(g_exposure);
D3DXVECTOR2 dirHorizontal = D3DXVECTOR2(1.0, 0.0); XMFLOAT2 dirHorizontal = XMFLOAT2(1.0, 0.0);
D3DXVECTOR2 dirVertical = D3DXVECTOR2(0.0, 1.0); XMFLOAT2 dirVertical = XMFLOAT2(0.0, 1.0);
// horizontal // horizontal
g_pDirVariableBloom->SetFloatVector((float *)dirHorizontal); g_pDirVariableBloom->SetFloatVector((float *)&dirHorizontal);
g_pDiffuseAVariableBloom->SetResource(g_pRenderTargetShaderResourceViewTexture[0]); g_pDiffuseAVariableBloom->SetResource(g_pRenderTargetShaderResourceViewTexture[0]);
g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetViewTexture[1], NULL); g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetViewTexture[1], NULL);
for (UINT p = 0; p < techDesc.Passes; p++) { for (UINT p = 0; p < techDesc.Passes; p++) {
@ -1492,7 +1470,7 @@ void RenderBloom()
g_pd3dDevice->PSSetShaderResources(0, 1, srv); g_pd3dDevice->PSSetShaderResources(0, 1, srv);
// vertical // vertical
g_pDirVariableBloom->SetFloatVector((float *)dirVertical); g_pDirVariableBloom->SetFloatVector((float *)&dirVertical);
g_pDiffuseAVariableBloom->SetResource(g_pRenderTargetShaderResourceViewTexture[1]); g_pDiffuseAVariableBloom->SetResource(g_pRenderTargetShaderResourceViewTexture[1]);
g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetViewTexture[0], NULL); g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetViewTexture[0], NULL);
for (UINT p = 0; p < techDesc.Passes; p++) { for (UINT p = 0; p < techDesc.Passes; p++) {
@ -1503,7 +1481,7 @@ void RenderBloom()
g_pd3dDevice->PSSetShaderResources(0, 1, srv); g_pd3dDevice->PSSetShaderResources(0, 1, srv);
// horizontal // horizontal
g_pDirVariableBloom->SetFloatVector((float *)dirHorizontal); g_pDirVariableBloom->SetFloatVector((float *)&dirHorizontal);
g_pDiffuseAVariableBloom->SetResource(g_pRenderTargetShaderResourceViewTexture[0]); g_pDiffuseAVariableBloom->SetResource(g_pRenderTargetShaderResourceViewTexture[0]);
g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetViewTexture[1], NULL); g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetViewTexture[1], NULL);
for (UINT p = 0; p < techDesc.Passes; p++) { for (UINT p = 0; p < techDesc.Passes; p++) {
@ -1516,7 +1494,7 @@ void RenderBloom()
g_pTechniqueBloomBlend->GetDesc(&techDescBlend); g_pTechniqueBloomBlend->GetDesc(&techDescBlend);
// vertical // vertical
g_pDirVariableBloom->SetFloatVector((float *)dirVertical); g_pDirVariableBloom->SetFloatVector((float *)&dirVertical);
g_pDiffuseAVariableBloom->SetResource(g_pRenderTargetShaderResourceViewTexture[1]); g_pDiffuseAVariableBloom->SetResource(g_pRenderTargetShaderResourceViewTexture[1]);
g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetView, NULL); g_pd3dDevice->OMSetRenderTargets(1, &g_pRenderTargetView, NULL);
@ -1528,27 +1506,25 @@ void RenderBloom()
void Update(float t) void Update(float t)
{ {
D3DXVECTOR4 vLightDirs[2] = { XMVECTOR vLightDirs[2] = {
D3DXVECTOR4(-0.577f, 0.577f, 0.0, 1.0f), {-0.577f, 0.577f, 0.0, 1.0},
D3DXVECTOR4(1.0f, 1.5f, 0.0f, 1.0f), {1.0f, 1.5f, 0.0f, 1.0},
}; };
D3DXVec4Normalize(&vLightDirs[0], &vLightDirs[0]);
D3DXVec4Normalize(&vLightDirs[1], &vLightDirs[1]);
D3DXMATRIX mRotate; XMMATRIX mRotate1 = XMMatrixRotationY(-1.0f * t);
D3DXVECTOR4 vOutDir; XMVECTOR lightDir1 = XMVector4Transform(vLightDirs[1], mRotate1);
D3DXMatrixRotationY(&mRotate, -1.0f * t); XMStoreFloat4(&g_vLightDirs[1], lightDir1);
D3DXVec3Transform(&g_vLightDirs[1], (D3DXVECTOR3 *)&vLightDirs[1], &mRotate);
D3DXMatrixRotationY(&mRotate, 0.4f * t); XMMATRIX mRotate0 = XMMatrixRotationY(0.4f * t);
D3DXVec3Transform(&g_vLightDirs[0], (D3DXVECTOR3 *)&vLightDirs[0], &mRotate); XMVECTOR lightDir0 = XMVector4Transform(vLightDirs[0], mRotate0);
XMStoreFloat4(&g_vLightDirs[0], lightDir0);
} }
void RenderVolume(float t) void RenderVolume(float t)
{ {
UINT stride[] = { UINT stride[] = {
(sizeof (D3DXVECTOR2)), (sizeof (XMFLOAT2)),
}; };
UINT offset[] = { 0 }; UINT offset[] = { 0 };
g_pd3dDevice->IASetInputLayout(g_pVertexLayoutVolume); g_pd3dDevice->IASetInputLayout(g_pVertexLayoutVolume);
@ -1590,16 +1566,14 @@ void RenderVolumeMesh()
D3D10_TECHNIQUE_DESC techDesc; D3D10_TECHNIQUE_DESC techDesc;
g_pTechniqueStatic->GetDesc(&techDesc); g_pTechniqueStatic->GetDesc(&techDesc);
D3DXMATRIX mWorldScale; XMMATRIX mWorldScale = XMMatrixScaling(0.2f, 0.2f, 0.2f);
D3DXMATRIX mWorldTranslate; XMMATRIX mWorldTranslate = XMMatrixTranslation(0.5f, 0.5f, 0.5f);
D3DXMatrixScaling(&mWorldScale, 0.2f, 0.2f, 0.2f); XMMATRIX mWorld = mWorldScale * mWorldTranslate;
D3DXMatrixTranslation(&mWorldTranslate, 0.5f, 0.5f, 0.5f);
D3DXMATRIX mWorld = mWorldScale * mWorldTranslate;
g_pWorldVariableStatic->SetMatrix((float *)&mWorld); g_pWorldVariableStatic->SetMatrix((float *)&mWorld);
D3DXMatrixIdentity(&mWorld); XMMATRIX mWorldNormal = XMMatrixIdentity();
g_pWorldNormalVariableStatic->SetMatrix((float *)&mWorld); g_pWorldNormalVariableStatic->SetMatrix((float *)&mWorldNormal);
D3DXVECTOR4 vColor = D3DXVECTOR4(0.0f, 0.9f, 0.0f, 1.0f) ; XMVECTOR vColor = XMVectorSet(0.0f, 0.9f, 0.0f, 1.0f);
g_pOutputColorVariableStatic->SetFloatVector((float *)&vColor); g_pOutputColorVariableStatic->SetFloatVector((float *)&vColor);
for (UINT p = 0; p < techDesc.Passes; p++) { for (UINT p = 0; p < techDesc.Passes; p++) {
@ -1612,7 +1586,7 @@ void Render()
{ {
static float t = 0.0f; static float t = 0.0f;
#ifdef _DEBUG #ifdef _DEBUG
t += (float)D3DX_PI * 0.0125f * 0.5; t += XM_PI * 0.0125f * 0.5f;
#else #else
static DWORD dwTimeStart = 0; static DWORD dwTimeStart = 0;
DWORD dwTimeCur = GetTickCount(); DWORD dwTimeCur = GetTickCount();
@ -1646,7 +1620,7 @@ void Render()
//RenderBloom(); //RenderBloom();
//print("%f\n", t); //print("%f\n", t);
//RenderVolume(t); //RenderVolume(t);
RenderVolumeMesh(); //RenderVolumeMesh();
// present // present
g_pSwapChain->Present(0, 0); g_pSwapChain->Present(0, 0);

View File

@ -2,7 +2,6 @@
#include <assert.h> #include <assert.h>
#include <d3d10.h> #include <d3d10.h>
#include <d3dx9.h>
#include "globals.hpp" #include "globals.hpp"
#include "print.hpp" #include "print.hpp"

File diff suppressed because it is too large Load Diff