Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.02 KB | None | 0 0
  1. Sprite2D::VertexIndex* Sprite2D::LoadGeometry(bool ind)
  2. {
  3.     m_vertexCount = 4;
  4.     m_indexCount = 6;
  5.     Vertex* vertices;
  6.     unsigned long* indices;
  7.     vertices = new Vertex[m_vertexCount];
  8.    
  9.     if (ind)
  10.     {
  11.         indices = new unsigned long[m_indexCount];
  12.     }
  13.     else indices = nullptr;
  14.  
  15.     // rotation
  16.     D3DXMATRIX rotateX;
  17.     D3DXMATRIX rotateY;
  18.     D3DXMATRIX rotateZ;
  19.     D3DXMatrixRotationX(&rotateX, rotation.x);
  20.     D3DXMatrixRotationY(&rotateY, rotation.y);
  21.     D3DXMatrixRotationZ(&rotateZ, rotation.z);
  22.     D3DXMATRIX rotationMatrix = rotateX*rotateY*rotateZ;
  23.     D3DXVECTOR4 outputVec[4];
  24.  
  25.  
  26.  
  27.     // load vertex array with data
  28.     vertices[0].position = D3DXVECTOR3(-1.0f, -1.0f, 0.0f); // BL
  29.     vertices[0].texture = D3DXVECTOR2(0.0f, 1.0f);
  30.     vertices[1].position = D3DXVECTOR3(-1.0f, 1.0f, 0.0f); // TL
  31.     vertices[1].texture = D3DXVECTOR2(0.0f, 0.0f);
  32.     vertices[2].position = D3DXVECTOR3(1.0f, -1.0f, 0.0f); // BR
  33.     vertices[2].texture = D3DXVECTOR2(1.0f, 1.0f);
  34.     vertices[3].position = D3DXVECTOR3(1.0f, 1.0f, 0.0f); // TR
  35.     vertices[3].texture = D3DXVECTOR2(1.0f, 0.0f);
  36.  
  37.     for (int i = 0; i < 4; i++)
  38.     {
  39.         D3DXVec3Transform(&outputVec[i], &vertices[i].position, &rotationMatrix);
  40.         vertices[i].position.x = (outputVec[i].x*scale.x + position.x);
  41.         vertices[i].position.y = (outputVec[i].y*scale.y + position.y);
  42.         vertices[i].position.z = (outputVec[i].z*scale.z + position.z);
  43.     }
  44.  
  45.     if (ind)
  46.     {
  47.         // load index array with data
  48.         indices[0] = 0; // BL
  49.         indices[1] = 1; // TL
  50.         indices[2] = 2; // BR
  51.         indices[3] = 2;
  52.         indices[4] = 1;
  53.         indices[5] = 3;
  54.     }
  55.  
  56.     VertexIndex* toReturn = new VertexIndex();
  57.     toReturn->vertexArrayPtr = vertices;
  58.     toReturn->indexArrayPtr = indices;
  59.     return toReturn;
  60. }
  61.  
  62. bool System::ProcessKeys()
  63. {
  64.     //string debug = to_string(player->position.x) + " " + to_string(player->position.y) + "\n";
  65.     //OutputDebugString(debug.c_str());
  66.     bool toReturn = true;
  67.     playerAnimation = false;
  68.     if (myInput->IsKeyDown(VK_ESCAPE)) toReturn = false;
  69.     if (myInput->IsKeyDown(VK_LEFT) /*&& player->GetPosition().x > -(signed int)(terrain->GetWidth()*terrain->GetSize())*/)
  70.     {
  71.         D3DXVECTOR3 newVec = (player->GetPosition() + D3DXVECTOR3((-myInput->movementDistance)*(m_Timer->GetTime()), 0.0f, 0.0f));
  72.         player->SetPosition(newVec);
  73.         player->SetRotation(D3DXVECTOR3(0.0f, 0.0f, 1.57079632679f));
  74.         //myInput->KeyUp(VK_LEFT);
  75.         playerAnimation = true;
  76.         toReturn = true;
  77.     }
  78.     if (myInput->IsKeyDown(VK_RIGHT))
  79.     {
  80.         D3DXVECTOR3 newVec = (player->GetPosition() + D3DXVECTOR3((myInput->movementDistance)*(m_Timer->GetTime()), 0.0f, 0.0f));
  81.         player->SetPosition(newVec);
  82.         player->SetRotation(D3DXVECTOR3(0.0f, 0.0f, 4.71238898038f));
  83.         //myInput->KeyUp(VK_RIGHT);
  84.         playerAnimation = true;
  85.         toReturn = true;
  86.     }
  87.     if (myInput->IsKeyDown(VK_UP))
  88.     {
  89.         D3DXVECTOR3 newVec = (player->GetPosition() + D3DXVECTOR3(0.0f, (myInput->movementDistance)*(m_Timer->GetTime()), 0.0f));
  90.         player->SetPosition(newVec);
  91.         player->SetRotation(D3DXVECTOR3(0.0f, 0.0f, 0.0f));
  92.         //myInput->KeyUp(VK_UP);
  93.         playerAnimation = true;
  94.         toReturn = true;
  95.     }
  96.     if (myInput->IsKeyDown(VK_DOWN))
  97.     {
  98.         D3DXVECTOR3 newVec = (player->GetPosition() + D3DXVECTOR3(0.0f, (-myInput->movementDistance)*(m_Timer->GetTime()), 0.0f));
  99.         player->SetPosition(newVec);
  100.         player->SetRotation(D3DXVECTOR3(0.0f, 0.0f, 3.14159265359f));
  101.         //myInput->KeyUp(VK_DOWN);
  102.         playerAnimation = true;
  103.         toReturn = true;
  104.     }
  105.     if (myInput->IsKeyDown(VK_DOWN) && myInput->IsKeyDown(VK_LEFT))
  106.     {
  107.         player->SetRotation(D3DXVECTOR3(0.0f, 0.0f, 2.35619449019f));
  108.     }
  109.     if (myInput->IsKeyDown(VK_DOWN) && myInput->IsKeyDown(VK_RIGHT))
  110.     {
  111.         player->SetRotation(D3DXVECTOR3(0.0f, 0.0f, 3.92699081699f));
  112.     }
  113.     if (myInput->IsKeyDown(VK_UP) && myInput->IsKeyDown(VK_LEFT))
  114.     {
  115.         player->SetRotation(D3DXVECTOR3(0.0f, 0.0f, 0.78539816339f));
  116.     }
  117.     if (myInput->IsKeyDown(VK_UP) && myInput->IsKeyDown(VK_RIGHT))
  118.     {
  119.         player->SetRotation(D3DXVECTOR3(0.0f, 0.0f, 5.49778714378f));
  120.     }
  121.     if (myInput->IsKeyDown(VK_SPACE))
  122.     {
  123.         PlayerShoot();
  124.         myInput->KeyUp(VK_SPACE);
  125.         toReturn = true;
  126.     }
  127.     return toReturn;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement