Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void render()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
- cM(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
- cVP(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, fwd);
- mult4m(M, VP, MVP); //this function multiplies two matrices and stores the result in the 3rd parameter
- glUniformMatrix4fv(MVPl, 1, false, &MVP[0][0]);
- glBindVertexArray(uiVAO[0]);
- glDrawArrays(GL_TRIANGLES, 0, type[0]);
- glBindVertexArray(uiVAO[1]);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, type[1]);
- SwapBuffers(hdc);
- }
- void cM(float ax, float ay, float az, float sx, float sy, float sz, float tx, float ty, float tz)
- {
- float Rx[4][4] =
- {
- { 1.0f,0.0f,0.0f,0.0f },
- { 0.0f,cos(ax),sin(ax),0.0f },
- { 0.0f,-sin(ax),cos(ax),0.0f },
- { 0.0f,0.0f,0.0f,1.0f }
- };
- float Ry[4][4] =
- {
- { cos(ay),0.0f,-sin(ay),0.0f },
- { 0.0f,1.0f,0.0f,0.0f },
- { sin(ay),0,cos(ay),0.0f },
- { 0.0f,0.0f,0.0f,1.0f }
- };
- float Rz[4][4] =
- {
- { cos(az),sin(az),0.0f,0.0f },
- { -sin(az),cos(az),0.0f,0.0f },
- { 0.0f,0.0f,1.0f,0.0f },
- { 0.0f,0.0f,0.0f,1.0f }
- };
- float ScaleTrans[4][4] =
- {
- { sx,0.0f,0.0f,0.0f },
- { 0.0f,sy,0.0f,0.0f },
- { 0.0f,0.0f,sz,0.0f },
- { tx,ty,tz,1.0 }
- };
- static float R[4][4], S[4][4];
- mult4m(Rx, Ry, R);
- mult4m(R, Rz, S);
- mult4m(S, ScaleTrans, M);
- }
- void cVP(float ax, float ay, float az, float posx, float posy, float posz)
- {
- float Rx[4][4] =
- {
- { 1.0f,0.0f,0.0f,0.0f },
- { 0.0f,cos(ax),-sin(ax),0.0f },
- { 0.0f,sin(ax),cos(ax),0.0f },
- { 0.0f,0.0f,0.0f,1.0f }
- };
- float Ry[4][4] =
- {
- { cos(ay),0.0f,sin(ay),0.0f },
- { 0.0f,1.0f,0.0f,0.0f },
- { -sin(ay),0.0f,cos(ay),0.0f },
- { 0.0f,0.0f,0.0f,1.0f }
- };
- float Rz[4][4] =
- {
- { cos(az),-sin(az),0.0f,0.0f },
- { sin(az),cos(az),0.0f,0.0f },
- { 0.0f,0.0f,1.0f,0.0f },
- { 0.0f,0.0f,0.0f,1.0f }
- };
- static float R[4][4], T[4][4], P[4][4], V[4][4];
- mult4m(Rx, Ry, R);
- mult4m(R, Rz, V);
- float View[4][4] =
- {
- { 1.0f,0.0f,0.0f,0.0f },
- { 0.0f,1.0f,0.0f,0.0f },
- { 0.0f,0.0f,-1.0f,0.0f },
- { posx,posy,posz,1.0f }
- };
- mult4m(V, View, P);
- float Proj[4][4] =
- {
- { (1 / tanf(FOV / 2.0f)) / aspect_ratio,0.0f, 0.0f,0.0f },
- { 0.0f,1 / tanf(FOV / 2.0f),0.0f,0.0f },
- { 0.0f,0.0f,-(1024.0f + 0.01) / (1024.f - 0.01),-1.0f },
- { 0.0f,0.0f,(-2.0f * (0.01f * 1024.0f) / (1024.f - 0.01f)), 1.0f }
- };
- mult4m(P, Proj, VP);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement