Computer Graphics Animation Techniques - PowerPoint PPT Presentation

1 / 46
About This Presentation
Title:

Computer Graphics Animation Techniques

Description:

10 (Paris) == 9 (London) to remove ambiguity, often use GMT ... e.g. point in city vs point on map of the city (less often a source of bugs) 18 ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 47
Provided by: RonenB6
Category:

less

Transcript and Presenter's Notes

Title: Computer Graphics Animation Techniques


1
Computer GraphicsAnimation Techniques
Ronen Barzel
  • Geometric programming
  • Parametric models
  • class 2
    22 january 2003

2
Outline for today
  • Course business
  • Geometric Programming
  • Parametric models (graphics programming)

3
Textbooks
  • Computer Animation Algorithms and Techniques.
    Rick Parent 2001
  • Computer Graphics Principles and Practice.
    Foley, van Dam, Feiner, Hughes 1995

4
Review Grading
  • I need some way to know how youre doing
  • You might want feedback
  • Email me your TD.
  • Feel free to expand it, have fun.

5
Go over TD1
  • (see my version)

6
Todays animation
  • Knick knack

7
Outline for today
  • Course business
  • Geometric Programming
  • Parametric models (graphics programming)

8
Linear geometry
  • Basic for all computer graphics
  • Linear Geometry
  • Coordinate-free geometry
  • Affine Space
  • Linear Algebra
  • Homogeneous coordinates

9
Geometric objects
  • Coordinate-free geometry
  • Affine Space
  • A vector space with points
  • Interesting Objects
  • Points
  • Vectors
  • Transformations
  • Frames
  • Spaces, normals, rotations,

10
Points and vectors
  • You know linear algebra, vector spaces
  • Why am I talking about this?
  • Emphasize differences
  • between a point and a vector
  • between point or vector and its representation as
    coordinates

11
Points and vectors
  • in R3, can represent point as 3 numbers
  • in R3, can represent vector as 3 numbers
  • 3-Tuple array of 3 numbers
  • Easy to think theyre the same thing
  • but theyre not!
  • different operations, different behaviors
  • many program libraries make this mistake
  • easy to have bugs in programs

12
In 1D, consider time
  • point in time a course meets at 8h
  • duration of time a course lasts 8 hours
  • operations
  • course at 8h course at 10h ? class at 18h !!
  • 8 hour course 10 hour course 18 hours course
  • course ends at 10h starts at 8h 2 hour course
  • course starts at 8h lasts 2 hours ends at 10h
  • 2 courses at 8h ? one course at 16h !!
  • 2 courses last 8 hours 16 hours of courses
  • starts at 8h, ends at 10h. half done at
    .58h.510h 9h

13
Programming with time
  • is this the start of the meeting or the duration?
  • float time // time of meeting
  • fewer bugs
  • class TimePoint TimeDuration
    subtract(TimePoint) TimePoint
    add(TimeDuration) etc.
  • class TimeDuration TimeDuration
    add(TimeDuration) TimeDuration scale(float
    s) etc.
  • In C, define , -, operators

14
Coordinate Systems for time
  • 8 oclock ambiguous use 8h00 vs 20h00
  • time zones same point, many representations
  • 10 (Paris) 9 (London)
  • to remove ambiguity, often use GMT
  • if always staying local, not imporant
  • if scheduling globally, must be careful.
  • convert from one time zone to another.
  • Also, hours only good within one day
  • need to specify date time
  • UNIX time seconds since 01/01/1970, 00h00 GMT
  • Notice time durations are unaffected!

15
Programming with time
  • what time zone is this?
  • TimePoint tp1 NewTimePoint(15)
  • float h tp2.hour
  • fewer bugs
  • class TimePoint TimePoint(TimeZone tz, float
    hour) float getHour(TimeZone tz) etc.
  • class TimeZone
  • Privately, the class might store GMT or Unix time.

16
Geometry, analogously
  • point describes a location in space
  • can subtract points to get a vector
  • can take weighted average of points to get a
    point
  • vector describes a displacement in space
  • has a magnitude
  • can add, subtract, scale vectors
  • can add vector to a point to get a point

17
Multiple spaces
  • Can also have multiple spaces
  • operations only on objects in same space
  • can have transformation from one space to another
  • e.g. point in city vs point on map of the city
  • (less often a source of bugs)

