Direct3D (DirectX 9.0) Code Samples - Page 10

High Dynamic Range Texture Loader
 

This sample demonstrates how to load a .hdr or "light probe" image file (High Dynamic Range) as a Direct3D texture.

The sample also demonstrates how to use a vertex and pixel shader to perform tone-mapping on the fragment colors generated by the HDR texture, so they can they can be rendered on low-dynamic display devices like CRTs and LCD panels.

Relevant Keywords: D3DXCreateEffectFromFile, SetTechnique, SetTexture, SetFloat, Begin, End, BeginPass, EndPass, RGBE_ReadHeader, RGBE_ReadPixels_RLE, rgbe_header_info, D3DXCreateTexture, LockRect, UnlockRect,  float4x4, texture, sampler_state, technique, pass, compile, ps_2_0, tex2D, LPD3DXEFFECT, D3DLOCKED_RECT, LPD3DXBUFFER, and D3DFMT_A16B16G16R16F.

Solid Node BSP Tree Compiler
 

One method of speeding up a game engine is to use a BSP-Tree (Binary-Space Partitioning Tree) to subdivide and sort your game's world geometry.

This is done by dividing up, sorting, and storing polys in a BSP Tree in a such as way as to denote their relationship to one another (i.e. being in front of or in back of another poly). Once the BSP tree is compiled or built, the engine can quickly decide whether or not it should render certain polys based on the view’s current location within the world.

For example, the BSP compiler in this sample demonstrates how early game programmers, who didn't have hardware accelerated z-buffers, used a simple solid-node style BSP tree to sort their scene polys into a back-to-front order for proper rendering. The sample also demonstrates how a BSP Tree can be used for collision detection by identifying whether or not a unobstructed line-of sight can be established between two 3D points.

Unfortunately, the code doesn't go into a lot of BSP Tree theory or teach the basics, so if you're new to the concept of a BSP Tree, check out this cool little Java Applet for a real-time demonstration of how they work.

This sample is based on one of the BSP demos that came with the "Advanced 3D BSP, PVS and CSG Techniques" course offered at GameInstitute.com. If you're truly interested in learning about BSP trees and how they're used in games, this course is the best by far and I highly recommend it.

Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: CreateDevice, SetSamplerState, SetDataFormat, GUID_SysMouse, SetCooperativeLevel, Acquire, Unacquire, GetDeviceState, DrawIndexedPrimitiveUP, D3DXVec3Dot, DISCL_NONEXCLUSIVE, DISCL_FOREGROUND, LPDIRECTINPUT8, LPDIRECTINPUTDEVICE8, D3DXVECTOR3, DIERR_INPUTLOST, DIMOUSESTATE2, D3DSAMP_MIPMAPLODBIAS, D3DSAMP_MAGFILTER, D3DSAMP_MINFILTER, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR, D3DFMT_INDEX16 and DIRECTINPUT_VERSION.

 

2D Demo Game of a Side-Scrolling Shooter
 

Re-live such classic side-scrolling shooters as Gradius and R-Type by writing your own. Of course, this sample is a far cry from a fully featured side-scroller, but it will definitely put you on the right track. Check out the DirectX 8.1 source code page for the DirectX 8.1 code equivalent of this sample.

 

Simple Introduction to the NovodeX Physics SDK
 

This sample demonstrates how to use the NovodeX Physics SDK by simply creating and dropping boxes on to a plane that represents the ground. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: NxPhysicsSDK, NxScene, NxVec3, ErrorStream, NxCreatePhysicsSDK, setMaterialAtIndex, createScene, shapes.pushBack, createActor, NX_BROADPHASE_COHERENT, release, releaseScene, NxBodyDesc, NxBoxShapeDesc, NxActorDesc, createActor, userData, getNbActors, getActors, getGlobalPose, getColumnMajor44, flushStream, and fetchResults.

 

How to use the Tokamak SDK to Create a Rope or Chain using Ball-Joints
 

This sample demonstrates how to use the Tokamak Physics SDK to create a chain or rope like object by using small collision cubes joined by ball-joints. For demonstration purposes, the chain is dropped onto a platform, which doesn’t quite catch all of it. This allows the chain to hang off and swing about. For fun, you can use the F1 key to lift up on the chain's last segment by applying some velocity to it. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant Keywords: neSimulator, neRigidBody, neAnimatedBody, neSimulatorSizeInfo, neBoxInertiaTensor,  neJoint, neGeometry, CreateSimulator, CreateRigidBody, AddGeometry, SetBoxSize, CollideConnected, UpdateBoundingInfo, SetInertiaTensor, SetMass, SetJointFrameWorld, SetType, SetEpsilon, SetIteration, Enable, and GetTransform.