GOT A README(ohhyeee)
This commit is contained in:
parent
85c9bb4eb8
commit
1a9b74f263
2 changed files with 85 additions and 18 deletions
33
README.md
Normal file
33
README.md
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# World of Cow - University assignment
|
||||||
|
|
||||||
|
This is the last assignment of the computer graphics course i took...
|
||||||
|
|
||||||
|
Code here is published under the [AGPL-v3](https://www.gnu.org/licenses/agpl-3.0.html)
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
[ ] Create a cow
|
||||||
|
[ ] Head
|
||||||
|
[ ] Tail
|
||||||
|
[ ] Body
|
||||||
|
[ ] Legs
|
||||||
|
[ ] Ears
|
||||||
|
[ ] Nose
|
||||||
|
[ ] Eyes
|
||||||
|
[ ] Allow user control of the cow
|
||||||
|
[ ] Movement - turn and move
|
||||||
|
[ ] Head
|
||||||
|
[ ] Tail
|
||||||
|
[ ] Legs? (optional)
|
||||||
|
[ ] Change camera position to be cow point of view
|
||||||
|
[ ] Add popping-floating text of funny cow thoughts
|
||||||
|
[ ] Add menu
|
||||||
|
[ ] Adjust ambient light
|
||||||
|
[ ] help
|
||||||
|
[ ] quit
|
||||||
|
[ ] Add multiple objects(that is not the cow)
|
||||||
|
[ ] User controlled light source
|
||||||
|
[ ] Add light source
|
||||||
|
[ ] move the light
|
||||||
|
[ ] change intensity
|
||||||
|
[ ] Add Textures and stuff :)
|
70
mmn_17.c
70
mmn_17.c
|
@ -15,6 +15,12 @@
|
||||||
float camRadius = 10.0;
|
float camRadius = 10.0;
|
||||||
vec3 camCenter = { 0.0, 0.0, 0.0 };
|
vec3 camCenter = { 0.0, 0.0, 0.0 };
|
||||||
vec3 camRot = { -PI * 0.125, 0.0, 0.0 };
|
vec3 camRot = { -PI * 0.125, 0.0, 0.0 };
|
||||||
|
struct {
|
||||||
|
unsigned char lockYMovement: 1;
|
||||||
|
GLenum textureFilter;
|
||||||
|
} settings = {
|
||||||
|
0, GL_NEAREST,
|
||||||
|
};
|
||||||
|
|
||||||
vec3 rotateByCameraRotation(vec3 v) {
|
vec3 rotateByCameraRotation(vec3 v) {
|
||||||
vec3 r;
|
vec3 r;
|
||||||
|
@ -32,32 +38,46 @@ vec3 rotateByCameraRotation(vec3 v) {
|
||||||
int lastMouseButton = GLUT_LEFT_BUTTON;
|
int lastMouseButton = GLUT_LEFT_BUTTON;
|
||||||
int lastMouseX = 0, lastMouseY = 0;
|
int lastMouseX = 0, lastMouseY = 0;
|
||||||
ui_slider* draggedSlider = NULL;
|
ui_slider* draggedSlider = NULL;
|
||||||
void testButtonClick();
|
void changeFilterButton();
|
||||||
|
void lockYButton();
|
||||||
ui_button buttons[] = {
|
ui_button buttons[] = {
|
||||||
{
|
{
|
||||||
/* pos */ { { 0.9, 0.5, 0.0 }, { -65.0, -20.0, 0.0 } },
|
/* pos */ { { 0.9, 0.5, 0.0 }, { -65.0, -20.0, 0.0 } },
|
||||||
/* size */ { 130.0, 40.0, 0.0 },
|
/* size */ { 130.0, 40.0, 0.0 },
|
||||||
/* onclick */ testButtonClick,
|
/* onclick */ changeFilterButton,
|
||||||
/* text */ "Focus center",
|
/* text */ "Cycle filter",
|
||||||
0
|
0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ { 0.9, 0.5, 0.0 }, { -50.0, 25.0, 0.0 } },
|
||||||
|
{ 100.0, 40.0, 0.0 },
|
||||||
|
lockYButton,
|
||||||
|
"Lock Y"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ui_slider sliders[] = {
|
ui_slider sliders[] = {
|
||||||
{
|
{
|
||||||
/* pos */ { { 0.9, 0.7, 0.0 }, {-50.0, -5.0, 0.0 } },
|
/* pos */ { { 0.9, 0.7, 0.0 }, { -50.0, -5.0, 0.0 } },
|
||||||
/* size */ { 100.0, 10.0, 10.0 },
|
/* size */ { 100.0, 10.0, 10.0 },
|
||||||
0.1
|
0.1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void testButtonClick() {
|
void changeFilterButton() {
|
||||||
printf("Focusing center!\n");
|
static int current = 0;
|
||||||
camCenter = vec3_new(0.0, 1.0, 0.0);
|
GLenum filters[] = { GL_NEAREST, GL_LINEAR };
|
||||||
|
current = (current + 1) % (sizeof(filters) / sizeof(GLenum));
|
||||||
|
settings.textureFilter = filters[current];
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
void lockYButton() {
|
||||||
|
settings.lockYMovement ^= 1;
|
||||||
|
buttons[1].text = settings.lockYMovement ? "Unlock Y" : "Lock Y";
|
||||||
|
}
|
||||||
|
|
||||||
void drawUi(void) {
|
void drawUi(void) {
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
@ -83,6 +103,8 @@ void drawUi(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawWorld(void) {
|
void drawWorld(void) {
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
// set perspective camera
|
// set perspective camera
|
||||||
GLdouble wWidth = (GLdouble) glutGet(GLUT_WINDOW_WIDTH);
|
GLdouble wWidth = (GLdouble) glutGet(GLUT_WINDOW_WIDTH);
|
||||||
GLdouble wHeight = (GLdouble) glutGet(GLUT_WINDOW_HEIGHT);
|
GLdouble wHeight = (GLdouble) glutGet(GLUT_WINDOW_HEIGHT);
|
||||||
|
@ -106,25 +128,34 @@ void drawWorld(void) {
|
||||||
glLightfv(GL_LIGHT0, GL_POSITION, light1);
|
glLightfv(GL_LIGHT0, GL_POSITION, light1);
|
||||||
// World
|
// World
|
||||||
// Ground
|
// Ground
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, settings.textureFilter);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, settings.textureFilter);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, grass_color_128);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, grass_color_128);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor3f(1.0, 1.0, 0.0);
|
glColor3f(1.0, 1.0, 0.0);
|
||||||
glNormal3f(0.0, 5.0, 0.0);
|
glNormal3f(0.0, 5.0, 0.0);
|
||||||
glTexCoord2f(0.0, 0.0); glVertex3f(-50.0, 0.0, -50.0);
|
glTexCoord2f(0.0, 0.0); glVertex3f(-50.0, 0.0, -50.0);
|
||||||
glTexCoord2f(5.0, 0.0); glVertex3f(50.0, 0.0, -50.0);
|
glTexCoord2f(0.0, 1.0); glVertex3f(-50.0, 0.0, 50.0);
|
||||||
glTexCoord2f(5.0, 5.0); glVertex3f(50.0, 0.0, 50.0);
|
glTexCoord2f(1.0, 1.0); glVertex3f(50.0, 0.0, 50.0);
|
||||||
glTexCoord2f(0.0, 5.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);
|
||||||
|
|
||||||
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(0.0, 5.0, 0.0);
|
||||||
|
glScalef(3.0, 3.0, 3.0);
|
||||||
|
glColor3f(1.0, 1.0, 1.0);
|
||||||
|
glutSolidDodecahedron();
|
||||||
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void display(void) {
|
void display(void) {
|
||||||
// Clear screen
|
// Clear screen
|
||||||
glClearColor(0.0, 0.0, 0.0, 1.0); // Dark theme :)
|
glClearColor(0.0, 0.0, 0.0, 1.0); // Dark theme :)
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
drawWorld();
|
drawWorld();
|
||||||
drawUi();
|
drawUi();
|
||||||
|
@ -172,11 +203,14 @@ void mouseMotionEvent(int x, int y) {
|
||||||
else if(lastMouseButton == GLUT_MIDDLE_BUTTON) {
|
else if(lastMouseButton == GLUT_MIDDLE_BUTTON) {
|
||||||
vec3 moveX = rotateByCameraRotation(vec3_new(1.0, 0.0, 0.0));
|
vec3 moveX = rotateByCameraRotation(vec3_new(1.0, 0.0, 0.0));
|
||||||
vec3 moveY = rotateByCameraRotation(vec3_new(0.0, 1.0, 0.0));
|
vec3 moveY = rotateByCameraRotation(vec3_new(0.0, 1.0, 0.0));
|
||||||
printf("moveY: %f %f %f\t", moveY.x, moveY.y, moveY.z);
|
|
||||||
|
if(settings.lockYMovement) {
|
||||||
|
moveX.y = 0;
|
||||||
|
moveY.y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
camCenter = vec3_add(camCenter, vec3_mult(moveX, (lastMouseX - x)));
|
camCenter = vec3_add(camCenter, vec3_mult(moveX, (lastMouseX - x)));
|
||||||
camCenter = vec3_add(camCenter, vec3_mult(moveY, (y - lastMouseY)));
|
camCenter = vec3_add(camCenter, vec3_mult(moveY, (y - lastMouseY)));
|
||||||
printf("new cam center %f %f %f\n", camCenter.x, camCenter.y, camCenter.z);
|
|
||||||
}
|
}
|
||||||
else if(lastMouseButton == GLUT_RIGHT_BUTTON) {
|
else if(lastMouseButton == GLUT_RIGHT_BUTTON) {
|
||||||
// rotate the camera
|
// rotate the camera
|
||||||
|
@ -185,7 +219,6 @@ void mouseMotionEvent(int x, int y) {
|
||||||
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) * 0.01 * PI));
|
camRot.x = fmin(PI * 0.5, fmax(-PI * 0.5, camRot.x - (y - lastMouseY) * 0.01 * PI));
|
||||||
printf("rotation x: %f\n", camRot.x);
|
|
||||||
}
|
}
|
||||||
lastMouseX = x; lastMouseY = y;
|
lastMouseX = x; lastMouseY = y;
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
|
@ -198,7 +231,6 @@ void mouseWheelEvent(int wheel, int dir, int x, int y) {
|
||||||
s->value += dir * 0.05;
|
s->value += dir * 0.05;
|
||||||
if(s->value < 0.0) s->value = 0.0;
|
if(s->value < 0.0) s->value = 0.0;
|
||||||
if(s->value > 1.0) s->value = 1.0;
|
if(s->value > 1.0) s->value = 1.0;
|
||||||
printf("Updated %p value to %f\n", s, s->value);
|
|
||||||
slided = 1;
|
slided = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,10 +251,9 @@ void keyboardEvent(unsigned char c, int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
printf("size of texture: %lu\n", sizeof(grass_color_128) / (sizeof(unsigned char) * 4));
|
|
||||||
/* initialize glut and window */
|
/* initialize glut and window */
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
|
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
|
||||||
glutInitWindowSize(800, 500);
|
glutInitWindowSize(800, 500);
|
||||||
glutInitWindowPosition(450, 450);
|
glutInitWindowPosition(450, 450);
|
||||||
/* create window and set callbacks */
|
/* create window and set callbacks */
|
||||||
|
@ -232,6 +263,9 @@ int main(int argc, char** argv) {
|
||||||
glutKeyboardFunc(keyboardEvent);
|
glutKeyboardFunc(keyboardEvent);
|
||||||
glutMouseWheelFunc(mouseWheelEvent);
|
glutMouseWheelFunc(mouseWheelEvent);
|
||||||
glutMotionFunc(mouseMotionEvent);
|
glutMotionFunc(mouseMotionEvent);
|
||||||
|
// set up some rendering related stuff
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue