// Author : masato masuda // //***************************************************************************** //***************************************************************************** // include //***************************************************************************** #include "sprite_smooth.h" #include "render/sprite.h" #include "system/system.h" #include "system/directx9/texture/texture.h" //***************************************************************************** // constant definition //***************************************************************************** const D3DXVECTOR2 SpriteSmooth::DEFAULT_POSITION = D3DXVECTOR2(0.0f, 0.0f); const D3DXVECTOR2 SpriteSmooth::DEFAULT_SIZE = D3DXVECTOR2(0.0f, 0.0f); const D3DXVECTOR2 CLEAR_VECTOR2 = D3DXVECTOR2(0.0f, 0.0f); const D3DXCOLOR CLEAR_COLOR = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); const f32 HALF_PI = D3DX_PI / 2.0f; //============================================================================= // constructor //============================================================================= SpriteSmooth::SpriteSmooth(void) :sprite_(nullptr) ,dest_frame_(0) ,now_frame_(0) ,is_move_(false)
HRESULT Engine::CTerrainTex::Create_Buffer(const _ushort& wCntX, const _ushort& wCntZ, const _ushort& wItv) { HANDLE hFile; _ulong dwByte; hFile = CreateFile(L"../Resource/Texture/StageScene/Terrain/Height.bmp", GENERIC_READ, 0 , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); BITMAPFILEHEADER fh; BITMAPINFOHEADER ih; ReadFile(hFile, &fh, sizeof(fh), &dwByte, NULL); ReadFile(hFile, &ih, sizeof(ih), &dwByte, NULL); _ulong* pdwPixel = new _ulong[ih.biWidth * ih.biHeight]; ReadFile(hFile, pdwPixel, sizeof(_ulong) * ih.biWidth * ih.biHeight, &dwByte, NULL); CloseHandle(hFile); m_dwVtxSize = sizeof(VTXTEX); m_dwVtxCnt = wCntX * wCntZ ; m_dwVtxFVF = VTXFVF_TEX; m_dwIdxSize = sizeof(INDEX16); m_IdxFmt = D3DFMT_INDEX16; m_dwTriCnt = (wCntX - 1) * (wCntZ - 1) * 2; FAILED_CHECK(CVIBuffer::Create_Buffer()); VTXTEX* pVtxTex = NULL; m_pVB->Lock(0, 0, (void**)&pVtxTex, 0); int iIndex = NULL; for(int z = 0; z < wCntZ; ++z) { for(int x = 0; x < wCntX; ++x) { iIndex = z * wCntX + x; pVtxTex[iIndex].vPos = D3DXVECTOR3( float(x) * wItv , (pdwPixel[iIndex] & 0x000000ff) / 5.f , float(z) * wItv); pVtxTex[iIndex].vNormal = D3DXVECTOR3(0.f, 0.f, 0.f); pVtxTex[iIndex].vTexUV = D3DXVECTOR2( x / (wCntX - 1.f), z / (wCntZ - 1.f) ); } } INDEX16* pIndex = NULL; m_pIB->Lock(0, 0, (void**)&pIndex, 0); int iTriCnt = 0; for(int z = 0; z < wCntZ - 1; ++z) { for(int x = 0; x < wCntX - 1; ++x) { iIndex = z * wCntX + x; pIndex[iTriCnt]._1 = iIndex + wCntX; //1-2 pIndex[iTriCnt]._2 = iIndex + wCntX + 1; // \| pIndex[iTriCnt]._3 = iIndex + 1; // 3 D3DXVECTOR3 vDest, vSour, vNormal; vDest = pVtxTex[ pIndex[iTriCnt]._2 ].vPos - pVtxTex[ pIndex[iTriCnt]._1 ].vPos; vSour = pVtxTex[ pIndex[iTriCnt]._3 ].vPos - pVtxTex[ pIndex[iTriCnt]._2 ].vPos; D3DXVec3Cross(&vNormal, &vDest, &vSour); pVtxTex[ pIndex[iTriCnt]._1 ].vNormal += vNormal; pVtxTex[ pIndex[iTriCnt]._2 ].vNormal += vNormal; pVtxTex[ pIndex[iTriCnt]._3 ].vNormal += vNormal; ++iTriCnt; pIndex[iTriCnt]._1 = iIndex + wCntX; pIndex[iTriCnt]._2 = iIndex + 1; pIndex[iTriCnt]._3 = iIndex; vDest = pVtxTex[ pIndex[iTriCnt]._2 ].vPos - pVtxTex[ pIndex[iTriCnt]._1 ].vPos; vSour = pVtxTex[ pIndex[iTriCnt]._3 ].vPos - pVtxTex[ pIndex[iTriCnt]._2 ].vPos; D3DXVec3Cross(&vNormal, &vDest, &vSour); pVtxTex[ pIndex[iTriCnt]._1 ].vNormal += vNormal; pVtxTex[ pIndex[iTriCnt]._2 ].vNormal += vNormal; pVtxTex[ pIndex[iTriCnt]._3 ].vNormal += vNormal; ++iTriCnt; } } for(_ushort i = 0; i < m_dwVtxCnt; ++i) { D3DXVec3Normalize(&pVtxTex[i].vNormal, &pVtxTex[i].vNormal); } m_pVB->Unlock(); m_pIB->Unlock(); Engine::Safe_Delete_Array(pdwPixel); return S_OK; }
void InBuilding::build(float w, float h, float d){ VertexPNTList vertices; VertexPNT v; float width = w; float height = h; float depth = d; float thrirdwidth = w/3; float twothirdwidth = (2*w)/3; float twothirdheight = (2*h)/3; //Front v.normal = D3DXVECTOR3( 0.0f, 0.0f, -1.0f); v.pos = D3DXVECTOR3(0.1f, 0.1f, 0.1f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.1f, height, 0.1f); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(thrirdwidth, height, 0.1f); v.texC = D3DXVECTOR2(0.4,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(thrirdwidth, 0.1f, 0.1f); v.texC = D3DXVECTOR2(0.4,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(thrirdwidth, twothirdheight, 0.1f); v.texC = D3DXVECTOR2(0.4,0.7); vertices.push_back(v); v.pos = D3DXVECTOR3(twothirdwidth, twothirdheight, 0.1f); v.texC = D3DXVECTOR2(0.8,0.7); vertices.push_back(v); v.pos = D3DXVECTOR3(twothirdwidth, height, 0.1f); v.texC = D3DXVECTOR2(0.8,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, 0.1f); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, 0.1f, 0.1f); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(twothirdwidth, 0.1f, 0.1f); v.texC = D3DXVECTOR2(0.8,0.0); vertices.push_back(v); //Left Face v.normal = D3DXVECTOR3( -1.0f, 0.0f, 0.0f); v.pos = D3DXVECTOR3(0.1f, 0.1f, 0.1f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.1f, height, 0.1f); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.1f, height, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.1f, 0.1f, depth); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); //Top v.normal = D3DXVECTOR3( 0.0f, 1.0f, 0.0f); v.pos = D3DXVECTOR3(0.1f, height, 0.1f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.1f, height, depth); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, 0.1f); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); //Right v.normal = D3DXVECTOR3( 1.0f, 0.0f, 0.0f); v.pos = D3DXVECTOR3(width, 0.1f, 0.1f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, 0.1f, depth); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, 0.1f); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); //Bottom v.normal = D3DXVECTOR3( 0.0f, -1.0f, 0.0f); v.pos = D3DXVECTOR3(0.1f, 0.1f, 0.1f); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.1f, 0.1f, depth); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, 0.1f, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, 0.1f, 0.1f); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); //Back v.normal = D3DXVECTOR3( 0.0f, 0.0f, 1.0f); v.pos = D3DXVECTOR3(width, 0.1f, depth); v.texC = D3DXVECTOR2(0.0,0.0); vertices.push_back(v); v.pos = D3DXVECTOR3(width, height, depth); v.texC = D3DXVECTOR2(0.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.1f, height, depth); v.texC = D3DXVECTOR2(1.0,1.0); vertices.push_back(v); v.pos = D3DXVECTOR3(0.1f, 0.1f, depth); v.texC = D3DXVECTOR2(1.0,0.0); vertices.push_back(v); mNumVertices = (UINT)vertices.size(); buildVB(vertices); IndexList indices; indices.push_back(0); indices.push_back(3); indices.push_back(2); indices.push_back(2); indices.push_back(1); indices.push_back(0); indices.push_back(4); indices.push_back(5); indices.push_back(6); indices.push_back(6); indices.push_back(2); indices.push_back(4); indices.push_back(9); indices.push_back(8); indices.push_back(7); indices.push_back(7); indices.push_back(6); indices.push_back(9); indices.push_back(10); indices.push_back(11); indices.push_back(12); indices.push_back(12); indices.push_back(13); indices.push_back(10); indices.push_back(14); indices.push_back(17); indices.push_back(16); indices.push_back(16); indices.push_back(15); indices.push_back(14); indices.push_back(18); indices.push_back(19); indices.push_back(16); indices.push_back(16); indices.push_back(21); indices.push_back(18); indices.push_back(22); indices.push_back(23); indices.push_back(24); indices.push_back(24); indices.push_back(25); indices.push_back(22); indices.push_back(26); indices.push_back(29); indices.push_back(28); indices.push_back(28); indices.push_back(27); indices.push_back(26); mNumFaces = (UINT)indices.size()/3; mNumIndices = (UINT)indices.size(); buildIB(indices); }
bool ModelClass::InitializeBuffers(ID3D11Device* device) { VertexType* vertices; unsigned long* indices; D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc; D3D11_SUBRESOURCE_DATA vertexData, indexData; HRESULT result; // Set the number of vertices in the vertex array. m_vertexCount = 3; // Set the number of indices in the index array. m_indexCount = 3; // Create the vertex array. vertices = new VertexType[m_vertexCount]; if(!vertices) { return false; } // Create the index array. indices = new unsigned long[m_indexCount]; if(!indices) { return false; } // Load the vertex array with data. vertices[0].position = D3DXVECTOR3(-1.0f, -1.0f, 0.0f); // Bottom left. vertices[0].texture = D3DXVECTOR2(0.0f, 1.0f); vertices[1].position = D3DXVECTOR3(0.0f, 1.0f, 0.0f); // Top middle. vertices[1].texture = D3DXVECTOR2(0.5f, 0.0f); vertices[2].position = D3DXVECTOR3(1.0f, -1.0f, 0.0f); // Bottom right. vertices[2].texture = D3DXVECTOR2(1.0f, 1.0f); // Load the index array with data. indices[0] = 0; // Bottom left. indices[1] = 1; // Top middle. indices[2] = 2; // Bottom right. // Set up the description of the static vertex buffer. vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount; vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; vertexBufferDesc.StructureByteStride = 0; // Give the subresource structure a pointer to the vertex data. vertexData.pSysMem = vertices; vertexData.SysMemPitch = 0; vertexData.SysMemSlicePitch = 0; // Now create the vertex buffer. result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); if(FAILED(result)) { return false; } // Set up the description of the static index buffer. indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount; indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; indexBufferDesc.StructureByteStride = 0; // Give the subresource structure a pointer to the index data. indexData.pSysMem = indices; indexData.SysMemPitch = 0; indexData.SysMemSlicePitch = 0; // Create the index buffer. result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer); if(FAILED(result)) { return false; } // Release the arrays now that the vertex and index buffers have been created and loaded. delete [] vertices; vertices = 0; delete [] indices; indices = 0; return true; }
void Warlock::Intro() { float x = this->mGe->GetEngineParameters().windowWidth * 0.5f - this->mGe->GetEngineParameters().windowWidth * 0.2125f; float y = this->mGe->GetEngineParameters().windowHeight * 0.4f; Text* intro = mGe->CreateText("Warlock", D3DXVECTOR2(x, y), 2.0f, "Media/Fonts/1"); mGe->LoadingScreen("Media/LoadingScreen/LoadingScreenBG.png", "Media/LoadingScreen/LoadingScreenPB.png", 0.0f, 1.0f, 1.0f, 1.0f); // Changed by MaloW intro->SetText(""); mGe->DeleteText(intro); float width = GetGraphicsEngine()->GetEngineParameters().windowWidth; float height = GetGraphicsEngine()->GetEngineParameters().windowHeight; /* Set hud */ this->mHud[0] = NULL; this->mHud[1] = NULL; this->mHud[2] = NULL; this->mHud[3] = NULL; this->mHud[4] = NULL; this->mHud[5] = NULL; this->mHud[6] = NULL; this->mHud[7] = NULL; this->mHud[8] = NULL; this->mHud[9] = NULL; this->mHud[10] = NULL; // Rework ScreenWidth to 4:3 const float UISCALE = 0.5f; float screenHeight = this->mGe->GetEngineParameters().windowHeight; float screenWidth = (screenHeight * 4) / 3; float distX = (mGe->GetEngineParameters().windowWidth - screenWidth) / 2; distX /= UISCALE; D3DXVECTOR2 imgDim = D3DXVECTOR2(screenWidth / 5, screenWidth / 5) * UISCALE; distX = (this->mGe->GetEngineParameters().windowWidth / 2.0f) - ((imgDim.x * 5.0f) / 2.0f); for(int i = 11; i < 16; i++) { this->mHud[i] = mGe->CreateText("",D3DXVECTOR2(distX + imgDim.x * (i-11) + (imgDim.x * 0.2f), screenHeight - imgDim.y * 0.65f), 1.0f, "Media/Fonts/1"); } this->mHud[16] = NULL; this->mProgressBars = new ProgressBar*[6]; float percentX = 0.02f; float percentY = 0.88f; for(int i = 0; i<5;i++) { D3DXVECTOR2 temp = D3DXVECTOR2(percentX,percentY); this->mProgressBars[i] = new ProgressBar(distX + imgDim.x * i, screenHeight - imgDim.y - (screenHeight * 0.03f), imgDim.x, (screenHeight * 0.03f)); this->mProgressBars[i]->SetPercentOfProgressBarColor1(0.0f); this->mProgressBars[i]->SetPercentOfProgressBarColor2(0.0f); this->mProgressBars[i]->SetPercentOfProgressBarColor3(0.0f); this->mProgressBars[i]->SetPercentOfProgressBarColor4(0.0f); percentX = percentX + 0.16f; } D3DXVECTOR2 temp = D3DXVECTOR2(percentX,percentY); this->mProgressBars[5] = new ProgressBar(distX, screenHeight - imgDim.y - (screenHeight * 0.08f) , imgDim.x * 5.0f, (screenHeight * 0.05f)); this->mProgressBars[5]->SetPercentOfProgressBarColor1(0.0f); this->mProgressBars[5]->SetPercentOfProgressBarColor2(0.0f); this->mProgressBars[5]->SetPercentOfProgressBarColor3(0.0f); this->mProgressBars[5]->SetPercentOfProgressBarColor4(0.0f); percentX = percentX + 0.16f; this->mTimeElapsedText = this->mGe->CreateText( "", D3DXVECTOR2(15.0f, 10.0f), 1.0f, "Media/Fonts/1"); // Add spell Icons Image* charge = mGe->CreateImage(D3DXVECTOR2(distX, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/ChargeIcon.png"); Image* sprint = mGe->CreateImage(D3DXVECTOR2(distX + imgDim.x, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/SprintIcon.png"); Image* harden = mGe->CreateImage(D3DXVECTOR2(distX + imgDim.x * 2, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/HardenIcon.png"); Image* invis = mGe->CreateImage(D3DXVECTOR2(distX + imgDim.x * 3, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/InvisIcon.png"); Image* jump = mGe->CreateImage(D3DXVECTOR2(distX + imgDim.x * 4, screenHeight - imgDim.y), imgDim, "Media/WarlockUI/JumpIcon.png"); this->SpellIcons.add(charge); this->SpellIcons.add(sprint); this->SpellIcons.add(harden); this->SpellIcons.add(invis); this->SpellIcons.add(jump); }
bool Model::InitBuffers(ID3D11Device* device) { Vertex* vertices; unsigned long* indices; D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc; D3D11_SUBRESOURCE_DATA vertexData, indexData; HRESULT result; int i; //new to 0.6 for counter // Create vertex array. vertices = new Vertex[_vertexCount]; // longer set to 3. new to 0.6 // Create index array. indices = new unsigned long[_indexCount]; // longer set to 3. new to 0.6 // Load vertex array and index array with data. new to 0.6 for(i=0; i<_vertexCount; i++) { vertices[i].position = D3DXVECTOR3(_model[i].x+20, _model[i].y, _model[i].z+60); vertices[i].texture = D3DXVECTOR2(_model[i].tu, _model[i].tv); vertices[i].normal = D3DXVECTOR3(_model[i].nx, _model[i].ny, _model[i].nz); indices[i] = i; } // Set up description of static vertex buffer. vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof(Vertex) * _vertexCount; vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; vertexBufferDesc.StructureByteStride = 0; // Give subresource structure a pointer to vertex data. vertexData.pSysMem = vertices; vertexData.SysMemPitch = 0; vertexData.SysMemSlicePitch = 0; // Now create vertex buffer. result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &_vertexBuffer); if(FAILED(result)) { return false; } // Set up description of static index buffer. indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(unsigned long) * _indexCount; indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; indexBufferDesc.StructureByteStride = 0; // Give subresource structure a pointer to index data. indexData.pSysMem = indices; indexData.SysMemPitch = 0; indexData.SysMemSlicePitch = 0; // Create index buffer. result = device->CreateBuffer(&indexBufferDesc, &indexData, &_indexBuffer); if(FAILED(result)) { return false; } //once ind and vert buffers been created arrays no longer needed as data in buffers // Release arrays now that vertex and index buffers have been created and loaded. delete [] vertices; vertices = 0; delete [] indices; indices = 0; return true; }
bool ModelClass::InitializeBuffers(ID3D10Device* device) { VertexType* vertices; unsigned long* indices; D3D10_BUFFER_DESC vertexBufferDesc, indexBufferDesc; D3D10_SUBRESOURCE_DATA vertexData, indexData; HRESULT result; int i; // Create the vertex array. vertices = new VertexType[m_vertexCount]; if(!vertices) { return false; } // Create the index array. indices = new unsigned long[m_indexCount]; if(!indices) { return false; } // Load the vertex array and index array with data. for(i=0; i<m_vertexCount; i++) { vertices[i].position = D3DXVECTOR3(m_model[i].x, m_model[i].y, m_model[i].z); vertices[i].texture = D3DXVECTOR2(m_model[i].tu, m_model[i].tv); indices[i] = i; } // Set up the description of the vertex buffer. vertexBufferDesc.Usage = D3D10_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount; vertexBufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; // Give the subresource structure a pointer to the vertex data. vertexData.pSysMem = vertices; // Now finally create the vertex buffer. result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); if(FAILED(result)) { return false; } // Set up the description of the index buffer. indexBufferDesc.Usage = D3D10_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount; indexBufferDesc.BindFlags = D3D10_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; // Give the subresource structure a pointer to the index data. indexData.pSysMem = indices; // Create the index buffer. result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer); if(FAILED(result)) { return false; } // Release the arrays now that the vertex and index buffers have been created and loaded. delete [] vertices; vertices = 0; delete [] indices; indices = 0; return true; }
void ElBillboardChain::_setupVertices(ElCamera* cam) { D3DXVECTOR3 chainDir(0.0f, 0.0f, 0.0f); if (!mChainElementList.empty()) chainDir = mChainElementList.back().position - mChainElementList.begin()->position; int numElements = (int)mChainElementList.size(); int lastElement = numElements - 1; for (int i = 0; i < numElements; ++i) { Element prevElement, nextElement; if (i != lastElement) { prevElement = mChainElementList[i]; nextElement = mChainElementList[i + 1]; } else if (i != 0) { prevElement = mChainElementList[i - 1]; nextElement = mChainElementList[i]; } else { prevElement = nextElement = mChainElementList[i]; } D3DXVECTOR3 segmentDir; if (mUseChainDirection) segmentDir = chainDir; else segmentDir = nextElement.position - prevElement.position; D3DXVECTOR3 lookAt(0.0f, 0.0f, 1.0f); if (cam) lookAt = -cam->getDirection(); D3DXVECTOR3 strechDir; D3DXVec3Cross(&strechDir, &lookAt, &segmentDir); D3DXVec3Normalize(&strechDir, &strechDir); // each element can be extended to two vertices, according to positions of // its neighbors and itself Element currentElement = mChainElementList[i]; int vertexIdx = i * 2; mVertices[vertexIdx].pos = currentElement.position + (currentElement.width * strechDir); mVertices[vertexIdx].color = currentElement.colour; if (mTexCoordMode == TextCoord_CustomX) mVertices[vertexIdx].tex = D3DXVECTOR2(currentElement.texCoord, 1.0f); else if (mTexCoordMode == TextCoord_CustomY) mVertices[vertexIdx].tex = D3DXVECTOR2(1.0f, currentElement.texCoord); ++vertexIdx; mVertices[vertexIdx].pos = currentElement.position - (currentElement.width * strechDir); mVertices[vertexIdx].color = currentElement.colour; if (mTexCoordMode == TextCoord_CustomX) mVertices[vertexIdx].tex = D3DXVECTOR2(currentElement.texCoord, 0.0f); else if (mTexCoordMode == TextCoord_CustomY) mVertices[vertexIdx].tex = D3DXVECTOR2(0.0f, currentElement.texCoord); } }
//============================================================================= // 更新処理 //============================================================================= void CGimmickBlock::Update() { // アントンのアドレスを取ってくる CAnton *pAnton = CGame::GetPlayer()->GetAnton(); CBeecon *pBeecon = CGame::GetPlayer()->GetBeecon(); CBlockManager *pBlockManager = CGame::GetBlockManager(); // アントンの座標を調べる。 D3DXVECTOR3 antonPos = pAnton->GetPosition(); D3DXVECTOR3 antonPosOld = pAnton->GetPositionOld(); D3DXVECTOR3 antonSize = D3DXVECTOR3(50.0f, 60.0f, 0.0f); D3DXVECTOR3 workPos = antonPos - antonPosOld; D3DXVECTOR3 blockSize = D3DXVECTOR3(BLOCK_WIDTH / 2.0f, BLOCK_HEIGHT / 2.0f, 0.0f); D3DXVECTOR3 blockPos = D3DXVECTOR3( m_pos.x, m_pos.y, 0.0f ) + blockSize; // 木箱の判定に必要な変数 CBlock* pBlock = nullptr; int nArrayNumX = 0, nArrayNumY = 0; int nWorkBlockArrayNumX = 0, nWorkBlockArrayNumY = 0; D3DXVECTOR3 underBlockPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); D3DXVECTOR3 workBlockPos = D3DXVECTOR3(0.0f, 0.0f, 0.0f); D3DXVECTOR3 workBlockPos2 = D3DXVECTOR3(0.0f, 0.0f, 0.0f); bool bCheckRightHit = false, bCheckLeftHit = false; // ギミック系のものを更新する switch (m_blockType) { case CBlock::BLOCKID_MAGNET: // アントンがメタルの状態なら判定を行う if (pAnton->GetState() == CAnton::STATE_METAL) { // マグネットブロックとメタルアントンの距離が一定の範囲内にいたら // メタルアントンを吸い付かせる。 float fLength = sqrtf( ( blockPos.x - antonPos.x ) * ( blockPos.x - antonPos.x ) + ( blockPos.y - antonPos.y ) * ( blockPos.y - antonPos.y ) ); if ( fLength <= STICK_LENGTH ) { if (antonPos.y + antonSize.y > blockPos.y - blockSize.y && antonPos.y < blockPos.y + blockSize.y) { if ( antonPos.x > blockPos.x ) { antonPos.x += ( ( blockPos.x + blockSize.x ) - antonPos.x ) * 0.3f; } else if ( antonPos.x < blockPos.x ) { antonPos.x += ( ( blockPos.x - blockSize.x ) - antonPos.x ) * 0.3f; } } else if ( antonPos.y > blockPos.y ) { antonPos.x += (blockPos.x - antonPos.x) * 0.3f; antonPos.y += (blockPos.y - antonPos.y) * 0.3f; } else if (antonPos.y < blockPos.y) { antonPos.x += (blockPos.x - antonPos.x) * 0.3f; } pAnton -> SetPosition( antonPos ); //CManager::GetSoundXAudio2()->Play(CSoundXAudio2::SL_SE_MAGNET); } } break; case CBlock::BLOCKID_WOODBOX: // ぶつかっており、パワフルアントンに変化していたら処理を行う if (blockPos.y - blockSize.y < antonPos.y + antonSize.y && blockPos.y + blockSize.y > antonPos.y - antonSize.y && blockPos.x - blockSize.x < antonPos.x + ( antonSize.x * 1.65f ) && blockPos.x + blockSize.x > antonPos.x && (blockPos.x - blockSize.x ) - ( antonPos.x + antonSize.x ) < BLOCK_WIDTH && (blockPos.x - blockSize.x) - (antonPos.x + antonSize.x) >= WOODBOX_MOVE && pAnton->GetState() == CAnton::STATE_POWERFUL) { blockPos.x += WOODBOX_MOVE; bCheckRightHit = true; pAnton->SetAction(CAnton::ACTION_PUSH); PlaySeBoxSlip(); } else if (blockPos.y - blockSize.y < antonPos.y + antonSize.y && blockPos.y + blockSize.y > antonPos.y - antonSize.y && blockPos.x - blockSize.x < antonPos.x + ( antonSize.x * 1.65f ) && blockPos.x + blockSize.x > antonPos.x && (blockPos.x + blockSize.x) - (antonPos.x) > -BLOCK_WIDTH && (blockPos.x - blockSize.x) - (antonPos.x + antonSize.x) <= -WOODBOX_MOVE && pAnton->GetState() == CAnton::STATE_POWERFUL) { blockPos.x -= WOODBOX_MOVE; bCheckLeftHit = true; pAnton->SetAction(CAnton::ACTION_PUSH); PlaySeBoxSlip(); } // 落下の判定は、変化前の座標からブロックIDを求めて // 1つ下のブロックのアドレスを求める。nullだった場合は、落下。 // nullでなくても地面と接していなかった場合も落下する。 CBlockManager::CalculateBlockArrayNum(D3DXVECTOR3(m_pos.x + BLOCK_WIDTH / 2.0f, m_pos.y + BLOCK_HEIGHT / 2.0f, 0), &nArrayNumX, &nArrayNumY); pBlock = CBlockManager::GetBlock(nArrayNumX, nArrayNumY + 1); if (pBlock == nullptr) { blockPos.y += WOODBOX_MOVE; } else if (pBlock->GetBlockId() >= CBlock::BLOCKID_FOOD_ACORN && pBlock->GetBlockId() <= CBlock::BLOCKID_FOOD_MUSHROOM) { blockPos.y += WOODBOX_MOVE; } else { underBlockPos = pBlock -> GetPosition() + blockSize; if ( ( underBlockPos.y - blockSize.y ) - ( blockPos.y + blockSize.y ) >= WOODBOX_MOVE ) { blockPos.y += WOODBOX_MOVE; } else if ( underBlockPos.x - blockSize.x < blockPos.x + blockSize.x && underBlockPos.x + blockSize.x > blockPos.x - blockSize.x && ( ( underBlockPos.y - blockSize.y ) - ( blockPos.y + blockSize.y ) ) < 0.0f ) { blockPos.y = underBlockPos.y - blockSize.y - BLOCK_HEIGHT; } } if ( bCheckRightHit == true ) { // もし、右に木箱があったらそれもずらしておく pBlock = CBlockManager::GetBlock(nArrayNumX + 1, nArrayNumY); if (pBlock != nullptr && pBlock->GetBlockId() == CBlock::BLOCKID_WOODBOX) { workBlockPos2 = pBlock->GetPosition() + blockSize; if (workBlockPos2.y - blockSize.y < blockPos.y + blockSize.y && workBlockPos2.y + blockSize.y > blockPos.y - blockSize.y && workBlockPos2.x - blockSize.x < blockPos.x + blockSize.x && workBlockPos2.x + blockSize.x > blockPos.x - blockSize.x && workBlockPos2.x - blockPos.x < BLOCK_WIDTH && workBlockPos2.x - blockPos.x > 0.0f) { workBlockPos2.x = blockPos.x + blockSize.x; workBlockPos2.y = blockPos.y - blockSize.y; pBlock->SetPosition(workBlockPos2); CBlockManager::CalculateBlockArrayNum(workBlockPos2, &nWorkBlockArrayNumX, &nWorkBlockArrayNumY); if (nWorkBlockArrayNumX != nArrayNumX + 1) { CBlockManager::SetBlock(nWorkBlockArrayNumX, nWorkBlockArrayNumY, pBlock); CBlockManager::SetBlock(nArrayNumX + 1, nArrayNumY, nullptr); } } } } else if ( bCheckLeftHit == true ) { // もし、左に木箱があったらそれもずらしておく pBlock = CBlockManager::GetBlock(nArrayNumX - 1, nArrayNumY); if (pBlock != nullptr && pBlock->GetBlockId() == CBlock::BLOCKID_WOODBOX) { workBlockPos2 = pBlock->GetPosition() + blockSize; if (workBlockPos2.y - blockSize.y < blockPos.y + blockSize.y && workBlockPos2.y + blockSize.y > blockPos.y - blockSize.y && workBlockPos2.x - blockSize.x < blockPos.x + blockSize.x && workBlockPos2.x + blockSize.x > blockPos.x - blockSize.x && workBlockPos2.x - blockPos.x > -BLOCK_WIDTH && workBlockPos2.x - blockPos.x < 0.0f) { workBlockPos2.x = blockPos.x - blockSize.x - BLOCK_WIDTH; workBlockPos2.y = blockPos.y - blockSize.y; pBlock->SetPosition(workBlockPos2); CBlockManager::CalculateBlockArrayNum(workBlockPos2, &nWorkBlockArrayNumX, &nWorkBlockArrayNumY); if (nWorkBlockArrayNumX != nArrayNumX - 1) { CBlockManager::SetBlock(nWorkBlockArrayNumX, nWorkBlockArrayNumY, pBlock); CBlockManager::SetBlock(nArrayNumX - 1, nArrayNumY, nullptr); } } } } // 落下していき、配列番号が変化する位置になった場合は、 // BlockManagerに登録してある場所を切り替える。その時、 // 前回いた場所を初期化しておく。 workBlockPos = blockPos - blockSize; CBlockManager::CalculateBlockArrayNum(workBlockPos, &nWorkBlockArrayNumX, &nWorkBlockArrayNumY); if ( nArrayNumX != nWorkBlockArrayNumX || nArrayNumY != nWorkBlockArrayNumY ) { CBlockManager::SetBlock(nWorkBlockArrayNumX, nWorkBlockArrayNumY, ( CBlock* )this); CBlockManager::SetBlock(nArrayNumX, nArrayNumY, nullptr); } m_pos = D3DXVECTOR2(workBlockPos.x, workBlockPos.y); break; case CBlock::BLOCKID_WARP_BLUE: // ワープするタイミングになったら if (m_bWarpFlag && m_pWarpPoint->GetWarpFlag() && m_pos.x < antonPos.x && m_pos.x + BLOCK_WIDTH > antonPos.x && m_pos.y < antonPos.y + BLOCK_HEIGHT && m_pos.y + BLOCK_HEIGHT > antonPos.y + BLOCK_HEIGHT) { // アントンを転移先の座標へ(ビーコンも移動する可能性あり) D3DXVECTOR3 warpPos = m_pWarpPoint->GetPosition(); warpPos.x = warpPos.x + BLOCK_WIDTH / 2.0f; warpPos.y = warpPos.y - (65.0f); pAnton->SetPosition(warpPos); pAnton->SetPositionOld(warpPos); pAnton->SetTargetPosition(warpPos.x, warpPos.y); warpPos.y -= BLOCK_HEIGHT; pBeecon->SetPosition(warpPos); pBeecon->SetPositionOld(warpPos); pBeecon->SetTargetPosition(warpPos.x, warpPos.y); // ワープ終了 m_bWarpFlag = false; m_pWarpPoint->SetWarpFlag(false); m_nRetryWarpWaitTime = WARP_WAIT_TIME; } else if (m_nRetryWarpWaitTime == 0) { // 前回と今回の座標の距離が一定の距離内だったら転移する if (sqrtf(workPos.x * workPos.x + workPos.y * workPos.y) <= 1.0f && m_pos.x < antonPos.x && m_pos.x + BLOCK_WIDTH > antonPos.x) { m_bWarpFlag = true; } // 転送元がワープ状態になっていたら、転送先であるこちらも // ワープフラグを立てる else if (m_pWarpPoint->GetWarpFlag() == true) { m_bWarpFlag = true; } } else { // 待ち時間がまだあれば減らす if (m_nRetryWarpWaitTime > 0) { m_nRetryWarpWaitTime--; } } break; case CBlock::BLOCKID_WARP_GREEN: // ワープするタイミングになったら if (m_bWarpFlag && m_pWarpPoint->GetWarpFlag() && m_pos.x < antonPos.x && m_pos.x + BLOCK_WIDTH > antonPos.x && m_pos.y < antonPos.y + BLOCK_HEIGHT && m_pos.y + BLOCK_HEIGHT > antonPos.y + BLOCK_HEIGHT) { // アントンを転移先の座標へ(ビーコンも移動する可能性あり) D3DXVECTOR3 warpPos = m_pWarpPoint->GetPosition(); warpPos.x = warpPos.x + BLOCK_WIDTH / 2.0f; warpPos.y = warpPos.y - (65.0f); pAnton->SetPosition(warpPos); pAnton->SetPositionOld(warpPos); pAnton->SetTargetPosition(warpPos.x, warpPos.y); warpPos.y -= BLOCK_HEIGHT; pBeecon->SetPosition(warpPos); pBeecon->SetPositionOld(warpPos); pBeecon->SetTargetPosition(warpPos.x, warpPos.y); // ワープ終了 m_bWarpFlag = false; m_pWarpPoint->SetWarpFlag(false); m_nRetryWarpWaitTime = WARP_WAIT_TIME; } else if (m_nRetryWarpWaitTime == 0) { // 前回と今回の座標の距離が一定の距離内だったら転移する if (sqrtf(workPos.x * workPos.x + workPos.y * workPos.y) <= 1.0f && m_pos.x < antonPos.x && m_pos.x + BLOCK_WIDTH > antonPos.x) { m_bWarpFlag = true; } // 転送元がワープ状態になっていたら、転送先であるこちらも // ワープフラグを立てる else if (m_pWarpPoint->GetWarpFlag() == true) { m_bWarpFlag = true; } } else { // 待ち時間がまだあれば減らす if (m_nRetryWarpWaitTime > 0) { m_nRetryWarpWaitTime--; } } break; case CBlock::BLOCKID_WARP_PINK: // ワープするタイミングになったら if (m_bWarpFlag && m_pWarpPoint->GetWarpFlag() && m_pos.x < antonPos.x && m_pos.x + BLOCK_WIDTH > antonPos.x && m_pos.y < antonPos.y + BLOCK_HEIGHT && m_pos.y + BLOCK_HEIGHT > antonPos.y + BLOCK_HEIGHT) { // アントンを転移先の座標へ(ビーコンも移動する可能性あり) D3DXVECTOR3 warpPos = m_pWarpPoint->GetPosition(); warpPos.x = warpPos.x + BLOCK_WIDTH / 2.0f; warpPos.y = warpPos.y - (65.0f); pAnton->SetPosition(warpPos); pAnton->SetPositionOld(warpPos); pAnton->SetTargetPosition(warpPos.x, warpPos.y); warpPos.y -= BLOCK_HEIGHT; pBeecon->SetPosition(warpPos); pBeecon->SetPositionOld(warpPos); pBeecon->SetTargetPosition(warpPos.x, warpPos.y); // ワープ終了 m_bWarpFlag = false; m_pWarpPoint->SetWarpFlag(false); m_nRetryWarpWaitTime = WARP_WAIT_TIME; } else if (m_nRetryWarpWaitTime == 0) { // 前回と今回の座標の距離が一定の距離内だったら転移する if (sqrtf(workPos.x * workPos.x + workPos.y * workPos.y) <= 1.0f && m_pos.x < antonPos.x && m_pos.x + BLOCK_WIDTH > antonPos.x) { m_bWarpFlag = true; } // 転送元がワープ状態になっていたら、転送先であるこちらも // ワープフラグを立てる else if (m_pWarpPoint->GetWarpFlag() == true) { m_bWarpFlag = true; } } else { // 待ち時間がまだあれば減らす if (m_nRetryWarpWaitTime > 0) { m_nRetryWarpWaitTime--; } } break; default: break; } }
//***************************************************************************** // 初期化関数 //***************************************************************************** void CRope::Init(D3DXVECTOR3& pos, float width, float height, TEXTURE_TYPE texType, CManager* pManager, int wblock, int hblock) { m_pManager = pManager; m_PosMin = pos.y; m_PosMax = 0; VF *pVtx; float DistanceXVertex, DistanceZVertex; // 頂点間の距離 float lineX = 0; float lineZ = 0; float tex_X = 0; float tex_Y = 0; int counter = 0; int i; float Add_tex_X = 1.f; float Add_tex_Y = 1.f; m_nNumWidthBlock = wblock; m_nNumHeightBlock = hblock; m_fWidth = width; m_fHeight = height; m_fGridWidth = m_fWidth / m_nNumWidthBlock; m_fGridHeight = m_fHeight / m_nNumHeightBlock; Add_tex_X = 1.f / (float)(m_nNumWidthBlock); Add_tex_Y = 1.f / (float)(m_nNumHeightBlock); // 総ポリゴン数の計算 ↓四角形は三角形2個なので m_nNumPolygon = wblock * hblock * 2 + ((hblock - 1) * 4); // +~の部分は縮退ポリゴン分 // 総インデックス数の計算 m_nNumVertexIndex = 3 + (m_nNumPolygon - 1); // 最初の1個以降は1頂点プラスでポリゴンが書ける // 頂点間の距離算出 DistanceXVertex = m_fGridWidth; DistanceZVertex = m_fGridHeight; //原点の位置 m_Pos = pos; // 頂点の数を設定 m_nNumVtxNum = (wblock + 1) * (hblock + 1); // 面法線バッファ作成 m_vFaceNormalBuf = new D3DXVECTOR3[wblock * hblock * 2]; for (int i = 0; i < wblock * hblock * 2; i++) { m_vFaceNormalBuf[i] = D3DXVECTOR3(0.0f, 0.0f, 0.0f); } // 頂点法線バッファの作成 m_vVtxNormalBuf = new D3DXVECTOR3[m_nNumVtxNum]; for (int i = 0; i < m_nNumVtxNum; i++) { m_vVtxNormalBuf[i] = D3DXVECTOR3(0.0f, 0.0f, 0.0f); } // ポリゴンのメモリ確保 if (FAILED((*m_pD3DDevice)->CreateVertexBuffer(sizeof(VF) * m_nNumVtxNum // VERTEX_2Dの型で確保 , D3DUSAGE_WRITEONLY // 変えない , 0 // 使用する頂点フォーマット , D3DPOOL_MANAGED // 変えない , &m_pD3DVtxBuff // 格納する場所 , NULL))) // 変えない { return; // メモリを確保できなかったらメインに返す } // インデックスバッファの生成 if (FAILED((*m_pD3DDevice)->CreateIndexBuffer(sizeof(WORD) * m_nNumVertexIndex // 総インデックス数 , D3DUSAGE_WRITEONLY , D3DFMT_INDEX16 , D3DPOOL_MANAGED , &m_pD3DIndexBuff , NULL))) { return; } //******************************************************************************************************************** // ポリゴンの設定 m_pD3DVtxBuff->Lock(0, 0, (void**)&pVtx, 0); // ロックしないと勝手に書き換わる場合がある(アンロックを忘れずに) // 頂点の設定 for (int i = 0, count = 0; i < m_nNumVtxNum; i++) { pVtx[i].vtx = D3DXVECTOR3((-width * 0.5f) + lineX // 中心からの距離なので半分に , pos.y , (height * 0.5f) - lineZ); pVtx[i].nor = D3DXVECTOR3(0.f, 0.f, 0.f); // 色と透明度の設定(テクスチャを張るのでポリゴンは白で) pVtx[i].diffuse = DEFAULT_POLYGON_COLOR; lineX += DistanceXVertex; if (i == wblock + (wblock + 1) * count) { lineX = 0; lineZ += DistanceZVertex; count++; } if (i == 0) { m_vCornerPos[0] = pVtx[i].vtx; m_vCornerPos[0].x += m_Pos.x; m_vCornerPos[0].y += m_Pos.y; m_vCornerPos[0].z += m_Pos.z; } if (i == wblock) { m_vCornerPos[1] = pVtx[i].vtx; m_vCornerPos[1].x += m_Pos.x; m_vCornerPos[1].y += m_Pos.y; m_vCornerPos[1].z += m_Pos.z; } if (i == m_nNumVtxNum - 1) { m_vCornerPos[2] = pVtx[i].vtx; m_vCornerPos[2].x += m_Pos.x; m_vCornerPos[2].y += m_Pos.y; m_vCornerPos[2].z += m_Pos.z; } if (i == m_nNumVtxNum - wblock - 1) { m_vCornerPos[3] = pVtx[i].vtx; m_vCornerPos[3].x += m_Pos.x; m_vCornerPos[3].y += m_Pos.y; m_vCornerPos[3].z += m_Pos.z; } } // 面法線の算出 int faceNormalCounter = 0, hblockCounter = 0, wblockCounter = 0, vtxIndexOne = 1, vtxIndexSecond = wblock + 1; D3DXVECTOR3 norOne, norSecond, vecOneA, vecOneB, vecSecondA, vecSecondB; // 縦のループ for (hblockCounter = 0; hblockCounter < hblock; hblockCounter++) { // 横のループ for (wblockCounter = 0; wblockCounter < wblock; wblockCounter++, vtxIndexOne++, vtxIndexSecond++) { // 横に見ていき2個ずつ作る // 1つ目 vecOneA = pVtx[vtxIndexSecond - (wblock + 1)].vtx - pVtx[vtxIndexSecond].vtx; vecOneB = pVtx[vtxIndexSecond + 1].vtx - pVtx[vtxIndexSecond].vtx; D3DXVec3Cross(&norOne, &vecOneA, &vecOneB); D3DXVec3Normalize(&norOne, &norOne); m_vFaceNormalBuf[faceNormalCounter] = norOne; // 頂点の法線の設定 pVtx[vtxIndexSecond - (wblock + 1)].nor += m_vFaceNormalBuf[faceNormalCounter]; D3DXVec3Normalize(&pVtx[vtxIndexSecond - (wblock + 1)].nor, &pVtx[vtxIndexSecond - (wblock + 1)].nor); pVtx[vtxIndexSecond].nor += m_vFaceNormalBuf[faceNormalCounter]; D3DXVec3Normalize(&pVtx[vtxIndexSecond].nor, &pVtx[vtxIndexSecond].nor); pVtx[vtxIndexSecond + 1].nor += m_vFaceNormalBuf[faceNormalCounter]; D3DXVec3Normalize(&pVtx[vtxIndexSecond + 1].nor, &pVtx[vtxIndexSecond + 1].nor); faceNormalCounter++; // 2つ目 vecSecondA = pVtx[vtxIndexOne + (wblock + 1)].vtx - pVtx[vtxIndexOne].vtx; vecSecondB = pVtx[vtxIndexOne - 1].vtx - pVtx[vtxIndexOne].vtx; D3DXVec3Cross(&norSecond, &vecSecondA, &vecSecondB); D3DXVec3Normalize(&norSecond, &norSecond); m_vFaceNormalBuf[faceNormalCounter] = norSecond; // 頂点の法線の設定 pVtx[vtxIndexOne + (wblock + 1)].nor += m_vFaceNormalBuf[faceNormalCounter]; D3DXVec3Normalize(&pVtx[vtxIndexOne + (wblock + 1)].nor, &pVtx[vtxIndexOne + (wblock + 1)].nor); pVtx[vtxIndexOne].nor += m_vFaceNormalBuf[faceNormalCounter]; D3DXVec3Normalize(&pVtx[vtxIndexOne].nor, &pVtx[vtxIndexOne].nor); pVtx[vtxIndexOne - 1].nor += m_vFaceNormalBuf[faceNormalCounter]; D3DXVec3Normalize(&pVtx[vtxIndexOne - 1].nor, &pVtx[vtxIndexOne - 1].nor); faceNormalCounter++; } vtxIndexOne++; vtxIndexSecond++; } // 使用したいテクスチャの座標 for (i = 0; i < m_nNumVtxNum; i++) { if (i != 0) { if (pVtx[i].vtx.x != pVtx[i - 1].vtx.x) { tex_X += Add_tex_X; // 1を超えないようにする if (tex_X > 1.f) { tex_X = 1.f; } } // 1列やったら //if (i - 1 == wblock + counter * (wblock + 1)) if (pVtx[i].vtx.z != pVtx[i - 1].vtx.z) { counter++; tex_Y += Add_tex_Y; tex_X = 0.f; if (tex_Y > 1.f) { tex_Y = 1.f; } } } // テクスチャ設定 pVtx[i].tex = D3DXVECTOR2((float)tex_X, (float)tex_Y); } m_pD3DVtxBuff->Unlock(); // ロックしたら必ずアンロック!! //******************************************************************************************************************** WORD *pIndex; // ロック m_pD3DIndexBuff->Lock(0, 0, (void**)&pIndex, 0); // インデックスの設定 2つづつ見てるので2つづつ進む for (int i = 0, first = wblock + 1, second = 0, counter = 0; i < m_nNumVertexIndex - 1; i += 2, first++, second++) { // 横に見たときに1づつ増えていくことを利用 pIndex[i] = first; pIndex[i + 1] = second; if (counter < hblock - 1) { // 折り返しの処理 if (second == wblock + (wblock + 1) * counter) { i += 2; // 2つづつ見てるので2つづつ進む pIndex[i] = second; pIndex[i + 1] = first + 1; // 折り返し数カウントアップ counter++; } } } // アンロック m_pD3DIndexBuff->Unlock(); // 頂点宣言したものを作る (*m_pD3DDevice)->CreateVertexDeclaration(GetVertexElement(), &m_pDecl); // リストに追加 CScene::AddLinkList(CRenderer::TYPE_RENDER_NORMAL); // テクスチャ設定 m_pD3DTexBuff = CTexture::GetTexture(texType); }
void cPart::Setup(float fWidth, float fHeight, float fDepth, Cube_Part type){ ST_PT_VERTEX v; D3DXMATRIXA16 matScale, matRotate, matTrans, matFinal; m_epart = type; float left = -0.5f; float top = 0.5f; float right = 0.5f; float bottom = -0.5f; float frontdepth = 0.5f; float backdepth = -0.5f; //front std::vector<ST_PT_VERTEX> plane; v.p = D3DXVECTOR3(left, top, 0); plane.push_back(v); v.p = D3DXVECTOR3(right, top, 0); plane.push_back(v); v.p = D3DXVECTOR3(left, bottom, 0); plane.push_back(v); v.p = D3DXVECTOR3(left, bottom, 0); plane.push_back(v); v.p = D3DXVECTOR3(right, top, 0); plane.push_back(v); v.p = D3DXVECTOR3(right, bottom, 0); plane.push_back(v); for (UINT j = 0; j < plane.size(); j++){ v = plane[j]; D3DXMatrixRotationY(&matRotate, D3DXToRadian(180.0f)); //D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z); //matFinal = matRotate * matTrans; D3DXVec3TransformCoord(&v.p, &v.p, &matRotate); v.p.z = v.p.z + frontdepth; m_vecVertex.push_back(v); } // right for (UINT j = 0; j < plane.size(); j++){ v = plane[j]; D3DXMatrixRotationY(&matRotate, D3DXToRadian(270.0f)); //D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z); //matFinal = matRotate * matTrans; D3DXVec3TransformCoord(&v.p, &v.p, &matRotate); v.p.x = v.p.x + right; m_vecVertex.push_back(v); } //back for (UINT j = 0; j < plane.size(); j++){ v = plane[j]; //D3DXMatrixRotationY(&matRotate, D3DXToRadian(0.0f)); //D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z); //matFinal = matRotate * matTrans; //D3DXVec3TransformCoord(&v.p, &v.p, &matRotate); v.p.z = v.p.z + backdepth; m_vecVertex.push_back(v); } //left for (UINT j = 0; j < plane.size(); j++){ v = plane[j]; D3DXMatrixRotationY(&matRotate, D3DXToRadian(90.0f)); //D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z); //matFinal = matRotate * matTrans; D3DXVec3TransformCoord(&v.p, &v.p, &matRotate); v.p.x = v.p.x + left; m_vecVertex.push_back(v); } //top for (UINT j = 0; j < plane.size(); j++){ v = plane[j]; D3DXMatrixRotationX(&matRotate, D3DXToRadian(90.0f)); //D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z); //matFinal = matRotate * matTrans; D3DXVec3TransformCoord(&v.p, &v.p, &matRotate); v.p.y = v.p.y + top; m_vecVertex.push_back(v); } // bottom // lefttop righttop leftbottom leftbottom righttop rightbottom for (UINT j = 0; j < plane.size(); j++){ v = plane[j]; D3DXMatrixRotationX(&matRotate, D3DXToRadian(270.0f)); //D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z); //matFinal = matRotate * matTrans; D3DXVec3TransformCoord(&v.p, &v.p, &matRotate); v.p.y = v.p.y + bottom; m_vecVertex.push_back(v); } D3DXMatrixScaling(&matScale, fWidth, fHeight, fDepth); for (UINT i = 0; i < m_vecVertex.size(); i++){ D3DXVec3TransformCoord(&m_vecVertex[i].p, &m_vecVertex[i].p, &matScale); } if (type == PT_head){ // right m_vecVertex[0].t = D3DXVECTOR2(128.0f / 1024.0f, 128.0f / 512.0f); m_vecVertex[1].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, 128.0f / 512.0f); m_vecVertex[2].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[3].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[4].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, 128.0f / 512.0f); m_vecVertex[5].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[6].t = D3DXVECTOR2(0.0f, 128.0f / 512.0f); m_vecVertex[7].t = D3DXVECTOR2(128.0f / 1024.0f, 128.0f / 512.0f); m_vecVertex[8].t = D3DXVECTOR2(0.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[9].t = D3DXVECTOR2(0.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[10].t = D3DXVECTOR2(128.0f / 1024.0f, 128.0f / 512.0f); m_vecVertex[11].t = D3DXVECTOR2(128.0f / 1024.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[12].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[13].t = D3DXVECTOR2(((128.0f * 4) - 1.0f) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[14].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[15].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[16].t = D3DXVECTOR2(((128.0f * 4) - 1.0f) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[17].t = D3DXVECTOR2(((128.0f * 4) - 1.0f) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[18].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[19].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[20].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[21].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[22].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[23].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[24].t = D3DXVECTOR2((128.0f * 1) / 1024.0f, (128.0f * 0) / 512.0f); m_vecVertex[25].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 0) / 512.0f); m_vecVertex[26].t = D3DXVECTOR2((128.0f * 1) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[27].t = D3DXVECTOR2((128.0f * 1) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[28].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 0) / 512.0f); m_vecVertex[29].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[30].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 0) / 512.0f); m_vecVertex[31].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 0) / 512.0f); m_vecVertex[32].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[33].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f); m_vecVertex[34].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 0) / 512.0f); m_vecVertex[35].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f); } else if (type == PT_body){ //front m_vecVertex[0].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[1].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f); m_vecVertex[2].t = D3DXVECTOR2(320.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[3].t = D3DXVECTOR2(320.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[4].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f); m_vecVertex[5].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 512.0f / 512.0f); m_vecVertex[6].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[7].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[8].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[9].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[10].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[11].t = D3DXVECTOR2(320.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[12].t = D3DXVECTOR2(510.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[13].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[14].t = D3DXVECTOR2(510.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[15].t = D3DXVECTOR2(510.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[16].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[17].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[18].t = D3DXVECTOR2(448.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[19].t = D3DXVECTOR2(560.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[20].t = D3DXVECTOR2(448.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[21].t = D3DXVECTOR2(448.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[22].t = D3DXVECTOR2(560.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[23].t = D3DXVECTOR2(560.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[24].t = D3DXVECTOR2(320.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[25].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[26].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[27].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[28].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[29].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f); m_vecVertex[30].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[31].t = D3DXVECTOR2((128.0f * 2 + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[32].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f); m_vecVertex[33].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f); m_vecVertex[34].t = D3DXVECTOR2((128.0f * 2 + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[35].t = D3DXVECTOR2((128.0f * 2 + 320.0f) / 1024.0f, 320.0f / 512.0f); } else if (type == PT_arm_left){ m_vecVertex[0].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[1].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[2].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[3].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[4].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[5].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[6].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[7].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[8].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[9].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[10].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[11].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[12].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[13].t = D3DXVECTOR2(896.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[14].t = D3DXVECTOR2(832.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[15].t = D3DXVECTOR2(832.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[16].t = D3DXVECTOR2(896.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[17].t = D3DXVECTOR2(896.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[18].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[19].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[20].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[21].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[22].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[23].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[24].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[25].t = D3DXVECTOR2(704.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[26].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[27].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[28].t = D3DXVECTOR2(704.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[29].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[30].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[31].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[32].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[33].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[34].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[35].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f); } else if (type == PT_arm_right || type == PT_fist){ m_vecVertex[0].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[1].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[2].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[3].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[4].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[5].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[6].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[7].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[8].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[9].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[10].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[11].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[12].t = D3DXVECTOR2(896.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[13].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[14].t = D3DXVECTOR2(896.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[15].t = D3DXVECTOR2(896.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[16].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[17].t = D3DXVECTOR2(832.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[18].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[19].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[20].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[21].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[22].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[23].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[24].t = D3DXVECTOR2(704.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[25].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[26].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[27].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[28].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[29].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[30].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[31].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[32].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[33].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[34].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[35].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f); } else if (type == PT_leg_left){ m_vecVertex[0].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[1].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[2].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[3].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[4].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[5].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[6].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[7].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[8].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[9].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[10].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[11].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[12].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[13].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[14].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[15].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[16].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[17].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[18].t = D3DXVECTOR2(0 / 1024.0f, 320.0f / 512.0f); m_vecVertex[19].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[20].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f); m_vecVertex[21].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f); m_vecVertex[22].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[23].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[24].t = D3DXVECTOR2(64.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[25].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[26].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[27].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[28].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[29].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[30].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[31].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[32].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[33].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[34].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[35].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f); } else if (type == PT_leg_right){ m_vecVertex[0].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[1].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[2].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[3].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[4].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[5].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[6].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[7].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[8].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[9].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[10].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[11].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[12].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[13].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[14].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[15].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[16].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[17].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[18].t = D3DXVECTOR2(0 / 1024.0f, 320.0f / 512.0f); m_vecVertex[19].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[20].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f); m_vecVertex[21].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f); m_vecVertex[22].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[23].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f); m_vecVertex[24].t = D3DXVECTOR2(64.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[25].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[26].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[27].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[28].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[29].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[30].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[31].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[32].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[33].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f); m_vecVertex[34].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f); m_vecVertex[35].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f); } }
bool QuadMesh::Initialize(DWORD m, DWORD n, float dx) { mNumRows = m; mNumCols = n; unsigned int uiNumVertices, uiNumFaces, uiNumIndices; uiNumVertices = m * n; uiNumFaces = (m-1) * (n-1) * 2; uiNumIndices = uiNumFaces * 3; U2TriListData *pData = NULL; nMeshGroup* pMeshGroup = NULL; pData = U2_NEW U2TriListData; //m_spMesh = U2_NEW U2N2Mesh(pData); this->SetModelData(pData); this->SetUsages(U2N2Mesh::WriteOnly); this->SetVertexComponents(U2N2Mesh::Coord | U2N2Mesh::Normal | U2N2Mesh::Tangent | U2N2Mesh::Uv0); //this->CreateMeshGroups(1); //m_meshGroups.Resize(1); m_meshGroups.AddElem(U2_NEW nMeshGroup); U2Mesh::m_uNumGroups = 1; pMeshGroup = static_cast<nMeshGroup*>(GroupPtr(0)); pMeshGroup->SetMesh(this); pMeshGroup->SetModelData(pData); // 저장하지 않음... pData->SetVertexCount(uiNumVertices, uiNumVertices); pData->CreateVertices(); pData->CreateNormals(false); pData->CreateTangents(false); pData->CreateTexCoords(1); //D3DXVECTOR3* pVert = pData->GetVertices(); float halfWidth = (n-1)*dx*0.5f; float halfDepth = (m-1)*dx*0.5f; uint16* pusIdxArray = U2_ALLOC(uint16, uiNumIndices); m_spModelData->SetIndices(uiNumFaces, uiNumFaces, pusIdxArray, 0, 1); if (!this->CreateEmptyBuffers()) { U2ASSERT(FALSE); return false; } float *vBasePtr = LockVertices(); U2ASSERT(vBasePtr); float du = 1.0f / (n-1); float dv = 1.0f / (m-1); for(DWORD i = 0; i < m; i++) { float z = halfDepth - i*dx; for(DWORD j = 0; j < n; j++) { float x = -halfWidth + j*dx; D3DXVECTOR3* pVert = pData->GetVertices(); D3DXVECTOR3* pNorm = pData->GetNormals(); D3DXVECTOR3* pTangent = pData->GetTangents(); D3DXVECTOR2* pUV0 = pData->GetTexCoordSet(0); pVert[i*n+j] = D3DXVECTOR3(x, 0.0f, z); pNorm[i*n+j] = D3DXVECTOR3(0.0f, 1.0f, 0.0f); pTangent[i*n+j] = D3DXVECTOR3(1.0f, 0.0f, 0.0f); pUV0[i*n+j] = D3DXVECTOR2(j * du, i * dv); *vBasePtr++ = x; *vBasePtr++ = 0.0f; *vBasePtr++ = z; *vBasePtr++ = 0.0f; *vBasePtr++ = 1.0f; *vBasePtr++ = 0.0f; *vBasePtr++ = 1.0f; *vBasePtr++ = 0.0f; *vBasePtr++ = 0.0f; *vBasePtr++ = j * du; *vBasePtr++ = i * dv; } } UnlockVertices(); pMeshGroup->SetFirstVertex(0); pMeshGroup->SetNumVertices(uiNumVertices); int ibSize = sizeof(uint16) * uiNumIndices; uint16* p = LockIndices(); U2ASSERT(p); DWORD k = 0; // Iterate over each quad and compute indices. for(DWORD i = 0; i < m-1; ++i) { for(DWORD j = 0; j < n-1; ++j) { pusIdxArray[k] = p[k] = i*n+j; pusIdxArray[k+1] = p[k+1] = i*n+j+1; pusIdxArray[k+2] = p[k+2] = (i+1)*n+j; pusIdxArray[k+3] = p[k+3] = (i+1)*n+j; pusIdxArray[k+4] = p[k+4] = i*n+j+1; pusIdxArray[k+5] = p[k+5] = (i+1)*n+j+1; k+=6; } } UnlockIndices(); m_spModelData->SetIndexArray(pusIdxArray); pMeshGroup->SetFirstIndex(0); pMeshGroup->SetNumIndices(uiNumIndices); pMeshGroup->UpdateMeshState(true); }
HRESULT KGraphicsEngine::Render2SmallerTexture() { LPTEXTURE pTexBuffer = NULL; LPTEXTURE pTexSmaller = NULL; LPTEXTURE pTexBlur = NULL; if (FAILED(g_cTextureTable.GetTexture(&pTexBuffer,m_BufferTextureID))) return E_FAIL; if (FAILED(g_cTextureTable.GetTexture(&pTexSmaller,m_SmallerTextureID))) return E_FAIL; if (FAILED(g_cTextureTable.GetTexture(&pTexBlur,m_BlurTextureID))) return E_FAIL; if(!pTexBuffer->m_lpTexture) return E_FAIL; if(!pTexSmaller->m_lpTexture) return E_FAIL; if(!pTexBlur->m_lpTexture) return E_FAIL; D3DSURFACE_DESC Desc; if(FAILED(pTexSmaller->m_lpTexture->GetLevelDesc(0,&Desc))) return E_FAIL; D3DSURFACE_DESC DescBlur; if(FAILED(pTexBlur->m_lpTexture->GetLevelDesc(0,&DescBlur))) return E_FAIL; LPDIRECT3DSURFACE9 lpSurfaceSmaller = NULL; if(FAILED(pTexSmaller->m_lpTexture->GetSurfaceLevel(0,&lpSurfaceSmaller))) return E_FAIL; lpSurfaceSmaller->Release(); LPDIRECT3DSURFACE9 lpSurfaceBlur = NULL; if(FAILED(pTexBlur->m_lpTexture->GetSurfaceLevel(0,&lpSurfaceBlur))) return E_FAIL; lpSurfaceBlur->Release(); D3DXMATRIX Mat_View_Save; D3DXMATRIX Mat_Proj_Save; LPDIRECT3DSURFACE9 lpSurfaceSave = NULL; D3DVIEWPORT9 ViewPort,ViewPortBlur,ViewPortSave; ////////////////////////////////////////////////////////////////////////// //Save back buffer & transform & viewport g_pd3dDevice->GetRenderTarget(0,&lpSurfaceSave); lpSurfaceSave->Release(); g_pd3dDevice->GetTransform( D3DTS_VIEW, &Mat_View_Save ); g_pd3dDevice->GetTransform( D3DTS_PROJECTION, &Mat_Proj_Save ); g_pd3dDevice->GetViewport(&ViewPortSave); ////////////////////////////////////////////////////////////////////////// ViewPort.X = 0;ViewPort.Y = 0; ViewPort.Width = Desc.Width; ViewPort.Height = Desc.Height; ViewPort.MinZ = 0;ViewPort.MaxZ = 1.0f; ViewPortBlur.X = 0;ViewPortBlur.Y = 0; ViewPortBlur.Width = DescBlur.Width; ViewPortBlur.Height = DescBlur.Height; ViewPortBlur.MinZ = 0;ViewPortBlur.MaxZ = 1.0f; D3DXVECTOR2 A(0,0); D3DXVECTOR2 C((float)Desc.Width,(float)Desc.Height); D3DXVECTOR2 A1(0,0); D3DXVECTOR2 C1((float)DescBlur.Width,(float)DescBlur.Height); ////////////////////////////////////////////////////////////////////////// g_pd3dDevice->SetViewport(&ViewPort); g_pd3dDevice->SetRenderTarget(0,lpSurfaceSmaller); ////////////////////////////////////////////////////////////////////////// //reade began to render //g_pd3dDevice->BeginScene(); g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0x00000000, 1.0f, 0 ); g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); float K = 2; D3DXVECTOR2 T1( K,K); D3DXVECTOR2 T2(-K,K); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); DWORD Color = m_lpCurScene->m_Glow.m_GateColor; g_cTextureTable.SetTexture(0,m_BufferTextureID); g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SUBTRACT); g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE); /*g_cTextureTable.SetTexture(1,m_BufferTextureID); g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_MODULATE2X); g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_CURRENT);*/ g_cGraphicsTool.DrawScreenRectNormal(&A,&C,0.0f,Color,Color,Color,Color); //g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); //g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE); //g_cGraphicsTool.DrawScreenRect(&A,&C,0.0f,Color,m_SmallerTextureID); //g_cGraphicsTool.DrawScreenRect(&(A-T1),&(C+T1),0.0f,Color,m_SmallerTextureID); //g_cGraphicsTool.DrawScreenRect(&A,&C,0.0f,Color,m_BufferTextureID); /*g_cGraphicsTool.DrawScreenRect(&(A-T1),&(C-T1),0.0f,Color,m_BufferTextureID); g_cGraphicsTool.DrawScreenRect(&(A+T1),&(C+T1),0.0f,Color,m_BufferTextureID); g_cGraphicsTool.DrawScreenRect(&(A-T2),&(C-T2),0.0f,Color,m_BufferTextureID); g_cGraphicsTool.DrawScreenRect(&(A+T2),&(C+T2),0.0f,Color,m_BufferTextureID);*/ if(1) { ////////////////////////////////////////////////////////////////////////// Color = 0x30FFFFFF; for(int i=0;i<8;i++) { g_pd3dDevice->SetViewport(&ViewPortBlur); g_pd3dDevice->SetRenderTarget(0,lpSurfaceBlur); //if(i==0) { g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0x00000000, 1.0f, 0 ); } g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); g_cGraphicsTool.DrawScreenRect(&A1,&C1,0.0f,0xFFFFFFFF,m_SmallerTextureID); g_pd3dDevice->SetViewport(&ViewPort); g_pd3dDevice->SetRenderTarget(0,lpSurfaceSmaller); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_BLENDFACTOR); g_pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR,0x60606060); g_cGraphicsTool.DrawScreenRect(&(A-T1),&(C+T1),0.0f,Color,m_BlurTextureID); } } else { //g_pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR,0x60606060); for(int i=0;i<10;i++) { g_pd3dDevice->SetViewport(&ViewPortBlur); g_pd3dDevice->SetRenderTarget(0,lpSurfaceBlur); g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0x00000000, 1.0f, 0 ); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); g_cGraphicsTool.DrawScreenRect(&A1,&C1,0.0f,0xFFFFFFFF,m_SmallerTextureID); g_pd3dDevice->SetViewport(&ViewPort); g_pd3dDevice->SetRenderTarget(0,lpSurfaceSmaller); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE); Color = 0x00FFFFFF|(255-i*25)<<24; float K = 5; T1 = D3DXVECTOR2(K*i,K*i); T2 = D3DXVECTOR2(-K*i,K*i); g_cGraphicsTool.DrawScreenRect(&(A-T2),&(C-T2),0.0f,Color,m_BlurTextureID); /*g_cGraphicsTool.DrawScreenRect(&(A+T1),&(C+T1),0.0f,Color,m_BlurTextureID); g_cGraphicsTool.DrawScreenRect(&(A-T2),&(C-T2),0.0f,Color,m_BlurTextureID); g_cGraphicsTool.DrawScreenRect(&(A+T2),&(C+T2),0.0f,Color,m_BlurTextureID);*/ } /*g_pd3dDevice->SetViewport(&ViewPortBlur); g_pd3dDevice->SetRenderTarget(0,lpSurfaceBlur); g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0x00000000, 1.0f, 0 ); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); g_cGraphicsTool.DrawScreenRect(&A1,&C1,0.0f,0xFFFFFFFF,m_SmallerTextureID); g_pd3dDevice->SetViewport(&ViewPort); g_pd3dDevice->SetRenderTarget(0,lpSurfaceSmaller); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_BLENDFACTOR); g_pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR,0x60606060);*/ Color = 0x30FFFFFF; g_cGraphicsTool.DrawScreenRect(&(A),&(C),0.0f,Color,m_BlurTextureID); } //g_pd3dDevice->EndScene(); ////////////////////////////////////////////////////////////////////////// //Restore g_pd3dDevice->SetTransform( D3DTS_VIEW, &Mat_View_Save ); g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &Mat_Proj_Save ); g_pd3dDevice->SetRenderTarget(0,lpSurfaceSave); g_pd3dDevice->SetViewport(&ViewPortSave); g_cTextureTable.SetTexture(1,NULL); g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLOROP,D3DTOP_DISABLE); g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_CURRENT); return S_OK; }
Sprite::Sprite(DeviceHandler *_deviceHandler, FLOAT2 position, FLOAT2 size,ID3D10ShaderResourceView *_texture, int _layer) { this->m_deviceHandler = _deviceHandler; this->m_texture = _texture; this->m_nrOfVertices = 6; this->m_layer = _layer; this->m_visible = true; m_position = position; m_size = size; //Convert the position and size to projection space //position.x = (position.x / this->m_deviceHandler->getScreenSize().x) * 2 - 1; //position.y = (position.y / this->m_deviceHandler->getScreenSize().y) * 2 - 1; //size.x = (size.x / this->m_deviceHandler->getScreenSize().x) * 2; //size.y = (size.y / this->m_deviceHandler->getScreenSize().y) * 2; //Create the modelmatrix D3DXMatrixTranslation(&this->m_modelMatrix, position.x, position.y, 0.0f); //Create the vertex buffer D3D10_BUFFER_DESC bd; bd.Usage = D3D10_USAGE_DYNAMIC; bd.ByteWidth = sizeof( Vertex ) * 6; bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; HRESULT hr = this->m_deviceHandler->getDevice()->CreateBuffer( &bd, 0, &this->m_buffer); if(FAILED(hr)) { MessageBox( 0, "Unable to create Vertex Buffer", "VB Error", 0 ); } //Load vertices D3DXVECTOR2 pos = D3DXVECTOR2(-size.x / 2, -size.y / 2); Vertex *vertexData = NULL; this->m_buffer->Map( D3D10_MAP_WRITE_DISCARD, 0, reinterpret_cast< void** >((void**)&vertexData)); vertexData[0].pos = D3DXVECTOR3(pos.x, pos.y + size.y, 0.0f); vertexData[0].texCoord = D3DXVECTOR2(0.0f, 0.0f); vertexData[1].pos = D3DXVECTOR3(pos.x + size.x, pos.y + size.y, 0.0f); vertexData[1].texCoord = D3DXVECTOR2(1.0f, 0.0f); vertexData[2].pos = D3DXVECTOR3(pos.x, pos.y, 0.0f); vertexData[2].texCoord = D3DXVECTOR2(0.0f, 1.0f); vertexData[3].pos = D3DXVECTOR3(pos.x + size.x, pos.y, 0.0f); vertexData[3].texCoord = D3DXVECTOR2(1.0f, 1.0f); vertexData[4].pos = D3DXVECTOR3(pos.x, pos.y, 0.0f); vertexData[4].texCoord = D3DXVECTOR2(0.0f, 1.0f); vertexData[5].pos = D3DXVECTOR3(pos.x + size.x, pos.y + size.y, 0.0f); vertexData[5].texCoord = D3DXVECTOR2(1.0f, 0.0f); this->m_buffer->Unmap(); }
void RaftMesh::GenerateMesh() { // Initial position where the mesh will be drawn. float mast_x = (width / 32); float mast_y = height; float mast_z = (depth / 32); float body_x = (width / 2); float body_y = 0.0f; float body_z = (depth / 2); float sail_x = (width / 4); float sail_y = height; float sail_z = mast_z; float height_dist = height/8.0f; // Create vertexes (Sail) // 13 14 // 15 16 // // 17 18 // 19 20 vertexes.push_back(Vertex(D3DXVECTOR3(-sail_x, sail_y, sail_z), D3DCOLOR_XRGB(128, 128, 128) , D3DXVECTOR2(0,0) )); vertexes.push_back(Vertex(D3DXVECTOR3(sail_x, sail_y, sail_z), D3DCOLOR_XRGB(128, 128, 128) , D3DXVECTOR2(0,0) )); vertexes.push_back(Vertex(D3DXVECTOR3(-sail_x, sail_y - height_dist, sail_z - height_dist), D3DCOLOR_XRGB(128, 128, 128) , D3DXVECTOR2(0,0) )); vertexes.push_back(Vertex(D3DXVECTOR3(sail_x, sail_y - height_dist, sail_z - height_dist), D3DCOLOR_XRGB(128, 128, 128) , D3DXVECTOR2(0,0) )); vertexes.push_back(Vertex(D3DXVECTOR3(-sail_x, sail_y - 5 * height_dist, sail_z - height_dist), D3DCOLOR_XRGB(128, 128, 128) , D3DXVECTOR2(0,0) )); vertexes.push_back(Vertex(D3DXVECTOR3(sail_x, sail_y - 5 *height_dist, sail_z - height_dist), D3DCOLOR_XRGB(128, 128, 128) , D3DXVECTOR2(0,0) )); vertexes.push_back(Vertex(D3DXVECTOR3(-sail_x, sail_y - 6 * height_dist, sail_z), D3DCOLOR_XRGB(128, 128, 128) , D3DXVECTOR2(0,0) )); vertexes.push_back(Vertex(D3DXVECTOR3(sail_x, sail_y - 6 * height_dist, sail_z), D3DCOLOR_XRGB(128, 128, 128) , D3DXVECTOR2(0,0) )); // Indexes (Sail) // 13 14 // 15 16 // // 17 18 // 19 20 indexes.push_back(0); indexes.push_back(1); indexes.push_back(2); indexes.push_back(2); indexes.push_back(1); indexes.push_back(3); indexes.push_back(2); indexes.push_back(3); indexes.push_back(4); indexes.push_back(4); indexes.push_back(3); indexes.push_back(5); indexes.push_back(4); indexes.push_back(5); indexes.push_back(6); indexes.push_back(6); indexes.push_back(5); indexes.push_back(7); indexCount = indexes.size(); triangleCount = indexCount / 3; vertexCount = vertexes.size(); }
bool RectClass::Initialize(ID3D11Device* pDevice, int rectRidus, float z) { float radius = rectRidus; float negRadius = -1 * radius; RectClass::VertexType s_RectClassVertexs[] = { { D3DXVECTOR3(negRadius, radius, z), D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f), D3DXVECTOR2(0.0f, 0.0f) }, { D3DXVECTOR3(radius, radius, z), D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f), D3DXVECTOR2(1.0f, 0.0f) }, { D3DXVECTOR3(negRadius, negRadius, z), D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f), D3DXVECTOR2(0.0f, 1.0f) }, { D3DXVECTOR3(radius, negRadius, z), D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f), D3DXVECTOR2(1.0f, 1.0f) }, }; int s_RectClassIndexs[] = {0,1,2,2,1,3}; D3D11_BUFFER_DESC vertexBufferDesc; // 顶点缓存的描述 D3D11_BUFFER_DESC indexBufferDesc; // 顶点索引缓存的描述 D3D11_SUBRESOURCE_DATA vertexData; // 顶点需要访问的资源 D3D11_SUBRESOURCE_DATA indexData; // 顶点索引需要访问的资源 HRESULT res = S_OK; // 设置顶点缓冲描述 vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof(s_RectClassVertexs); vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; // 将资源绑定到顶点,供管线访问 vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; vertexBufferDesc.StructureByteStride = 0; // 指向保存顶点数据的临时缓冲. vertexData.pSysMem = s_RectClassVertexs; // 将三角形的顶点数据放入顶点缓冲中 vertexData.SysMemPitch = 0; vertexData.SysMemSlicePitch = 0; // 创建顶点缓冲. res = pDevice->CreateBuffer(&vertexBufferDesc, &vertexData, &m_pVertexBuffer); assert(SUCCEEDED(res)); // 设置顶点索引缓冲描述 indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(s_RectClassIndexs); indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; // 将资源绑定到顶点索引,供管线访问 indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; indexBufferDesc.StructureByteStride = 0; // 指向保存顶点数据的临时缓冲. indexData.pSysMem = s_RectClassIndexs; // 将三角形的顶点数据放入顶点缓冲中 indexData.SysMemPitch = 0; indexData.SysMemSlicePitch = 0; // 创建顶点缓冲. res = pDevice->CreateBuffer(&indexBufferDesc, &indexData, &m_pIndexBuffer); assert(SUCCEEDED(res)); // 初始化Shader ID3D10Blob *pErr = NULL; // 存放编译shader的错误信息 ID3D10Blob *pVertexShaderBuffer = NULL; // 编译出来的VS字节 ID3D10Blob *pPixelShaderBuffer = NULL; // 编译出来的PS字节 D3D11_INPUT_ELEMENT_DESC polygonLayout[3]; // 描述 unsigned int numElem = sizeof(polygonLayout) / sizeof(polygonLayout[0]); // 一个点中的成员量 D3D11_BUFFER_DESC matrixBufferDesc = { 0 }; // 编译VS res = D3DX11CompileFromMemory((LPCSTR)s_RectShaderStr, sizeof(s_RectShaderStr), NULL, NULL, NULL, "ColorVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pVertexShaderBuffer, &pErr, NULL); assert(SUCCEEDED(res)); // 编译PS res = D3DX11CompileFromMemory((LPCSTR)s_RectShaderStr, sizeof(s_RectShaderStr), NULL, NULL, NULL, "ColorPixelShader", "ps_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pPixelShaderBuffer, &pErr, NULL); assert(SUCCEEDED(res)); // 创建VS Shader res = pDevice->CreateVertexShader(pVertexShaderBuffer->GetBufferPointer(), pVertexShaderBuffer->GetBufferSize(), NULL, &m_pVertexShader); assert(SUCCEEDED(res)); // 创建PS Shader res = pDevice->CreatePixelShader(pPixelShaderBuffer->GetBufferPointer(), pPixelShaderBuffer->GetBufferSize(), NULL, &m_pPixelShader); assert(SUCCEEDED(res)); // 创建定点布局,在Input-Assemble 阶段使用 polygonLayout[0].SemanticName = "POSITION"; // 语义 polygonLayout[0].SemanticIndex = 0; // 语义 polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; // 语义 polygonLayout[0].InputSlot = 0; polygonLayout[0].AlignedByteOffset = 0; polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[0].InstanceDataStepRate = 0; polygonLayout[1].SemanticName = "COLOR"; // 语义 polygonLayout[1].SemanticIndex = 0; // 语义 polygonLayout[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; // 语义 polygonLayout[1].InputSlot = 0; polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[1].InstanceDataStepRate = 0; polygonLayout[2].SemanticName = "TEXCOORD"; // 语义 polygonLayout[2].SemanticIndex = 0; // 语义 polygonLayout[2].Format = DXGI_FORMAT_R32G32_FLOAT; // 语义 polygonLayout[2].InputSlot = 0; polygonLayout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[2].InstanceDataStepRate = 0; res = pDevice->CreateInputLayout(polygonLayout, numElem, pVertexShaderBuffer->GetBufferPointer(), pVertexShaderBuffer->GetBufferSize(), &m_pLayout); assert(SUCCEEDED(res)); pVertexShaderBuffer->Release(); pVertexShaderBuffer = NULL; pPixelShaderBuffer->Release(); pPixelShaderBuffer = NULL; // 创建Content 矩阵Buffer matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC; matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType); matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; matrixBufferDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; matrixBufferDesc.MiscFlags = 0; matrixBufferDesc.StructureByteStride = 0; res = pDevice->CreateBuffer(&matrixBufferDesc, NULL, &m_pContantBuffer); assert(SUCCEEDED(res)); return true; }
void DirectX::render_frame() { CUSTOMVERTEX OurVertices[] = { D3DXVECTOR2(-1.f,0.f), D3DXVECTOR2(0.f,1.f), D3DXVECTOR2(-1.f,1.f), D3DXVECTOR2(0.f,0.f), D3DXVECTOR2(1.f,0.f), D3DXVECTOR2(1.f,1.f), D3DXVECTOR2(-1.f,1.f), D3DXVECTOR2(0.f,0.f), D3DXVECTOR2(1.f,1.f), D3DXVECTOR2(1.f,0.f), D3DXVECTOR2(1.f,0.f), D3DXVECTOR2(1.f,1.f), //{0.0f, 0.0f/*, 0.0f*/}, //{0.1f, 0.1f/*, 0.0f*/}, //{0.1f, 0.0f/*, 0.0f*/}, }; LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL; // create a vertex buffer interface called v_buffer HRESULT res = m_d3ddev->CreateVertexBuffer(2*3*sizeof(CUSTOMVERTEX), 0, 0, D3DPOOL_MANAGED, &v_buffer, NULL); VOID* pVoid; // a void pointer // lock v_buffer and load the vertices into it res = v_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, OurVertices, sizeof(OurVertices)); v_buffer->Unlock(); float rotation(0); D3DXMATRIX matRotationX, matRotationY; //x rotation (NEW) D3DXMatrixRotationZ(&matRotationX,rotation * 0.0174532925f ); //y rotation (NEW) //MOVE ME D3DXHANDLE MatrixHandle = m_SimpleSurfaceShader.Effect->GetParameterByName(0, "World"); D3DXHANDLE TextureHandle = m_SimpleSurfaceShader.Effect->GetParameterByName(0,"Sprite"); m_d3ddev->SetVertexDeclaration(m_declaration); m_d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO); m_d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE); //m_d3ddev->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME ); // clear the window to a deep blue m_d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100, 40, 250), 1.0f, 0); m_d3ddev->BeginScene(); // begins the 3D scene // select the vertex buffer to display m_d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); m_SimpleSurfaceShader.Effect->SetMatrix(MatrixHandle,&(matRotationX) ); m_SimpleSurfaceShader.Effect->SetTexture(TextureHandle, pPyramideTexture); m_SimpleSurfaceShader.Effect->Begin(0,0); m_SimpleSurfaceShader.Effect->BeginPass(0); // copy the vertex buffer to the back buffer res = m_d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST , 0, 2); m_SimpleSurfaceShader.Effect->EndPass(); m_SimpleSurfaceShader.Effect->End(); // do 3D rendering on the back buffer here m_d3ddev->EndScene(); // ends the 3D scene m_d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame }
bool SkyBox::createVertexBuffer(ID3D11Device* currDevice) { mTotalIndices = 36; D3D11_BUFFER_DESC vBufferStruct, iBufferStruct; D3D11_SUBRESOURCE_DATA vertexData, indexData; vBufferStruct.Usage = D3D11_USAGE_DYNAMIC; vBufferStruct.ByteWidth = sizeof(basicVertex) * mTotalIndices; vBufferStruct.BindFlags = D3D11_BIND_VERTEX_BUFFER; vBufferStruct.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; vBufferStruct.MiscFlags = 0; basicVertex* vertexSet = new basicVertex[mTotalIndices]; if(!vertexSet) { return false; } int index = 0; for(int i = -1; i < 2; i += 2) { for(int j = -1; j < 2; j += 2) { for(int k = -1; k < 2; k += 2) { vertexSet[index] = basicVertex(D3DXVECTOR3((float)i, (float)j, (float)k), D3DXVECTOR2((float)i, (float)j), D3DXVECTOR2((float)i, (float)j)); index++; } } } vertexData.pSysMem = &vertexSet[0]; currDevice->CreateBuffer(&vBufferStruct, &vertexData, &mVBuffer); if(!mVBuffer) { return false; } if(vertexSet) { delete [] vertexSet; vertexSet = 0; } iBufferStruct.Usage = D3D11_USAGE_IMMUTABLE; iBufferStruct.ByteWidth = sizeof(unsigned int) * mTotalIndices; iBufferStruct.BindFlags = D3D11_BIND_INDEX_BUFFER; iBufferStruct.CPUAccessFlags = 0; iBufferStruct.MiscFlags = 0; unsigned int indices[] = { 0, 2, 1, 2, 3, 1, // 0, 2, 4, 2, 6, 4, // 2, 3, 6, 3, 7, 6, // 0, 1, 4, 1, 5, 4, // 1, 3, 5, 3, 7, 5, // 4, 6, 5, 6, 7, 5 }; indexData.pSysMem = &indices[0]; currDevice->CreateBuffer(&iBufferStruct, &indexData, &mIBuffer); if(!mIBuffer) { return false; } return true; }
/****************************************************************************** * 関数名:InitShadow * * 引数 : * 戻り値: * 説明 : ******************************************************************************/ HRESULT InitShadow( void ) { LPDIRECT3DDEVICE9 pDevice = GetDevice(); for( int cntShadow = 0 ; cntShadow < SHADOW_MAX ; cntShadow++ ) { if( FAILED ( pDevice -> CreateVertexBuffer( sizeof( VERTEX_3D ) * SHADOW_NUM_VTX , D3DUSAGE_WRITEONLY , FVF_VERTEX_3D , D3DPOOL_MANAGED , &g_Shadow[cntShadow].pVtxBuffShadow , NULL ) ) ) { return E_FAIL; } } g_pTextureShadow = NULL; //テクスチャ読み込み if( SHADOW_USE_TEX ) { D3DXCreateTextureFromFile( pDevice , "data/TEXTURE/shadow000.jpg" , &g_pTextureShadow ); } for( int cntShadow = 0 ; cntShadow < SHADOW_MAX ; cntShadow++ ) { VERTEX_3D *pVtx; g_Shadow[cntShadow].pVtxBuffShadow -> Lock( 0 , 0 , ( void** ) &pVtx , 0 ); g_Shadow[cntShadow].posShadow = D3DXVECTOR3( 0.0f , 0.5f , 0.0f ); g_Shadow[cntShadow].rotShadow = D3DXVECTOR3( 0.0f , 0.0f , 0.0f ); g_Shadow[cntShadow].sclShadow = D3DXVECTOR3( 1.0f , 1.0f , 1.0f ); g_Shadow[cntShadow].shadowUse = false; g_Shadow[cntShadow].shadowHeight = 0.0f; g_Shadow[cntShadow].shadowWidth = 0.0f; //座標設定 pVtx[0].pos = D3DXVECTOR3( - g_Shadow[cntShadow].shadowWidth / 2 , 0.0f , g_Shadow[cntShadow].shadowHeight / 2 ); pVtx[1].pos = D3DXVECTOR3( g_Shadow[cntShadow].shadowWidth / 2 , 0.0f , g_Shadow[cntShadow].shadowHeight / 2 ); pVtx[2].pos = D3DXVECTOR3( - g_Shadow[cntShadow].shadowWidth / 2 , 0.0f , - g_Shadow[cntShadow].shadowHeight / 2 ); pVtx[3].pos = D3DXVECTOR3( g_Shadow[cntShadow].shadowWidth / 2 , 0.0f , - g_Shadow[cntShadow].shadowHeight / 2 ); //頂点カラー設定 pVtx[0].col = D3DXCOLOR( 1.0f , 1.0f , 1.0f, 0.5f ); pVtx[1].col = D3DXCOLOR( 1.0f , 1.0f , 1.0f , 0.5f ); pVtx[2].col = D3DXCOLOR( 1.0f , 1.0f , 1.0f , 0.5f ); pVtx[3].col = D3DXCOLOR( 1.0f , 1.0f , 1.0f , 0.5f ); //テクスチャ pVtx[0].tex = D3DXVECTOR2( 0 , 0 ); pVtx[1].tex = D3DXVECTOR2( 1 , 0 ); pVtx[2].tex = D3DXVECTOR2( 0 , 1 ); pVtx[3].tex = D3DXVECTOR2( 1 , 1 ); //法線 pVtx[0].nor = D3DXVECTOR3( 0.0f , 1.0f , 0.0f ); pVtx[1].nor = D3DXVECTOR3( 0.0f , 1.0f , 0.0f ); pVtx[2].nor = D3DXVECTOR3( 0.0f , 1.0f , 0.0f ); pVtx[3].nor = D3DXVECTOR3( 0.0f , 1.0f , 0.0f ); g_Shadow[cntShadow].pVtxBuffShadow -> Unlock(); } return S_OK; }
struct VertexType { D3DXVECTOR3 position; D3DXVECTOR4 color; D3DXVECTOR2 texcoord; //D3DXVECTOR3 normal; // 法线 }; VertexType g_vertices[] = { //{ D3DXVECTOR3(-1.0f, -1.0f, 0.1f), D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f) }, //{ D3DXVECTOR3(0.0f, 1.0f, 0.1f), D3DXVECTOR4(1.0f, 0.5f, 0.0f, 1.0f) }, //{ D3DXVECTOR3(1.0f, -1.0f, 0.1f), D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f) } //{ D3DXVECTOR3(-0.5f, -.5f, 10.0f), D3DXVECTOR4(0.0f, 0.0f, 1.0f, 1.0f) }, //{ D3DXVECTOR3(0.0f, 0.5f, 10.0f), D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f) }, //{ D3DXVECTOR3(0.5f, -0.5f, 10.0f), D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f) } { D3DXVECTOR3(0.0f, 0.0f, 1.0f), D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f), D3DXVECTOR2(0.0f,1.0f)}, { D3DXVECTOR3(2.0f, 0.0f, 1.0f), D3DXVECTOR4(0.0f, 1.0f, 0.0f, 1.0f), D3DXVECTOR2(0.0f,0.0f)}, { D3DXVECTOR3(2.0f, -2.0f, 1.0f), D3DXVECTOR4(0.0f, 0.0f, 1.0f, 1.0f), D3DXVECTOR2(1.0f,0.0f)}, }; unsigned int g_indexVertice[sizeof(g_vertices) / sizeof(g_vertices[0])] = { 0, 1, 2 }; TriangleClass::TriangleClass(void) { m_pVertexBuffer = NULL; m_pIndexBuffer = NULL; m_vertexCount = (sizeof(g_vertices) / sizeof(g_vertices[0])); m_indexCount = m_vertexCount; m_pTextureClass = NULL; }
void CGui::HandleMouseInput( const D3DXVECTOR2 mousePosition ) { CBitmap *const overlay = m_textOverlay[m_state]; if (overlay != nullptr) { D3DXVECTOR2 x1 = overlay->GetPosition() + D3DXVECTOR2(0, -40); D3DXVECTOR2 x2 = x1 + D3DXVECTOR2(static_cast<FLOAT>(overlay->GetWidth()), static_cast<FLOAT>(overlay->GetHeight())); if (mousePosition.x < x1.x) return; if (mousePosition.y < x1.y) return; if (mousePosition.x > x2.x) return; if (mousePosition.y > x2.y) return; // The mouse is over this overlay. // This code should only be called on mouse click, so handle what ever this overlay is. switch (m_state) { case TextOverlay::File: { D3DXVECTOR2 bx1 = x1 + D3DXVECTOR2(54, 10); D3DXVECTOR2 bx2 = x1 + D3DXVECTOR2(135, 50); if (mousePosition.x > bx1.x && mousePosition.x < bx2.x && mousePosition.y > bx1.y && mousePosition.y < bx2.y) { CVisCraft::GetInstance()->NewTerrain(); SetVisible(false); return; } bx1 = x1 + D3DXVECTOR2(154, 10); bx2 = x1 + D3DXVECTOR2(268, 50); if (mousePosition.x > bx1.x && mousePosition.x < bx2.x && mousePosition.y > bx1.y && mousePosition.y < bx2.y) { CVisCraft::GetInstance()->OpenTerrain(); SetVisible(false); return; } bx1 = x1 + D3DXVECTOR2(276, 10); bx2 = x1 + D3DXVECTOR2(375, 50); if (mousePosition.x > bx1.x && mousePosition.x < bx2.x && mousePosition.y > bx1.y && mousePosition.y < bx2.y) { CVisCraft::GetInstance()->SaveTerrain(); SetVisible(false); return; } bx1 = x1 + D3DXVECTOR2(396, 10); bx2 = x1 + D3DXVECTOR2(474, 50); if (mousePosition.x > bx1.x && mousePosition.x < bx2.x && mousePosition.y > bx1.y && mousePosition.y < bx2.y) { CVisCraft::GetInstance()->Close(); SetVisible(false); return; } } break; } // Brushes text D3DXVECTOR2 bx1 = x1 + D3DXVECTOR2(10, 90); D3DXVECTOR2 bx2 = x1 + D3DXVECTOR2(124, 124); if (mousePosition.x > bx1.x && mousePosition.x < bx2.x && mousePosition.y > bx1.y && mousePosition.y < bx2.y) { m_state = GuiState::Brushes; return; } // File text bx1 = x1 + D3DXVECTOR2(230, 90); bx2 = x1 + D3DXVECTOR2(300, 124); if (mousePosition.x > bx1.x && mousePosition.x < bx2.x && mousePosition.y > bx1.y && mousePosition.y < bx2.y) { m_state = GuiState::File; return; } // About text bx1 = x1 + D3DXVECTOR2(410, 90); bx2 = x1 + D3DXVECTOR2(510, 124); if (mousePosition.x > bx1.x && mousePosition.x < bx2.x && mousePosition.y > bx1.y && mousePosition.y < bx2.y) { ShellExecute(NULL, "open", "http://www.samoatesgames.com", NULL, NULL, SW_SHOWMAXIMIZED); SetVisible(false); return; } } }
void CStageBack::Render() { D3DXMATRIX matTrans; TCHAR szTmp[128] = L""; //for (unsigned int i=0; i<m_vecTile.size(); ++i) for (int i = 0; i< 19; ++i) { for (int j = 0; j<8; ++j) { int nIndex = (i + -int(m_vScroll.y)/(TILESIZEY/2)) * TILECNTX + (j + -int(m_vScroll.x)/TILESIZEX); if(nIndex >= TILECNTX * TILECNTY || nIndex<0 ) continue; const TEXINFO* pTexInfo= GET_SINGLE(CTextureMgr)->GetTexture(m_pObjKey,m_pStateKey,m_vecTile[nIndex]->byDrawId); if (pTexInfo == NULL) { return; } D3DXMatrixTranslation(&matTrans,m_vecTile[nIndex]->vPos.x+m_vScroll.x, m_vecTile[nIndex]->vPos.y+m_vScroll.y, m_vecTile[nIndex]->vPos.z); m_Info.matWorld = matTrans; m_Info.matWorld = matTrans; m_Info.vCenter = D3DXVECTOR3(65.f, 34.f, 0.f); GET_SINGLE(CDevice)->GetSprite()->SetTransform(&m_Info.matWorld); GET_SINGLE(CDevice)->GetSprite()->Draw(pTexInfo->pTexture, NULL,&m_Info.vCenter, NULL, D3DCOLOR_ARGB(255,255,255,255)); wsprintf(szTmp,L"%d",nIndex); RECT rcRect = {0}; GET_SINGLE(CDevice)->GetFont()->DrawTextW(GET_SINGLE(CDevice)->GetSprite(),szTmp,lstrlen(szTmp),&rcRect,DT_NOCLIP,D3DCOLOR_ARGB(255,0,0,0)); } } D3DXVECTOR2 vPoint[4]; vPoint[0] = D3DXVECTOR2(400.f, 300.f); vPoint[1] = D3DXVECTOR2(500.f, 400.f); vPoint[2] = D3DXVECTOR2(300.f, 400.f); vPoint[3] = D3DXVECTOR2(400.f, 300.f); GET_SINGLE(CDevice)->GetSprite()->End(); GET_SINGLE(CDevice)->GetDevice()->EndScene(); GET_SINGLE(CDevice)->GetDevice()->BeginScene(); GET_SINGLE(CDevice)->GetSprite()->Begin(D3DXSPRITE_ALPHABLEND); GET_SINGLE(CDevice)->GetLine()->SetWidth(10.f); GET_SINGLE(CDevice)->GetLine()->Draw(vPoint,4,D3DCOLOR_ARGB(255,255,0,0)); GET_SINGLE(CDevice)->GetSprite()->End(); GET_SINGLE(CDevice)->GetDevice()->EndScene(); GET_SINGLE(CDevice)->GetDevice()->BeginScene(); GET_SINGLE(CDevice)->GetSprite()->Begin(D3DXSPRITE_ALPHABLEND); }
//-------------------------------------------------------------------------------------- // DisplayLuminance( ) // // DESC: // This function is for presentation purposes only - and isn't a *required* // part of the HDR rendering pipeline. It draws the 6 stages of the luminance // calculation to the appropriate part of the screen. // // PARAMS: // pDevice : The device to be rendered to. // pFont : The font to use when adding the annotations // pTextSprite : Used to improve performance of the text rendering // pArrowTex : Stores the 4 (up/down/left/right) icons used in the GUI // // NOTES: // This code uses several hard-coded ratios to position the elements correctly // - as such, changing the underlying diagram may well break this code. // //-------------------------------------------------------------------------------------- HRESULT DisplayLuminance( IDirect3DDevice9* pDevice, ID3DXFont* pFont, ID3DXSprite* pTextSprite, IDirect3DTexture9* pArrowTex ) { // [ 0 ] COMMON INITIALIZATION //---------------------------- LPDIRECT3DSURFACE9 pSurf = NULL; D3DSURFACE_DESC d; if( FAILED( pDevice->GetRenderTarget( 0, &pSurf ) ) ) { // Couldn't get the current render target! OutputDebugString( L"Luminance::DisplayLuminance() - Could not get current render target to extract dimensions.\n" ); return E_FAIL; } pSurf->GetDesc( &d ); SAFE_RELEASE( pSurf ); // Cache the dimensions as floats for later use float fW = static_cast< float >( d.Width ); float fH = static_cast< float >( d.Height ); float fCellH = ( fH - 36.0f ) / 4.0f; float fCellW = ( fW - 48.0f ) / 4.0f; float fLumCellSize = ( ( fH - ( ( 2.0f * fCellH ) + 32.0f ) ) - 32.0f ) / 3.0f; float fLumStartX = ( fCellW + 16.0f ) - ( ( 2.0f * fLumCellSize ) + 32.0f ); // Fill out the basic TLQuad information - this // stuff doesn't change for each stage Luminance::TLVertex v[4]; v[0].t = D3DXVECTOR2( 0.0f, 0.0f ); v[1].t = D3DXVECTOR2( 1.0f, 0.0f ); v[2].t = D3DXVECTOR2( 0.0f, 1.0f ); v[3].t = D3DXVECTOR2( 1.0f, 1.0f ); // Configure the device for it's basic states pDevice->SetVertexShader( NULL ); pDevice->SetFVF( FVF_TLVERTEX ); pDevice->SetPixelShader( g_pLumDispPS ); CDXUTTextHelper txtHelper( pFont, pTextSprite, 12 ); txtHelper.SetForegroundColor( D3DXCOLOR( 1.0f, 0.5f, 0.0f, 1.0f ) ); // [ 1 ] RENDER FIRST LEVEL //------------------------- v[0].p = D3DXVECTOR4( fLumStartX, ( 2.0f * fCellH ) + 32.0f, 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + fLumCellSize, ( 2.0f * fCellH ) + 32.0f, 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX, ( 2.0f * fCellH ) + 32.0f + fLumCellSize, 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + fLumCellSize, ( 2.0f * fCellH ) + 32.0f + fLumCellSize, 0.0f, 1.0f ); pDevice->SetTexture( 0, Luminance::g_pTexLuminance[ 5 ] ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); txtHelper.Begin(); { txtHelper.SetInsertionPos( static_cast< int >( fLumStartX ) + 2, static_cast< int >( ( 2.0f * fCellH ) + 32.0f + fLumCellSize ) - 24 ); txtHelper.DrawTextLine( L"1st Luminance" ); D3DSURFACE_DESC d2; Luminance::g_pTexLuminance[ 5 ]->GetLevelDesc( 0, &d2 ); WCHAR str[100]; swprintf_s( str, 100, L"%dx%d", d2.Width, d2.Height ); txtHelper.DrawTextLine( str ); } txtHelper.End(); // [ 2 ] RENDER SECOND LEVEL //-------------------------- v[0].p = D3DXVECTOR4( fLumStartX, ( 2.0f * fCellH ) + 48.0f + fLumCellSize, 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + fLumCellSize, ( 2.0f * fCellH ) + 48.0f + fLumCellSize, 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX, ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + fLumCellSize, ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); pDevice->SetTexture( 0, Luminance::g_pTexLuminance[ 4 ] ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); txtHelper.Begin(); { txtHelper.SetInsertionPos( static_cast< int >( fLumStartX ) + 2, static_cast< int >( ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ) ) - 24 ); txtHelper.DrawTextLine( L"2nd Luminance" ); D3DSURFACE_DESC d; Luminance::g_pTexLuminance[ 4 ]->GetLevelDesc( 0, &d ); WCHAR str[100]; swprintf_s( str, 100, L"%dx%d", d.Width, d.Height ); txtHelper.DrawTextLine( str ); } txtHelper.End(); // [ 3 ] RENDER THIRD LEVEL //------------------------- v[0].p = D3DXVECTOR4( fLumStartX, ( 2.0f * fCellH ) + 64.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + fLumCellSize, ( 2.0f * fCellH ) + 64.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX, ( 2.0f * fCellH ) + 64.0f + ( 3.0f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + fLumCellSize, ( 2.0f * fCellH ) + 64.0f + ( 3.0f * fLumCellSize ), 0.0f, 1.0f ); pDevice->SetTexture( 0, Luminance::g_pTexLuminance[ 3 ] ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); txtHelper.Begin(); { txtHelper.SetInsertionPos( static_cast< int >( fLumStartX ) + 2, static_cast< int >( ( 2.0f * fCellH ) + 64.0f + ( 3.0f * fLumCellSize ) ) - 24 ); txtHelper.DrawTextLine( L"3rd Luminance" ); D3DSURFACE_DESC d; Luminance::g_pTexLuminance[ 3 ]->GetLevelDesc( 0, &d ); WCHAR str[100]; swprintf_s( str, 100, L"%dx%d", d.Width, d.Height ); txtHelper.DrawTextLine( str ); } txtHelper.End(); // [ 4 ] RENDER FOURTH LEVEL //-------------------------- v[0].p = D3DXVECTOR4( fLumStartX + fLumCellSize + 16.0f, ( 2.0f * fCellH ) + 64.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 16.0f, ( 2.0f * fCellH ) + 64.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX + fLumCellSize + 16.0f, ( 2.0f * fCellH ) + 64.0f + ( 3.0f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 16.0f, ( 2.0f * fCellH ) + 64.0f + ( 3.0f * fLumCellSize ), 0.0f, 1.0f ); pDevice->SetTexture( 0, Luminance::g_pTexLuminance[ 2 ] ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); txtHelper.Begin(); { txtHelper.SetInsertionPos( static_cast< int >( fLumStartX + fLumCellSize + 16.0f ) + 2, static_cast< int >( ( 2.0f * fCellH ) + 64.0f + ( 3.0f * fLumCellSize ) ) - 24 ); txtHelper.DrawTextLine( L"4th Luminance" ); D3DSURFACE_DESC d; Luminance::g_pTexLuminance[ 2 ]->GetLevelDesc( 0, &d ); WCHAR str[100]; swprintf_s( str, 100, L"%dx%d", d.Width, d.Height ); txtHelper.DrawTextLine( str ); } txtHelper.End(); // [ 5 ] RENDER FIFTH LEVEL //-------------------------- v[0].p = D3DXVECTOR4( fLumStartX + fLumCellSize + 16.0f, ( 2.0f * fCellH ) + 48.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 16.0f, ( 2.0f * fCellH ) + 48.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX + fLumCellSize + 16.0f, ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 16.0f, ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); pDevice->SetTexture( 0, Luminance::g_pTexLuminance[ 1 ] ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); txtHelper.Begin(); { txtHelper.SetInsertionPos( static_cast< int >( fLumStartX + fLumCellSize + 16.0f ) + 2, static_cast< int >( ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ) ) - 24 ); txtHelper.DrawTextLine( L"5th Luminance" ); D3DSURFACE_DESC d; Luminance::g_pTexLuminance[ 1 ]->GetLevelDesc( 0, &d ); WCHAR str[100]; swprintf_s( str, 100, L"%dx%d", d.Width, d.Height ); txtHelper.DrawTextLine( str ); } txtHelper.End(); // [ 6 ] RENDER SIXTH LEVEL //-------------------------- v[0].p = D3DXVECTOR4( fLumStartX + fLumCellSize + 16.0f, ( 2.0f * fCellH ) + 32.0f + ( 0.0f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 16.0f, ( 2.0f * fCellH ) + 32.0f + ( 0.0f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX + fLumCellSize + 16.0f, ( 2.0f * fCellH ) + 32.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 16.0f, ( 2.0f * fCellH ) + 32.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); pDevice->SetTexture( 0, Luminance::g_pTexLuminance[ 0 ] ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); txtHelper.Begin(); { txtHelper.SetInsertionPos( static_cast< int >( fLumStartX + fLumCellSize + 16.0f ) + 2, static_cast< int >( ( 2.0f * fCellH ) + 32.0f + ( 1.0f * fLumCellSize ) ) - 24 ); txtHelper.DrawTextLine( L"6th Luminance" ); D3DSURFACE_DESC d; Luminance::g_pTexLuminance[ 0 ]->GetLevelDesc( 0, &d ); WCHAR str[100]; swprintf_s( str, 100, L"%dx%d", d.Width, d.Height ); txtHelper.DrawTextLine( str ); } txtHelper.End(); // [ 7 ] RENDER ARROWS //-------------------- pDevice->SetPixelShader( NULL ); pDevice->SetTexture( 0, pArrowTex ); // Select the "down" arrow v[0].t = D3DXVECTOR2( 0.50f, 0.0f ); v[1].t = D3DXVECTOR2( 0.75f, 0.0f ); v[2].t = D3DXVECTOR2( 0.50f, 1.0f ); v[3].t = D3DXVECTOR2( 0.75f, 1.0f ); // From 1st down to 2nd v[0].p = D3DXVECTOR4( fLumStartX + ( fLumCellSize / 2.0f ) - 8.0f, ( 2.0f * fCellH ) + 32.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + ( fLumCellSize / 2.0f ) + 8.0f, ( 2.0f * fCellH ) + 32.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX + ( fLumCellSize / 2.0f ) - 8.0f, ( 2.0f * fCellH ) + 48.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + ( fLumCellSize / 2.0f ) + 8.0f, ( 2.0f * fCellH ) + 48.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); // From 2nd down to 3rd v[0].p = D3DXVECTOR4( fLumStartX + ( fLumCellSize / 2.0f ) - 8.0f, ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + ( fLumCellSize / 2.0f ) + 8.0f, ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX + ( fLumCellSize / 2.0f ) - 8.0f, ( 2.0f * fCellH ) + 64.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + ( fLumCellSize / 2.0f ) + 8.0f, ( 2.0f * fCellH ) + 64.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); // Select "right" arrow v[0].t = D3DXVECTOR2( 0.25f, 0.0f ); v[1].t = D3DXVECTOR2( 0.50f, 0.0f ); v[2].t = D3DXVECTOR2( 0.25f, 1.0f ); v[3].t = D3DXVECTOR2( 0.50f, 1.0f ); // Across from 3rd to 4th v[0].p = D3DXVECTOR4( fLumStartX + fLumCellSize, ( 2.0f * fCellH ) + 56.0f + ( 2.5f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + fLumCellSize + 16.0f, ( 2.0f * fCellH ) + 56.0f + ( 2.5f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX + fLumCellSize, ( 2.0f * fCellH ) + 72.0f + ( 2.5f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + fLumCellSize + 16.0f, ( 2.0f * fCellH ) + 72.0f + ( 2.5f * fLumCellSize ), 0.0f, 1.0f ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); // Select "up" arrow v[0].t = D3DXVECTOR2( 0.00f, 0.0f ); v[1].t = D3DXVECTOR2( 0.25f, 0.0f ); v[2].t = D3DXVECTOR2( 0.00f, 1.0f ); v[3].t = D3DXVECTOR2( 0.25f, 1.0f ); // Up from 4th to 5th v[0].p = D3DXVECTOR4( fLumStartX + ( 1.5f * fLumCellSize ) + 8.0f, ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + ( 1.5f * fLumCellSize ) + 24.0f, ( 2.0f * fCellH ) + 48.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX + ( 1.5f * fLumCellSize ) + 8.0f, ( 2.0f * fCellH ) + 64.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + ( 1.5f * fLumCellSize ) + 24.0f, ( 2.0f * fCellH ) + 64.0f + ( 2.0f * fLumCellSize ), 0.0f, 1.0f ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); // Up from 5th to 6th v[0].p = D3DXVECTOR4( fLumStartX + ( 1.5f * fLumCellSize ) + 8.0f, ( 2.0f * fCellH ) + 32.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + ( 1.5f * fLumCellSize ) + 24.0f, ( 2.0f * fCellH ) + 32.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX + ( 1.5f * fLumCellSize ) + 8.0f, ( 2.0f * fCellH ) + 48.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + ( 1.5f * fLumCellSize ) + 24.0f, ( 2.0f * fCellH ) + 48.0f + ( 1.0f * fLumCellSize ), 0.0f, 1.0f ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); // Select "right" arrow v[0].t = D3DXVECTOR2( 0.25f, 0.0f ); v[1].t = D3DXVECTOR2( 0.50f, 0.0f ); v[2].t = D3DXVECTOR2( 0.25f, 1.0f ); v[3].t = D3DXVECTOR2( 0.50f, 1.0f ); // From 6th to final image composition v[0].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 16.0f, ( 2.0f * fCellH ) + 24.0f + ( 0.5f * fLumCellSize ), 0.0f, 1.0f ); v[1].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 32.0f, ( 2.0f * fCellH ) + 24.0f + ( 0.5f * fLumCellSize ), 0.0f, 1.0f ); v[2].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 16.0f, ( 2.0f * fCellH ) + 40.0f + ( 0.5f * fLumCellSize ), 0.0f, 1.0f ); v[3].p = D3DXVECTOR4( fLumStartX + ( 2.0f * fLumCellSize ) + 32.0f, ( 2.0f * fCellH ) + 40.0f + ( 0.5f * fLumCellSize ), 0.0f, 1.0f ); pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, v, sizeof( Luminance::TLVertex ) ); return S_OK; }
SceneID Scene::Control() { //m_mousePushState = M_NONE; int tmp_mousePushState = M_NONE; // 各デバイスの情報を取得 InputGamepad* pGamePad = m_pInput->Gamepad(); InputKeyboard* pKeyBoard = m_pInput->Keyboard(); InputMouse* pMouse = m_pInput->Mouse(); //keyPushTime = pKeyBoard->ChkRelease(); // マウスの座標を更新 m_mousePos = D3DXVECTOR2((float)m_pInput->Mouse()->PosX(),(float)m_pInput->Mouse()->PosY()); //// 長押し // keyPushTime[DIK_RIGHT]; //このまうす状態取得方法は変だと思うので後で直す。 // マウス左クリック tmp_mousePushState = 0; if( pMouse->IsLAction() ) { tmp_mousePushState |= M_LEFT; if( ( m_mousePushState & M_LEFT ) ) { tmp_mousePushState |= M_LEFT_DOWN; } else { tmp_mousePushState |= M_LEFT_PUSH; } } else { if( ( m_mousePushState & M_LEFT ) ) { tmp_mousePushState |= M_LEFT_RELEASE; } } // 右クリック if( pMouse->IsRAction() ) { tmp_mousePushState |= M_RIGHT; if ((m_mousePushState & M_RIGHT)) { tmp_mousePushState |= M_RIGHT_DOWN; m_mouseClickTime++; if (m_mouseClickTime >= 6) { tmp_mousePushState |= M_RIGHT_DRAG; } } else { tmp_mousePushState |= M_RIGHT_PUSH; m_mouseDragPos = m_mousePos; m_mouseClickTime = 0; } } else { if ((m_mousePushState & M_RIGHT)) { tmp_mousePushState |= M_RIGHT_RELEASE; m_mouseClickTime = 0; } } // 中央クリック if( pMouse->IsMAction() ) { tmp_mousePushState |= M_CENTER; if( ( m_mousePushState & M_CENTER ) ) { //tmp_mousePushState |= M_CENTER_DOWN; } else { tmp_mousePushState |= M_CENTER_PUSH; } } // ホイールアップ if( pMouse->Wheel() == InputMouse::WHEEL_UP ) { tmp_mousePushState = M_WHEEL_UP; } if( pMouse->Wheel() == InputMouse::WHEEL_DOWN ) { tmp_mousePushState = M_WHEEL_DOWN; } // マウス情報更新 m_mousePushState = tmp_mousePushState; if( pKeyBoard->ChkKeyDown(DIK_RIGHT) || pGamePad->ChkGamePadAction(InputGamepad::GamePadLStick_RIGHT) == InputGamepad::KEY_ON) { m_keyStateOn |= RIGHT; } //if( pKeyBoard->ChkKeyDown(DIK_LEFT) || pGamePad->ChkGamePadAction(InputGamepad::GamePadLStick_LEFT) == InputGamepad::KEY_ON) { // m_keyStateOn |= LEFT; //} //if( pKeyBoard->ChkKeyDown(DIK_UP) || pGamePad->ChkGamePadAction(InputGamepad::GamePadLStick_UP) == InputGamepad::KEY_ON) { // 上矢印キーが押されたら // m_keyStateOn |= UP; //} //if( pKeyBoard->ChkKeyDown(DIK_DOWN) || pGamePad->ChkGamePadAction(InputGamepad::GamePadLStick_DOWN) == InputGamepad::KEY_ON) { // 下矢印キーが押されたら // m_keyStateOn |= DOWN; //} ////// 以下11/26 追加 //前のキー情報初期化 m_keyStateOn = 0; if( pKeyBoard->ChkKeyDown(DIK_S) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_B) == InputGamepad::KEY_PUSH) { // 下矢印キーが押されたら m_keyStateOn |= KEY_S; } if( pKeyBoard->ChkKeyDown(DIK_D) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_A) == InputGamepad::KEY_PUSH ){ m_keyStateOn |= KEY_D; } if( pKeyBoard->ChkKeyDown(DIK_W) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_Y) == InputGamepad::KEY_PUSH ){ m_keyStateOn |= KEY_W; } if( pKeyBoard->ChkKeyDown(DIK_A) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_X) == InputGamepad::KEY_PUSH){ m_keyStateOn |= KEY_A; } if (pKeyBoard->ChkKeyDown(DIK_ESCAPE) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_X) == InputGamepad::KEY_PUSH){ m_keyStateOn |= KEY_ESC; } if( pKeyBoard->ChkKeyDown(DIK_E) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_RB) == InputGamepad::KEY_PUSH){ m_keyStateOn |= KEY_E; } if( pKeyBoard->ChkKeyDown(DIK_Q) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_LB) == InputGamepad::KEY_PUSH){ m_keyStateOn |= KEY_Q; } if( pKeyBoard->ChkKeyDown(DIK_Z) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_BACK) == InputGamepad::KEY_PUSH){ m_keyStateOn |= KEY_Z; } //if( pKeyBoard->ChkKeyAction(DIK_SPACE) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_START) == InputGamepad::KEY_PUSH){ // m_keyStateOn |= KEY_SPACE; //} //if( pKeyBoard->ChkKeyAction(DIK_RIGHT) || pGamePad->ChkGamePadAction(InputGamepad::GamePadLStick_RIGHT) == InputGamepad::KEY_PUSH) { // m_keyStatePush |= RIGHT; //} //if( pKeyBoard->ChkKeyAction(DIK_LEFT) || pGamePad->ChkGamePadAction(InputGamepad::GamePadLStick_LEFT) == InputGamepad::KEY_PUSH) { // m_keyStatePush |= LEFT; //} //if( pKeyBoard->ChkKeyAction(DIK_UP) || pGamePad->ChkGamePadAction(InputGamepad::GamePadLStick_UP) == InputGamepad::KEY_PUSH) { // 上矢印キーが押されたら // m_keyStatePush |= UP; //} //if( pKeyBoard->ChkKeyAction(DIK_DOWN) || pGamePad->ChkGamePadAction(InputGamepad::GamePadLStick_DOWN) == InputGamepad::KEY_PUSH) { // 下矢印キーが押されたら // m_keyStatePush |= DOWN; //} //Pushを取るために初期化 m_keyStatePush = 0; ////// 以下11/26 追加 if( pKeyBoard->ChkKeyAction(DIK_S) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_B) == InputGamepad::KEY_PUSH) { // 下矢印キーが押されたら m_keyStatePush |= KEY_S; } if( pKeyBoard->ChkKeyAction(DIK_D) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_A) == InputGamepad::KEY_PUSH ){ m_keyStatePush |= KEY_D; } if( pKeyBoard->ChkKeyAction(DIK_W) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_Y) == InputGamepad::KEY_PUSH ){ m_keyStatePush |= KEY_W; } if( pKeyBoard->ChkKeyAction(DIK_A) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_A) == InputGamepad::KEY_PUSH){ m_keyStatePush |= KEY_A; } if (pKeyBoard->ChkKeyAction(DIK_ESCAPE) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_A) == InputGamepad::KEY_PUSH){ m_keyStatePush |= KEY_ESC; } if( pKeyBoard->ChkKeyAction(DIK_E) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_RB) == InputGamepad::KEY_PUSH){ m_keyStatePush |= KEY_E; } if( pKeyBoard->ChkKeyAction(DIK_Q) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_LB) == InputGamepad::KEY_PUSH){ m_keyStatePush |= KEY_Q; } if( pKeyBoard->ChkKeyAction(DIK_Z) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_R3) == InputGamepad::KEY_PUSH){ m_keyStatePush |= KEY_Z; } //if( pKeyBoard->ChkKeyAction(DIK_SPACE) || pGamePad->ChkGamePadAction(InputGamepad::GamePadBtn_START) == InputGamepad::KEY_PUSH){ // m_keyStatePush |= KEY_SPACE; //} //if( pKeyBoard->ChkKeyDown('E') | pGamePad->ChkGamePadDownKEY_E // Scene::m_keyStateOn |= KEY_E; //} return m_sceneID; }
bool Toolbar::initialise() { int barPosition; // get height of the window barPosition = (-WindowManager::getInstance()->getWindowResolution().height * 0.8f) / 2; //==================== // initialise Sprites //==================== // Background m_background = new Sprite; if (!m_background) { return false; } m_result = m_background->initialise(Rect3D(728, 88), "ui_toolbar.dds"); if (!m_result) { return false; } m_background->getTransform()->setY(barPosition); m_background->setShader("texture"); // Toolbar Icons m_toolbarIcons = new InstancedSprite; if (!m_toolbarIcons) { return false; } m_result = m_toolbarIcons->initialise(Rect3D(64, 64), "ui_icons.dds"); if (!m_result) { return false; } m_toolbarIcons->setShader("instancedtexture"); m_toolbarIcons->setBlendMode(BlendMode::AlphaMasked); // Highlighter m_highlighter = new Sprite; if (!m_highlighter) { return false; } m_result = m_highlighter->initialise(Rect3D(92, 92), "ui_toolbar_select.dds"); if (!m_result) { return false; } m_highlighter->setShader("texture"); m_highlighter->setBlendMode(BlendMode::AlphaMasked); //================== // initialise Tools //================== // Add Icon Data m_toolData.push_back(InstanceData(D3DXVECTOR3(-320, barPosition, 1), D3DXVECTOR2(31, 17), D3DXVECTOR2(32, 21))); // Pickaxe m_toolData.push_back(InstanceData(D3DXVECTOR3(-240, barPosition, 1), D3DXVECTOR2(18, 11), D3DXVECTOR2(32, 21))); // Dirt m_toolData.push_back(InstanceData(D3DXVECTOR3(-160, barPosition, 1), D3DXVECTOR2(3, 12), D3DXVECTOR2(32, 21))); // Sand m_toolData.push_back(InstanceData(D3DXVECTOR3(-80, barPosition, 1), D3DXVECTOR2(10, 8), D3DXVECTOR2(32, 21))); // Cobblestone m_toolData.push_back(InstanceData(D3DXVECTOR3( 0, barPosition, 1), D3DXVECTOR2(7, 12), D3DXVECTOR2(32, 21))); // Stone m_toolData.push_back(InstanceData(D3DXVECTOR3( 80, barPosition, 1), D3DXVECTOR2(6, 9), D3DXVECTOR2(32, 21))); // Wood m_toolData.push_back(InstanceData(D3DXVECTOR3(160, barPosition, 1), D3DXVECTOR2(30, 1), D3DXVECTOR2(32, 21))); // Water Bucket // create Instanced Sprite for (unsigned int i = 0; i < m_toolData.size(); i++) { m_toolbarIcons->addInstance(m_toolData[i]); } m_toolbarIcons->rebuildInstanceBuffer(); //================= // initialise Vars //================= m_selectedIndex = 0; refresh(); return true; }
CloudOfDarknessClientSkillEffect::CloudOfDarknessClientSkillEffect(unsigned int _masterId, FLOAT3 _position) { m_position = _position; //m_graphicalEffects[0] = g_graphicsEngine->createModel("CloudOfDarkness", FLOAT3(_position.x, 0.1f, _position.z), "color2"); //m_graphicalEffects[1] = g_graphicsEngine->createModel("CloudOfDarkness", FLOAT3(_position.x, 0.2f, _position.z), "color1"); //m_graphicalEffects[2] = g_graphicsEngine->createModel("CloudOfDarkness", FLOAT3(_position.x, 0.3f, _position.z), "color"); //m_graphicalEffects[0]->setScale(0.5f, 0.5f, 0.5f); //m_graphicalEffects[2]->setScale(0.5f, 0.5f, 0.5f); //m_graphicalEffects[1]->setScale(0.5f, 0.5f, 0.5f); //m_graphicalEffects[0]->setAlpha(0.999f); //m_graphicalEffects[1]->setAlpha(0.999f); //m_graphicalEffects[2]->setAlpha(0.999f); //m_graphicalEffects[0]->neutralize(); //m_graphicalEffects[1]->neutralize(); //m_graphicalEffects[2]->neutralize(); m_lifetime = 0.0f; m_cloud = g_graphicsEngine->createParticleEngine("CloudOfDarkness", D3DXVECTOR4(_position.toD3DXVector(), 1), D3DXQUATERNION(0, 0, 0, 1), D3DXVECTOR2(1, 1)); int sound = createSoundHandle("skills/codWindStartEnd.wav", false, true, _position); playSound(sound); deactivateSound(sound); m_masterId = _masterId; Entity *e = ClientEntityHandler::getEntity(_masterId); if(e != NULL) { e->m_model->getAnimation()->Play("Spell"); m_weapon = e->m_model->getRightHand(); e->m_model->SetRightHand(NULL); } }
Player::Player(): Billboard(D3DXVECTOR2(9, 9), 1.f) { mLives = 3; mPoints = 0; }
void EnemyBigGunShooting::Shoot() { BulletPoolManager::getInstance()->addBulletIntoList(eIDTypeBullet::BULLET_OF_ENEMY, D3DXVECTOR3(m_Position.x - 35, m_Position.y + 18, 1), D3DXVECTOR2(-1.0f, 0.0f), 0.0f); }
namespace mesh { //***************************************************************************** // constant definition //***************************************************************************** const D3DCOLOR MeshDome::DEFAULT_COLOR = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); const D3DXVECTOR2 MeshDome::DEFAULT_POSITION = D3DXVECTOR2(0.0f, 0.0f); //============================================================================= // constructor //============================================================================= MeshDome::MeshDome(const u32& in_width_count, const u32& in_height_count) :MeshDome(1.0f, 1.0f, in_width_count, in_height_count) { } //============================================================================= // constructor //============================================================================= MeshDome::MeshDome(const f32& in_block_width, const f32& in_block_height, const u32& in_width_count, const u32& in_height_count) :Mesh(true, true) , size_(in_width_count * in_block_width, in_height_count *in_block_height) , block_size_(in_block_width, in_block_height) , width_count_(in_width_count) , height_count_(in_height_count) , index_count_(0) , indexs_(nullptr) , division_width_(1) , division_height_(1) { auto directx9 = GET_DIRECTX9_DEVICE(); vertex_count_ = 4 * width_count_*height_count_; index_count_ = 4 * width_count_*height_count_ + 2 * (width_count_ - 1)*height_count_ + 2 * (height_count_ - 1); indexs_ = new u32[width_count_*height_count_]; memset(indexs_, 0, sizeof(u32)*width_count_*height_count_); // create vertex buffer directx9->CreateVertexBuffer(sizeof(VERTEX) * vertex_count_, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &direct3dvertexbuffer9_, NULL); // create index buffer directx9->CreateIndexBuffer(sizeof(u32) * index_count_, D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_MANAGED, &direct3dindexbuffer9_, NULL); u32* index = nullptr; u32 rect_count = vertex_count_ / 4; u32 count = 0; direct3dindexbuffer9_->Lock(NULL, NULL, (void**)&index, NULL); for (u32 i = 0; i < height_count_; ++i) { for (u32 j = 0; j < width_count_; ++j) { index[count + 0] = (i * width_count_ + j) * 4 + 0; index[count + 1] = (i * width_count_ + j) * 4 + 1; index[count + 2] = (i * width_count_ + j) * 4 + 2; index[count + 3] = (i * width_count_ + j) * 4 + 3; count += 4; if (j != (width_count_ - 1)) { index[count + 0] = (i * width_count_ + j) * 4 + 3; index[count + 1] = (i * width_count_ + j) * 4 + 4; count += 2; } else if (i != (height_count_ - 1)) { index[count + 0] = (i * width_count_ + j) * 4 + 3; index[count + 1] = ((i + 1) * width_count_) * 4 + 0; count += 2; } } } direct3dindexbuffer9_->Unlock(); primitive_count_ = index_count_ - 2; primitive_type_ = D3DPT_TRIANGLESTRIP; stride_ = sizeof(VERTEX); UpdateVertexBuffer_(); } //============================================================================= // destructor //============================================================================= MeshDome::~MeshDome(void) { //relase vertex buffer SafeRelease(direct3dvertexbuffer9_); SafeRelease(direct3dindexbuffer9_); SafeDeleteArray(indexs_); } //============================================================================= // set index //============================================================================= void MeshDome::SetIndex(u32 x, u32 y, u32 index) { indexs_[y * width_count_ + x] = index; is_dirty_ = true; } //============================================================================= // set index //============================================================================= void MeshDome::SetIndex(const std::vector<u32>& in_indexs) { DEBUG_ASSERT(in_indexs.size() == width_count_ * height_count_); auto size = width_count_ * height_count_; for (u32 i = 0; i < size; ++i) { indexs_[i] = in_indexs[i]; } is_dirty_ = true; } //============================================================================= // set color //============================================================================= //============================================================================= // set texcoord //============================================================================= void MeshDome::SetTexcoord(u32 in_division_width, u32 in_division_height) { division_width_ = in_division_width; division_height_ = in_division_height; is_dirty_ = true; } //============================================================================= // update vertex buffer //============================================================================= void MeshDome::UpdateVertexBuffer_(void) { VERTEX* vertex = nullptr; float2 offset = float2(-size_._x * anchor_point_._x, size_._y * anchor_point_._y); //ドームの一番大きい場所の半径 float domemaxradius = size_._x/D3DX_PI/2; //面一枚ごとの角度(X) float faceangle_x = (D3DX_PI * 2) / width_count_; //面一枚ごとの角度(Y) float faceangle_y = (D3DX_PI * 2) / height_count_; // lock direct3dvertexbuffer9_->Lock(0, 0, (void**)&vertex, 0); for (u32 i = 0; i < height_count_; ++i) { //高さによる変動する半径XZ float dr_xz = domemaxradius*((float)i / (float)height_count_)*((float)i / (float)height_count_); float olddr_xz = domemaxradius*((float)(i - 1) / (float)height_count_)*((float)(i - 1) / (float)height_count_); float yh = ((float)i / (float)height_count_)*((float)i / (float)height_count_); float oldyh= ((float)(i-1) / (float)height_count_)*((float)(i-1) / (float)height_count_); float yc = height_count_*(block_size_._y) / 2; for (u32 j = 0; j < width_count_; ++j) { /*float left = 1.0f / division_width_ * ((indexs_[i * width_count_ + j] % division_width_) + 0); float right = 1.0f / division_width_ * ((indexs_[i * width_count_ + j] % division_width_) + 1); float top = 1.0f / division_height_ * ((indexs_[i * width_count_ + j] / division_width_) + 0); float bottom = 1.0f / division_height_ * ((indexs_[i * width_count_ + j] / division_width_) + 1);*/ float left = (1.0f / width_count_)*j; float right = (1.0f / width_count_)*j + (1.0f/ width_count_); float top = 1.0f / division_height_ * ((indexs_[i * width_count_ + j] / division_width_) + 0); float bottom = 1.0f / division_height_ * ((indexs_[i * width_count_ + j] / division_width_) + 1); vertex[(i * width_count_ + j) * 4 + 0]._position = float3(-(cosf(faceangle_x*(j + 0)))*dr_xz, (-block_size_._y*(i + 1))*yh + yc, (sinf(faceangle_x*(j + 0)))*dr_xz); vertex[(i * width_count_ + j) * 4 + 1]._position = float3(-(cosf(faceangle_x*(j + 0)))*olddr_xz, (-block_size_._y*(i + 0))*oldyh + yc, (sinf(faceangle_x*(j + 0)))*olddr_xz); vertex[(i * width_count_ + j) * 4 + 2]._position = float3(-(cosf(faceangle_x*(j + 1)))*dr_xz, (-block_size_._y*(i + 1))*yh + yc, (sinf(faceangle_x*(j + 1)))*dr_xz); vertex[(i * width_count_ + j) * 4 + 3]._position = float3(-(cosf(faceangle_x*(j + 1)))*olddr_xz, (-block_size_._y*(i + 0))*oldyh + yc, (sinf(faceangle_x*(j + 1)))*olddr_xz); vertex[(i * width_count_ + j) * 4 + 0]._normal = float3(0.0f, 1.0f, 0.0f); vertex[(i * width_count_ + j) * 4 + 1]._normal = float3(0.0f, 1.0f, 0.0f); vertex[(i * width_count_ + j) * 4 + 2]._normal = float3(0.0f, 1.0f, 0.0f); vertex[(i * width_count_ + j) * 4 + 3]._normal = float3(0.0f, 1.0f, 0.0f); vertex[(i * width_count_ + j) * 4 + 0]._texcoord = float2(left, bottom); vertex[(i * width_count_ + j) * 4 + 1]._texcoord = float2(left, top); vertex[(i * width_count_ + j) * 4 + 2]._texcoord = float2(right, bottom); vertex[(i * width_count_ + j) * 4 + 3]._texcoord = float2(right, top); vertex[(i * width_count_ + j) * 4 + 0]._color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); vertex[(i * width_count_ + j) * 4 + 1]._color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); vertex[(i * width_count_ + j) * 4 + 2]._color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); vertex[(i * width_count_ + j) * 4 + 3]._color = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); } } // unlock direct3dvertexbuffer9_->Unlock(); } } //namespace mesh
void HeightMap::Initialize(char* mapFileName, char* textureFileName) { D3DXMatrixIdentity(&world); if (textureFileName != nullptr) { pTexDiffuse = TextureManager::GetTexture(textureFileName); if (SupportsBumpMapping( )) // 현재의 장치에서의 범프 맵핑의 지원을 검출한다. { pTexNormal = TextureManager::GetNormalMap(textureFileName, 3.f); } } ZeroMemory(&material, sizeof(D3DMATERIAL9)); material.Ambient = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f); material.Diffuse = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f); material.Specular = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f); char fullPath[256]; strcpy_s(fullPath, HEIGHTMAP_DIRECTORY); strcat_s(fullPath, mapFileName); FILE* fp = nullptr; fopen_s(&fp, fullPath, "rb"); if (fp != nullptr) { fseek(fp, 0, SEEK_END); vertexCount = ftell(fp); fseek(fp, 0, SEEK_SET); mapSize = (int)(sqrt(vertexCount)); assert(vertexCount == mapSize*mapSize && "가로세로길이가 동일해야 합니다."); std::vector<unsigned char> fileData; fileData.resize(vertexCount); for (int i = 0; i < vertexCount; ++i) { fileData[i] = fgetc(fp); } fclose(fp); tileCount = mapSize - 1; std::vector<FVF_PositionNormalTexture> fvfVertex; fvfVertex.resize(vertexCount); vertex.resize(vertexCount); for (int z = 0; z < mapSize; ++z) { for (int x = 0; x < mapSize; ++x) { int index = z * mapSize + x; FVF_PositionNormalTexture v; v.pos = D3DXVECTOR3((float)x, fileData[index] * 0.2f, (float)-z); v.normal = D3DXVECTOR3(0, 1, 0); v.tex = D3DXVECTOR2(x / (float)tileCount, z / (float)tileCount); fvfVertex[index] = v; vertex[index] = v.pos; } } //노말값들 갱신 //필요한건 벡터 4개 //왼쪽, 오른쪽, 위쪽, 아래쪽 for (int z = 1; z < tileCount; ++z) { for (int x = 1; x < tileCount; ++x) { int index = z * mapSize + x; D3DXVECTOR3 left = vertex[index - 1]; D3DXVECTOR3 right = vertex[index + 1]; D3DXVECTOR3 front = vertex[index - mapSize]; D3DXVECTOR3 rear = vertex[index + mapSize]; D3DXVECTOR3 leftToRight = right - left; D3DXVECTOR3 frontToRear = rear - front; D3DXVECTOR3 normal; D3DXVec3Cross(&normal, &leftToRight, &frontToRear); D3DXVec3Normalize(&normal, &normal); fvfVertex[index].normal = normal; } } //버벡스 버퍼, 인덱스 버퍼 만들기 triangleCount = tileCount * tileCount * 2; indexData.resize(triangleCount * 3); for (int z = 0; z < tileCount; ++z) { for (int x = 0, k = 0; x < tileCount; ++x, ++k) { int _0 = (x + 0) + (z + 0) * mapSize; int _1 = (x + 1) + (z + 0) * mapSize; int _2 = (x + 0) + (z + 1) * mapSize; int _3 = (x + 1) + (z + 1) * mapSize; indexData[z * (6 * tileCount) + k] = (_0); indexData[z * (6 * tileCount) + ++k] = (_1); indexData[z * (6 * tileCount) + ++k] = (_2); indexData[z * (6 * tileCount) + ++k] = (_3); indexData[z * (6 * tileCount) + ++k] = (_2); indexData[z * (6 * tileCount) + ++k] = (_1); } } int bufferSize = fvfVertex.size( ) * sizeof(FVF_PositionNormalTexture); GameManager::GetDevice( )->CreateVertexBuffer( bufferSize, 0, FVF_PositionNormalTexture::FVF, D3DPOOL_MANAGED, &vertexBuffer, nullptr); LPVOID pV; vertexBuffer->Lock(0, 0, &pV, 0); memcpy_s(pV, bufferSize, &fvfVertex[0], bufferSize); vertexBuffer->Unlock( ); bufferSize = indexData.size( ) * sizeof(DWORD); GameManager::GetDevice( )->CreateIndexBuffer( bufferSize, 0, D3DFMT_INDEX32, D3DPOOL_MANAGED, &indexBuffer, nullptr); LPVOID pI; indexBuffer->Lock(0, 0, &pI, 0); memcpy_s(pI, bufferSize, &indexData[0], bufferSize); indexBuffer->Unlock( ); } if (m_pQuadTree == nullptr) { m_fLODRatio = 0.05f; m_pQuadTree = new QuadTree(mapSize, mapSize); // 텍스쳐 파일의 크기에 맞춰서 쿼드트리를 생성한다. m_pQuadTree->Build(&vertex[0]); } }