Transformations for Modeling & Animation

14
Transformations for Modeling & Animation Open GL Lab 10 1 BSCS – 514 Computer Graphics Instructor Humera Tariq

description

Transformations for Modeling & Animation. Open GL Lab 10. Lab Objectives /Tasks. Modeling & Animating Gear Wheel Drawing Symmetric Object Making Patterns Square & Hexagonal Tiling Next More on Transformations. 1. Modeling a gearwheel Drawing the axes, title and circle are easy - PowerPoint PPT Presentation

Transcript of Transformations for Modeling & Animation

Page 1: Transformations for Modeling & Animation

Transformationsfor Modeling &

Animation

Open GL Lab 10

1BSCS – 514 Computer Graphics Instructor Humera Tariq

Page 2: Transformations for Modeling & Animation

BSCS – 514 Computer Graphics Instructor Humera Tariq

1. Modeling & Animating Gear Wheel2. Drawing Symmetric Object3. Making Patterns4. Square & Hexagonal Tiling 5. Next More on Transformations

2

Lab Objectives /Tasks

Page 3: Transformations for Modeling & Animation

3

void tooth0() {glBegin( GL_LINE_STRIP);

glVertex2f(0.0, 0.0); glVertex2f(0.2, 0.2);

glVertex2f(0.6, 0.2); glVertex2f(0.6, 0.8);

glVertex2f(0.2, 0.8); glVertex2f(0.0, 1.0);

glEnd();}

1. Modeling a gearwheel Drawing the axes, title and circle

are easy There are 30 teeth. Each is

transformed from a basic tooth

.2

.6

.2

.8

1.

Page 4: Transformations for Modeling & Animation

4

2 r sin6o

6o

To transform the basic tooth to theright tooth on the x axis In both x and y dimensions, scale

down by 2 r sin 6o

Translate the scaled tooth byTx = r cos 6o ,Ty = -r sin 6o

void tooth1( double r) { double rad = 6.0 * 3.1416 / 180.0, sin6 = r * sin( rad), cos6 = r * cos( rad);

glPushMatrix(); glTranslatef( cos6, -sin6, 0.0); glScalef( 2.0*sin6, 2.0*sin6, 1.0); tooth0(); glPopMatrix();

}

(r cos6o, -r sin6o)

Page 5: Transformations for Modeling & Animation

5

To draw the entire set of teeth ofradius r and centered at the origin

void gear( double r){

glPushMatrix(); for (int i=1; i<=30; ++i) { tooth1( r); glRotatef( 12.0, 0.0, 0.0, 1.0); } glPopMatrix();

}

r

Page 6: Transformations for Modeling & Animation

6

//Standard Setup for animation

float speed = 0.0001; static int oldTime = clock(), newTime;

newTime = clock(); deg += (newTime - oldTime) * speed; //printf("%d\n",newTime - oldTime); oldTime = newTime;

glutPostRedisplay();

AnimationAn object will appear moving if we keep redrawing it with minute changes.

void move() {

}

Page 7: Transformations for Modeling & Animation

• It is easy to produce a complex snowflake by designing one half of a spoke, and drawing it 12 times.

7BSCS – 514 Computer Graphics Instructor Humera Tariq

2. Drawing Symmetric Object

Page 8: Transformations for Modeling & Animation

8BSCS – 514 Computer Graphics Instructor Humera Tariq

Snowflake example continued….

• (a) # include “turtle.h”• (b) gluOrtho2D(-10,10,-10,10)• (c) L = 1 ; Implement void flakeMotif(float L)• (d) Complete one spoke(reflection w.r.t x-axis)

• Draw entire snowflake

??????????????????????

Page 9: Transformations for Modeling & Animation

BSCS – 514 Computer Graphics Instructor Humera Tariq

9

3. Making Patterns from dino motif

Page 10: Transformations for Modeling & Animation

BSCS – 514 Computer Graphics Instructor Humera Tariq

10

4. Tiling and its Applications

Simple Square Tiling

Page 11: Transformations for Modeling & Animation

BSCS – 514 Computer Graphics Instructor Humera Tariq

11

a) b)

W

HD

L

Tiling example from book

Page 12: Transformations for Modeling & Animation

BSCS – 514 Computer Graphics Instructor Humera Tariq

12

Tiling Code for fig.5.46

cvs.pushCT(); // so we can return herecvs.translate2D(W, H); // position for the first motiffor(row = 0; row < 3; row++){ // draw each row pushCT(); for(col = 0 ; col < 3; col++){ motif(); cvs.translate2D(L, 0);} //move to the right cvs.popCT(); // back to the start of this row cvs.translate2D(0, D); }//move up to the next rowcvs.popCT(); //back to where we started

Page 13: Transformations for Modeling & Animation

BSCS – 514 Computer Graphics Instructor Humera Tariq

13

Tiling Important exercise

Page 14: Transformations for Modeling & Animation

BSCS – 514 Computer Graphics Instructor Humera Tariq

14

More on

Transfo

rmati

ons