Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gl/glos.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <gl/glaux.h>
- #include <conio.h>
- #include <math.h>
- void MakeShadowMatrix(GLfloat points[3][3], GLfloat lightPos[4], GLfloat destMat[4][4])
- {
- GLfloat planeCoeff[4];
- GLfloat dot;
- calcNormal(points, planeCoeff);
- planeCoeff[3] = -(planeCoeff[0] * points[2][0] + planeCoeff[1] * points[2][1] + planeCoeff[2] * points[2][2]);
- dot = planeCoeff[0] * lightPos[0] +
- planeCoeff[1] * lightPos[1] +
- planeCoeff[2] * lightPos[2] +
- planeCoeff[3] * lightPos[3];
- destMat[0][0] = dot - lightPos[0] * planeCoeff[0];
- destMat[1][0] = 0.0f - lightPos[0] * planeCoeff[1];
- destMat[2][0] = 0.0f - lightPos[0] * planeCoeff[2];
- destMat[3][0] = 0.0f - lightPos[0] * planeCoeff[3];
- destMat[0][1] = dot - lightPos[1] * planeCoeff[0];
- destMat[1][1] = 0.0f - lightPos[1] * planeCoeff[1];
- destMat[2][1] = 0.0f - lightPos[1] * planeCoeff[2];
- destMat[3][1] = 0.0f - lightPos[1] * planeCoeff[3];
- destMat[0][2] = dot - lightPos[2] * planeCoeff[0];
- destMat[1][2] = 0.0f - lightPos[2] * planeCoeff[1];
- destMat[2][2] = 0.0f - lightPos[2] * planeCoeff[2];
- destMat[3][2] = 0.0f - lightPos[2] * planeCoeff[3];
- destMat[0][3] = dot - lightPos[3] * planeCoeff[0];
- destMat[1][3] = 0.0f - lightPos[3] * planeCoeff[1];
- destMat[2][3] = 0.0f - lightPos[3] * planeCoeff[2];
- destMat[3][3] = 0.0f - lightPos[3] * planeCoeff[3];
- }
- void CALLBACK deseneaza(void)
- {
- GLfloat ambietLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
- GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f };
- GLfloat specuulatLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- GLfloat lightPos[] = { 0, 50, -100, 1 };
- GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- GLfloat mynormal[3];
- GLfloat plan[4][3] = {
- {-500, -50, 500},
- {500, -50, 500},
- {500, -50, -500},
- {-500, -50, -500}
- };
- GLfloat plan_[4][3] = {
- {-500, -49.9, 500},
- {500, -49.9, 500},
- {500, -49.9, -500},
- {-500, -49.9, -500}
- };
- GLfloat shadowMat[4][4];
- GLfloat pi = 3.14159f;
- GLint i, j, lx = 100, ly = 100;
- lightPos[0] = sin(arot[1] * pi * 2 / 360) * 40;
- lightPos[1] = 50;
- lightPos[2] = cos(arot[1] * pi * 2 / 360) * 40 - 150;
- MakeShadowMatrix(plan_, lightPos, shadowMat);
- glEnable(GL_DEPTH_TEST);
- glFrontFace(GL_CCW);
- glEnable(GL_LIGHTING);
- glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
- glLightfx(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
- glLightfx(GL_LIGHT0, GL_SPECULAR, specularLight);
- glLightfx(GL_LIGHT0, GL_POSITION, lightPos);
- glEnable(GL_LIGHT0);
- glEnable(GL_COLOR_MATERIAL);
- glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMaterialfx(GL_FRONT, GL_SPECULAR, specref);
- glMateriali(GL_FRONT, GL_SHININESS, 128);
- glMatrixMode(GL_MODELVIEW);
- glPushAttrib(GL_LIGHTING_BIT);
- glDisable(GL_LIGHTING);
- glPopMatrix();
- glPushMatrix();
- glMultMatrixf((GLfloat *)shadowMat);
- glColor3f(0, 0.3, 0);
- glTranslatef(0, 0, -150);
- glRotatef(a, 0, 1, 0);
- glRotatef(b, 1, 0, 0);
- auxSolidCube(20.0);
- glPopMatrix();
- glPopAttrib();
- glPushMatrix();
- glColor3f(1, 0, 0);
- glTranslatef(0, 0, -150);
- glRotatef(a, 0, 1, 0);
- glRotatef(b, 1, 0, 0);
- auxSolidCube(20.0);
- glPopMatrix();
- glPushMatrix();
- glColor3f(0, 1.0, 0);
- glBegin(GL_QUADS);
- glVertex3fv(plan[0]);
- glVertex3fv(plan[1]);
- glVertex3fv(plan[2]);
- glVertex3fv(plan[3]);
- glEnd();
- glPopMatrix();
- glFluash();
- }
- void main()
- {
- //initializare modului de afisare –
- //un singur buffer – afisare direct pe ecran –
- //culori după standardul RGBA
- auxInitDisplayMode(AUX_SINGLE | AUX_RGBA);
- //poziţia si dimensiunile ferestrei de afisare
- auxInitPosition(100, 100, 300, 300);
- //initializam fereastra precizand titlul acesteia
- auxInitWindow("Program OpenGL");
- // aici se scrie codul OpenGL pentru afişare
- //stergem fereastra folosind culoarea albastru
- glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- auxMainLoop(deseneaza);
- glFlush();
- // Nu inchide! Asteapta apasarea unei taste
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement