1 / 47

COM 366

Reading Data. COM 366. #Data for a cube # First the link data 12 1,2 2,3 3,4 4,1 1,5 2,6 3,7 4,8 5,6 6,7 7,8 8,5 #Now the node data 8 1,-1,1 -1,-1,1 -1,1,1 1,1,1 1,-1,-1 -1,-1,-1 -1,1,-1 1,1,-1. Reading data from disc files.

chloe
Télécharger la présentation

COM 366

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Reading Data COM 366

  2. #Data for a cube # First the link data 12 1,2 2,3 3,4 4,1 1,5 2,6 3,7 4,8 5,6 6,7 7,8 8,5 #Now the node data 8 1,-1,1 -1,-1,1 -1,1,1 1,1,1 1,-1,-1 -1,-1,-1 -1,1,-1 1,1,-1 Reading data from disc files Organise the data in a logical fashion with comments as necessary. COM 366

  3. A simple procedure to read the text file • Open filename For Input As #1 • Input #1, temp_line • While Left$(temp_line, 1)= "#" • Input #1, temp_line • Wend • num_lines = Clnt(temp_line) • ReDim L(2, num_lines) • For i = 1 To num lines • Input #1, L(1, i), L(2, i) • Next i • input #1, temp_line • While Left$(temp_line, 1)= "#" • Input #1, temp_line • Wend • num_points = Clnt(temp_line) • ReDim X(num_points), Y(num_points), Z(num_points) • For i = 1 To num_points • Input #1, V(i).X, V(i).Y, V(i).Z • Next i • Close #1 COM 366

  4. Topic 6 Data structures revisited COM 366

  5. (d) (a) (b) (c) Figure 6.1 Representing Objects with polygons COM 366

  6. OBJECT Properties Face # Node # Co-ordinates FACE LIST Colour, texture Appearance etc. V1,V2,V3,.... F1 x1,y1,z1 V1 V2 x2,y2,z2 V2,V3,V12,.... “ F2 x3,y3,z3 V3 V6,V3,V9,.... “ F3   F4 V11,V21,V3,.... “ Vm xm,ym,zm    Figure 6.2 : Object Data Structure Data structure for an object COM 366

  7. Z Z H2O Z Y X Y Y Z CO Y X X H1O GO X Figure 6.3 Local & global co-ordinates COM 366

  8. Scene Object 1 Object 2 Object 3 Lighting Camera view Figure 6.4 Data structure for a scene COM 366

  9. Figure 6.5 Sweep generation of an object COM 366

  10. N = 6 N = 30 Axis of symmetry COM 366

  11. function RevObject(n) %To generate a 3D object from profile in 'goblet.txt' %NOTE this version only works with 5 nodes in the profile %First read in the data, set the number of nodes and faces U = dlmread('goblet.txt'); [a,b] = size(U); numnodes = a*n; numpatch = (a-1)*n; Node = zeros(numnodes,3); PSet = zeros(numpatch,4); %Now calculate all the node values for k = 0:n-1 for L = 1:a theta = 2*k*pi/n; Node(L+a*k,1) = U(L,1)*cos(theta); Node(L+a*k,2) = U(L,1)*sin(theta); Node(L+a*k,3) = U(L,2); end; end; COM 366

  12. for k = 1:n term = 5*(k-1); for L = 1:4 Pset(4*(k-1)+L,:) = [(term+L) (term+L+1) (term+L+6) (term+L+5)]; end end; %Finally ensure that the last but one profile connects to the first for k = numpatch-3:numpatch Pset(k,3)=Pset(k,3)-numnodes; Pset(k,4) = Pset(k,4) - numnodes; end %Uncomment the following line if you want to see the patch array %Pset patch('Vertices',Node,'Faces',Pset,'facevertexCdata',[0.2 0.2 1],'facecolor','flat') axis square rotate3d on COM 366

  13. A B X Figure 6.3 Constructive solid geometry - 1 COM 366

  14. A X B Figure 6.4 Constructive solid geometry - 2 COM 366

  15. B - A A - B B A Figure 6.5 Constructive solid geometry - 3 COM 366

  16. Three forms of the cylinder function [X,Y,Z] = cylinder [X,Y,Z] = cylinder(r) [X,Y,Z] = cylinder(r,n) COM 366

  17. Generating a cone function [X,Y,Z] = Cone(R,h,L) %To create X,Y,Z data to draw a truncated cone. %R = base radius of the cone. %h = height to which the cone is drawn %L = apex of the cone %Note setting h = L will draw the full cone if nargin < 3, L = 1; end if nargin < 2, h = L; end if nargin == 0, R = 1; end stepsize = h/10; t = 0:stepsize:h; [X,Y,Z] = cylinder((R*(1-t/L))); When t = 0 then r = R When t = L then r = 0 COM 366

  18. Examples of cone h = L h < L COM 366

  19. Superquadratics Example the super ellipse m = 1 gives a normal ellipse m >1 gives a cusped figure m < 1 gives a ‘fatter figure m = 0 gives a rectangle COM 366

  20. Superquadratics in 3D (superquad) COM 366

  21. Using Fractals COM 366

  22. The Koch Curve N=0 N=1 N=5 N=2 COM 366

  23. Length of the Koch Curve …………… m N = 1 2 3 COM 366

  24. Definition of space dimension If N is the number of self similar copies required when an object is scaled by r then the Dimension of the object ‘D’ is given by : 1 = NrD If a line is scaled by 1/3 then 3 copies are required thus the dimension of a line is 1 = 3(1/3)D. Therefore D = 1 If a square is scaled by 1/3 then 9 copies are required thus the dimension of a square is 1 = 9(1/3)D. Therefore D = 2 Dimension of the Koch Curve For the Koch curve if we scale by 1/3 we require 4 sections and the dimension is COM 366

  25. A A A A B B B A A A A B A A A A A B B A A B Using ‘graftals’ The correct name is parallel graph grammars • Definitions (you can improvise your own) • A  AA • B  A[B]AA[B] • [ ] means ‘branch left If we start with A we generate a dull sequence A AA AAAA etc. But lets start with B and Record the first 3 generations : (0) B (1) A[B]AA[B] (2) AA[A[B]AA[B]]AAAA[A[B]AA[B]] COM 366

  26. Change the angle between turns and introduce () to mean branch right and we start to Get more interesting shapes COM 366

  27. Making ‘graftals’ realistic Use curved segments and colour Finally add some random variation in angles and lengths COM 366

  28. Modelling mountains P is a perturbation based on the length ‘s’ of the line e.g. 2-s and R is a random number between 0 and 1 1 2 0 In three dimensions the concept is exactly the same but using a triangle or pyramid as a starting point COM 366

  29. Add some colour and and shading ! COM 366

  30. Topic 7 Hidden Surface Removal COM 366

  31. Convex Solids A solid is convex if a straight line joining any two points on the surface passes entirely through the body of the solid or through its surface. Examples of common convex solids include : Sphere, cube, cone, cylinder, pyramid All remaining solids are non convex COM 366

  32. N L  Towards the viewer

  33. Criteria of Visibility The polygon surface is visible if 0  90o or 270o 360o Or in terms of the angle cosine Cos()  0 COM 366

  34. Numerical evaluation of the visibility condition Viewing direction L = (Lx,Ly,Lz) Surface normal N = (Nx,Ny,Nz) If these two vectors are of unit length then |L| = |N| = 1 When viewing along the z axis L reduces to (0,0,-1) COM 366

  35. Programming the visibility criterion My recommendation is that you add all the normals to your data structure (NX,NY,NZ) and then rotate them with the nodes before applying the visibility criterion COM 366

  36. Hidden Surface Removal for Non Convex Objects The painters ( or z buffer) algorithm If we can, in an unambiguous manner, sort the polygons into order of increasing z values then we can correctly render the object by drawing the polygons with the largest z values first. Remember that for a left handed co-ordinate system the polygons with the largest z value will be the furthest from the view point. COM 366

  37. Test 1 : Do the X extents of P and Q not overlap ? Test2 : Do the Y extents of P and Q not overlap ? Test3 : Is P completely on the side of the plane of Q away from the viewer ? Test4 : Is Q completely on the side of the plane of P nearer to the viewer ? Test5 : Do the projections of the two polygons on the viewing plane not overlap ?

  38. The depth buffer method This method like the z buffer algorithm begins with a list of polygons but makes no attempt to sort the polygons by z depth instead two pixel based buffers are created. For each pixel position we store the current pixel colour in one buffer. The second buffer contains a single z value at each pixel position representing the depth of the currently displayed pixel. COM 366

  39. For all pixels • Set pixel_colour = background • Set pixel_depth = maximum_value • End for all pixels • For each polygon • For each projected_polygon_pixel • If z_co_ord < pixel_depth then • Set pixel_colour = ploygon_colour • Set pixel_depth = z_co_ord • Endif • End for each projected_polygon_pixel • End for each polygon COM 366

  40. COM 366

  41. Type Vector x as single y as single z as single End type Programming in VB Type Polygon N as vector CR as integer CG as integer CB as integer V() as integer End Type GLOBAL Object() as integer ‘The array of polygon numbers GLOBAL Poly() as Polygon ‘ The array of polygons GLOBAL Node() as Vector ‘ The array of vertex co-ordinates GLOBAL num_polygons, num_nodes as integer. COM 366

More Related