Z-buffer and Shading

Dec 26 2022 Computer Graphics Course Project C++ OpenGLUT

There are many test data in the forder and many input commands in each test data. I read the files and complete the following instructions. Otherwise, the program would delete the graphic that is backward from camera.

🔗 See more details here.

Operating instructions

  • Read the file:

    Read file with command line name + lab4X.in.

  • The instruction is Width Height
    In the head of the files will give 2 integrals that represent the windows’ width and height respectively.

  • Comment:

    The instruction is # ......
    If # appears, skip the line. (i.e. You don’t need to execute the line which # appears.) 

  • Reset:

    The instruction is reset
    Reset the transformation matrix.

  • Translate:

    The instruction is translate x y z
    x means moving along x-axis by x unit.
    y means moving along y-axis by y unit.
    z means moving along z-axis by z unit.

  • Scale:

    The instruction is scale x y z
    x means scaling along x-axis by x unit.
    y means scaling along y-axis by y unit.
    z means scaling along z-axis by z unit.

  • Rotate:

    The instruction is rotate x y z
    x means rotating along x-axis by x degree.
    y means rotating along y-axis by y degree.
    z means rotating along z-axis by z degree.
    The rotating part should be implement in the order of y-axis -> z-axis -> x-axis.

  • Clear data:

    The instruction is clearData or cleardata
    Clear the objects that you read from .obj file.

  • Clear screen:

    The instruction is clearScreen
    Clear the screen.

  • Observe:

    The instruction is observe epx epy epz COIx COIy COIz Tilt Hither Yon Hav

    Set the camera’s parameter:

    1. epx epy epz are the x y z position of the camera.
    2. COIx COIy COIz are the point that the camera look at.
    forward = COI - ep
    
    1. Tilt is the angle that the camera tilt.
    2. Hither Yon are the near plane position and far plane position.
    3. Hav is field of view.

    By i ~ iii, I can get View matrix. By iv ~ v, I can get Projection matrix.

  • Viewport:

    The instruction is view vxl vxr vyb vyt
    Since the perspective divide, all graphic will lies in [-1, 1] X [-1, 1].
    -1 1 -1 1 means the left, right, botton, top boundary after perspective divide.
    vxl vxr vyb vyt means the left, right, botton, top boundary of viewport after perspective divide.

    In math words

      f(-1, 1) = (0, Width)
      f(-1, 1) = (0, Height)
    

    where it is a linear transformation.
    The objects outside the viewport boundary need to clipped.
    Need to display the graphic in display.

  • Object:

    The instruction is object **.obj Or Og Ob Kd Ks N
    **.obj means the name of the files. Please load the document into your code and also slice square into triangles.
    Or Og Ob are the color of the object, using the color space RGB.
    Kd is the parameter diffuse.
    Ks is the parameter specular.
    N is gloss.

  • Display:

    The instruction is display
    Do the clearScreen when display is occured.
    Use flat shading to rendering.
    Add fgetc(stdin); when display.

  • Background:

    The instruction is background Br Bg Bd
    Br Bg Bd are the background color.

  • Ambient:

    The instruction is ambient KIr KIg KIb
    KIr KIg KIb are the parameter of ambient light. 

  • Light

    The instruction is light index Ipr Ipg Ipb Ix Iy Iz
    index is the light of number index.
    Ipr Ipg Ipb are the color of light.
    Ix Iy Iz are the position of the light.
    Both use point lights.

  • End:

    The instruction is end
    Destory the window.

  • Bonus function: (haven’t finish yet)

    Use the blinn phong to calculte the direction light.
    Use the Gourand Shading to rendering.

Results