Welcome to DIG 1705 3 D Programming Follow

  • Slides: 16
Download presentation
Welcome to DIG 1705 3 D Programming Follow on : dig 1705 3 D

Welcome to DIG 1705 3 D Programming Follow on : dig 1705 3 D Programming Joerg Meyer – DIG 1705

Scan Conversion 3 D Programming Joerg Meyer – DIG 1705

Scan Conversion 3 D Programming Joerg Meyer – DIG 1705

Line Drawing • Algorithm: – Draw a straight line between two points – Set

Line Drawing • Algorithm: – Draw a straight line between two points – Set all pixels along line to foreground color – Set all other pixels to background color 3 D Programming Joerg Meyer – DIG 1705

Line Drawing • Algorithm (Bresenham): 3 D Programming Joerg Meyer – DIG 1705

Line Drawing • Algorithm (Bresenham): 3 D Programming Joerg Meyer – DIG 1705

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color Seed

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color Seed point 3 D Programming Joerg Meyer – DIG 1705

Fill Algorithms • Flood Fill: – Start from seed point – Recursively fill neighboring

Fill Algorithms • Flood Fill: – Start from seed point – Recursively fill neighboring pixels if not contour pixels 3 D Programming Joerg Meyer – DIG 1705

Fill Algorithms • Flood Fill: – Start from seed point – Recursively fill 4

Fill Algorithms • Flood Fill: – Start from seed point – Recursively fill 4 neighboring pixels if not contour pixels Flood_fill (x, y, bg, fg) if (get_pixel(x, y) == bg) put_pixel(x, y, fg); Flood_fill (x+1, y, bg, fg); Flood_fill (x-1, y, bg, fg); Flood_fill (x, y+1, bg, fg); Flood_fill (x, y-1, bg, fg); 3 D Programming Joerg Meyer – DIG 1705

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color 3

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color 3 D Programming Joerg Meyer – DIG 1705

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color Problem:

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color Problem: • Narrow areas Solution: • Include diagonally connected pixels (8 neighbors) 3 D Programming Joerg Meyer – DIG 1705

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color 3

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color 3 D Programming Joerg Meyer – DIG 1705

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color Flood_fill

Fill Algorithms • Goal: – Fill all pixels inside contour with foreground color Flood_fill (x, y, bg, fg) if (get_pixel(x, y) == bg) put_pixel(x, y, fg); Flood_fill (x+1, y, bg, fg); Flood_fill (x-1, y, bg, fg); Flood_fill (x, y+1, bg, fg); Flood_fill (x, y-1, bg, fg); Flood_fill (x+1, y+1, bg, fg); Flood_fill (x+1, y-1, bg, fg); Flood_fill (x-1, y+1, bg, fg); Flood_fill (x-1, y-1, bg, fg); 3 D Programming Joerg Meyer – DIG 1705

Task 5. 1 • Goal: Implement recursive flood fill • Use Program. cs from

Task 5. 1 • Goal: Implement recursive flood fill • Use Program. cs from Homework 2 • Add function Color get_pixel (int x, int y, int size_x, int size_y, byte[] array); • Add function void flood_fill (int x, int y, int size_x, int size_y, Color bg, Color fg, byte[] array); • In Main function: – Comment out draw_line statements – Use same color for both gradient colors – Call: flood_fill (size_x/2, size_y/2, size_x, size_y, your_frame_color, your_fill_color, pixels); 3 D Programming Joerg Meyer – DIG 1705

Recap: Open. GL • Concepts – GL. Clear (Clear. Buffer. Mask mask) clears frame

Recap: Open. GL • Concepts – GL. Clear (Clear. Buffer. Mask mask) clears frame buffer and selects type, e. g. , Color. Buffer. Bit – GL. Matrix. Mode(Matrix. Modelview); GL. Load. Matrix(ref modelview); selects and loads transformation matrix – GL. Begin(Primitive. Type. Triangles); GL. Color 3(1. 0 f, 0. 0 f); GL. Vertex 3(-1. 0 f, 4. 0 f); GL. Color 3(1. 0 f, 0. 0 f); GL. Vertex 3(1. 0 f, -1. 0 f, 4. 0 f); GL. Color 3(0. 2 f, 0. 9 f, 1. 0 f); GL. Vertex 3(0. 0 f, 1. 0 f, 4. 0 f); GL. End(); creates a triangle – Swap. Buffers(); 3 D Programming Joerg Meyer – DIG 1705

Task 4 • Goal: Create Open. GL program • In Visual Studio, open "New

Task 4 • Goal: Create Open. GL program • In Visual Studio, open "New Project" dialog and select "Open Visual Studio Installer". • Under "Individual Components", find "Nu. Get Package Manager”. • Create new project called "Open. GL" • Open in Tools->Nu. Get Package Manager: Nu. Get Package Manager Console • At the prompt, type: Install-Package Open. TK -Version 2. 0. 0 • Overwrite “Program. cs” with “opengl. txt” from http: //tinyurl. com/dig 1705 3 D Programming Joerg Meyer – DIG 1705

Task 5. 2 • Goal: Add rotation to Open. GL program • Add the

Task 5. 2 • Goal: Add rotation to Open. GL program • Add the following declarations to the beginning of the Game class: float angle = 0. 0 f; static Vector 3 axis; • Add the following line to Main: axis = new Vector 3(0. 0 f, 1. 0 f, 0. 0 f); // y axis • Add the following lines to On. Render. Frame below GL. Load. Matrix(ref modelview); : GL. Translate(0. 0 f, 4. 0 f); GL. Rotate(angle, axis); GL. Translate(0. 0 f, -4. 0 f); angle += 1. 0 f; if (angle >= 360. 0 f) angle = 0. 0 f; 3 D Programming Joerg Meyer – DIG 1705

Questions? Joerg Meyer, Ph. D. Miami Dade College Wolfson Campus jmeyer 2@mdc. edu http:

Questions? Joerg Meyer, Ph. D. Miami Dade College Wolfson Campus jmeyer 2@mdc. edu http: //joergmeyer. ddns. net/COURSES/DIG 1705 3 D Programming Joerg Meyer – DIG 1705