Graphics Transformation kucg korea ac kr Graphics Lab
Graphics Transformation 고려대학교 컴퓨터 그래픽스 연구실 kucg. korea. ac. kr Graphics Lab @ Korea University
Contents n KUCG Affine transformation Translation n Rotation n Scaling n Setting matrix directly n n Hierarchical modeling kucg. korea. ac. kr Graphics Lab @ Korea University
Open. GL Transformation Matrices n KUCG Matrix modes n model-view and projection matrices vertices model-view projection vertices CTM (Current Transformation Matrix) n Three functions: translation, rotation, scaling gl. Translatef(dx, dy, dz); gl. Rotatef(angle, vx, vy, vz); gl. Scalef(sx, sy, sz); kucg. korea. ac. kr Graphics Lab @ Korea University
Translation (1/5) n KUCG Add a displacement to every vertex on the object void gl. Translate{fd} (TYPE dx, TYPE dy, TYPE dz) object centered at origin kucg. korea. ac. kr object moved away from the camera Graphics Lab @ Korea University
Translation (2/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Translation (3/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Translation (4/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Translation (5/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
gl. Push. Matrix, gl. Pop. Matrix (1/2) n KUCG gl. Push. Matrix( ), gl. Pop. Matrix( ) n perform a transformation and then return to the same state as before its execution o ex) instance transformation gl. Push. Matrix(); gl. Translatef(. . . ); gl. Rotatef(. . . ); gl. Scalef(. . . ); /* draw object here */ gl. Pop. Matrix(); kucg. korea. ac. kr Graphics Lab @ Korea University
gl. Push. Matrix, gl. Pop. Matrix (2/2) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Rotation n KUCG Rotate in counterclockwise direction about the given axis with fixed point of the origin void gl. Rotate{fd} (TYPE angle, TYPE ax, TYPE ay, TYPE az) gl. Matrix. Mode(GL_MODELVIEW); gl. Load. Identity(); gl. Translatef(xf, yf, zf); gl. Rotatef(angle, ax, ay, az); gl. Translatef(-xf, -yf, -zf) general rotation kucg. korea. ac. kr Graphics Lab @ Korea University
Scaling n KUCG Make an object bigger or smaller with scale factors and fixed point of the origin void gl. Scale{fd} (TYPE sx, TYPE sy, TYPE sz) scaling with nonuniform scale factors kucg. korea. ac. kr Graphics Lab @ Korea University
Setting Matrices Directly (1/5) n KUCG Construct a matrix directly or use it not a transformation function void gl. Load. Matrix{fd} (TYPE *m) void gl. Mult. Matrix{fd} (TYPE *m) n matrix: 16 -element one-dimensional arrays in column order rather than 4 x 4 two-dimensional arrays kucg. korea. ac. kr Graphics Lab @ Korea University
Setting Matrices Directly (2/5) n KUCG Example: Shearing shearing a cube kucg. korea. ac. kr Graphics Lab @ Korea University
Setting Matrices Directly (3/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Setting Matrices Directly (4/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Setting Matrices Directly (5/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Hierarchical Model (1/2) n KUCG Parts of a model depend on one another n One part move, it cause other parts to move a simple robot arm kucg. korea. ac. kr hierarchical representation Graphics Lab @ Korea University
Hierarchical Model (2/2) n KUCG Figure constructed from GLU spheres and cylinders hierarchical representation kucg. korea. ac. kr Graphics Lab @ Korea University
Modeling of H. M. (1/7) n KUCG Example: simple robot arm base lower arm upper arm glu. Cylinder(GLUqadric. Obj *q, GLdouble base_radius, glut. Solid. Cube(GLdouble size) GLdouble top_radius, glut. Wire. Cube(GLdouble size) GLdouble height, GLint slices, Glint stacks) kucg. korea. ac. kr Graphics Lab @ Korea University
Modeling of H. M. (2/7) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Modeling of H. M. (3/7) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Modeling of H. M. (4/7) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Modeling of H. M. (5/7) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Modeling of H. M. (6/7) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Modeling of H. M. (7/7) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Exercise 1 – Translations kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
Transformation of H. M. n KUCG Example: simple robot arm base kucg. korea. ac. kr lower arm upper arm Graphics Lab @ Korea University
Exercise 2 – Rotations (1/2) n KUCG Rotate each part if the following keys are pressed: n n n ‘left arrow’ – clockwise rotation of the base ‘right arrow’ – counterclockwise rotation of the base ‘up arrow’ – counterclockwise rotation of the lower arm ‘down arrow’ – clockwise rotation of the lower arm ‘home’ – counterclockwise rotation of the upper arm ‘end’ – clockwise rotation of the upper arm kucg. korea. ac. kr Graphics Lab @ Korea University
Exercise 2 – Rotations (2/2) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
- Slides: 30