Additional Examples


 

§         Line-Sphere Intersection:

o       Here is the source

o       Here is the accompanied diagram

 

Some of the following examples are based on older versions of the libraries. In all cases, the idea remains the same though.

1. Problem with Hardware Shading: Some examples of confusing hardware shading problems. (Download Source Code)

2. Drawing 2D and 3D in the same window: Pay attention to DrawOnlyHandler::DrawGraphics(), after we are done drawing 3D is where all the 2D stuff happens. (Download Source Code)

3. Working with 2D and 3D Windows: Check on 2D Control Window to see the 2D view of the 3D world. In the 2D window, you can LMB click and drag either the teapot or the plane. The 2D window is like a 2D plane for supporting UI.  (Download Source Code)

4. Shadow Reflection and Stencil: We will discuss this in class! (Download Source Code)

5. Interesting Texture Effects:

o        Draw textures: (here is the source code)

1.        TdrawTexture class: now sub-class from Ttexture ….

    1. CreateD3DTexture: creating a 2D array of number, _and_ creating something in the D3D pipe!!
    2. UpdateTexture: Copy our 2D array into the pipe!!
    3. DrawCircleInTexture: draw circle in the 2D array of number!!

2.        Tworld: for any primitive that we can display textures (primitives with area: i.e. Tfillable): we have these new attributes:

    1. Two DrawTextures: in the Tworld constructor, we need to pass in Td3dDrawable … why do we need to pass into two drawables?
    2. TdrawTexture::Update: notice in Tworld::Update(), we are calling the TdrawTexture update …

o        Bubble texture: (here is the source code): simple tiny changes in TdrawTexture::UpdateTexture(), now instead of simply copy my 2D numbers into the hardware … I did a little bit of a trick … floating my texture and enlighten things a little … ok, pretty lame bubbles, but kind of interesting isn’t it? Now .what if I can control what is in the buffer, such that …

 

o        Fire Texture: (here is the source code):

  1. TupwardEffect class: basically … take color (index) and smear it upwards decrease as we go ….
  2. TfireTexure and TsmokeTexture: different color table to get different effects.

 

6. Fog: purely based on distance to camera. If you have ore than one views, the result looks strange! (here  is the source code).

7. X-Ray-light: now we are really hacking! I will talk about this in class. (here is the source code).