• Tidak ada hasil yang ditemukan

CS303 GameDev Practical 2 Rolling Dice, 2014

N/A
N/A
Protected

Academic year: 2025

Membagikan "CS303 GameDev Practical 2 Rolling Dice, 2014"

Copied!
2
0
0

Teks penuh

(1)

CS303 GameDev Practical 2   Rolling Dice, 2014 

Hand‐in deadline Wed September, 2pm.   (First Wednesday next term.) 

This prac is about drawing some primitive shapes, and manipulating them.  You'll need to create your  own vertices, triangles, and map a texture onto the faces.   This practical draws from chapter Chapter 9  of the textbook, and from the class lectures.  

Download the zip skeleton file from the prac folder.  It is built on the same framework / libraries as the  samples from the 3D lecture.  It adds an incomplete skeleton for a Die object, and has added a texture  for the dice to the RU_Content project.   At this stage it probably draws just one triangle on one face of  the die, without any texture.  

Download the zip exe file from the prac folder and run it.  This will give you a good idea of what your  final product should look like.  (Try the keys  ypr, fgh, t and the space bar). 

a) Read, understand, and fix so that the first side of the coloured die displays properly.   

 

b) Then turn it into a 6‐sided die with different colours on each face.    

 

c) Put textures on the faces of the die.   Do you know that opposite faces of a die always sum to 7? 

 

d) Make the fg, and h keys translate the object towards more positive X, Y, Z, by updating the die.    If  the shift key is down, reverse the movement direction.    

 

e) Similarly, use the ypr keys to add positive yaw, pitch and roll to the die.   If the shift key is down  reverse the direction.    

 

f) Provide a new controller keyboard key that can cycle between four viewing modes:  Colour fill,  Wireframe, TextureOnly, or Colour+Texture.     

Then do any one or more of the following 

extensions, or substitute your own extension that  interests you, and implement it.  

g) The term “Geometry instancing” means that although  you only have one mesh (geometry), you re‐draw it 

many times in different  positions in your scene, each  time transformed a little.  Each 

instance that you draw uses a different World matrix.   This is especially  useful if you need to draw a forest of trees, or a room full of I‐Robots or a  squadron of marching Dudes.   Draw a herd of dice (so what is the collective  noun for dice?) in your world, all at different positions, scales, or orientations.  

(2)

 

h) Provide a single key that triggers a "throw" of one die, by assigning some (random) initial rotational  momentum in each axis, and slowly reducing this momentum frame‐by‐frame until some lower‐

bound threshold.   

 

i) Add an initial position, near the camera, and get the die to move to some point near the origin, with  a random velocity.  Decay the velocity so that the die moves away from the viewer when thrown.    

Straight‐line motion without gravity is acceptable!      Hint: If you have a moveable camera, like the  orbit camera, one problem is to find out where the camera is, so that you can start the throw there  (or nearby).  Since the only things that define a camera are its View and Projection matrices, we  need a way to get the world position from the camera’s View.  The View matrix transforms from our  World to Camera Space.  In camera space, the camera is at its own origin.  So we have this identity        (0,0,0) ==  CamPos * theCam.View       

All you need to do is to solve for CamPos.  If you can do the inverse of that transform, you can find  out where the camera is, in World coordinate space.    So it becomes just one line of code 

        Vector3 camPos = Vector3.Zero * Matrix.Invert(theCam.View)

(remember how the Zero vector is padded to become (0,0,0,1) before multiplication by a matrix?)  An alternative but equivalent one‐liner is  

Vector3 camPos =  Matrix.Invert(theCam.View).Translation;    

 

j) After motion, perhaps add gravity.  Can you collide the die with the table, and make it bounce? 

 

k) Can you settle the die flat on the table? (One face should settle on the XZ grid).  (Quite challenging  perhaps, but lots of fun and certainly your lecturer's favourite!) 

 

l)  The BasicEffect class (even in XNA3) 

provides for up to three directional  lights, and for giving the whole  scene an ambient light colour, or  some spectral lighting.  Can you add  some secondary lighting effect to  your scene to give your scene  something extra?    A metallic look?  

An appearance as if it is in a casino  setting?  Perhaps some fog effect if  it is a really smokey casino, or disco 

strobe spotlighting.   You might need to add normals to the vertexes to do some of this.  (Turning  scene strobe lights on and off rapidly may also cause discomfort and epilepsy!  But for some  computer scientists, an epileptic fit may not be noticeably 

different from their normal behavior.)   

m) Investigate making some 3D dice that are viewable with  these … 

Referensi

Dokumen terkait