this is getting annoying now

This commit is contained in:
Rusty Striker 2023-08-07 18:33:47 +03:00
parent eac3583e8a
commit 07bbd626e7
3 changed files with 112 additions and 51 deletions

View file

@ -6,14 +6,12 @@ Code here is published under the [AGPL-v3](https://www.gnu.org/licenses/agpl-3.0
# TODO
- Allow changing the move/rotation speed(or just a multiplier)
- Change camera position to be cow point of view - DONE, need to do the sub thing
- Add popping-floating text of funny cow thoughts
- Add multiple objects(that is not the cow)(is grass an object?)
- at least 3
- on needs to be metalic
- one needs to be metalic
- User controlled light source
- Add light source
- move the light
- change intensity
- Add popping-floating text of funny cow thoughts when in cow view
- Add Textures and stuff :)(optional)

2
cow.c
View file

@ -11,7 +11,7 @@ const vec3 headLimit = { 30.0, 30.0, 45.0 };
vec3 tailRot = { 0.0, 0.0, 0.0 };
const vec3 tailLimit = { 90.0, 90.0, 0.0 };
vec3 cowPos = { 0.0, 6.0, 0.0 };
vec3 cowPos = { 0.0, 4.9, 0.0 };
float cowRot = 0.0; // rotation along the Y axis
const float COW_ROT_SPEED = 5.0;
const float COW_MOVE_SPEED = 1.0;

155
mmn_17.c
View file

@ -31,44 +31,10 @@ struct {
int cowControl;
int filters;
} menus; // to simply hold the menues in a labed manner
GLuint grassList = -1;
void generateGrassVertexList() {
grassList = glGenLists(1);
glNewList(grassList, GL_COMPILE);
glDisable(GL_CULL_FACE);
for(float x = -50.0; x < 50.0; x += 1.0) {
for(float z = -50.0; z < 50.0; z += 1.0) {
glPushMatrix();
glTranslatef(x, 0.0, z);
glRotatef(rand() % 360, 0.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.5, 0.0, 0.0);
glVertex3f(0.0, 1.5, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.5);
glVertex3f(0.0, 1.5, 0.0);
glEnd();
glPopMatrix();
}
}
glEnable(GL_CULL_FACE);
glEndList();
}
vec3 rotateByCameraRotation(vec3 v) {
vec3 r;
// rotate along the x axis(yz plane)
r.z = cosf(camRot.x) * v.z + sinf(camRot.x) * v.y;
r.y = -sinf(camRot.x) * v.z + cosf(camRot.x) * v.y;
v = r;
// rotate along the y axis(xy plane)
r.z = cosf(camRot.y) * v.z + sinf(camRot.y) * v.x;
r.x = -sinf(camRot.y) * v.z + cosf(camRot.y) * v.x;
return r;
}
struct {
GLuint grass;
} lists;
// Ui stuff
int lastMouseButton = GLUT_LEFT_BUTTON;
@ -90,10 +56,90 @@ ui_slider sliders[] = {
/* pos */ { { 0.9, 0.9, 0.0 }, { -50.0, -70.0, 0.0 } },
/* size */ { 100.0, 10.0, 10.0 },
0.3
},
{ // drag speed
/* pos */ { { 0.9, 0.9, 0.0 }, { -50.0, -120.0, 0.0 } },
/* size */ { 100.0, 10.0, 10.0 },
0.5
},
{ // rotation speed
/* pos */ { { 0.9, 0.9, 0.0 }, { -50.0, -170.0, 0.0 } },
/* size */ { 100.0, 10.0, 10.0 },
0.3
}
};
void generateGrassVertexList() {
lists.grass = glGenLists(1);
glNewList(lists.grass, GL_COMPILE);
glDisable(GL_CULL_FACE);
for(float x = -50.0; x < 50.0; x += 1.0) {
for(float z = -50.0; z < 50.0; z += 1.0) {
float tx = -0.03 * (rand() % 21), tz = -0.03 * (rand() % 21);
glPushMatrix();
glTranslatef(x, 0.0, z);
glRotatef(rand() % 360, 0.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.3, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glColor3f(0.0, 0.5, 0.0);
glVertex3f(0.5, 0.0, 0.0);
glVertex3f(tx, 1.5, tz);
glColor3f(0.0, 0.2, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 0.5);
glColor3f(0.0, 0.5, 0.0);
glVertex3f(tx, 1.5, tz);
glEnd();
glPopMatrix();
}
}
glEnable(GL_CULL_FACE);
glEndList();
}
void drawTree(float rad, float height) {
// Bark
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.3, 0.1, 0.3);
glPushMatrix();
glTranslatef(0.0, height, 0.0);
glRotatef(90.0, 1.0, 0.0, 0.0);
glutSolidCylinder(rad, height, 16, 3);
glPopMatrix();
glColor3f(0.0, 1.0, 0.0);
glPushMatrix();
glTranslatef(0.0, height, 0.0);
vec3 ts[] = {
vec3_new(1.0, 0.0, 0.0), vec3_new(-1.0, 0.0, 0.0),
vec3_new(0.0, 0.0, -1.0), vec3_new(0.0, 0.0, 1.0),
vec3_new(0.0, 1.0, 0.0),
};
for(int i = 0; i < 5; i += 1) {
vec3 t = ts[i];
glPushMatrix();
glTranslatef(t.x * rad, t.y * rad, t.z * rad);
glutSolidSphere(rad, 8, 8);
glPopMatrix();
}
glPopMatrix();
glColor3f(1.0, 1.0, 1.0);
glDisable(GL_COLOR_MATERIAL);
}
vec3 rotateByCameraRotation(vec3 v) {
vec3 r;
// rotate along the x axis(yz plane)
r.z = cosf(camRot.x) * v.z + sinf(camRot.x) * v.y;
r.y = -sinf(camRot.x) * v.z + cosf(camRot.x) * v.y;
v = r;
// rotate along the y axis(xy plane)
r.z = cosf(camRot.y) * v.z + sinf(camRot.y) * v.x;
r.x = -sinf(camRot.y) * v.z + cosf(camRot.y) * v.x;
return r;
}
void drawUi(void) {
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
@ -121,6 +167,12 @@ void drawUi(void) {
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, t);
glRasterPos2f(wWidth * 0.9 - 75.0, wHeight * 0.9 - 10.0);
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (unsigned char*)"r\ng\nb");
unsigned char td[] = "Drag speed";
unsigned char tr[] = "Rotate speed";
glRasterPos2f(wWidth * 0.9 - glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, td) * 0.5, wHeight * 0.9 - 100.0);
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, td);
glRasterPos2f(wWidth * 0.9 - glutBitmapLength(GLUT_BITMAP_TIMES_ROMAN_24, tr) * 0.5, wHeight * 0.9 - 150.0);
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, tr);
if(settings.showHelp) {
glColor3f(0.3, 0.3, 0.3);
@ -165,6 +217,7 @@ void drawWorld(void) {
gluPerspective(90, wWidth / wHeight , 0.5, 500.0);
// Lights
glEnable(GL_LIGHTING);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
// Ambient light
GLfloat ambient[] = { sliders[0].value, sliders[1].value, sliders[2].value, 1.0 };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
@ -192,15 +245,24 @@ void drawWorld(void) {
glTexCoord2f(1.0, 0.0); glVertex3f(50.0, 0.0, -50.0);
glEnd();
glDisable(GL_TEXTURE_2D);
// Add a simple cube to see where the cow was originally facing
glPushMatrix();
glTranslatef(25.0, 0.0, 25.0);
drawTree(3.0, 20.0);
glTranslatef(-50.0, 0.0, 0.0);
drawTree(2.0, 19.0);
glPopMatrix();
// Scary shady cube
glPushMatrix();
glTranslatef(0.0, 10.0, 50.0);
glEnable(GL_COLOR_MATERIAL);
glColor3f(1.0, 1.0, 1.0);
glColor3f(0.05, 0.5, 1.0);
glMaterialf(GL_FRONT, GL_SHININESS, 58.0);
glutSolidCube(20.0);
glMaterialf(GL_FRONT, GL_SHININESS, 0.0);
glPopMatrix();
glColor3f(0.1, 0.3, 0.0);
glCallList(grassList);
glCallList(lists.grass);
glColor3f(1.0, 1.0, 1.0);
glDisable(GL_COLOR_MATERIAL);
}
@ -254,11 +316,12 @@ void mouseMotionEvent(int x, int y) {
}
else {
// rotate the camera
camRot.y -= (x - lastMouseX) * PI * 0.01;
float speed = sliders[4].value * 0.095 + 0.005;
camRot.y -= (x - lastMouseX) * speed;
if(camRot.y > 2 * PI) camRot.y -= 2 * PI;
else if(camRot.y < 0.0) camRot.y += 2 * PI;
camRot.x = fmin(PI * 0.5, fmax(-PI * 0.5, camRot.x - (y - lastMouseY) * 0.01 * PI));
camRot.x = fmin(PI * 0.5, fmax(-PI * 0.5, camRot.x - (y - lastMouseY) * speed));
}
}
@ -270,9 +333,9 @@ void mouseMotionEvent(int x, int y) {
moveX.y = 0;
moveY.y = 0;
}
camCenter = vec3_add(camCenter, vec3_mult(moveX, (lastMouseX - x) * 0.5));
camCenter = vec3_add(camCenter, vec3_mult(moveY, (y - lastMouseY) * 0.5));
float speed = sliders[3].value * 0.9 + 0.1;
camCenter = vec3_add(camCenter, vec3_mult(moveX, (lastMouseX - x) * speed));
camCenter = vec3_add(camCenter, vec3_mult(moveY, (y - lastMouseY) * speed));
}
lastMouseX = x; lastMouseY = y;
glutPostRedisplay();