Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Graphics Expert

1. Relative positioning of Objects in a Window

The program should draw a rectangle at the middle of the screen when started. The program could maintain a "relative" positioning of the object when resized.

For illustration, when the program is first executed, the figure is drawn at the center of the window, e.g., at 200, 200 with a 400 x 400 window. If the window is resized to, e.g., 600 x 600, the figure should remain at the center ( ½ x and ½ y ), now, 300 x 300. That is, the figure's position have to be relative to the area displayed by the window. A figure positioned at the center of a window will remain at the center of the window (rather than at the same x, y coordinates), even when the window is resized, and, hence, the client area size changes. Similarly, a figure at, e.g., x center and ¼ of the y size when the window size is changed will remain at those relative positions with any size windows, e.g., at 150, 100 with a 300 x 400 window will be 75, 50 when resized to 150 x 200. Note that resizing typically will not be symmetric for x and y change, which is fine, just have the same relative positions for the fig-ure's x and y.

2. Clicking and Dragging

The user should be able to "drag" the figure (object) anywhere on the screen by "mousing down", i.e., depressing and holding down the left mouse button, in the object and then moving the mouse.

The object in essence "follows" the cursor, as long as the left button is pressed down. This is accomplished by re-peatedly drawing and erasing the object as the mouse position moves. Erase only the object, vs. the entire client area. Again, when the object is dragged, feedback about its position is to be given to the user, i.e., it is repeatedly repositioned as the mouse cursor moves. Also, when it is selected and being dragged, feedback to the user is to be given to the user that is has been selected, by changing the solid outline of the figure to a dashed outline.

When the user releases the left mouse button, dragging is over, and the object has a new position. Recall that resiz-ing of the window should result in the relative positioning of the object (at its new location) in the window.

3. Animated Repositioning by Clicking

Provide functionality to allow the user to reposition the figure at a point indicated by "clicking", i.e., pressing and releasing, the right mouse button. When the right mouse button is clicked, the movement of the object should be animated in its movement to the new location, i.e., the figure should move in a straight line from its old position to its new position.

4. Enhancement: Differing Animation Speeds

Use the timer (as described in Petzold and which we'll talk about later, or any other method) to vary the speed at which the figure is repositioned using the right button, such that the figure initially moves slowly toward its new position when the button is released, speeds up toward the middle, and slows down at the end, using, say 1/3's of distance to define start, middle, and end.

Implementation notes:

As noted in class, programming complex API's can be, well, complex. One way to handle the complexity is to pro-gram "incrementally" by making a series of fairly small (often 1 line) modifications, testing each thoroughly (e.g., MessageBox's for variable values and to slow it all down, MessageBeeps to see what's executing), and proceeding iteratively until all functionality is implemented in your program. Though I'm in general glad to help in any way, it is in practice quite a challenge to go beyond a function call or two in finding any problems, and the best help I might give would be when the question is quite narrow. The debugger with breakpoints and single stepping can be a very valuable, and perhaps necessary, tool in Windows API programming. If you've not mastered it by now, it's time.

Detecting when button presses occur in particular areas of the screen is hit testing, as discussed in class. Doing it simply and transparently is likely preferable for your first programs to using the several Windows API functions that are available to do similar things. As a general note on Windows API programming for this course, as with any pro-gramming, there are certainly many ways to do things! What happens as one begins to explore the wide range of functions not discussed in class or in Petzold is that "subtleties" of usage arise, plenty of which have no real docu-mentation, and then you're pretty much on your own to figure things out - which is fine, just heads up! The presentations in class to date have been designed to introduce you to the rudiments of event driven programming and have focused on transparency of control flow and functionality. These pedagogic examples are also pretty easy to debug. Similarly for the Petzold examples, despite some elements of advanced C programming, those ex-amples are about as straightforward as can be. They were designed to be that way. The class presentations have also focused on "unpacking" those programs and have been selected to provide code examples useful in your as-signments.

For the relative positioning with window resize, etc., recall that the event handling function is repeatedly called, so use of static variables for figure location.

The animation can be accomplished with a simple loop at this point that does not relinquish processor control. Bad form later, but ok for now. We'll eventually learn about the timer. If you've had a course in graphics, Bresenham's algorithm would be perfect to determine the successive x and y locations for drawing the animated figure. If you're not familiar with Bresenham's algorithm for line drawing, fine, just use real values from the old y=mx+b equation (what's a microsecond more or less). There are lots of ways to do the animation that are inelegant, but work, and they are fine.

Computer Graphics, Computer Science

  • Category:- Computer Graphics
  • Reference No.:- M9131796

Have any Question?


Related Questions in Computer Graphics

The saffir-simpson hurricane scale classifies hurricanes

The Saffir-Simpson Hurricane Scale classifies hurricanes into five categories numbered 1 through 5. Write an application named Hurricane that outputs a hurricane's category based on the user's input of the wind speed. CA ...

The problemyou are to search a bitmap in rgb format and

The problem: You are to search a bitmap in RGB format and count the number of pixels which match a set of colors. The bitmap will be 1024 by 1024 pixels for the purposes of explaining this problem. The set of colors will ...

You have a program draw a rectangle on the screen and allow

You have a program draw a rectangle on the screen and allow the user to change the color/size of the rectangle. The program will store in the browser the settings of the color/size so that upon revisiting the page, the v ...

Please read my question if you post copy and pasted code

Please read my question if you post copy and pasted code you will get a negative review. This is java In this graphical program, you are going to simulate arcade car racing game. You need a single player that is movable ...

The problemsit is strongly recommended that you tackle the

The problems: It is strongly recommended that you tackle the following tasks in a modular way -- a separate standalone function for each task. Draw a rectangle as a Rectangle and as a Polygon. Make the lines of the Polyg ...

Question a describe the architecture of simple raster

Question : a) Describe the architecture of simple raster graphics system? b) Explain raster scan display processor?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As