Presentation is loading. Please wait.

Presentation is loading. Please wait.

Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 6 Graphics Contents F Geometry and.

Similar presentations


Presentation on theme: "Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 6 Graphics Contents F Geometry and."— Presentation transcript:

1 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 6 Graphics Contents F Geometry and appearance, the basic attributes of visual objects F Points and vectors F GeometryArray family of classes for constructing geometry F GeometryInfo class for constructing geometry F Geometric primitives F Texts and fonts as geometric objects F Appearance class and the associated node component classes

2 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 2 Points and Vectors F Point represents position F Vector represents direction F Both can be represented as a tuple F An n-dimensional vector is an n-tuple of numbers –(x 1, x 2, …, x n )

3 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 3 Classes for Points and Vectors F Tuple* are abstract classes F Naming convention –number for dimension (3 or 4) –letter for type (f, d, I, b) F Quaternions provide an alternate representation

4 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 4 Tuple Operations F All Tuples have –Binary arithmetic u add u sub u scale - multiplication by a constant –negation u unary u same as scalar multiply by -1 –and several more F For points, also need distance –Euclidean, Manhatten, L-infinite F For vectors –dot-product (scalar) –cross-product (vector) –length (magnitude) –angle (to another vector)

5 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 5 Modeling 3D Shapes F Points now have 3 coordinates –for homogeneous coordinates we use 4 values F Lines –Straight lines follow a linear equation in x, y and z –Curves can be specified with an implicit equation or a parametric equation with one parameter

6 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 6 Surface Equations F As for curves in 2D, surfaces in 3D can be represented in several ways –Implicit equation u F( x, y, z) = 0 –Parametric equation for a surface u x = f( u, v) u y = g( u, v) u z = h( u, v)

7 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 7 Ellipsoid F An ellipsoidal surface is defined by (x/r x ) 2 + (y/r y ) 2 + (z/r z ) 2 = 1 F The parametric equations for an ellpsoid are x = r x cos  cos  y = r y cos  sin  z = r z sin 

8 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 8 Modeling 3D Shapes F Arbitrary surfaces are complicated to specify F Mostly use a collection of simpler surfaces to model a 3D shape –simple polygons can be used to construct a polygon mesh that can approximate the surface as closely as necessary

9 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 9 Surface Represented with Polygons F Number of triangles used determines the accuracy

10 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 10 Shape3D Node F Use a Shape3D Node to represent visual objects –A Shape3D leaf node usually references Geometry and Appearance objects

11 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 11 Geometry Classes F Geometry is abstract class with many subclasses

12 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 12 GeometryArray F Supports construction of objects using arrays of points, lines and polygons F Defines an array of vertices along with other properties that are associated with them –normals –color (3 or 4 elements) –texture coordinates (2, 3 or 4 elements)

13 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 13 GeometryArray F Constructors specify number of vertices and type of data F set methods are used to add the data setCoordinate( int index, Point3f coord) setCoordinates( int startIndex, Point3f [] coords) setNormals(int startIndex, Vector3f [] normals) similarly for other properties

14 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 14 GeometryArray Constants F Definition of a vertex contains coordinates and may optionally contain other data F Bit masks are used to specify which data is present –Bits can be combined using bitwise OR ( | ) GeometryArray.COORDINATES | GeometryArray.NORMALS

15 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 15 PointArray PointArray pa = new PointArray(3, GeometryArray.COORDINATES); pa.setCoordinate(0, new Point3f(0f, 0f, 0f)); pa.setCoordinate(1, new Point3f(1f, 0f, 0f)); pa.setCoordinate(2, new Point3f(0f, 1f, 0f)); F Defines a geometry consisting of a set of points

16 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 16 LineArray LineArray la = new LineArray(6, GeometryArray.COORDINATES); Point3f[] coords = new Point3f[6]; coords[0] = new Point3f(0f, 0f, 0f); coords[1] = new Point3f(1f, 1f, 0f); coords[2] = new Point3f(1f, 0f, 0f); coords[3] = new Point3f(2f, 1f, 0f); coords[4] = new Point3f(2f, 1f, 0f); coords[5] = new Point3f(3f, 0f, 0f); la.setCoordinates(0, coords); F Geometry consisting of line segments

17 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 17 TriangleArray TriangleArray ta = new TriangleArray(6, GeometryArray.COORDINATES); Point3f[] coords = new Point3f[6]; coords[0] = new Point3f(0f, 0f, 0f); coords[1] = new Point3f(1f, 1f, 0f); coords[2] = new Point3f(1f, 0f, 0f); coords[3] = new Point3f(1f, 0f, 0f); coords[4] = new Point3f(2f, 1f, 0f); coords[5] = new Point3f(3f, 0f, 0f); ta.setCoordinates(0, coords); F Note duplication of shared point

18 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 18 QuadArray QuadArray qa = new QuadArray(8, GeometryArray.COORDINATES); Point3f[] coords = new Point3f[8]; coords[0] = new Point3f(0f, 0f, 0f); coords[1] = new Point3f(1f, 0f, 0f); coords[2] = new Point3f(1f, 1f, 0f); coords[3] = new Point3f(0f, 1f, 0f); coords[4] = new Point3f(1f, 1f, 0f); coords[5] = new Point3f(0f, 1f, 0f); coords[6] = new Point3f(0f, 1f, 1f); coords[7] = new Point3f(1f, 1f, 1f); qa.setCoordinates(0, coords);

19 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 19 StripArray and FanArray TriangleStripArray TriangleFanArray

20 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 20 IndexedArray int[] stripIndexCounts = {4, 4}; IndexedTriangleStripArray itsa = new IndexedTriangleStripArray(7, GeometryArray.COORDINATES, 8, stripIndexCounts); Point3f[] coords = new Point3f[7]; coords[0] = new Point3f(0f, 0f, 0f); coords[1] = new Point3f(0f, 1f, 0f); coords[2] = new Point3f(1f, 1f, 0f); coords[3] = new Point3f(2f, 1f, 0f); coords[4] = new Point3f(-1f, 0f, 0f); coords[5] = new Point3f(-1f, -1f, 0f); coords[6] = new Point3f(-2f, -1f, 0f); itsa.setCoordinates(0, coords); int[] indices = {0, 1, 2, 3, 0, 4, 5, 6}; itsa.setCoordinateIndices(0, indices);

21 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 21 Five Regular Polyhedra (Platonic Solids) Solid# Faces# VertexesFace Shape Tetrahedron44Triangle Cube86Square Octagon68Triangle Dodecahedron1220Pentagon Icosahedron2012Triangle

22 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 22 Platonic solids F A tetrahedron can be fitted inside a cube –it shares 4 of the 8 vertexes F Dual Polehedra –Connecting the centers of the faces of a tetrahedron forms another tetrahedron –Connecting the centers of the faces of a cube creates an octahedron u and vice versa –Similarly for dodecahedron and icosahedron

23 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 23 Tetrahedron.java F extends IndexedTriangleArray F Create a Shape3D object from Tetrahedron F Vertices: –(1, 1, 1), (1, -1, -1), (-1, 1, -1), (-1, -1, 1) F Indices: –0,1,2, 0,3,1, 1,3,2, 2,3,0 F Normals: –(1, 1, -1), (1, -1, 1), (-1, -1, -1), (-1, 1, 1)

24 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 24 TestTetrahedron.java

25 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 25 Surface Normals F The surface normal at a point is perpendicular to the tangent plane –From 3 points, create two vectors F The cross product is useful for calculating normals

26 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 26 Normal Calculation F Normals should be calculated from the curve (not the polygon mesh) F Parametric equations x = f( u, v); y = g( u, v); z = h( u, v) F Derivatives give the tangent lines (f u, g u, h u ) = (dx/du, dy/du, dz/du) (f v, g v, h v ) = (dx/dv, dy/dv, dz/dv) F Use cross product to get normals n = (f u, g u, h u ) x (f v, g v, h v )

27 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 27 Example: Parabolic Ellipsoid F Parametric equations x = u cos v y = u sin v z = u 2 F Tangents (cos v, sin v, 2u), (u sin v, u cos v, 0) F Normal (-2 u 2 cos v, 2 u 2 sin v, u)

28 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 28 GeometryInfo Class F A different way to generate geometry F Constructors –public GeometryInfo( GeometryArray ga) –public GeometryInfo( int primitiveType) u where primitiveType = TRIANGLE_ARRAY, TRIANGLE_FAN_ARRAY, TRIANGLE_FAN_ARRAY, QUAD_ARRAY or POLYGON_ARRAY u Use setCoordinates to set all coordinates at once

29 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 29 GeometryInfo Class F Utility classes for GeometryInfo –NormalGenerator: generates normals –Stripifier: converts polygons to triangles

30 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 30 Dodecahedron.java F Uses GeometryInfo F extends Shape3D

31 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 31 Polygon Mesh F To approximate curved surface, use an array of small polygon patches F x=f(u,v), y=g(u,v), z=h(u,v) with a<=u<=b and c<=v<=d  Use m x n grid in parameter space to form patches –u i = a + i (b - a) / m, i= 0, 1, …, m –vj = c + j (d - c) / n, j=0, 1, …, n

32 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 32 Polygon Mesh F Quadrilateral patch formed from (u i, v j ), (u i+1, v j ), (u i+1, v j+1 ), (u i, v j+1 ) F These can be divided into two triangles –(u i, v j ), (u i+1, v j ), (u i+1, v j+1 ) –(u i, v j ), (u i+1, v j+1 ), (u i, v j+1 ) F ViewData generates a polygon mesh for y = 2 cos (x 2 ) sin(z 2 )e.025(x x+z z) - 1

33 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 33 Primitives F Primitive abstract class –extends Group u can be added to scene graph as a node –has subclasses for common geometric primitives F TestPrimitives.java

34 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 34 Primitive Subclasses GeometryDimensions Box 1 x 1 x 1 or 2 x 2 x 2? Coneheight =2, radius=1 Cylinderheight =2, radius=1 Sphereradius=1

35 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 35 Text in 3D Graphics F There are both Text2D and Text3D classes F Text3D –Extends Geometry so can be used by Shape3D node F Text2D –Extends Shape3D –Implemented as rectangle with text written on it Text2D text = new Text2D(“Hello”, new Color3f(Color.blue), “Serif”, 16, Font.ITALIC);

36 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 36 Font3D and FontExtrusion F Font3D stores an extruded 2D glyph –NodeComponent –Consists of u Font u Extrusion path u Tesselation tolerance F FontExtrusion –A path that describes the shape of the edge perpendicular to the glyph –Line from 0 to.2 by default

37 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 37 Creating a Text3D F Create a Font Font font = new Font(“Serif”, Font.BOLD, 1); F Create a FontExtrusion FontExtrusion extrusion = new FontExtrusion(); F Create a Font3D Font3D font3d = new Font3D(font, extrusion); F Create a Text3D Text3D text = new Text3D(font3d, “Hello”);

38 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 38 Appearance Classes F Attributes that define the appearance of an object F Appearance is a NodeComponent –Contains attribute objects that affect the rendering of an object F TestAppearance.java

39 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 39 Drawing-Mode Attributes F PointAttributes - size and antialiasing F LineAttributes - line width, pattern –PATTERN_SOLID, PATTERN_DASH, PATTERN_DOT, PATTERN_DASH_DOT, PATTERN_USER_DEFINED F PolygonAttributes - rendering mode –POLYGON_POINT, POLYGON_LINE, POLYGON_FILL F TransparencyAttributes –1.0 for fully transparent, 0.0 for opaque

40 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 40 Rules for Drawing Mode F POLYGON_POINT - only points are drawn using PointAttributes settings F POLYGON_LINE - wireframe drawing using settings of LineAttributes F POLYGON_FILL - filled polygons

41 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 41 Coloring Control F Rendering Attributes used to enable vertex colors F ColoringAttributes specifies a shading model and a color to use when vertex colors are not defined –SHAD_FLAT - solid color –SHAD_GOURAUD -interpolate colors between vertexes –SHAD_FASTEST, SHAD_NICEST are platform dependent F Material - related to illumination (more later)

42 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 42 Coloring F The lighting model is applied if the Appearance references a valid Material object and the Material object enables lighting. F If vertex colors are present and not ignored, they are used to render the polygons. The enabling of the vertex colors is controlled by a RenderingAttributes object. When vertex colors are used, the shading mode of the polygons is determined by the ColoringAttributes object. F If lighting is not enabled and the vertex colors of the geometry are not present or ignored, the color specified by the ColoringAttributes object will be used for coloring the geometry.

43 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 43 Shading Models F Flat shading: a fixed color for a face F Gouraud shading: interpolating vertex colors

44 Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 44 Texture Mapping F For objects with complex surface detail, it is more efficient to paint a raster image onto the surface than to render the details from scratch F Attributes related to texture include Texture, TextureAttributes, TexCoordGeneration, TextureUnitState F More about this later


Download ppt "Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 6 Graphics Contents F Geometry and."

Similar presentations


Ads by Google