18
Reference frames for geometry
  • A reference frame origin basis vectors
  • Given origin point O, vectors v0, v1, v2
  • any point P expressible as P Oav0bv1cv2
  • Use many frames at once when doing CG.
  • Use mostly orthonormal (Cartesian) frames
  • Right-handed vs. left-handed

19
Coordinates of a Frame
  • Frame f origin O, vectors v0, v1, v2
  • In world coordinates, might have
  • O (10,10,3) v0 (0,-1,0), v1
    (0.7,0,0.7), v2 (-0.7,0,0.7)
  • But in frame f, always have
  • O (0,0,0) v0 (1,0,0), v1 (0,1,0), v2
    (0,0,1)

20
Programming geometry
  • class GeomPoint GeomPoint(GeomFrame f,
    float coords) void getCoords(GeomFrame f,
    float coords) GeomVector subtract(GeomPoint)
    GeomPoint add(GeomVector) etc
  • class GeomVector GeomVector(GeomFrame f,
    float coords) void getCoords(GeomFrame f,
    float coords) GeomVector add(GeomVector)
    GeomVector scale(float) etc
  • class GeomFrame GeomFrame(GeomPoint origin,
    GeomVector basis) etc
  • Bootstrap start with standard frame for the
    space

21
Computing using components
  • Privately, class keeps array of coordinates.
  • Operations work in any coordinate frame
  • v0 pa0 pb0 v1 pa1 pb1
    v2 pa2 pb2
  • if all coordinates are from the same frame!
  • Internally, might convert all objects to standard
    frame.

22
Affine Transformations
  • Several types
  • From one space to another different objects
  • From a space to itself different object
  • Change frame same object, different
    representation
  • Linear F(aPbQ) aF(P)bF(Q)
  • parallel lines stay parallel lines
  • angles not necessarily preserved

23
Affine Transformations
  • To define a transform M(A)gtB,
  • sufficient to specify a FrameA gt FrameB,
  • I.e., OriginA gt OriginB and BasisA gt BasisB
  • Programming an affine Transform
  • class AffineTransform AffineTransform(GeomFrame
    A, GeomFrame B) GeomPoint apply(GeomPoint)
    GeomVector apply(GeomVector) AffineTransform
    compose(AffineTransform)

24
Affine Transformations
  • Rotations, Translations, Scaling
  • Build transformations by composition
  • not commutative G(F(P)) ? F(G(P))
  • Rotate then translate ? translate then rotate
  • vectors unaffected by translation parts
  • analogous to duration not affected by time zone

25
Computing using components
  • Given frames for the domain and range!
  • Point P with coordinates (P0,P1,P2)
  • F(P)0 m00 P0 m01 P1 m02 P2 b0F(P)1 m10
    P0 m11 P1 m12 P2 b1F(P)2 m20 P0 m21 P1
    m22 P2 b2
  • Vector V with coordinates (V0,V1,V2)
  • F(V)0 m00 V0 m01 V1 m02 V2 F(V)1 m10 V0
    m11 V1 m12 V2 F(V)2 m20 V0 m21 V1 m22
    V2

26
Matrix operations Linear algebra
  • When working with coordinates
  • Affine transform general form is
  • F(P) M P B F(V) M V
  • B contains translation
  • M contains rotation, scale, shear

27
Some Coordinate Equivalences
  • Given a frame with origin O
  • point P ? vector v P O
  • coordinates P (a,b,c)
  • coordinates v (a,b,c)
  • given a standard frame s
  • frame f ? transformation F(s) gt f
  • coordinates of origin B, basis columns of M
  • transforming point vs changing from one
    representation to another same matrix

28
Inconveniences
  • Different rules for points and vectors
  • Inconvenient to compose transformations
  • F(P) M P B
  • G(P) N P C
  • G(F(P)) (NM) P (NBC)
  • Inconvenient to compute inverse, etc.
  • Introduce Homogeneous Coordinates

29
Homogeneous coordinates
  • Basic a trick to unify/simplify computations.
  • Deeper projective geometry
  • Interesting mathematical properties
  • Good to know, but less immediately practical

30
Homogeneous coordinates
  • add an extra component to a point or a vector
  • point (a,b,c,1)
  • vector (a,b,c,0)
  • combine M and B into single matrix
  • (in this figure M?r, B?t. sorry! )
  • Transformation is always matrix operation
  • F(P) M P
  • F(V) M V

31
Homogeneous coordinates
  • Legal operations always end in 0 or 1
  • Last row of matrix always (0,0,0,1)
  • Compose transformations by multiplying matrices

32
Final note transforming normals
  • A normal vector perpendicular to surface
  • Not really a vector
  • represents relationship to other vectors
  • (a co-vector, a linear functional)
  • Transform using transpose of inverse of M

33
Programming in practice
  • Everyone uses homogeneous matrices.
  • built into low-level software, hardware
  • In practice, nobody explicitly uses 1 and 0.
  • no need for storage computation
  • keep track of points vs vectors explicitly

34
Programming in practice
  • Standard libraries linear algebra, homogeneous
    coordinates not geometric.
  • e.g. Javas Point2D and AffineTransform
  • No Vector2D, you must use Point2D
  • Remember to use a.transform(p)or
    a.deltaTransform(v)
  • No support for transforming a normal
  • Keep track of coordinate frames yourself.

35
Geometric programming
  • A few academic libraries
  • http//www.cgl.uwaterloo.ca/njlitke/geometry/
  • Why not in wider use?
  • Not many people familiar with it
  • Existing libraries very minimal
  • Not integrated with platform
  • Depending on how implemented and how general, can
    be less efficient
  • Even without geometric libraries, its very
    useful to think about it this way.

36
Note assuming Euclidean space
  • Affine Space with a metric
  • Vectors are freesame everywhere
  • Other spaces (curved, finite, etc.) are messier
  • a vector is defined only for a given point

37
Aside perspective projection
  • homogeneous coordinates for 3D gt 2D
  • introduce perspective divide
  • (a,b,c,1) gt (x,y,z,w) gt (x/w, y/w, z/w, 1)
  • frustum changes to cube

38
Outline for today
  • Administrative stuff
  • Geometric programming
  • Parametric models (graphics programming)

39
Parametric models
  • also, procedural modeling
  • modeling by executing a program
  • at the core of all CG
  • parameters for location
  • parameters for pose
  • compute shape of parts
  • compute relationship between parts

40
Example model Snowman
  • Basic model Three circles on top of each other.
  • Parameters
  • squash stretch for each
  • position of torso on base
  • position of head on torso
  • tilt each part
  • This will be TD2

41
Programming Graphics
  • You provide a draw()routine.
  • Library maintains current state
  • Fill color, line style, shading, lighting,
  • current transformation
  • g.setTransform(xf) // replaces the transform
  • g.transform(xf) // composes transform
  • g.rotate(angle) // composes rotation
  • g.translate(tx,ty) // composes translation
  • g.scale(sx,sy) // composes scale
  • etc

42
Current transformation
  • Typically, have a graphics stack
  • g.push() // saves current state
  • g.pop() // restores to saved
  • Typically, split into two parts
  • Local to World Modeling transformation
  • World to Screen Viewing transformation
  • Java Graphics2D doesnt do either
  • (TD2 includes a wrapper that does)

43
Typical use in a program
  • drawHighLevelObject(parameters)
  • g.push()g.rotate()g.translate()g.scale()g.
    drawSimpleShape()g.pop()
  • drawModel() g.push()drawHighLevelObject()g.tr
    anslate()drawHighLevelObject()etcg.pop()

44
Thinking top-down vs bottom-up
  • Sample sequence
  • 1. Rotate(45)2. translate(0,5)3. scale(2,1)4.
    drawSquare()
  • Top-down transform a coordinate frame
  • rotate it 45 degrees about its origin, then
    translate it along its Y, then stretch it in X,
    then draw the primitive.
  • Bottom-up transform the object
  • create a square, then scale it in X then
    translate it along the Y axis, then rotate 45
    degrees about the origin.
  • Both ways useful

45
Building your own transform
  • Often, want not just to draw, but also to operate
    or compute.
  • Instead of
  • g.rotate()g.translate()g.scale()
  • can do
  • xf new AffineTransform()xf.rotate()xf.transl
    ate()xf.scale()g.transform(xf)
  • Now xf is available for xf.transform(pt), etc.

46
end of class 2
Write a Comment
User Comments (0)
About PowerShow.com