Homework #6

Hints, Tips, and Corrections

Wednesday, Mar 10, 1999

Fixed problem with bounded objects

Fixed a bug with bounded objects that made it not work correctly with multiple items in a draw list. Simply redownload boundedobject.cpp and overwrite your current one.

Documentation on file format of drawing primitives

The documentation regarding the file format of drawing primitives is now available by popular request. The API documentation has also been updated to contain this.

Tuesday, Mar 9, 1999

New version of the Hw6 API available

  1. We think that it finally fixes the line selection problem. Let us know if there's a case we didn't think up of.
  2. An incovenience regarding the non-const method DrawableObject::intersects. Because it does not modify the object, we've made it a const method.

The next version will most likely have some bitmap support. Stay tuned....

Clarification on return values of InteractableObject methods

The following applies only to the user input handling methods that are a part of the InteractableObject class. Note that the return type for each of these methods is a boolean. If the method returns true, then that means that the user event was captured by the method, and no further objects' user event handler will be called for that particular event. For example, if an object handled a left click and returned true, then no other object's left click handling method in the InteractableObjectList will be called for that particular left-click. If, on the other hand, the return value is false, then other objects' left-click handlers will be called for that particular event.

Bounded object support

There was a groundswell of people asking the TAs for support for collision, so we've written a class, BoundedObject, that supports collision detection of bounding boxes.

A bounding box is defined as a rectangle that is big enough to completely encompass an object's drawing primitives. BoundedObject contains methods allowing for the calculation and checking the intersection of these bounding boxes.

The files for the BoundedObject, along with an example of a class that uses BoundedObjects, CrashingObject, is available. Unarchive the files into the same directory as your Hw6 API. Three files will be overwritten: DraggableObject is now made a subclass of BoundedObject, so draggableobject.h is modified; sampleworld.txt is modified to have crashing objects; worldio.cpp is modified, to allow for loading in of crashable objects. In addition, 4 new files consisting of the BoundedObject specification and implementation files, as well as the CrashingObject specification and implementation are included in the archive, so you'll need to add these to your project file.

The bounded object is an excellent example of a class that utilizes available functionality to do something interesting, and should be studied to get an idea as to how to perform manipulations on the drawlist. It traverses the drawlist to find drawing primitives and performs calculations on them, depending on the type of the drawing primitive.

The crashable object is a good example of a class that uses the update method to run down the world's list of objects to figure out what objects it can collide with and do something interesting if there is a collision (draws a blue rectangle representing the bounding area).

The only real "gotcha" to remember when using the BoundedObject is that you will need to call the BoundedObject::calculateBounds() method whenever you change the object's drawlist.

There might be students that actually are creating the BoundedObject behaviour in their programs. If you fit this category, talk to your TA about either doing something different (something that uses the bounded object), or going ahead and doing your version of the bounded object (in which case, you will definitely need to arrange something with your TA to ensure that you haven't looked at the code).

Monday, Mar 8, 1999

New version of the Hw6 API available

  1. Fixes error in the update method. Note that in order to refresh the world, you will need to return true.
  2. Fixes error in picking lines.

You will probably want to move the files that you created and the worldio.cpp file to a safe location, reinstall the hw6 API, and then move your files back. You will probably also need to add the files you created back to the project.

Clarifications on the UpdateableObject::update method

Due to the error that we have just fixed, there was a lot of confusion regarding the exact behaviour of the update methods being called by the world.

The update methods for all world-registered updateable objects are called once every approximately 1/10 second. If the update method does something that requires a screen redraw, then the update method should return true. If the update method does something that does not require a screen redraw, then the update method should return false.

Some list manipulation examples:

The following example defines a function that iterates across lst and returns a position pointing to the nth item in the list. If we don't find the nth item in the list, then the returned position will point of end-of-list.

ObjectList::Position getNthItem(const ObjectList& lst, int n)
{
	ObjectList::Position pos;
	lst.reset(pos);				// pos now points to head of list
	int i=0;
	while (i < pos && !lst.endOfList(pos))	// Stop if we're there or if we run
						// off list
	{
		i=i+1;
		lst.advance(pos);		// pos is now pointing to the next
						// list item
	}
	return pos;
}

The following example finds obj in lst and replaces it with robj. Returns true if replacing succeeds, else returns false.

bool replaceObject(ObjectList& lst, Object* obj, Object* robj)
{
	ObjectList::Position pos = lst.find(obj);	// Find obj in lst

	if (lst.endOfList(pos))		// Found obj?
		return false;		// Nope, so return false

	lst.insertBefore(pos, robj);	// Insert just before obj's pos
	lst.advance(pos);		// Advance pos back to obj's pos
	lst.deleteItem(pos);		// Remove obj from the list
	return true;			// Report success
}