CSS 450: Programming Assignment #4

Deep dive into WC and Viewport

 

Due time: Please refer to our course web-site

 

Objectives

This assignment aims at letting your practice with working with the World Coordinate (WC) and the Device (or Canvas, or Pixel) Coordinate (DC) systems. We will gain understanding of these systems by transforming positions between them. In addition, we will experience a little with direct user manipulation.

 

Note: The number of lines of code required for this assignment is not large, but you must understand the system we are working with, the math for transformation, and the GUI binding. Make sure you understand what you are doing!

 

Approach

You will build a web-site with a user interface as in Example 5.5 from our class examples. You will implement a SquareArea class to support functionality of drawing and manipulating rectangular areas in WC space. You will create two instances of the SquareArea class to show the positions of the WC‑Window and to show the bounds of the Viewport-Region of the SmallView. For example the following screenshot shows the area viewed by the SmallView WC-Window in white and bounds the Viewport-Region in blue.

The WC-Window and Viewport-Region must respect the GUI slider settings. This is to say, when the user adjust the corresponding slider bars. For example, if the adjusts the WC-Width slider bar, the white WC-Window SquareArea should update its size as the slider bar moves. As a policy, when the Viewports width/height adjusts, the WC-Window dimension must also change proportionally. This is to say,

         When viewport-width/height increases by dw%

o    WC-width/height should also increase by dw%

         When viewport-width/height decreases by dw%

o    WC-width/height should also decrease by dw%

 

Direct user manipulation: you will experience with direct user manipulation in the moving of the WC-Window. When user LMB-click on the center position of the WC-Window, the red square in the middle of the white WC-Window as shown in the above screen shot, she will grab the WC-Window, subsequent LMB-drag will drag the WC-Window causing the white WC-Window to follow the mouse pointer until LMB is released. In your implementation:

         You can define a successful grab as a LMB-click position that is within 5 WC-units away from the middle position of the WC-Window.

         You must bind the WC-Window position changes to the GUI slider-bar update.

 

The following is a screen shot of the WC-Window and Viewport-Region after some user manipulations.

Notice that:

         The aspect ratio of the WC-Window always respects and follows that of the Viewport-Region.

         The GUI WC-CX/CY slider bar is always consistent with the current WC-Window center position. Make sure you bind these GUI elements to the direct user manipulations.

         Drawing order: the SquareArea is essentially drawn last, after the drawing of the mView and mSmallView! This is to say, in the MainController, the drawing order is essentially:

o    myWorld.draw(mView)

o    myWorld.draw(mSmallView) so that the small view is drawn over the mView

o    draw the two SquareArea this can be tricky! Because you want to draw to the mView, and yet the current webgl-viewport is set to that of the mSmallView.

  Think about this!

  You must set the webgl-viewport to that of the mView before you draw the two SquareAreas.

 

Simple APP behavior: When LMB-click does not successfully grab the WC-Window, you must support a simple application behavior just like that of Example 5.5 (LMB-click drag to create rectangles with random color).

 

 

Hints:

         My implementation is based on Example 5.6.

         I took the GUI definition (index.html and relevant MainControler.js) and merged in the ClassExample behavior from Example 5.5.

         My SquareArea is a subclass of the SceneNode class as introduced in Example 5.6.

o    I draw the bounds of the SquareArea as four narrow rectangles with initial width/height of 0.02 WC-unit.

         I defined a new class: ViewManipulator to implement the WC-Window and Viewport-Region functionality.

o    My ViewManipulator::draw() function literally reach into the mView and change the webgl-viewport using the mViews viewport setting.

 

 

Credit Distribution

Here is how the credits are distributed in this assignment:

 

1.

Simple LMB-Click and drag behavior of Example 5.5

 

5%

a.    Ability to draw multiple rectangles with random color

5%

2.

Proper display of WC-Window

 

20%

 

 

 

 

a.    Position is properly controlled by the GUI slider bars

b.    Width is properly controlled by the GUI slider bar

c.     Viewport-Region properly updated when WC-Window changes

 

Note: only showing a white SquareArea with no connection to mSmallView WC window will receive 0 credit.

10%
10%

10%

3.

Direct User Manipulation of WC-Window Location

 

30%

 

a.    Able to grab and move the SquareArea shape

b.    Properly update WC-Window as SquareArea moves

c.     Properly update GUI-slider bars as SquareArea moves

d.    Properly update ViewportRegion as SquareArea moves

10%

5%

5%

10%

4.

Proper display of ViewportRegion

 

30%

 

a.   Position is properly controlled by the GUI slider bars

b.   Width/Height is properly controlled by the GUI slider bars

c.    WC-Window width/height updates accordingly

 

Note: only showing a blue SquareArea with no connection to mSmallView Viewport region will receive 0 credit.

 

10%

10%

15%

5.

Proper drawing order

 

10%

 

 

 

a.    The two SquareArea drawn last (where the center pivot positions of both are visible)

10%

7.

Submission:

 

5%

a.    proper zip file and project name

b.    No useless files submitted

 

 

 

Extra Credit:

 

Make sure your extra efforts are related to this assignment: examples:

         20pt: SquareArea bound size. Notice my SquareArea bounds changes sizes as you scale the area. This looks ugly.

         Support direction user manipulation on others:

o    20pt: mouse click on WC-Window some location and change size of WC window. Notice this is rather tricky to implement as while change size, you MUST respect the aspect ratio of the Viewporr-Region

o    20pt: mouse click on Viewport-Region some location and move the Viewport-Region accordingly. This is, again tricky. You need to comfortably transform from WC back into DC.

o    20pt: mouse click on Viewport-Region some location and scale the Viewport-Region. Again, WC to DC transform is necessary here.

 

This programming assignment will count 12% towards your final grade for this class.