Graphics View Volume http kucg korea ac kr















![VECTOR Class KUCG void VECTOR: : Normalize() { float magnitude = sqrt(dir[0]*dir[0] + dir[1]*dir[1] VECTOR Class KUCG void VECTOR: : Normalize() { float magnitude = sqrt(dir[0]*dir[0] + dir[1]*dir[1]](https://slidetodoc.com/presentation_image/eb24c99c54d7944eb4c8b2415b715188/image-16.jpg)
![VECTOR Class KUCG float VECTOR: : Inner. Product(VECTOR v) { float result = dir[0] VECTOR Class KUCG float VECTOR: : Inner. Product(VECTOR v) { float result = dir[0]](https://slidetodoc.com/presentation_image/eb24c99c54d7944eb4c8b2415b715188/image-17.jpg)








![Rotation KUCG VERTEX input, output; MATRIX rot. Matrix; input. pos[0] = 3. 0; input. Rotation KUCG VERTEX input, output; MATRIX rot. Matrix; input. pos[0] = 3. 0; input.](https://slidetodoc.com/presentation_image/eb24c99c54d7944eb4c8b2415b715188/image-26.jpg)



- Slides: 29
Graphics View Volume 고려대학교 컴퓨터 그래픽스 연구실 http: //kucg. korea. ac. kr Graphics Lab @ Korea University
View Volume KUCG Projection window n Determine how much of the scene is caught n <Window Specification on the View Plane> http: //kucg. korea. ac. kr Graphics Lab @ Korea University
View Volume for a Perspective Projection KUCG <Perspective-projection View Volume for Various Positions of the Projection Reference Point> http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Finite View Volume n Obtained by limiting the extent in zv n With a perspective projection n KUCG The front (near) and back (far) clipping planes o o znear, zfar Truncate the infinite pyramidal view volume o View Frustum o Parallel to the view plane o On the same side of the projection reference point http: //kucg. korea. ac. kr Graphics Lab @ Korea University
View Volumes Bounded by Six Planes http: //kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Orthographic View Volume n KUCG (left, right, bottom, top, near, far) http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Specification of a Frustum (1/2) n KUCG (left, right, bottom, top, near, far) http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Specification of a Frustum (2/2) n KUCG (fovy, aspect, near, far) http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Graphics Basic Implementation http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Basic Classes n n n KUCG VERTEX POLYGON TRIANGLE VECTOR MATRIX http: //kucg. korea. ac. kr Graphics Lab @ Korea University
VERTEX Class class VERTEX { public: float unsigned char VECTOR }; http: //kucg. korea. ac. kr KUCG pos[4]; rgb[3]; norm; Graphics Lab @ Korea University
POLYGON Class class POLYGON { public: int unsigned char VECTOR }; http: //kucg. korea. ac. kr KUCG v. Num; *index; rgb[3]; norm; Graphics Lab @ Korea University
TRIANGLE Class class TRIANGLE { public: int unsigned char VECTOR }; http: //kucg. korea. ac. kr KUCG index[3]; rgb[3]; norm; Graphics Lab @ Korea University
VECTOR Class class VECTOR { public: VECTOR float void VECTOR float KUCG Add(VECTOR v); Cross. Product(VECTOR v); Inner. Product(VECTOR v); Normalize(); Subtract(VECTOR v); dir[3]; }; http: //kucg. korea. ac. kr Graphics Lab @ Korea University
VECTOR Class KUCG VECTOR: : Add(VECTOR v) { VECTOR result; for(int i = 0; i < 3; i++) result. dir[i] = dir[i] + v. dir[i]; return result; } VECTOR: : Subtract(VECTOR v) { VECTOR result; for(int i = 0; i < 3; i++) result. dir[i] = dir[i] - v. dir[i]; return result; } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
VECTOR Class KUCG void VECTOR: : Normalize() { float magnitude = sqrt(dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2]; for(int i = 0; i < 3; i++) dir[i] /= magnitude; } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
VECTOR Class KUCG float VECTOR: : Inner. Product(VECTOR v) { float result = dir[0] * v. dir[0] + dir[1] * v. dir[1] + dir[2] * v. dir[2]; return result; } VECTOR: : Cross. Product(VECTOR v) { VECTOR result; result. dir[0] = dir[1] * v. dir[2] - dir[2] * v. dir[1]; result. dir[1] = dir[2] * v. dir[0] - dir[0] * v. dir[2]; result. dir[2] = dir[0] * v. dir[1] - dir[1] * v. dir[0]; return result; } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
MATRIX Class class MATRIX { public: MATRIX VERTEX MATRIX MATRIX KUCG Multiply(MATRIX m); Multiply(VERTEX v); Rotation. X(float degree); Rotation. Y(float degree); Rotation. Z(float degree); Scale(float sx, float sy, float sz); Translation(float tx, float ty, float tz); unsigned char float row. Num; col. Num; element[4][4]; }; http: //kucg. korea. ac. kr Graphics Lab @ Korea University
MATRIX Class KUCG MATRIX: : Multiply(MATRIX m) { MATRIX result; for(int i = 0; i < row. Num; i++) for(int j = 0; j < col. Num; j++) result. element[i][j] = 0. 0; if(col. Num == m. row. Num) { result. row. Num = row. Num; result. col. Num = m. col. Num; for(i = 0; i < row. Num; i++) for(int j = 0; j < m. col. Num; j++) for(int k =0; k < col. Num; k++) result. element[i][j] += element[i][k] * m. element[k][j]; } return result; } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
MATRIX Class KUCG VERTEX MATRIX: : Multiply(VERTEX v) { VERTEX result; for(int i = 0; i < 4; i++) result. pos[i] = 0. 0; for(i = 0; i < 4; i++) for(int j = 0; j < 4; j++) result. pos[i] += element[i][j] * v. pos[j]; return result; } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
MATRIX Class KUCG void MATRIX: : Rotation. X(float degree) { float rad = M_PI * degree / 180. 0; for(int i = 0; i < row. Num; i++) for(int j = 0; j < col. Num; j++) element[i][j] = 0. 0; element[0][0] = 1. 0; element[1][1] = cos(rad); element[1][2] = -sin(rad); element[3][3] = 1. 0; element[2][2] = cos(rad); element[2][1] = sin(rad); } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
MATRIX Class KUCG void MATRIX: : Rotation. Y(float degree) { float rad = M_PI * degree / 180. 0; for(int i = 0; i < row. Num; i++) for(int j = 0; j < col. Num; j++) element[i][j] = 0. 0; element[1][1] = 1. 0; element[0][0] = cos(rad); element[0][2] = sin(rad); element[3][3] = 1. 0; element[2][2] = cos(rad); element[2][0] = -sin(rad); } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
MATRIX Class KUCG void MATRIX: : Rotation. Z(float degree) { float rad = M_PI * degree / 180. 0; for(int i = 0; i < row. Num; i++) for(int j = 0; j < col. Num; j++) element[i][j] = 0. 0; element[2][2] = 1. 0; element[0][0] = cos(rad); element[0][1] = -sin(rad); element[3][3] = 1. 0; element[1][1] = cos(rad); element[1][0] = sin(rad); } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
MATRIX Class KUCG void MATRIX: : Scale(float sx, float sy, float sz) { for(int i = 0; i < row. Num; i++) for(int j = 0; j < col. Num; j++) element[i][j] = 0. 0; element[0][0] = sx; element[1][1] = sy; element[2][2] = sz; element[3][3] = 1. 0; } void MATRIX: : Translation(float tx, float ty, float tz) { for(int i = 0; i < row. Num; i++) for(int j = 0; j < col. Num; j++) element[i][j] = 0. 0; for(i = 0; i < 4; i++) element[i][i] = 1. 0; element[0][3] = tx; element[1][3] = ty; element[2][3] = tz; } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Graphics Examples in Practice http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Rotation KUCG VERTEX input, output; MATRIX rot. Matrix; input. pos[0] = 3. 0; input. pos[1] = 1. 0; input. pos[3] = 1. 0; // w coordinate rot. Matrix. Rotation. X(30. 0); output = rot. Matrix. Multiply(input); http: //kucg. korea. ac. kr input. pos[2] = -1. 0; Graphics Lab @ Korea University
Viewing Transformation (1/2) KUCG View reference point (x. Eye, x. Eye y. Eye, y. Eye z. Eye) z. Eye n View direction vector (x. View, x. View y. View, y. View z. View) z. View n View up vector (x. Up, x. Up y. Up, y. Up z. Up) z. Up n MATRIX Viewport. Trans(VECTOR eye, VECTOR view, VECTOR up) { MATRIX trans, rot, result; trans. Translation(-eye. dir[0], -eye. dir[1], -eye. dir[2]); rot = UVN(view, up); result = rot. Multiply(trans); return result; } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Viewing Transformation (2/2) KUCG MATRIX UVN(VECTOR view, VECTOR up) { VECTOR u, v, n; MATRIX result; result. row. Num = 4; result. col. Num = 4; for(int i = 0; i < 3; i++) {result. element[i][3] = 0. 0; result. element[3][i] = 0. 0; } result. element[3][3] = 1. 0; n = view; n. Normalize(); v = up; v. Normalize(); u = v. Cross. Product(n); for(i = 0; i < 3; i++) { result. element[0][i] = u. dir[i]; result. element[1][i] = v. dir[i]; result. element[2][i] = n. dir[i]; } return result; } http: //kucg. korea. ac. kr Graphics Lab @ Korea University
Notice KUCG After the calculation, you must divide by z/D!!!! http: //kucg. korea. ac. kr Graphics Lab @ Korea University