Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics in Java1 Objects and Viewers Two basic entities (one object seen from two different positions) :

Similar presentations


Presentation on theme: "Computer Graphics in Java1 Objects and Viewers Two basic entities (one object seen from two different positions) :"— Presentation transcript:

1 Computer Graphics in Java1 Objects and Viewers Two basic entities (one object seen from two different positions) :

2 Computer Graphics in Java2 Lights & Images Others attributes:  light sources

3 Computer Graphics in Java3 Colors Light is a form of electromagnetic radiation Visible spectrum 350 – 780 nm

4 Computer Graphics in Java4 Ray Tracing Ray tracing  building an imaging model by following light from a source  a ray is a semi-infinite line that emanates from a point and “travels” to infinity in a particular direction  portion of these infinite rays contributes to the image on the film plane of the camera surfaces:  diffusing  reflecting  refracting

5 Computer Graphics in Java5 Ray Tracing A different approach must be used: for each pixel intensity must be computed all contributions must be taken into account a ray is “followed” in the opposite direction, when intersect a surface it is split into two rays contribution from light sources and reflection from other resources are counted

6 Computer Graphics in Java6 Pinhole Camera Box with a small hole film plane z = - d !!!yp,-d

7 Computer Graphics in Java7 Pinhole Camera point (x p,y p,-d) – projection of the point (x,y,z) angle of view or field of the camera – angle  ideal camera – infinite depth of field

8 Computer Graphics in Java8 Synthetic Camera Model computer-generated image based on an optical system – Synthetic Camera Model viewer behind the camera can move the back of the camera – change of the distance d i.e. additional flexibility objects and viewer specifications are independent – different functions within a graphics library Imaging system

9 Computer Graphics in Java9 Synthetic Camera Model a – situation with a camera b – mathematical model – image plane moved in front of the camera center of projection – center of the lens projection plane – film plane

10 Computer Graphics in Java10 Synthetic Camera Model Imaging with the Synthetic Camera Model film plane position in a camera projected scene to the projection plane

11 Computer Graphics in Java11 Synthetic Camera Model Not all objects can be seen limit due to viewing angle Solution: Clipping rectangle or clipping window placed inn front of the camera ad b shows the case when the clipping rectangle is shifted aside – only part of the the scene is projected

12 Computer Graphics in Java12 Programmer’s Interface Numerous ways for user interaction with a graphics system using input devices - pads, mouse, keyboards etc. different orientation of coordinate systems canvas

13 Computer Graphics in Java13 Application Programmer’s Interface API functionality should match the conceptual model Synthetic Camera Model used for APIs like Java3D, VRML etc. Functionality needed in the API to specify: Objects Viewers Light sources Material properties

14 Computer Graphics in Java14 Application Programmer’s Interface Objects are defined by points or vertices, line segments, polygons etc. to represent complex objects API primitives are displayed rapidly on the hardware usual API primitives:  points  line segments  polygons  text

15 Computer Graphics in Java15 Application Programmer’s Interface Camera specification in APIs: position – usually center of lens orientation – camera coordinate system in center of lens camera can rotate around those three axis focal length of lens determines the size of the image on the film actually viewing angle film plane - camera has a height and a width

16 Computer Graphics in Java16 Graphics Architectures Early graphics systems – CRT had just basic capability to generate line segments connecting two points vector based with refreshing – length of line segments limited light pen often used for manipulation systems with memory CRT – the whole picture redrawn if changed

17 Computer Graphics in Java17 Graphics Architectures Display processors standard architecture with capabilities to display primitives composition made at the host memory – display list – contains primitives to be displayed.

18 Computer Graphics in Java18 Pipeline Architectures VLSI circuits enabled major advances in graphics architectures - simple arithmetic pipeline a + b * c - when addition of (b * c) and a is performing new b * c is computed in parallel – pipelining enabled significant speed up - similar approach can be used for processing of geometric primitives as well

19 Computer Graphics in Java19 Pipeline Architectures There are 4 major steps in the geometric pipeline: transformations – like scaling, rotations, translation, mirroring, sheering etc. clipping – removal of those parts that are out of the viewing field projection rasterization homogeneous coordinates and matrix operations geometric transformations are used

20 Computer Graphics in Java20 Clipping, Projection & Rasterization Clipping is used to remove those parts of the world that cannot be seen. Objects representation is “kept” in 3D as long as possible. After transformation and clipping must be projected to 2D somehow projected objects or their parts must be displayed – and therefore rasterized. All those steps are performed on your graphics cards in haerware nowadays.

21 Computer Graphics in Java21 Where We’re Going Today’s lectures:  Mathematical Foundations  The graphics pipeline: the big picture  Rigid-body transforms  Homogeneous coordinates

22 Computer Graphics in Java22 Mathematical Foundations A brief, informal review of some of the mathematical tools employed in graphics  Geometry (2D, 3D)  Trigonometry  Vector and affine spaces Points, vectors, and coordinates  Dot and cross products  Linear transforms and matrices

23 Computer Graphics in Java23 2D Geometry Know your high-school geometry:  Total angle around a circle is 360° or 2π radians  When two lines cross: Opposite angles are equivalent Angles along line sum to 180°  Similar triangles: All corresponding angles are equivalent Corresponding pairs of sides have the same length ratio and are separated by equivalent angles Any corresponding pairs of sides have same length ratio

24 Computer Graphics in Java24 Trigonometry Sine: “opposite over hypotenuse” Cosine: “adjacent over hypotenuse” Tangent: “opposite over adjacent” Unit circle definitions:  sin (  ) = x  cos (  ) = y  tan (  ) = x/y  Etc… (x, y)

25 Computer Graphics in Java25 3D Geometry To model, animate, and render 3D scenes, we must specify:  Location  Displacement from arbitrary locations  Orientation We’ll look at two types of spaces:  Vector spaces  Affine spaces The distinction is often sloppy or loose

26 Computer Graphics in Java26 Vector Spaces Two types of elements:  Scalars (real numbers):  …  Vectors (n-tuples): u, v, w, … Supports two operations:  Addition operation u + v, with: Identity 0 v + 0 = v Inverse - v + (- v ) = 0  Scalar multiplication: Distributive rule:  ( u + v ) =  ( u ) +  ( v ) (  +  ) u =  u +  u

27 Computer Graphics in Java27 Vector Spaces A linear combination of vectors results in a new vector: v =  1 v 1 +  2 v 2 + … +  n v n If the only set of scalars such that  1 v 1 +  2 v 2 + … +  n v n = 0 is  1 =  2 = … =  3 = 0 then we say the vectors are linearly independent The dimension of a space is the greatest number of linearly independent vectors possible in a vector set For a vector space of dimension n, any set of n linearly independent vectors form a basis

28 Computer Graphics in Java28 Vector Spaces: A Familiar Example Our common notion of vectors in a 2D plane is (you guessed it) a vector space:  Vectors are “arrows” rooted at the origin  Scalar multiplication “streches” the arrow, changing its length (magnitude) but not its direction  Addition uses the “trapezoid rule”: u+v y x u v

29 Computer Graphics in Java29 Vector Spaces: Basis Vectors Given a basis for a vector space:  Each vector in the space is a unique linear combination of the basis vectors  The coordinates of a vector are the scalars from this linear combination  Best-known example: Cartesian coordinates Draw example on the board  Note that a given vector v will have different coordinates for different bases

30 Computer Graphics in Java30 Vectors And Point We commonly use vectors to represent:  Points in space (i.e., location)  Displacements from point to point  Direction (i.e., orientation) But we want points and directions to behave differently  Ex: To translate something means to move it without changing its orientation  Translation of a point = different point  Translation of a direction = same direction

31 Computer Graphics in Java31 Affine Spaces To be more rigorous, we need an explicit notion of position Affine spaces add a third element to vector spaces: points (P, Q, R, …) Points support these operations  Point-point subtraction: Q - P = v Result is a vector pointing from P to Q  Vector-point addition: P + v = Q Result is a new point  Note that the addition of two points is not defined P Q v

32 Computer Graphics in Java32 Affine Spaces Points, like vectors, can be expressed in coordinates  The definition uses an affine combination  Net effect is same: expressing a point in terms of a basis Thus the common practice of representing points as vectors with coordinates

33 Computer Graphics in Java33 Affine Lines: An Aside Parametric representation of a line with a direction vector d and a point P 1 on the line: P(  ) = P origin +  d Restricting 0   produces a ray Setting d to P - Q and restricting 0    1 produces a line segment between P and Q

34 Computer Graphics in Java34 Dot Product The dot product or, more generally, inner product of two vectors is a scalar: v 1 v 2 = x 1 x 2 + y 1 y 2 + z 1 z 2 (in 3D) Useful for many purposes  Computing the length of a vector: length(v) = sqrt(v v)  Normalizing a vector, making it unit-length  Computing the angle between two vectors: u v = |u| |v| cos(θ)  Checking two vectors for orthogonality  Projecting one vector onto another θ u v

35 Computer Graphics in Java35 Cross Product The cross product or vector product of two vectors is a vector: The cross product of two vectors is orthogonal to both Right-hand rule dictates direction of cross product Use a determinate to compute the cross product

36 Computer Graphics in Java36 Linear Transformations A linear transformation:  Maps one vector to another  Preserves linear combinations Thus behavior of linear transformation is completely determined by what it does to a basis Turns out any linear transform can be represented by a matrix

37 Computer Graphics in Java37 Matrices By convention, matrix element M rc is located at row r and column c: By (OpenGL) convention, vectors are columns:

38 Computer Graphics in Java38 Matrices Matrix-vector multiplication applies a linear transformation to a vector: Recall how to do matrix multiplication

39 Computer Graphics in Java39 Matrix Transformations A sequence or composition of linear transformations corresponds to the product of the corresponding matrices  Note: the matrices to the right affect vector first  Note: order of matrices matters! The identity matrix I has no effect in multiplication Some (not all) matrices have an inverse:

40 Computer Graphics in Java40 3-D Graphics: A Whirlwind Tour Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

41 Computer Graphics in Java41 The Display You Know Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

42 Computer Graphics in Java42 The Framebuffer You Know Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

43 Computer Graphics in Java43 The Rendering Pipeline Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay Why do we call it a pipeline?

44 Computer Graphics in Java44 2-D Rendering You Know Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

45 Computer Graphics in Java45 The Rendering Pipeline: 3-D Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay

46 Computer Graphics in Java46 The Rendering Pipeline: 3-D Modeling Transforms Scene graph Object geometry Lighting Calculations Viewing Transform Clipping Projection Transform Result: All vertices of scene in shared 3-D “world” coordinate system All vertices of scene in shared 3-D “world” coordinate system Vertices shaded according to lighting model Vertices shaded according to lighting model Scene vertices in 3-D “view” or “camera” coordinate system Scene vertices in 3-D “view” or “camera” coordinate system Exactly those vertices & portions of polygons in view frustum Exactly those vertices & portions of polygons in view frustum 2-D screen coordinates of clipped vertices 2-D screen coordinates of clipped vertices

47 Computer Graphics in Java47 The Rendering Pipeline: 3-D Scene graph Object geometry Lighting Calculations Clipping Result: All vertices of scene in shared 3-D “world” coordinate system All vertices of scene in shared 3-D “world” coordinate system Vertices shaded according to lighting model Vertices shaded according to lighting model Scene vertices in 3-D “view” or “camera” coordinate system Scene vertices in 3-D “view” or “camera” coordinate system Exactly those vertices & portions of polygons in view frustum Exactly those vertices & portions of polygons in view frustum 2-D screen coordinates of clipped vertices 2-D screen coordinates of clipped vertices Modeling Transforms Viewing Transform Projection Transform


Download ppt "Computer Graphics in Java1 Objects and Viewers Two basic entities (one object seen from two different positions) :"

Similar presentations


Ads by Google