Issue dated - 2nd August 2004

-


Previous Issues

CURRENT ISSUE
INDIA NEWS
NEWSANALYSIS
COLUMNS
TECH FORUM

THE C# COLUMN

BETWEEN THE BYTES
TECHNOLOGY
SPECIALS <NEW>
Symantec Report
Security Headquarters
JobsDB
MINDPRINTS
HMA BANKBIZ
EC SERVICES
ARCHIVES/SEARCH
IT APPOINTMENTS
Openings At Jobstreet.com
WRITE TO US
SUBSCRIBE/RENEW
CUSTOMER SERVICE
ADVERTISE
ABOUT US

 Network Sites
  IT People
  Network Magazine
  Business Traveller
  Exp. Hotelier & Caterer
  Exp. Travel & Tourism
  Exp. Pharma Pulse
  Exp. Healthcare Mgmt.
  Express Textile
 Group Sites
  ExpressIndia
  Indian Express
  Financial Express

 
Front Page > TechSpace > Story Print this Page|  Email this page

The C# Columun

DirectX 3D Basics - I

DirectX is an immensely powerful library that supports multimedia programming. The new version of this library, known as DirectX 9.0 provides multimedia functionality for managed applications. DirectX 9.0 supports managed languages like C#, Visual Basic.NET, VC++.NET and JScript.NET.

Components

DirectX 9.0 for Managed Code provides following components

DirectDraw – Provides pixels drawing support. Enables direct access to video memory, specially used for high-speed rendering.

Direct3D – Used for 3-D graphics programming. It internally uses DirectDraw.

DirectSetup – Used to detect whether DirectX is installed on the user’s machine. It contains set of functions that can be used to install DirectX. It eases the installation of the complex DirectX components.

DirectShow – Used for playback of multimedia streams and media capture. It supports a wide variety of formats (ASF, MP3, etc). It automatically detects and uses video and audio acceleration hardware when available.

DirectMusic – Used to load and play music from different sources.

DirectInput – Used for programming with various input devices. It is used to handle the data coming from mouse, keyboard, joysticks and other game controller devices.

DirectPlay – Used for creating network applications like multiplayer games. It abstracts all the complications for connecting/disconnecting users, sending/receiving messages, managing sessions, etc.

DirectSound – Used for capturing sounds from input devices and playing sound through playback devices.

Direct3D Concepts

We will start our journey through DirectX 9.0 by understanding the terms and concepts involved in it.

Direct3D uses a left-handed Cartesian coordinate system. The values on the x-axis increase from left to right. The values on the y-axis increase from bottom to top and the values on the z-axis increase from back to front. This is shown in the following figure.

Consider your left hand with the palm up as shown in the above figure. Then the thumb would represent the z-direction, which is traveling away from the body.

In the left handed coordinate system we can position 3D objects in one of the three different types of space coordinates.

Model Space: Suppose we are drawing different 3D entities like a cube, a sphere, a pyramid etc. Each such object can be called a model. In the model space each such model has a different origin.

World Space: In the world space there is a fixed origin. The world transformation matrix changes coordinates from model space, where vertices are defined relative to a model’s local origin to world space where vertices are defined relative to an origin common to all the objects in a scene. In essence, the world transformation places a model into the world and hence its name.

Camera Space (View Space): This view of the world places the viewer (user) at the origin and faces him or her in the direction of the positive z-axis. The view matrix is used to transform vertices from the world space to the Camera space. Following figures depict these three spaces.

Let us now take an example and combine these three spaces together. If we want to spin two cubes the first thing that we need to do is create the two cubes using the model coordinates. In the above figure for depicting the model space the two cubes have their own coordinate separate coordinate systems. We have placed both the cubes at origin in their respective coordinate systems. Then using the world transformation matrix we place the cubes into the world space. The origin of the model space and world space may be same or different. (In the above example the origin of the model space and the camera space are the same).

Then we have translated the cube 2 in the world space using transformations because had we done that the two cubes would have got overlapped. Note that the camera is placed at (-200,100) in the world space. In the world space, to rotate scale and translate the cube various transformation matrices are used. Next to look at the cube we have to indicate the position of the eye/camera in the world space. When we do so the origin of the world space is mapped to the eye position (Camera space origin). Due to this the camera or the eye is placed at the origin and the two cubes are reoriented with respect to the camera. Now if we display the cubes on the screen they would hardly appear like real cubes. To make the cubes appear more realistic we need to make some more effort.

There are two facts involved when a human eye sees an object:

(a) A human eye sees what falls in the conical volume as shown in the following figure.

(b) That part of the object that is nearer to the eye appears bigger than the part that is farther away from it. This way of looking at an object is known as perspective projection.

To be continued…

Yashavant Kanetkar, one of the first Express Computer columnists, is an established software expert, speaker and author with several best-sellers to his credit, including titles like “Let Us C” and the “Fundas” series. Contact him at kanetkar@dcubesoft.com
<Back to top>


© Copyright 2003: Indian Express Group (Mumbai, India). All rights reserved throughout the world. This entire site is compiled in
Mumbai by The Business Publications Division of the Indian Express Group of Newspapers.
Please contact our Webmaster for any queries on this site.