Introduction to 3d

download Introduction to 3d

of 12

Transcript of Introduction to 3d

  • 7/31/2019 Introduction to 3d

    1/12

    INTRODUCTION TO 3D 3-D Coordinate System-The figure below shows three dimensional Cartesian coordinate system. This

    is called as right-handed system because right-hand thumb points in positive z direction.Most Graphics packages utilize right-handed system.

    RIGHT HAND CO-ORDINATE SYSTEM.

    Another possible arrangement is left handed system.

    Put fingers around the z axis and the thumb should point the positive direction of z axis. CYLIDRICAL-In this system, vertical cylinder with radius r is taken. The surface of the constant z is

    horizontal plane which will be parallel to x-y plane. The surface of constant is a vertical plane whichcontains z axis. Then x, y and z are given as,x = cos , y = rsin , z = z

    SPHERICAL -The surface of constant r is a sphere. The surface of constant is a vertical plane whichcontains z axis. The surface with constant is a cone which is having apex at origin. From the diagram,

    x = rcossin y = rsinsin z = rcos.

    3-D Display Techniques

    To obtain a display of three dimensional scene, we must set a view plane or display plane. The objectcoordinates are transferred to the display plane coordinates and are projected onto the display plane.

  • 7/31/2019 Introduction to 3d

    2/12

    Parallel Projection-One method of generating a view of solid object is to project points on the objectsurface along parallel lines onto the display planes. By selecting different viewing positions, different

    visible points are mapped onto the display plane to obtain different two dimensional views.

    The following diagram shows 3D object and its views from two different directions. The diagram showsthese directions and also the display planes.

    Perspective Projection -Another method for generating a view of three dimensional scene is to projectpoints to the display the plane along converging paths. In this method, the objects away from viewing

    position are displayed smaller than the objects of some size which are near to the viewing position.

    In perspective projection, parallel lines in a scene are not parallel on the display plane.This is morerealistic, because that is how our eyes understands any scene.

    Depth Cuing-Knowing the depth information of the object is important, because from this informationwe can decide which is front and which is back of the displayed object.

  • 7/31/2019 Introduction to 3d

    3/12

    From dia-a, it is difficult to decide whether the object is like dia-b or dia-c. In depth wing, the lineswhich are closer to view position are displayed with more intensity and lines away from view position

    are displayed with decreasing intensity. Depth cuing can be applied by deciding maximum and

    minimum intensity values.

    In depth wing, the lines which are closer to view position are displayed with more intensity and linesaway from view position are displayed with decreasing intensity. Depth cuing can be applied bydeciding maximum and minimum intensity values.

    Visible line and Surface identification-The visible lines and surfaces can be identified by thealgorithms. There are different methods to give 3D effects. Display visible lines in different color orhighlight them. Draw non-visible lines as dashed lines or simply remove non-visible lines. Applying

    shading to visible surfaces, also gives the appearance of removal of hidden lines without actually

    removing them.

    Surface Rendering -Realistic images can be obtained by shading different surfaces with differentintensities. Using Ray-Tracing, the shiny surfaces are displayed. The objects can be shown as shiny,

    transparent by illuminating objects with different styles.

    Cutway Views - The objects can be defined by hierarchical structures, so that, by cutting the object intodifferent pieces, the internal details of an object can be shown.

    Projections.-Once the worlds coordinates are converted into view coordinates then the threedimensional object can be projected onto two dimensional plane (view plane). There are two basic

    methods of projection.

    a) Parallel Projectionb) Perspective Projection

    a) Parallel Projection -In parallel projection, coordinate positions are transformed to a view plane alongthe lines which are parallel. A parallel projection can be defined with the projection vector Vp whichdefines direction of projection lines.

    If projection vector is perpendicular to view plane, then the parallel projection achieved is calledas orthographic parallel projection.

    Ifprojection vector is not perpendicular to view plane, then oblique parallel projection isachieved.

  • 7/31/2019 Introduction to 3d

    4/12

    The transformation equations for orthographic parallel projection are simple. If the view plane is placedat position Zvp along the Zv axis then (x, y, z) in viewing coordinates is transformed to projectioncoordinates as, xp = x yp = y zp = zvp.

    -However, original z coordinates are stored for depth information

  • 7/31/2019 Introduction to 3d

    5/12

  • 7/31/2019 Introduction to 3d

    6/12

  • 7/31/2019 Introduction to 3d

    7/12

  • 7/31/2019 Introduction to 3d

    8/12

  • 7/31/2019 Introduction to 3d

    9/12

    Sample jogl programThis program displays a simple 3D rendering of a polygon using JOGL. Please note though that this

    code is a demonstration of the use of JOGL and as such makes use of immediate mode drawingcommands, this serves to show how the conventional C style API is used through JOGL but you are

    strongly recommended to make use of modern OpenGL techniques.

    JOGLQuad classThis class uses the JOGL API (version 2.0) to render a polygon.

    import java.awt.Component;

    import java.awt.Frame;

    import java.awt.event.KeyEvent;

    import java.awt.event.KeyListener;import java.awt.event.WindowAdapter;

    import java.awt.event.WindowEvent;

    import javax.media.opengl.GL;

    import javax.media.opengl.GL2;import javax.media.opengl.GL2ES1;

    import javax.media.opengl.GLAutoDrawable;

    import javax.media.opengl.GLEventListener;

    import javax.media.opengl.awt.GLCanvas;import javax.media.opengl.fixedfunc.GLLightingFunc;

  • 7/31/2019 Introduction to 3d

    10/12

    import javax.media.opengl.fixedfunc.GLMatrixFunc;import javax.media.opengl.glu.GLU;

    import com.jogamp.opengl.util.Animator;

    public class JOGLQuad implements GLEventListener, KeyListener {

    float rotateT = 0.0f;

    static GLU glu = new GLU();

    static GLCanvas canvas = new GLCanvas();

    static Frame frame = new Frame("Jogl Quad drawing");

    static Animator animator = new Animator(canvas);

    public void display(GLAutoDrawable gLDrawable) {

    final GL2 gl = gLDrawable.getGL().getGL2();gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glClear(GL.GL_DEPTH_BUFFER_BIT);gl.glLoadIdentity();

    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    // rotate on the three axis

    gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);

    gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);

    // Draw A Quadgl.glBegin(GL2.GL_QUADS);

    gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quadgl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Leftgl.glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right

    gl.glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right

    gl.glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left// Done Drawing The Quad

    gl.glEnd();

    // increasing rotation for the next iteration

    rotateT += 0.2f;

    }

    public void displayChanged(GLAutoDrawable gLDrawable, boolean modeChanged, boolean

    deviceChanged) {

    }

    public void init(GLAutoDrawable gLDrawable) {

    GL2 gl = gLDrawable.getGL().getGL2();

    gl.glShadeModel(GLLightingFunc.GL_SMOOTH);gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    gl.glClearDepth(1.0f);

    gl.glEnable(GL.GL_DEPTH_TEST);

  • 7/31/2019 Introduction to 3d

    11/12

    gl.glDepthFunc(GL.GL_LEQUAL);gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);

    ((Component) gLDrawable).addKeyListener(this);

    }

    public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {

    GL2 gl = gLDrawable.getGL().getGL2();

    if (height

  • 7/31/2019 Introduction to 3d

    12/12