Vous êtes sur la page 1sur 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 which contains 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 which contains 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 object coordinates are transferred to the display plane coordinates and are projected onto the display plane.

Parallel Projection-One method of generating a view of solid object is to project points on the object surface 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 shows these directions and also the display planes.

Perspective Projection -Another method for generating a view of three dimensional scene is to project points 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 more realistic, because that is how our eyes understands any scene. Depth Cuing-Knowing the depth information of the object is important, because from this information we can decide which is front and which is back of the displayed object.

From dia-a, it is difficult to decide whether the object is like dia-b or dia-c. In depth wing, the lines which 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 lines away from view position are displayed with decreasing intensity. Depth cuing can be applied by deciding maximum and minimum intensity values. Visible line and Surface identification-The visible lines and surfaces can be identified by the algorithms. There are different methods to give 3D effects. Display visible lines in different color or highlight 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 different intensities. 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 into different pieces, the internal details of an object can be shown. Projections.-Once the worlds coordinates are converted into view coordinates then the three dimensional object can be projected onto two dimensional plane (view plane). There are two basic methods of projection. a) Parallel Projection b) Perspective Projection a) Parallel Projection -In parallel projection, coordinate positions are transformed to a view plane along the lines which are parallel. A parallel projection can be defined with the projection vector Vp which defines direction of projection lines. If projection vector is perpendicular to view plane, then the parallel projection achieved is called as orthographic parallel projection. If projection vector is not perpendicular to view plane, then oblique parallel projection is achieved.

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

-However, original z coordinates are stored for depth information

Sample jogl program This 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 drawing commands, 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;

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 Quad gl.glBegin(GL2.GL_QUADS); gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left gl.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);

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 <= 0) { height = 1; } float h = (float) width / (float) height; gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(50.0f, h, 1.0, 1000.0); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); } public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { exit(); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } public static void exit() { animator.stop(); frame.dispose(); System.exit(0); } public static void main(String[] args) { canvas.addGLEventListener(new JOGLQuad()); frame.add(canvas); frame.setSize(640, 480); frame.setUndecorated(true); frame.setExtendedState(Frame.MAXIMIZED_BOTH); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { exit(); } }); frame.setVisible(true); animator.start(); canvas.requestFocus(); }

public void dispose(GLAutoDrawable gLDrawable) { // do nothing } }

Vous aimerez peut-être aussi