Sunday, February 10, 2008
Computer Graphic assignment 2(FINAL)
Wednesday, December 26, 2007
Computer Graphic Assignment 2
This is the 'space' that I am going to draw out using openGL. This JPEC picture is supposed to be wrapped around a cube, thus it is not how it suppose to look like.
I am planning to model a chair(which will replace the 2 chairs outside the balcony), the bed as well as a hi-fi set table.
The following chair is used to replace the chair at the balcony as I could not see it properly:
Thursday, December 13, 2007
Computer Graphic Assignment 1
'1' - Move Forward
'2' - Move backward
'3' - Shoot bullet and move forward
'4' - Rotate the camera view to right
'5' - Rotate the camera view to left
'6' - Move the cannon upwards
'7' - Move the cannon downwards
Monday, December 3, 2007
Computer Graphic Practical 6
Thursday, November 15, 2007
Computer Graphic Practical 5
How did it arrive with the transformed coordinates?
Answer:
(2 3 1 1) is the transformation and it is alined vertically at the right side of the vertex.
First column:
(4 0 0 2) = (X 0 0 2)
Second column:
(0 4 0 3) = (0 Y 0 3)
Third column:
(0 0 4 1) = (0 0 Z 1)
glBegin();
glVertex3f(0,0,0); ----> [(0 * 4 + 2), (0 * 4 + 3), (0 * 4 + 1) ] ----> (2, 3, 1)
glVertex3f(0,1,0); ----> [(0 * 4 + 2), (1 * 4 + 3), (0 * 4 + 1) ] ----> (2, 7, 1)
glVertex3f(1,1,0); ----> [(1 * 4 + 2), (1 * 4 + 3), (0 * 4 + 1) ] ----> (6, 7, 1)
glVertex3f(1,0,0); ----> [(1 * 4 + 2), (0 * 4 + 3), (0 * 4 + 1) ] ----> (6, 3, 1)
glEnd();
Question 2 -
What is/are the transformation(s) applied?
Answer:
Translation and scaling.
Question 3 -
OpenGL keeps track of only 1 matrix for transformation.
It will be tedious to do transformation for more than 1 mesh/
polygon/objects to different locations.
Why?
Answer:
When having more than 1 transformation, the previous transformation matrix will be overwritten by the others as OpenGL will run the transformation one at a time.
Question 4 -
(a) What is the current operation matrix after this function?
Answer:
Translation and Scaling.
(5 0 0 10)
(0 5 0 2 )
(0 0 5 4 )
(0 0 0 1 )
(b) What is the current operation matrix after this function?
Answer:
Rotation.
(5 0 0 10) * (0 0 5 1) (0 0 5 10)
(0 5 0 2 ) * (0 5 0 1 ) = (0 5 0 2)
(0 0 5 4 ) * (5 0 0 1) (-5 0 0 4)
(0 0 0 1 ) * (0 0 0 1) (0 0 0 1)
(c) What is the current operation matrix after this function?
Answer:
translation.
(0 0 5 10) (0 0 0 2) (0 0 5 12)
(0 5 0 2) + (0 0 0 2) = (0 5 0 4)
(-5 0 0 4) (0 0 0 2) (-5 0 0 6)
(0 0 0 1) (0 0 0 1) (0 0 0 1)
(d) What is the current operation matrix after this function?
Answer:
scaling of (2, 1, 1)
(0 0 5 10) (2 0 0 1) (0 0 5 10)
(0 5 0 2) * (0 1 0 1) = (0 5 0 2)
(-5 0 0 4) (0 0 1 1) (-5 0 0 4)
(0 0 0 1) (0 0 0 1) (0 0 0 1)
(e) What is the current operation matrix after this function?
Answer:
(1 0 0 0) (0 0 0 0) (1 0 0 0)
(0 1 0 0) + (0 0 0 5) = (0 1 0 5)
(0 0 1 0) (0 0 0 0) (0 0 1 0)
(0 0 0 1) (0 0 0 1) (0 0 0 1)
(f) What is the current operation matrix after this function?
Answer:
(0 0 5 12)
(0 5 0 4 ) * =
(-5 0 0 6)
(0 0 0 1)
(0,0,0)?
glTranslatef(-5,0,0) is applied, it goes back to (0, 0, 0).
glPushMatrix();
glTranslatef(5,0,0);
DrawCube();
glPopMatrix();
glTranslatef(-5,0,0);
DrawCube();
#include "glut.h"
void DrawCube()
{
glColor3ub(255,0,0); // red, back-side
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, -2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(-2.0f, 2.0f, -2.0);
glEnd();
glColor3ub(0,255,255); // green, back
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(-2.0f, 2.0f, 2.0);
glEnd();
glColor3ub(0,100,100); // dark-green, top
glBegin(GL_POLYGON);
glVertex3f(-2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(-2.0f, 2.0f, -2.0);
glEnd();
glColor3ub(255,255,0); // yellow, bottom
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(-2.0f, -2.0f, -2.0);
glEnd();
glColor3ub(0,0,255); // blue, front
glBegin(GL_POLYGON);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glEnd();
glColor3ub(255, 100, 0); //orange, front-side
glBegin(GL_POLYGON);
glVertex3f(-2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(-2.0f, -2.0f, 2.0);
glEnd();
}
void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
glColor3ub(255,255,255);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 100.0);
glVertex3f(0.0f, 0.0f, -10.0);
glVertex3f(100.0f, 0.0f, 0.0);
glVertex3f(-10.0f, 0.0f, 0.0);
glVertex3f(0.0f, 100.0f, 0.0);
glVertex3f(0.0f, -10.0f, 0.0);
glEnd();
glPushMatrix();
glTranslatef(5,0,0);
DrawCube();
glPopMatrix();
glTranslatef(-5,0,0);
DrawCube();
glutSwapBuffers();
}
void Rescale(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
}
void SetupRC()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-64, 64, -48, 48, 1, 100);
gluLookAt(30.0, 30.0, 30.0, 0, 1.0, 0.0, 0.0, 1.0, 0.0);
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My Practical 5");
glutDisplayFunc(MyDisplay);
glutReshapeFunc(Rescale);
SetupRC();
glutMainLoop();
}
Exercise 5
1) Yes.
2) Yes.
3) Yes.
Exercise 6
I am still unable to move the cubes, but I still looking into it.
#include "glut.h"
void DrawCube()
{
glColor3ub(255,0,0); // red, back-side
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, -2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(-2.0f, 2.0f, -2.0);
glEnd();
glColor3ub(0,255,255); // green, back
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(-2.0f, 2.0f, 2.0);
glEnd();
glColor3ub(0,100,100); // dark-green, top
glBegin(GL_POLYGON);
glVertex3f(-2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(-2.0f, 2.0f, -2.0);
glEnd();
glColor3ub(255,255,0); // yellow, bottom
glBegin(GL_POLYGON);
glVertex3f(-2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(-2.0f, -2.0f, -2.0);
glEnd();
glColor3ub(0,0,255); // blue, front
glBegin(GL_POLYGON);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, -2.0);
glVertex3f(2.0f, -2.0f, -2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glEnd();
glColor3ub(255, 100, 0); //orange, front-side
glBegin(GL_POLYGON);
glVertex3f(-2.0f, 2.0f, 2.0);
glVertex3f(2.0f, 2.0f, 2.0);
glVertex3f(2.0f, -2.0f, 2.0);
glVertex3f(-2.0f, -2.0f, 2.0);
glEnd();
}
void MyDisplay()
{
glClear(GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT);
glColor3ub(255,255,255);
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 100.0);
glVertex3f(0.0f, 0.0f, -10.0);
glVertex3f(100.0f, 0.0f, 0.0);
glVertex3f(-10.0f, 0.0f, 0.0);
glVertex3f(0.0f, 100.0f, 0.0);
glVertex3f(0.0f, -10.0f, 0.0);
glEnd();
glPushMatrix();
glTranslatef(5,0,0);
DrawCube();
glPopMatrix();
glTranslatef(-5,0,0);
DrawCube();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'w':
y++;
break;
case 's':
y--;
break;
case 'a':
x--;
break;
case 'd':
x--;
break;
}
}
void Rescale(GLsizei w, GLsizei h)
{
glViewport(0, 0, w, h);
}
void SetupRC()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-64, 64, -48, 48, 1, 100);
gluLookAt(30.0, 30.0, 30.0, 0, 1.0, 0.0, 0.0, 1.0, 0.0);
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE GLUT_RGB GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My Practical 5");
glutDisplayFunc(MyDisplay);
glutReshapeFunc(Rescale);
glutKeyboardFunc(keyboard);
SetupRC();
glutMainLoop();
}