Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. void render()
  2. {
  3. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  4.  
  5. cM(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
  6.  
  7. cVP(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, fwd);
  8.  
  9. mult4m(M, VP, MVP); //this function multiplies two matrices and stores the result in the 3rd parameter
  10.  
  11. glUniformMatrix4fv(MVPl, 1, false, &MVP[0][0]);
  12.  
  13. glBindVertexArray(uiVAO[0]);
  14.  
  15. glDrawArrays(GL_TRIANGLES, 0, type[0]);
  16.  
  17. glBindVertexArray(uiVAO[1]);
  18.  
  19. glDrawArrays(GL_TRIANGLE_STRIP, 0, type[1]);
  20.  
  21. SwapBuffers(hdc);
  22.  
  23. }
  24.  
  25.  
  26. void cM(float ax, float ay, float az, float sx, float sy, float sz, float tx, float ty, float tz)
  27. {
  28. float Rx[4][4] =
  29. {
  30. { 1.0f,0.0f,0.0f,0.0f },
  31. { 0.0f,cos(ax),sin(ax),0.0f },
  32. { 0.0f,-sin(ax),cos(ax),0.0f },
  33. { 0.0f,0.0f,0.0f,1.0f }
  34. };
  35. float Ry[4][4] =
  36. {
  37. { cos(ay),0.0f,-sin(ay),0.0f },
  38. { 0.0f,1.0f,0.0f,0.0f },
  39. { sin(ay),0,cos(ay),0.0f },
  40. { 0.0f,0.0f,0.0f,1.0f }
  41. };
  42. float Rz[4][4] =
  43. {
  44. { cos(az),sin(az),0.0f,0.0f },
  45. { -sin(az),cos(az),0.0f,0.0f },
  46. { 0.0f,0.0f,1.0f,0.0f },
  47. { 0.0f,0.0f,0.0f,1.0f }
  48. };
  49.  
  50. float ScaleTrans[4][4] =
  51. {
  52. { sx,0.0f,0.0f,0.0f },
  53. { 0.0f,sy,0.0f,0.0f },
  54. { 0.0f,0.0f,sz,0.0f },
  55. { tx,ty,tz,1.0 }
  56. };
  57.  
  58. static float R[4][4], S[4][4];
  59.  
  60. mult4m(Rx, Ry, R);
  61. mult4m(R, Rz, S);
  62. mult4m(S, ScaleTrans, M);
  63.  
  64. }
  65.  
  66. void cVP(float ax, float ay, float az, float posx, float posy, float posz)
  67. {
  68.  
  69. float Rx[4][4] =
  70. {
  71. { 1.0f,0.0f,0.0f,0.0f },
  72. { 0.0f,cos(ax),-sin(ax),0.0f },
  73. { 0.0f,sin(ax),cos(ax),0.0f },
  74. { 0.0f,0.0f,0.0f,1.0f }
  75. };
  76.  
  77. float Ry[4][4] =
  78. {
  79. { cos(ay),0.0f,sin(ay),0.0f },
  80. { 0.0f,1.0f,0.0f,0.0f },
  81. { -sin(ay),0.0f,cos(ay),0.0f },
  82. { 0.0f,0.0f,0.0f,1.0f }
  83. };
  84.  
  85. float Rz[4][4] =
  86. {
  87. { cos(az),-sin(az),0.0f,0.0f },
  88. { sin(az),cos(az),0.0f,0.0f },
  89. { 0.0f,0.0f,1.0f,0.0f },
  90. { 0.0f,0.0f,0.0f,1.0f }
  91. };
  92.  
  93.  
  94. static float R[4][4], T[4][4], P[4][4], V[4][4];
  95.  
  96. mult4m(Rx, Ry, R);
  97. mult4m(R, Rz, V);
  98.  
  99. float View[4][4] =
  100. {
  101. { 1.0f,0.0f,0.0f,0.0f },
  102. { 0.0f,1.0f,0.0f,0.0f },
  103. { 0.0f,0.0f,-1.0f,0.0f },
  104. { posx,posy,posz,1.0f }
  105. };
  106.  
  107. mult4m(V, View, P);
  108.  
  109. float Proj[4][4] =
  110. {
  111. { (1 / tanf(FOV / 2.0f)) / aspect_ratio,0.0f, 0.0f,0.0f },
  112. { 0.0f,1 / tanf(FOV / 2.0f),0.0f,0.0f },
  113. { 0.0f,0.0f,-(1024.0f + 0.01) / (1024.f - 0.01),-1.0f },
  114. { 0.0f,0.0f,(-2.0f * (0.01f * 1024.0f) / (1024.f - 0.01f)), 1.0f }
  115. };
  116.  
  117. mult4m(P, Proj, VP);
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement