3D Part3 CMT3317
Scene objects Some cheap world objects can be made with simple shapes like planes and transparency – like transparency is used in 2D Far away objects that the player will never be let near can be approximated by images or photos attached to planes
Fir tree This cheap fir tree is an image attached to a plane
Oak tree This slightly more complex example uses two planes Many other simple shapes can be used to make objects e.g. cones etc In the game the black areas need to be transparent
Class changes Since 3D step1 some classes have changed. The helper class() has been removed and simpleObject updated. It seem logical to revise the ship class to input handing is done in the main program The ship class now has function to rotate around each axis in a positive or negative direction – and to advance, retreat and reset its position.
Ship: rotation around the y axis – x and z are similar
Ship: advance, retreat, reset
Input handling Input handling is now done in Game1.cs
Simple object SimpleObject() is as it was but the functions … SetupEffectTransformDefaults() Draw() … have been moved out of the Helper Class and into SimpleObject()
SimpleBlendedObject() In order to use transparency we need to turn on alpha blending in the Draw() function We create a new class SimpleBlendedObject which is subclassed from SimpleObject and contains a draw function DrawBlendedModel()
DrawBlendedModel DrawBlendedModel() turns on alpha blending Draws as usual Then turns alpha blending off
Class SimpleBlendedObject
Objects with alpha blending
Billboarding A billboard is a plane with a texture on it that always rotates to face the camera so that the player never sees that it is just a plane We make a class BillboardObject which is a subclass of SimpleBlendedObject () The matrix class has a method to rotate the object based on the camera parameters: Matrix.CreateConstrainedBillboard()
Billboard: draw() and billboard() functions
The fir tree always faces the camera. See Step3_3D_Billboard.zip
Lighting problem One problem with billboarding is that the lighting of the object means that its brightness changes as it rotates To stop this we turn of lighting inside the SetupEffectTransformDefaults() function, so the Billboard class overrides the inherited version of this function
Beware of textures on plane Mathematically planes only have an inside and an outside - they are one sided -which means textured planes disappear when viewed from the wrong side, as with this red tree
MS example There is a nice example also at XNA creators club Its complex though, nearly all the work is done in the shader – it includes a wind model that appears to blow the trees and grass around http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Billboard-Sample.aspx
MS Example