Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////
- // Filename: triangle_modelclass.cpp
- ////////////////////////////////////////////////////////////////////////////////
- #include "triangle_modelclass.h"
- TriangleModelClass::TriangleModelClass() :IndexModelClass()
- {
- }
- TriangleModelClass::TriangleModelClass(const TriangleModelClass& other)
- {
- }
- TriangleModelClass::~TriangleModelClass()
- {
- }
- bool TriangleModelClass::InitializeBuffers(ID3D11Device* device)
- {
- HRESULT result;
- //
- // Process the vertex buffer
- //
- VertexType* vertices;
- D3D11_BUFFER_DESC vertexBufferDesc;
- D3D11_SUBRESOURCE_DATA vertexData;
- // Set the number of vertices in the vertex array.
- int vCount = 40;
- SetVertexCount(vCount);
- // Create the vertex array.
- vertices = new VertexType[vCount];
- if (!vertices)
- {
- return false;
- }
- // Load the vertex array with data.
- vertices[0].position = D3DXVECTOR3(0, 1.6f, 0); // 1 KAIRĖ PUSĖ KARDO
- vertices[0].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[1].position = D3DXVECTOR3(0, 1.4f, 0.2f); // 2
- vertices[1].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[2].position = D3DXVECTOR3(0, 0.6f, 0.2f); // 3
- vertices[2].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[3].position = D3DXVECTOR3(0, 0.6f, 0.4f); // 4
- vertices[3].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[4].position = D3DXVECTOR3(0, 0.5f, 0.3f); // 5
- vertices[4].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[5].position = D3DXVECTOR3(0, 0.5f, 0.2f); // 6
- vertices[5].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[6].position = D3DXVECTOR3(0, 0.4f, 0.1f); // 7
- vertices[6].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[7].position = D3DXVECTOR3(0, 0.2f, 0.1f); // 8
- vertices[7].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[8].position = D3DXVECTOR3(0, 0, 0); // 9
- vertices[8].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f); // BAIGTA
- vertices[9].position = D3DXVECTOR3(0, 1.4f, -0.2f); // 9 DEŠINĖ PUSĖ
- vertices[9].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[10].position = D3DXVECTOR3(0, 0.6f, -0.2f); // 10
- vertices[10].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[11].position = D3DXVECTOR3(0, 0.6f, -0.4f); // 11
- vertices[11].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[12].position = D3DXVECTOR3(0, 0.5f, -0.3f); // 12
- vertices[12].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[13].position = D3DXVECTOR3(0, 0.5f, -0.2f); // 13
- vertices[13].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[14].position = D3DXVECTOR3(0, 0.4f, -0.1f); // 14
- vertices[14].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[15].position = D3DXVECTOR3(0, 0.2f, -0.1f); // 15
- vertices[15].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f); // BAIGTA
- // ANTRAS KARDAS //////////////////////////////////////////////////////////////////////////////////////////
- vertices[16].position = D3DXVECTOR3(0.15f, 1.6f, 0); // 1 KAIRĖ PUSĖ KARDO
- vertices[16].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[17].position = D3DXVECTOR3(0.15f, 1.4f, 0.2f); // 2
- vertices[17].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[18].position = D3DXVECTOR3(0.15f, 0.6f, 0.2f); // 3
- vertices[18].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[19].position = D3DXVECTOR3(0.15f, 0.6f, 0.4f); // 4
- vertices[19].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[20].position = D3DXVECTOR3(0.15f, 0.5f, 0.3f); // 5
- vertices[20].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[21].position = D3DXVECTOR3(0.15f, 0.5f, 0.2f); // 6
- vertices[21].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[22].position = D3DXVECTOR3(0.15f, 0.4f, 0.1f); // 7
- vertices[22].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[23].position = D3DXVECTOR3(0.15f, 0.2f, 0.1f); // 8
- vertices[23].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[24].position = D3DXVECTOR3(0.15f, 0, 0); // 9
- vertices[24].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[25].position = D3DXVECTOR3(0.15f, 1.4f, -0.2f); // 9 DEŠINĖ PUSĖ
- vertices[25].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[26].position = D3DXVECTOR3(0.15f, 0.6f, -0.2f); // 10
- vertices[26].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[27].position = D3DXVECTOR3(0.15f, 0.6f, -0.4f); // 11
- vertices[27].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[28].position = D3DXVECTOR3(0.15f, 0.5f, -0.3f); // 12
- vertices[28].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[29].position = D3DXVECTOR3(0.15f, 0.5f, -0.2f); // 13
- vertices[29].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[30].position = D3DXVECTOR3(0.15f, 0.4f, -0.1f); // 14
- vertices[30].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- vertices[31].position = D3DXVECTOR3(0.15f, 0.2f, -0.1f); // 15
- vertices[31].color = D3DXVECTOR4(0.15f, 0.65f, 0.95f, 1.0f);
- // Set up the description of the static vertex buffer.
- vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
- vertexBufferDesc.ByteWidth = sizeof(VertexType) * vCount;
- 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.
- ZeroMemory(&vertexData, sizeof(vertexData));
- 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;
- }
- // Release the array now that the vertex buffer has been created and loaded.
- delete[] vertices;
- vertices = 0;
- //
- // Process the index buffer
- //
- unsigned long* indices;
- D3D11_BUFFER_DESC indexBufferDesc;
- D3D11_SUBRESOURCE_DATA indexData;
- // Set the number of indices in the index array.
- int iCount = 220;
- SetIndexCount(iCount);
- // Create the index array.
- indices = new unsigned long[iCount];
- if (!indices)
- {
- return false;
- }
- // Load the index array with data.
- indices[0] = 0;
- indices[1] = 1;
- indices[2] = 7;
- indices[3] = 1;
- indices[4] = 2;
- indices[5] = 0;
- indices[6] = 2;
- indices[7] = 3;
- indices[8] = 4;
- indices[9] = 2;
- indices[10] = 4;
- indices[11] = 5;
- indices[12] = 5;
- indices[13] = 6;
- indices[14] = 0;
- indices[15] = 6;
- indices[16] = 7;
- indices[17] = 8;
- indices[18] = 8;
- indices[19] = 0;
- indices[20] = 6;
- indices[21] = 2;
- indices[22] = 5;
- indices[23] = 6; // KAIRĖ PUSĖ BAIGTA
- indices[24] = 0;
- indices[25] = 9;
- indices[26] = 7;
- indices[27] = 9;
- indices[28] = 10;
- indices[29] = 7;
- indices[30] = 10;
- indices[31] = 11;
- indices[32] = 12;
- indices[33] = 10;
- indices[34] = 12;
- indices[35] = 13;
- indices[36] = 13;
- indices[37] = 14;
- indices[38] = 0;
- indices[39] = 14;
- indices[40] = 15;
- indices[41] = 8;
- indices[42] = 8;
- indices[43] = 0;
- indices[44] = 14;
- indices[45] = 10;
- indices[46] = 13;
- indices[47] = 14;
- indices[48] = 6;
- indices[49] = 0;
- indices[50] = 2; // DEŠINĖ PUSĖ BAIGTA
- // 2 DALIS KARDO
- indices[51] = 16;
- indices[52] = 17;
- indices[53] = 23;
- indices[54] = 17;
- indices[55] = 18;
- indices[56] = 16;
- indices[57] = 18;
- indices[58] = 19;
- indices[59] = 20;
- indices[60] = 18;
- indices[61] = 20;
- indices[62] = 21;
- indices[63] = 21;
- indices[64] = 22;
- indices[65] = 16;
- indices[66] = 22;
- indices[67] = 23;
- indices[68] = 24;
- indices[69] = 24;
- indices[70] = 16;
- indices[71] = 22;
- indices[72] = 18;
- indices[73] = 21;
- indices[74] = 22; // KAIRĖ PUSĖ BAIGTA
- indices[75] = 16;
- indices[76] = 25;
- indices[77] = 23;
- indices[78] = 25;
- indices[79] = 26;
- indices[80] = 23;
- indices[81] = 26;
- indices[82] = 27;
- indices[83] = 28;
- indices[84] = 26;
- indices[85] = 28;
- indices[86] = 29;
- indices[87] = 29;
- indices[88] = 30;
- indices[89] = 16;
- indices[90] = 30;
- indices[91] = 31;
- indices[92] = 24;
- indices[93] = 24;
- indices[94] = 16;
- indices[95] = 30;
- indices[96] = 26;
- indices[97] = 29;
- indices[98] = 30;
- indices[99] = 22;
- indices[100] = 16;
- indices[101] = 18; // DEŠINĖ PUSĖ BAIGTA
- indices[102] = 16;
- indices[103] = 0;
- indices[104] = 9;
- indices[105] = 16;
- indices[106] = 17;
- indices[107] = 0; // 1 - virsus
- indices[108] = 0;
- indices[109] = 1;
- indices[110] = 16;
- indices[111] = 17;
- indices[112] = 16;
- indices[113] = 1; // 1 - virsus
- indices[114] = 17;
- indices[115] = 1;
- indices[116] = 2;
- indices[117] = 18;
- indices[118] = 17;
- indices[119] = 2; // 2 - sonai
- indices[120] = 31;
- indices[121] = 30;
- indices[122] = 10;
- indices[123] = 9;
- indices[124] = 31;
- indices[125] = 10; // 2 - sonai
- indices[126] = 2;
- indices[127] = 3;
- indices[128] = 18;
- indices[129] = 19;
- indices[130] = 18;
- indices[131] = 3; // 3 - mazi sonai virsus
- indices[132] = 30;
- indices[133] = 29;
- indices[134] = 11;
- indices[135] = 10;
- indices[136] = 30;
- indices[137] = 11; // 3 - mazi sonai virsus
- indices[138] = 3;
- indices[139] = 4;
- indices[140] = 20;
- indices[141] = 19;
- indices[142] = 20;
- indices[143] = 3; // 4 mazi sonai apacia
- indices[144] = 29;
- indices[145] = 28;
- indices[146] = 11;
- indices[147] = 21;
- indices[148] = 11;
- indices[149] = 28; // 4 mazi sonai apacia
- indices[150] = 4;
- indices[151] = 5;
- indices[152] = 20;
- indices[153] = 21;
- indices[154] = 20;
- indices[155] = 5; // 4 mazi sonai apacia apacia
- indices[156] = 27;
- indices[157] = 28;
- indices[158] = 13;
- indices[159] = 12;
- indices[160] = 13;
- indices[161] = 28; // 4 mazi sonai apacia apacia
- indices[162] = 4;
- indices[163] = 5;
- indices[164] = 20;
- indices[165] = 5;
- indices[166] = 6;
- indices[167] = 21; // 4 mazi sonai apacia apacia
- indices[168] = 22;
- indices[169] = 21;
- indices[170] = 6;
- indices[171] = 12;
- indices[172] = 13;
- indices[173] = 28; // apacia lenkta
- indices[174] = 26;
- indices[175] = 27;
- indices[176] = 13;
- indices[177] = 14;
- indices[178] = 26;
- indices[179] = 13; // apacia lenkta
- indices[180] = 6;
- indices[181] = 7;
- indices[182] = 23;
- indices[183] = 22;
- indices[184] = 23;
- indices[185] = 6; // apacia sonai
- indices[186] = 26;
- indices[187] = 25;
- indices[188] = 15;
- indices[189] = 14;
- indices[190] = 15;
- indices[191] = 26; // apacia sonai
- indices[192] = 7;
- indices[193] = 8;
- indices[194] = 24;
- indices[195] = 23;
- indices[196] = 24;
- indices[197] = 7; // apacia
- indices[198] = 25;
- indices[199] = 24;
- indices[200] = 8;
- indices[201] = 15;
- indices[202] = 8;
- indices[203] = 25; // apacia
- // Set up the description of the static index buffer.
- indexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
- indexBufferDesc.ByteWidth = sizeof(unsigned long) * iCount;
- 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 array now that the vertex buffer has been created and loaded.
- delete[] indices;
- indices = 0;
- return true;
- }
- void TriangleModelClass::Render(ID3D11DeviceContext* deviceContext)
- {
- //Update the world transformations
- UINT iTime = timeGetTime() % 2000;
- float fAngle = iTime * 2 * D3DX_PI / 2000.0f;
- D3DXMATRIX rotMatrix;
- D3DXMatrixRotationY(&rotMatrix, fAngle);
- //D3DXMatrixRotationAxis(&rotMatrix, 1.0f, 1.0f,1.0f, fAngle );
- SetModelWorldMatrix(rotMatrix);
- //SetModelWorldMatrix(XMMatrixIdentity());
- // Put the vertex and index buffers on the graphics pipeline to prepare them for drawing.
- RenderBuffers(deviceContext);
- return;
- }
- void TriangleModelClass::RenderBuffers(ID3D11DeviceContext* deviceContext)
- {
- unsigned int stride;
- unsigned int offset;
- // Set vertex buffer stride and offset.
- stride = sizeof(VertexType);
- offset = 0;
- // Set the vertex buffer to active in the input assembler so it can be rendered.
- deviceContext->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
- // Set the index buffer to active in the input assembler so it can be rendered.
- deviceContext->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
- // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
- deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- // render primitives
- deviceContext->DrawIndexed(GetIndexCount(), 0, 0);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement