Syracuse University 3D Framework using GDI+.Net Carmen Vaca Ruiz Independent Study Fall 2004 Instructor: Dr. Jim Fawcett.

Slides:



Advertisements
Similar presentations
Computer Graphics Prof. Muhammad Saeed Dept. of Computer Science & IT Federal Urdu University of Arts, Sciences and Technology.
Advertisements

2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
Lecture 5 Rendering lines 1.Steps of line rendering 2.Scan-conversion for line segments 3.A1 tutorial CP411 Computer Graphics Fall 2007 Wilfrid Laurier.
Introduction to shapes
Lecture Fall 2001 Visibility Back-Face Culling Painter’s Algorithm.
User Interface Programming in C#: Graphics
CS 4363/6353 INTRODUCTION TO COMPUTER GRAPHICS. WHAT YOU’LL SEE Interactive 3D computer graphics Real-time 2D, but mostly 3D OpenGL C/C++ (if you don’t.
Computer Graphics - Class 14
, Fall 2006IAT 800 Lab 2: Polygons, Transformations, and Arrays.
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
CS 450: Computer Graphics 2D TRANSFORMATIONS
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Graphics Images – PictureBox control Drawing graphics - Graphics object Multimedia controls PictureBox control Image property – select image Choose how.
Computer Graphics Prof. Muhammad Saeed. Drawing and Transformation of Figures in C# August 1,
1 Chapter 26 D&D – Graphics Outline 26.1 Introduction 26.3 Graphics Contexts and Graphics Objects 26.4 Color Control 26.5 Font Control 26.6 Drawing Lines,
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Whiteboardmaths.com © 2011 All rights reserved
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
COMP 175: Computer Graphics March 24, 2015
CST238 Week 5 Questions / Concerns? Announcements – HW#1 due (Project ideas) – Check-off Take Home lab#4 Recap New topics – Drawing Coming up: – GUI Bloopers.
CSE 381 – Advanced Game Programming Basic 3D Graphics
1 Windows Graphics. 2 Objectives You will be able to Use the Windows GDI+ to draw arbitrary figures and text on a Windows form. Add a handler for the.
C# Programming Lecture 4 “GDI+” PGL01/CSP/2006.
Graphics and Multimedia Part #2
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
2D Graphics: Rendering Details
Introduction to Flash. Topics What is Flash? What can you do with it? Simple animation Complex interactive web application, such as an online store. Starting.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
CAP4730: Computational Structures in Computer Graphics 3D Transformations.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Digital Media Dr. Jim Rowan ITEC So far… We have compared bitmapped graphics and vector graphics We have discussed bitmapped images, some file formats.
1 Graphic Device Interface (GDI). 2 Class Form A Form is a representation of any window displayed in your application. The Form class can be used to create.
Computer Graphics Rendering 2D Geometry CO2409 Computer Graphics Week 2.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
1 OGRE Programming Intermediate Tutorial: Volume Selection.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
Fall UI Design and Implementation1 Lecture 6: Output.
Digital Media Dr. Jim Rowan ITEC Vector Graphics Elegant way to construct digital images that –have a compact representation –are scalable –are.
Rendering Pipeline Fall, D Polygon Rendering Many applications use rendering of 3D polygons with direct illumination.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
Coordinates and Design. What You Will Learn: To use ordered pairs to plot points on a Cartesian plane To draw designs on a Cartesian plane To identify.
In the last several lessons, you have described translations using coordinates. You have also developed strategies for determining where an object started.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Introduction to Computer Graphics
Visible Surface Detection
Flash Interface, Commands and Functions
Polygons, Transformations, and Arrays
Building Java Programs
Graphics and Multimedia
Basic Graphics Drawing Shapes 1.
CASE Tools Graphical User Interface Programming Using C#
Digital Media Dr. Jim Rowan ITEC 2110.
Transformations for GCSE Maths
Transformations for GCSE Maths
Presentation transcript:

Syracuse University 3D Framework using GDI+.Net Carmen Vaca Ruiz Independent Study Fall 2004 Instructor: Dr. Jim Fawcett

Syracuse University Objective The implementation of a 3D framework using C# gives us a combination for a promising application There are 4 main topics to cover: 3D Objects as a collection of points Perspective Transformations Lighting Sphere construction using a triangle mesh Implementation will use... GDI+

Syracuse University.NET GDI+ GDI+ provides.NET developers with a simple-to-use wrapper around the graphics services provided by Windows. The Graphics class provides the most important object you'll encounter when working with GDI+. With it you can draw: Lines Ellipses Rectangles Pollygons: filled with some given color In addition to the Graphics class, we have Pen Brush, and Font classes. Each of these classes provides members that let you draw and fill shapes.

Syracuse University.NET GDI+ Where do we get a graphics object? Graphics g = this.CreateGraphics(); The graphics object holds a resource managed by Windows. We are responsible for releasing the resource (even when an exception ocurrs) try{ g.DrawEllipse(... } finally{ g.Dispose(); } Let’s use C# facilities for this: using( Graphics g = this.CreateGraphics() ) { g.FillEllipse(Brushes.DarkKhaki, 30, 30, 130,90); } // g.Dispose called automatically here

Syracuse University.NET GDI+ : The Paint event After we’ve got the Graphics resources managed properly, we have another issue Cover and Uncover the form Resizing the form Windows asks a forms to redraw newly content via the Paint event, which provides a PaintEventArgs argument private void Form_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics;... } Demo ….

Syracuse University.NET GDI+ : Resizing What happens when we resize the form? Demo …. Luckily, you can set a style to request that Windows redraw the entire form during a resize: this.SetStyle(ControlStyles.ResizeRedraw, true);

Syracuse University.NET GDI+ : Y coordinates The origin of the coordinates in GDI+ is located in the left upper corner of the screen. Thus, any y-coordinate is measured from top to bottom. GDI+ provides transformations in 2D that we can use to avoid changing the sign of y-coordinates. g.Transform = new Matrix(1, 0, 0, -1, 0, 0); g.TranslateTransform(0, ClientRectangle.Height, MatrixOrder.Append);

Syracuse University.NET GDI+ : Y coordinates

Syracuse University.NET GDI+ : Origin position The position of the origin should be in the center of the screen We can use GDI+ transformations float width = this.ClientRectangle.Width/4; float heigth = this.ClientRectangle.Height/2; g.TranslateTransform(width, heigth);

Syracuse University 3D Framework

Syracuse University Module Diagram

Syracuse University Important Modules Description 3DRepresentation Module This module provides the definition of classes that represent points, shapes and objects in three dimensions. The classes will be defined in an incremental way. This approach will be useful when we apply transformations Transformation Module The transformation module contains most of the math involved for 3D Projection Translation Scale Rotation Sorting Module The 3D objects will be rendered using Painter’s algorithm. We need a module to sort the objects. The closer objects will be drawn first.

Syracuse University Class Design

Syracuse University Class Design: Triangle Shape TriangleShape derives from Shape. The triangle class will be useful in building a sphere. This class override can override the method Draw of the base class by defining a particular way of rendering the triangle. Light effects can be obtained by getting the angle between the triangle normal and the Light coordinates. The color is determined according to the angle.

Syracuse University Transformations Transformations defined in 3D are: Projection Rotation Translation Scale The transformations allow us to move, rotate, scale objects in 3D. Transformations are propagated from objects to shapes to coordinates3D We’ll see this again later!!!

Syracuse University Projections Once we define a class to represent an object in 3D, we need to draw it in the screen, but The screen is a 2D device. How do we get a 3D object represented in a 2D screen? Here we need the first transformation defined in the 3D world: Projections. If we project all the vertices of an object, we get the 3D representation we are looking for.

Syracuse University Projections How does a point in 3D look like in our program? square = new Shape(new Coordinates3D[]{ new Coordinates3D(30.0f, 0.0f, 0.0f), new Coordinates3D(30.0f, 0.0f, 30.0f), new Coordinates3D(60.0f, 0.0f, 30.0f), new Coordinates3D(60.0f, 0.0f, 0.0f), new Coordinates3D(30.0f, 0.0f, 0.0f) }); Projection transformation takes a (x, y, z) point and returns its representation in 2D

Syracuse University Projections : some math Simple projection: Z=0

Syracuse University Projections : some math Project again from (x,y) to (xp, yp) Is it z involved in the new projection?

Syracuse University Projections : some math z is there !!! Connect original and projected point: Betha will help us!

Syracuse University Projections : Cabinet Projection Coordinates3d my3DPoint;... Projection project = new Projection(); PointF pointProjected = project.transform(my3DPoint) Cabinet Projection Lambda= 0.5 Alpha =30, 60

Syracuse University When do we apply the projection? Remember that transformations are propagated from objects to shapes to points: Pen aPen = new Pen(linesColor, 1); Projection project = new Projection(); for (int i = 0; i < Corners.Count-1; i++) { g.DrawLine(aPen, project.transform(((Coordinates3D)Corners[i])), project.transform(((Coordinates3D)Corners[i+1]))); }

Syracuse University Rotation We can rotate objects by transforming all the points belonging to it. We can derive the equations to rotate objects around any of the axis.

Syracuse University Spheres GDI+ provides a library for drawing in 2D There are not primitives to draw a 3D object ( this includes spheres!) Our sphere object will be built using triangles. To get a good approximation the vertices of the triangles should be points in the sphere surface

Syracuse University Spheres Parametric equations of the sphere are a useful representation for our purposes

Syracuse University Spheres Rotating phi and theta we can get the vertices for the triangles on the sphere surface

Syracuse University Again: Triangle Shape TriangleShape derives from Shape. The triangle class will be useful in building a sphere. Using the Draw method provided by Shape we will get a wireframe figure. We can, instead draw the triangle by using the FillPolygon function provided by GDI+. Projection project = new Projection(); PointF[] vertex = { project.transform(p1),project.transform(p2), project.transform(p3),project.transform(p1) }; Brush br = Get a new brush g.FillPolygon(br, vertex);

Syracuse University Light How can we add light effects Triangles again!!! Easy method: Obtain 2 vectors using the vertices of the triangle Obtain the normal of the plane given by those vectors Obtain the center of the trianle Define a line between the center of the triangle and the light source (L) Obtain the angle between the normal and L Set the brightness of the triangle color according to the angle

Syracuse University Light

Syracuse University Light

Syracuse University Light

Syracuse University Setting the color There is an issue with setting the color according to the light in GDI+ GDI+ provides functions to generate colors using RGB scheme. However, this scheme will give us different scales of gray. We need to use a piece of code to setup the brightness of the color instead: Color myColor = Color.FromArgb((int)dot1,(int)dot1,(int)dot1); Color myColor = HSL.SetBrightness(Color.FromArgb(_r,_g,_b), dot0);

Syracuse University Setting the color

Syracuse University Setting the color

Syracuse University Representing spheres, using light

Syracuse University Representing spheres, using light

Syracuse University Representing spheres, using light

Syracuse University References Dr. Fawcett guidance howto_p.html