Made a rather good looking cow :D
This commit is contained in:
parent
02117f4354
commit
eac3583e8a
3 changed files with 104 additions and 44 deletions
13
README.md
13
README.md
|
@ -6,20 +6,7 @@ Code here is published under the [AGPL-v3](https://www.gnu.org/licenses/agpl-3.0
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
- Add menu - partially done
|
|
||||||
- Adjust ambient light
|
|
||||||
- Allow changing the move/rotation speed(or just a multiplier)
|
- Allow changing the move/rotation speed(or just a multiplier)
|
||||||
- Create a cow - IM SO BAD AT IT IM SO SORRY COWS
|
|
||||||
- Head
|
|
||||||
- Tail
|
|
||||||
- Body
|
|
||||||
- Legs
|
|
||||||
- Ears
|
|
||||||
- Nose
|
|
||||||
- Eyes
|
|
||||||
- Allow user control of the cow
|
|
||||||
- Tail
|
|
||||||
- Legs? (optional)
|
|
||||||
- Change camera position to be cow point of view - DONE, need to do the sub thing
|
- 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 popping-floating text of funny cow thoughts
|
||||||
- Add multiple objects(that is not the cow)(is grass an object?)
|
- Add multiple objects(that is not the cow)(is grass an object?)
|
||||||
|
|
129
cow.c
129
cow.c
|
@ -6,8 +6,10 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
vec3 headRot = { -30.0, 0.0, 0.0 };
|
vec3 headRot = { 0.0, 0.0, 0.0 };
|
||||||
const vec3 headLimit = { 90.0, 90.0 ,90.0 };
|
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, 6.0, 0.0 };
|
||||||
float cowRot = 0.0; // rotation along the Y axis
|
float cowRot = 0.0; // rotation along the Y axis
|
||||||
|
@ -26,6 +28,12 @@ float addAndWrapRot(float rot, float add) {
|
||||||
else if(rot < -180.0) { rot += 360.0; }
|
else if(rot < -180.0) { rot += 360.0; }
|
||||||
return rot;
|
return rot;
|
||||||
}
|
}
|
||||||
|
float addAndLimitRot(float rot, float add, float limit) {
|
||||||
|
rot += add;
|
||||||
|
if(rot > limit) { rot = limit; }
|
||||||
|
else if(rot < -limit) { rot = -limit; }
|
||||||
|
return rot;
|
||||||
|
}
|
||||||
|
|
||||||
void cowMove(char c) {
|
void cowMove(char c) {
|
||||||
// check for rotations
|
// check for rotations
|
||||||
|
@ -42,9 +50,14 @@ void cowMove(char c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void cowHead(char c) {
|
void cowHead(char c) {
|
||||||
headRot.z = addAndWrapRot(headRot.z, ((c == 'e') - (c == 'q')) * COW_ROT_SPEED);
|
headRot.z = addAndLimitRot(headRot.z, ((c == 'e') - (c == 'q')) * COW_ROT_SPEED, headLimit.z);
|
||||||
headRot.y = addAndWrapRot(headRot.y, ((c == 'a') - (c == 'd')) * COW_ROT_SPEED);
|
headRot.y = addAndLimitRot(headRot.y, ((c == 'a') - (c == 'd')) * COW_ROT_SPEED, headLimit.y);
|
||||||
headRot.x = addAndWrapRot(headRot.x, ((c == 's') - (c == 'w')) * COW_ROT_SPEED);
|
headRot.x = addAndLimitRot(headRot.x, ((c == 's') - (c == 'w')) * COW_ROT_SPEED, headLimit.x);
|
||||||
|
glutPostRedisplay();
|
||||||
|
}
|
||||||
|
void cowTail(char c) {
|
||||||
|
tailRot.y = addAndLimitRot(tailRot.y, ((c == 'a') - (c == 'd')) * COW_ROT_SPEED, tailLimit.y);
|
||||||
|
tailRot.x = addAndLimitRot(tailRot.x, ((c == 's') - (c == 'w')) * COW_ROT_SPEED, tailLimit.x);
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,45 +68,101 @@ void drawCow(char cowsPOV) {
|
||||||
// Main cow position - as center of cow body
|
// Main cow position - as center of cow body
|
||||||
glTranslatef(cowPos.x, cowPos.y, cowPos.z);
|
glTranslatef(cowPos.x, cowPos.y, cowPos.z);
|
||||||
glRotatef(cowRot, 0.0, 1.0, 0.0);
|
glRotatef(cowRot, 0.0, 1.0, 0.0);
|
||||||
|
glScalef(2.0, 2.0, 2.0); // general cow scale, as i blocked it in blender and it was mostly normalized
|
||||||
// Draw cow body
|
// Draw cow body
|
||||||
glPushMatrix(); // cow body scale
|
glPushMatrix(); // cow body scale
|
||||||
glColor3f(0.8,0.4,0.11);
|
glColor3f(0.8,0.4,0.11);
|
||||||
glScalef(1.0, 1.0, 1.5);
|
glScalef(1.2, 1.2, 2.3);
|
||||||
glutSolidSphere(4.0, 16, 16);
|
glutSolidSphere(1.0, 16, 16);
|
||||||
glPopMatrix(); // cow body scale
|
glPopMatrix(); // cow body scale
|
||||||
if(!cowsPOV) {
|
if(!cowsPOV) {
|
||||||
// head
|
// head
|
||||||
glPushMatrix(); // head center
|
glPushMatrix(); // head center
|
||||||
glTranslatef(0.0, 1.0, 5.0);
|
glTranslatef(0.0, 1.0, 1.8);
|
||||||
glRotatef(headRot.y, 0.0, 1.0, 0.0);
|
glRotatef(headRot.y, 0.0, 1.0, 0.0);
|
||||||
glRotatef(headRot.x, 1.0, 0.0, 0.0);
|
glRotatef(headRot.x, 1.0, 0.0, 0.0);
|
||||||
glTranslatef(0.0, 0.0, 1.0);
|
// glTranslatef(0.0, 0.0, 1.0);
|
||||||
glRotatef(headRot.z, 0.0, 0.0 ,1.0);
|
glRotatef(headRot.z, 0.0, 0.0 ,1.0);
|
||||||
glutSolidSphere(2.0, 16, 16);
|
glPushMatrix(); // head sphere 1
|
||||||
vec3 ePos = vec3_new(0.7, 0.8, 1.3);
|
glScalef(0.6, 0.4, 0.7);
|
||||||
vec3 pPos = vec3_new(0.0, 0.2, 0.5);
|
glutSolidSphere(1.0, 8, 8);
|
||||||
|
glPopMatrix(); // head sphere 1
|
||||||
|
glPushMatrix(); // head sphere 2
|
||||||
|
glTranslatef(0.0, 0.3, -0.3);
|
||||||
|
glScalef(0.6, 0.45, 0.75);
|
||||||
|
glutSolidSphere(1.0, 8, 8);
|
||||||
|
glPopMatrix();
|
||||||
|
// eyes :)
|
||||||
|
glColor3f(0.0,0.0,0.0); // Eyes black as night
|
||||||
glPushMatrix(); // eye 1
|
glPushMatrix(); // eye 1
|
||||||
glTranslatef(ePos.x, ePos.y, ePos.z);
|
glTranslatef(-0.3, 0.5, 0.0);
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
glScalef(0.17, 0.17, 0.17);
|
||||||
glutSolidSphere(0.5, 8, 8);
|
glutSolidSphere(1.0, 8, 8);
|
||||||
glPushMatrix(); // pupil 1
|
|
||||||
glTranslatef(pPos.x, pPos.y, pPos.z);
|
|
||||||
glColor3f(0.0, 0.0, 0.0);
|
|
||||||
glutSolidSphere(0.1, 8, 8);
|
|
||||||
glPopMatrix(); // pupil 1
|
|
||||||
glPopMatrix(); // eye 1
|
glPopMatrix(); // eye 1
|
||||||
glPushMatrix(); // eye 2
|
glPushMatrix(); // eye 2
|
||||||
glTranslatef(-ePos.x, ePos.y, ePos.z);
|
glTranslatef(0.3, 0.5, 0.0);
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
glScalef(0.17, 0.17, 0.17);
|
||||||
glutSolidSphere(0.5, 8, 8);
|
glutSolidSphere(1.0, 8, 8);
|
||||||
glPushMatrix(); // pupil 2
|
|
||||||
glTranslatef(pPos.x, pPos.y, pPos.z);
|
|
||||||
glColor3f(0.0, 0.0, 0.0);
|
|
||||||
glutSolidSphere(0.1, 8, 8);
|
|
||||||
glPopMatrix(); // pupil 2
|
|
||||||
glPopMatrix(); // eye 2
|
glPopMatrix(); // eye 2
|
||||||
|
glColor3f(0.8,0.4,0.11); // go back to the normal cow color
|
||||||
|
// EARS! they look like little pancakes to the side of the head
|
||||||
|
glPushMatrix(); // ear 1
|
||||||
|
glTranslatef(-0.7, 0.5, -0.4);
|
||||||
|
glScalef(0.3, 0.18, 0.07);
|
||||||
|
glutSolidSphere(1.0, 8, 8);
|
||||||
|
glPopMatrix(); // ear 1
|
||||||
|
glPushMatrix(); // ear 2
|
||||||
|
glTranslatef(0.7, 0.5, -0.4);
|
||||||
|
glScalef(0.3, 0.18, 0.07);
|
||||||
|
glutSolidSphere(1.0, 8, 8);
|
||||||
|
glPopMatrix(); // ear 2
|
||||||
|
// Add a little teapon earing :D
|
||||||
|
glPushMatrix();
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
glTranslatef(-0.8, 0.19, -0.4);
|
||||||
|
glRotatef(146.0, 0.0, 1.0, 0.0);
|
||||||
|
glRotatef(-90.0, 1.0, 0.0, 0.0);
|
||||||
|
glRotatef(90.0, 0.0, 1.0, 0.0);
|
||||||
|
glCullFace(GL_FRONT); // for some reason, teapot normals are backwards to all other
|
||||||
|
glutSolidTeapot(0.17);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glPopMatrix(); // teapot!
|
||||||
|
glPushMatrix(); // little nose
|
||||||
|
glColor3f(0.9, 0.3, 0.4);
|
||||||
|
glTranslatef(0.0, 0.1, 0.6);
|
||||||
|
glScalef(0.3, 0.15, 0.14);
|
||||||
|
glutSolidSphere(1.0, 8, 8);
|
||||||
|
glPopMatrix(); // little nose
|
||||||
glPopMatrix(); // head center
|
glPopMatrix(); // head center
|
||||||
}
|
}
|
||||||
|
// tins
|
||||||
|
glColor3f(0.9, 0.3, 0.4);
|
||||||
|
glPushMatrix(); // TINS!
|
||||||
|
glTranslatef(0.0, -1.0, -0.58);
|
||||||
|
glScalef(0.7, 0.4, 0.7);
|
||||||
|
glutSolidSphere(1.0, 8, 8);
|
||||||
|
glPopMatrix(); // Thins!
|
||||||
|
glColor3f(0.8,0.4,0.11); // go back to the normal cow color
|
||||||
|
vec3 legs[] = {
|
||||||
|
vec3_new(1.0, 0.0, 1.0), vec3_new(-1.0, 0.0, 1.0),
|
||||||
|
vec3_new(1.0, 0.0, -1.0), vec3_new(-1.0, 0.0, -1.0)
|
||||||
|
};
|
||||||
|
for(int i = 0; i < 4; i += 1) {
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(0.5 * legs[i].x, -1.2, 1.4 * legs[i].z);
|
||||||
|
glScalef(0.4, 1.2, 0.4);
|
||||||
|
glutSolidSphere(1.0, 8, 8);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
// now a tail
|
||||||
|
glPushMatrix(); // tail
|
||||||
|
glTranslatef(0.0, 0.0, -2.2); // connection point to the cow
|
||||||
|
glRotatef(tailRot.y, 0.0 ,1.0, 0.0);
|
||||||
|
glRotatef(tailRot.x, 1.0, 0.0, 0.0);
|
||||||
|
glTranslatef(0.0, -0.83, 0.0);
|
||||||
|
glScalef(0.2, 1.0, 0.2);
|
||||||
|
glutSolidSphere(1.0, 8, 8);
|
||||||
|
glPopMatrix(); // Tails(from sonic the hedgehog)
|
||||||
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);
|
||||||
|
@ -105,6 +174,10 @@ void onCowKeyboardInput(char key) {
|
||||||
break;
|
break;
|
||||||
case COW_CONTROL_HEAD:
|
case COW_CONTROL_HEAD:
|
||||||
cowHead(key);
|
cowHead(key);
|
||||||
|
break;
|
||||||
|
case COW_CONTROL_TAIL:
|
||||||
|
cowTail(key);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
4
mmn_17.c
4
mmn_17.c
|
@ -271,8 +271,8 @@ void mouseMotionEvent(int x, int y) {
|
||||||
moveY.y = 0;
|
moveY.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
camCenter = vec3_add(camCenter, vec3_mult(moveX, (lastMouseX - x)));
|
camCenter = vec3_add(camCenter, vec3_mult(moveX, (lastMouseX - x) * 0.5));
|
||||||
camCenter = vec3_add(camCenter, vec3_mult(moveY, (y - lastMouseY)));
|
camCenter = vec3_add(camCenter, vec3_mult(moveY, (y - lastMouseY) * 0.5));
|
||||||
}
|
}
|
||||||
lastMouseX = x; lastMouseY = y;
|
lastMouseX = x; lastMouseY = y;
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
|
Loading…
Reference in a new issue