cow got a flashlight yay

This commit is contained in:
Rusty Striker 2023-08-08 20:12:58 +03:00
parent 2fe1b677b7
commit 790fee53b5
Signed by: RustyStriker
GPG key ID: 87E4D691632DFF15
2 changed files with 24 additions and 9 deletions

24
cow.c
View file

@ -1,3 +1,4 @@
#include <GL/freeglut.h>
#include <GL/freeglut_std.h> #include <GL/freeglut_std.h>
#include <GL/glut.h> #include <GL/glut.h>
#include <GL/gl.h> #include <GL/gl.h>
@ -163,6 +164,27 @@ void drawCow(char cowsPOV) {
glScalef(0.2, 1.0, 0.2); glScalef(0.2, 1.0, 0.2);
glutSolidSphere(1.0, 8, 8); glutSolidSphere(1.0, 8, 8);
glPopMatrix(); // Tails(from sonic the hedgehog) glPopMatrix(); // Tails(from sonic the hedgehog)
// Give the cow a little flashlight because its dark outside
glPushMatrix(); // fl
glTranslatef(0.5, -1.2, 1.4);
glColor3f(0.3, 0.3 ,0.3);
glutSolidCylinder(0.3, 2.0, 8, 1);
glTranslatef(0.0, 0.0, 2.0);
glRotatef(180.0, 0.0, 1.0, 0.0);
glutSolidCone(0.6, 0.6, 8, 2);
glEnable(GL_LIGHT0);
// Directional light - aka light
GLfloat light1[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat lightColor[] = {0.9, 0.9, 0.1, 1.0};
GLfloat dir[] = { 0.0, 0.0, -1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light1);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightColor);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightColor);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 30.0);
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 2.0);
glPopMatrix(); // fl
glPopMatrix(); // cow pos glPopMatrix(); // cow pos
glColor3f(1.0, 1.0, 1.0); glColor3f(1.0, 1.0, 1.0);
glDisable(GL_COLOR_MATERIAL); glDisable(GL_COLOR_MATERIAL);
@ -199,6 +221,6 @@ void setCameraToCowPOV() {
glRotatef(-headRot.y, 0.0, 1.0, 0.0); glRotatef(-headRot.y, 0.0, 1.0, 0.0);
glTranslatef(0.0, 0.0, -5.0); glTranslatef(0.0, 0.0, -5.0);
// body // body
glTranslatef(-cowPos.x, -cowPos.y, -cowPos.z);
glRotatef(-cowRot, 0.0, 1.0, 0.0); glRotatef(-cowRot, 0.0, 1.0, 0.0);
glTranslatef(-cowPos.x, -cowPos.y, -cowPos.z);
} }

View file

@ -272,14 +272,7 @@ void drawWorld(void) {
// Ambient light // Ambient light
GLfloat ambient[] = { slidersN.ambientRed->value, slidersN.ambientGreen->value, slidersN.ambientBlue->value, 1.0 }; GLfloat ambient[] = { slidersN.ambientRed->value, slidersN.ambientGreen->value, slidersN.ambientBlue->value, 1.0 };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
// glEnable(GL_LIGHT0); // GL_LIGHT0 is reserved for the cow's flashlight
// // Directional light - aka light
// GLfloat light1[] = { 0.0, 1.0, 0.0, 0.0 };
// glLightfv(GL_LIGHT0, GL_POSITION, light1);
// GLfloat lightColor[] = {0.5, 0.4, 0.1, 1.0};
// glLightfv(GL_LIGHT0, GL_AMBIENT, lightColor);
// glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);
// glLightfv(GL_LIGHT0, GL_SPECULAR, lightColor);
// user light // user light
glEnable(GL_LIGHT1); glEnable(GL_LIGHT1);
GLfloat ulPos[] = { lightPos.x, lightPos.y, lightPos.z, 1.0 }; GLfloat ulPos[] = { lightPos.x, lightPos.y, lightPos.z, 1.0 };