Compare commits
No commits in common. "60024859bfe439f55a9cd3016b1a0a07f5f26578" and "eac3583e8adde7103000eb9a40b4f0289acdba43" have entirely different histories.
60024859bf
...
eac3583e8a
3 changed files with 53 additions and 119 deletions
|
@ -6,9 +6,14 @@ Code here is published under the [AGPL-v3](https://www.gnu.org/licenses/agpl-3.0
|
||||||
|
|
||||||
# TODO
|
# 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
|
||||||
- User controlled light source
|
- User controlled light source
|
||||||
- Add light source
|
- Add light source
|
||||||
- move the light
|
- move the light
|
||||||
- change intensity
|
- change intensity
|
||||||
- Add popping-floating text of funny cow thoughts when in cow view
|
|
||||||
- Add Textures and stuff :)(optional)
|
- Add Textures and stuff :)(optional)
|
2
cow.c
2
cow.c
|
@ -11,7 +11,7 @@ const vec3 headLimit = { 30.0, 30.0, 45.0 };
|
||||||
vec3 tailRot = { 0.0, 0.0, 0.0 };
|
vec3 tailRot = { 0.0, 0.0, 0.0 };
|
||||||
const vec3 tailLimit = { 90.0, 90.0, 0.0 };
|
const vec3 tailLimit = { 90.0, 90.0, 0.0 };
|
||||||
|
|
||||||
vec3 cowPos = { 0.0, 4.9, 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
|
||||||
const float COW_ROT_SPEED = 5.0;
|
const float COW_ROT_SPEED = 5.0;
|
||||||
const float COW_MOVE_SPEED = 1.0;
|
const float COW_MOVE_SPEED = 1.0;
|
||||||
|
|
163
mmn_17.c
163
mmn_17.c
|
@ -31,10 +31,44 @@ struct {
|
||||||
int cowControl;
|
int cowControl;
|
||||||
int filters;
|
int filters;
|
||||||
} menus; // to simply hold the menues in a labed manner
|
} menus; // to simply hold the menues in a labed manner
|
||||||
|
GLuint grassList = -1;
|
||||||
|
|
||||||
struct {
|
|
||||||
GLuint grass;
|
void generateGrassVertexList() {
|
||||||
} lists;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
// Ui stuff
|
// Ui stuff
|
||||||
int lastMouseButton = GLUT_LEFT_BUTTON;
|
int lastMouseButton = GLUT_LEFT_BUTTON;
|
||||||
|
@ -56,90 +90,10 @@ ui_slider sliders[] = {
|
||||||
/* pos */ { { 0.9, 0.9, 0.0 }, { -50.0, -70.0, 0.0 } },
|
/* pos */ { { 0.9, 0.9, 0.0 }, { -50.0, -70.0, 0.0 } },
|
||||||
/* size */ { 100.0, 10.0, 10.0 },
|
/* size */ { 100.0, 10.0, 10.0 },
|
||||||
0.3
|
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) {
|
void drawUi(void) {
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
@ -167,12 +121,6 @@ void drawUi(void) {
|
||||||
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, t);
|
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, t);
|
||||||
glRasterPos2f(wWidth * 0.9 - 75.0, wHeight * 0.9 - 10.0);
|
glRasterPos2f(wWidth * 0.9 - 75.0, wHeight * 0.9 - 10.0);
|
||||||
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, (unsigned char*)"r\ng\nb");
|
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) {
|
if(settings.showHelp) {
|
||||||
glColor3f(0.3, 0.3, 0.3);
|
glColor3f(0.3, 0.3, 0.3);
|
||||||
|
@ -217,7 +165,6 @@ void drawWorld(void) {
|
||||||
gluPerspective(90, wWidth / wHeight , 0.5, 500.0);
|
gluPerspective(90, wWidth / wHeight , 0.5, 500.0);
|
||||||
// Lights
|
// Lights
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
|
|
||||||
// Ambient light
|
// Ambient light
|
||||||
GLfloat ambient[] = { sliders[0].value, sliders[1].value, sliders[2].value, 1.0 };
|
GLfloat ambient[] = { sliders[0].value, sliders[1].value, sliders[2].value, 1.0 };
|
||||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
|
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
|
||||||
|
@ -245,32 +192,15 @@ void drawWorld(void) {
|
||||||
glTexCoord2f(1.0, 0.0); glVertex3f(50.0, 0.0, -50.0);
|
glTexCoord2f(1.0, 0.0); glVertex3f(50.0, 0.0, -50.0);
|
||||||
glEnd();
|
glEnd();
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glPushMatrix();
|
// Add a simple cube to see where the cow was originally facing
|
||||||
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();
|
glPushMatrix();
|
||||||
glTranslatef(0.0, 10.0, 50.0);
|
glTranslatef(0.0, 10.0, 50.0);
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
glEnable(GL_COLOR_MATERIAL);
|
||||||
glColor3f(0.05, 0.05, 0.1);
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
GLfloat mat[] = { 0.25, 0.25, 0.25, 0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6 };
|
|
||||||
glMaterialf(GL_FRONT, GL_SHININESS, mat[9] * 128.0);
|
|
||||||
glMaterialfv(GL_FRONT, GL_AMBIENT, mat);
|
|
||||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat + 3);
|
|
||||||
glMaterialfv(GL_FRONT, GL_SPECULAR, mat + 6);
|
|
||||||
glutSolidCube(20.0);
|
glutSolidCube(20.0);
|
||||||
GLfloat matReset[] = {0.0, 0.0, 0.0};
|
|
||||||
glMaterialf(GL_FRONT, GL_SHININESS, 0.0);
|
|
||||||
glMaterialfv(GL_FRONT, GL_AMBIENT, matReset);
|
|
||||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, matReset);
|
|
||||||
glMaterialfv(GL_FRONT, GL_SPECULAR, matReset);
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glColor3f(0.1, 0.3, 0.0);
|
glColor3f(0.1, 0.3, 0.0);
|
||||||
glCallList(lists.grass);
|
glCallList(grassList);
|
||||||
glColor3f(1.0, 1.0, 1.0);
|
|
||||||
glDisable(GL_COLOR_MATERIAL);
|
glDisable(GL_COLOR_MATERIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,12 +254,11 @@ void mouseMotionEvent(int x, int y) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// rotate the camera
|
// rotate the camera
|
||||||
float speed = sliders[4].value * 0.095 + 0.005;
|
camRot.y -= (x - lastMouseX) * PI * 0.01;
|
||||||
camRot.y -= (x - lastMouseX) * speed;
|
|
||||||
if(camRot.y > 2 * PI) camRot.y -= 2 * PI;
|
if(camRot.y > 2 * PI) camRot.y -= 2 * PI;
|
||||||
else if(camRot.y < 0.0) 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) * speed));
|
camRot.x = fmin(PI * 0.5, fmax(-PI * 0.5, camRot.x - (y - lastMouseY) * 0.01 * PI));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -341,9 +270,9 @@ void mouseMotionEvent(int x, int y) {
|
||||||
moveX.y = 0;
|
moveX.y = 0;
|
||||||
moveY.y = 0;
|
moveY.y = 0;
|
||||||
}
|
}
|
||||||
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(moveX, (lastMouseX - x) * 0.5));
|
||||||
camCenter = vec3_add(camCenter, vec3_mult(moveY, (y - lastMouseY) * speed));
|
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