-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Barnacle
committed
Dec 10, 2018
0 parents
commit fcc024f
Showing
24 changed files
with
4,480 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Debug/ | ||
Release/ | ||
D3D/Debug/ | ||
D3D/Release/ | ||
main/Debug/ | ||
main/Release/ | ||
# Visual Studio 2015 cache/options directory | ||
.vs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,291 @@ | ||
#include "D3D.h" | ||
|
||
CD3DRender::CD3DRender() | ||
{ | ||
m_emaRenderer = new EMARenderer; | ||
} | ||
|
||
CD3DRender::~CD3DRender() | ||
{} | ||
|
||
struct Vertex | ||
{ | ||
D3DXVECTOR3 p; | ||
D3DXVECTOR3 n; | ||
float u, v; | ||
|
||
enum FVF | ||
{ | ||
FVF_Flags = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 | ||
}; | ||
}; | ||
|
||
HRESULT CD3DRender::init(HWND hwnd, int Width, int Height) | ||
{ | ||
// Create the D3D object. | ||
if (NULL == (g_D3D = Direct3DCreate9(D3D_SDK_VERSION))) | ||
return E_FAIL; | ||
|
||
g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm); | ||
|
||
ZeroMemory(&d3dpp, sizeof(d3dpp)); | ||
d3dpp.Windowed = TRUE; | ||
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; | ||
d3dpp.BackBufferFormat = d3ddm.Format; | ||
d3dpp.EnableAutoDepthStencil = TRUE; | ||
d3dpp.AutoDepthStencilFormat = D3DFMT_D16; | ||
d3dpp.BackBufferWidth = Width; | ||
d3dpp.BackBufferHeight = Height; | ||
d3dpp.MultiSampleType = D3DMULTISAMPLE_8_SAMPLES; | ||
|
||
// Create the D3DDevice | ||
if (FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, | ||
D3DCREATE_SOFTWARE_VERTEXPROCESSING, | ||
&d3dpp, &g_d3dDevice))) | ||
{ | ||
return E_FAIL; | ||
} | ||
|
||
g_d3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); | ||
g_d3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE); | ||
g_d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); | ||
|
||
D3DXMATRIX matProj; | ||
D3DXMatrixPerspectiveFovLH(&matProj, D3DXToRadian(45.0f), | ||
(float)Width / (float)Height, 0.1f, 100.0f); | ||
g_d3dDevice->SetTransform(D3DTS_PROJECTION, &matProj); | ||
|
||
|
||
|
||
return S_OK; | ||
} | ||
|
||
// Ôóíêöèÿ ïðåäâàðèòåëüíîãî ñîçäàíèÿ áóôåðîâ. | ||
HRESULT CD3DRender::CreateBuffers(ushort EMGcount) | ||
{ | ||
g_pIndexBuffer = new LPDIRECT3DINDEXBUFFER9*[EMGcount]; | ||
g_pVertexBuffer = new LPDIRECT3DVERTEXBUFFER9[EMGcount]; | ||
|
||
CD3DRender::EMGcount = EMGcount; | ||
EMGsubmodels = new ushort[EMGcount]; | ||
|
||
IndexCount = new ushort*[EMGcount]; | ||
VertexCount = new ushort[EMGcount]; | ||
VertexSize = new ushort[EMGcount]; | ||
|
||
DDSid = new Byte*[EMGcount]; | ||
|
||
return S_OK; | ||
} | ||
|
||
// Ôóíêöèÿ çàïîëíåíèÿ ìàññèâà áóôåðîâ. | ||
HRESULT CD3DRender::LoadEMG(ushort CurrentEMG, ushort EMGsubmodels, Byte* DDSid, ushort* IndexCount, | ||
ushort VertexCount, ushort VertexSize, ushort** IndiceArray, Byte* VertexArray) | ||
{ | ||
// Çàïîëíåíèå ìàññèâîâ äëÿ èñïîëüçîâàíèÿ â ProcessFrame(). | ||
CD3DRender::IndexCount[CurrentEMG] = new ushort[EMGsubmodels]; | ||
CD3DRender::VertexCount[CurrentEMG] = VertexCount; | ||
CD3DRender::VertexSize[CurrentEMG] = VertexSize; | ||
CD3DRender::EMGsubmodels[CurrentEMG] = EMGsubmodels; | ||
|
||
CD3DRender::DDSid[CurrentEMG] = new Byte[EMGsubmodels]; | ||
|
||
g_pIndexBuffer[CurrentEMG] = new LPDIRECT3DINDEXBUFFER9[EMGsubmodels]; | ||
|
||
for (ushort i = 0; i < EMGsubmodels; i++) | ||
{ | ||
CD3DRender::IndexCount[CurrentEMG][i] = IndexCount[i]; | ||
CD3DRender::DDSid[CurrentEMG][i] = DDSid[i]; | ||
|
||
// Create an index buffer to use with our indexed vertex buffer... | ||
g_d3dDevice->CreateIndexBuffer(IndexCount[i] * sizeof(WORD), | ||
D3DUSAGE_WRITEONLY, | ||
D3DFMT_INDEX16, | ||
D3DPOOL_MANAGED, | ||
&(g_pIndexBuffer[CurrentEMG][i]), | ||
NULL); | ||
WORD *pIndices = NULL; | ||
|
||
g_pIndexBuffer[CurrentEMG][i]->Lock(0, IndexCount[i] * sizeof(WORD), (void**)&pIndices, 0); | ||
memcpy(pIndices, IndiceArray[i], IndexCount[i] * sizeof(WORD)); | ||
g_pIndexBuffer[CurrentEMG][i]->Unlock(); | ||
} | ||
|
||
// Create a vertex buffer... | ||
g_d3dDevice->CreateVertexBuffer(VertexCount * VertexSize, | ||
D3DUSAGE_WRITEONLY, | ||
Vertex::FVF_Flags, | ||
D3DPOOL_MANAGED, | ||
&(g_pVertexBuffer[CurrentEMG]), | ||
NULL); | ||
void *pVertices = NULL; | ||
|
||
g_pVertexBuffer[CurrentEMG]->Lock(0, VertexCount * VertexSize, (void**)&pVertices, 0); | ||
memcpy(pVertices, VertexArray, VertexCount * VertexSize); | ||
g_pVertexBuffer[CurrentEMG]->Unlock(); | ||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT CD3DRender::LoadDDS(ushort DDScount, unsigned long* DDSsize, Byte** DDScontent) | ||
{ | ||
g_Texture = new LPDIRECT3DTEXTURE9[DDScount]; | ||
CD3DRender::DDScount = DDScount; | ||
for (ushort i = 0; i < DDScount; i++) | ||
D3DXCreateTextureFromFileInMemory(g_d3dDevice, DDScontent[i], DDSsize[i], &g_Texture[i]); | ||
|
||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT CD3DRender::Shutdown() | ||
{ | ||
for (ushort i = 0; i < EMGcount; i++) | ||
{ | ||
for (ushort a = 0; a < EMGsubmodels[i]; a++) | ||
{ | ||
if (g_pIndexBuffer != NULL) | ||
g_pIndexBuffer[i][a]->Release(); | ||
} | ||
|
||
if (g_pVertexBuffer != NULL) | ||
g_pVertexBuffer[i]->Release(); | ||
} | ||
|
||
for (ushort i = 0; i < DDScount; i++) | ||
{ | ||
if (g_Texture != NULL) | ||
g_Texture[i]->Release(); | ||
} | ||
|
||
if( g_d3dDevice != NULL ) | ||
g_d3dDevice->Release(); | ||
|
||
if( g_D3D != NULL ) | ||
g_D3D->Release(); | ||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT CD3DRender::OnMouseMove(short x, short y, bool RMousing) | ||
{ | ||
ptCurrentMousePosit.x = x; | ||
ptCurrentMousePosit.y = y; | ||
|
||
if (bMousing) | ||
{ | ||
if (bRMousing != RMousing) | ||
{ | ||
m_zoom += (ptCurrentMousePosit.y - ptLastMousePosit.y) / (float)1000; | ||
} | ||
else | ||
{ | ||
g_fSpinX -= (ptCurrentMousePosit.x - ptLastMousePosit.x); | ||
g_fSpinY -= (ptCurrentMousePosit.y - ptLastMousePosit.y); | ||
} | ||
} | ||
|
||
ptLastMousePosit.x = ptCurrentMousePosit.x; | ||
ptLastMousePosit.y = ptCurrentMousePosit.y; | ||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT CD3DRender::OnMouseButtonUp() | ||
{ | ||
bMousing = false; | ||
bRMousing = false; | ||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT CD3DRender::OnMouseButtonDown(short x, short y) | ||
{ | ||
ptLastMousePosit.x = ptCurrentMousePosit.x = x; | ||
ptLastMousePosit.y = ptCurrentMousePosit.y = y; | ||
bMousing = true; | ||
bRMousing = false; | ||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT CD3DRender::Reset() | ||
{ | ||
return S_OK; | ||
} | ||
|
||
HRESULT CD3DRender::ProcessFrame() | ||
{ | ||
// Clear the backbuffer and the zbuffer | ||
g_d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, | ||
D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); | ||
|
||
D3DXMATRIX matTrans; | ||
D3DXMATRIX matRot; | ||
D3DXMATRIX matWorld; | ||
|
||
D3DXMatrixTranslation(&matTrans, 0.0f, 0.0f, m_zoom); | ||
|
||
D3DXMatrixRotationYawPitchRoll( &matRot, | ||
D3DXToRadian(g_fSpinX), | ||
D3DXToRadian(g_fSpinY), | ||
0.0f); | ||
matWorld = matRot * matTrans; | ||
g_d3dDevice->SetTransform(D3DTS_WORLD, &matWorld); | ||
|
||
// Begin the scene | ||
if (SUCCEEDED(g_d3dDevice->BeginScene())) | ||
{ | ||
if (g_pIndexBuffer != 0 && g_pVertexBuffer != 0) | ||
{ | ||
for (int i = 0; i < EMGcount; i++) | ||
{ | ||
g_d3dDevice->SetStreamSource(0, g_pVertexBuffer[i], 0, VertexSize[i]); | ||
g_d3dDevice->SetFVF(Vertex::FVF_Flags); | ||
|
||
for (ushort a = 0; a < EMGsubmodels[i]; a++) | ||
{ | ||
if (g_Texture != NULL) | ||
{ | ||
g_d3dDevice->SetTexture(0, g_Texture[DDSid[i][a]]); | ||
|
||
g_d3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC); | ||
g_d3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC); | ||
g_d3dDevice->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 4); | ||
|
||
} | ||
|
||
g_d3dDevice->SetIndices(g_pIndexBuffer[i][a]); | ||
g_d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, VertexCount[i], 0, IndexCount[i][a] - 2); | ||
} | ||
} | ||
} | ||
// End the scene | ||
g_d3dDevice->EndScene(); | ||
} | ||
|
||
// Present the backbuffer contents to the display | ||
g_d3dDevice->Present(NULL, NULL, NULL, NULL); | ||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT CD3DRender::Resize(int Width, int Height) | ||
{ | ||
d3dpp.BackBufferWidth = Width; | ||
d3dpp.BackBufferHeight = Height; | ||
|
||
g_d3dDevice->Reset(&d3dpp); | ||
|
||
g_d3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); | ||
g_d3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE); | ||
g_d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); | ||
|
||
D3DXMATRIX matProj; | ||
D3DXMatrixPerspectiveFovLH(&matProj, D3DXToRadian(45.0f), | ||
(float)Width / (float)Height, 0.1f, 100.0f); | ||
g_d3dDevice->SetTransform(D3DTS_PROJECTION, &matProj); | ||
|
||
return S_OK; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#pragma once | ||
|
||
#ifdef _EXPORTING | ||
#define CLASS_DECLSPEC __declspec(dllexport) | ||
#else | ||
#define CLASS_DECLSPEC __declspec(dllimport) | ||
#endif | ||
|
||
#include <windows.h> | ||
#include <d3dx9.h> | ||
#include "Ema.h" | ||
|
||
#pragma comment( lib, "d3d9.lib" ) | ||
#pragma comment( lib, "d3dx9d.lib" ) | ||
#pragma comment( lib, "winmm.lib" ) | ||
|
||
typedef unsigned short ushort; | ||
typedef unsigned char Byte; | ||
|
||
class CLASS_DECLSPEC CD3DRender | ||
{ | ||
public: | ||
CD3DRender(); | ||
~CD3DRender(); | ||
|
||
LPDIRECT3D9 g_D3D = NULL; // Used to create the D3DDevice | ||
LPDIRECT3DDEVICE9 g_d3dDevice = NULL; // Our rendering device | ||
|
||
LPDIRECT3DINDEXBUFFER9** g_pIndexBuffer = NULL; // Áóôåð èíäåêñîâ | ||
LPDIRECT3DVERTEXBUFFER9* g_pVertexBuffer = NULL; // Áóôåð âåðòåêñîâ | ||
LPDIRECT3DTEXTURE9* g_Texture = NULL; | ||
|
||
D3DDISPLAYMODE d3ddm; | ||
D3DPRESENT_PARAMETERS d3dpp; | ||
|
||
POINT ptLastMousePosit; | ||
POINT ptCurrentMousePosit; | ||
|
||
bool bMousing = false; | ||
float g_fSpinX = 0.0f; | ||
float g_fSpinY = 0.0f; | ||
|
||
bool bRMousing = false; | ||
float m_zoom = 2.5f; | ||
|
||
unsigned short EMGcount; | ||
unsigned short* EMGsubmodels = NULL; | ||
unsigned short**IndexCount = NULL; | ||
unsigned short* VertexCount = NULL; | ||
unsigned short* VertexSize = NULL; | ||
|
||
ushort DDScount; | ||
Byte** DDSid = NULL; | ||
|
||
HRESULT init(HWND hwnd, int Width, int Height); | ||
HRESULT CreateBuffers(ushort EMGcount); | ||
HRESULT LoadEMG(ushort CurrentEMG, ushort EMGsubmodels, Byte* DDSid, ushort* IndexCount, | ||
ushort VertexCount, ushort VertexSize, | ||
ushort** IndiceArray, Byte* VertexArray); | ||
HRESULT LoadDDS(ushort DDScount, unsigned long* DDSsize, Byte** DDScontent); | ||
HRESULT Shutdown(); | ||
HRESULT Reset(); | ||
HRESULT ProcessFrame(); | ||
HRESULT Resize(int Width, int Height); | ||
HRESULT OnMouseMove(short x, short y, bool RMousing); | ||
HRESULT OnMouseButtonUp(); | ||
HRESULT OnMouseButtonDown(short x, short y); | ||
|
||
EMARenderer* m_emaRenderer; | ||
HRESULT Setup(std::string emaFileName, unsigned long emaBlockOffset) | ||
{ | ||
m_emaRenderer->setup(emaFileName, emaBlockOffset); | ||
|
||
return S_OK; | ||
} | ||
|
||
HRESULT Update(float(&structure)[500][6], std::string(&names)[500], std::string AnimationName, int frame) | ||
{ | ||
m_emaRenderer->updateDeviceObjects(AnimationName, (float)frame, structure, names); | ||
|
||
return S_OK; | ||
} | ||
}; |
Binary file not shown.
Oops, something went wrong.