Graphics Reference
In-Depth Information
Source file. Model.cpp file
in the Model folder of the the
D3D _ MultipleBalls project.
void CModel::UpdateSimulation() {
// Compute elapsed second since previous update
float elapsed _ seconds = ...
// update ball velocities based on gravity
float accel _ y = -15.0f * elapsed _ seconds;
Velocity : Update all balls' velocity
foreach ball in m _ AllBalls
// accelerated velocity
velocity = ball.GEtVelocity() + accel _ y
// set the new velocity to the ball
ball.SetVelocity(velocity);
Position : Update all balls' position
foreach ball in m _ AllBalls
// compute new position based on current + velocity
center = ball.GetCenter() + ball.GetVelocity()
// Set the new position to the ball
ball.SetCenter(center);
Membership : Destroy balls that travel outside of the world
foreach ball in m _ AllBalls
if (ball.IsOutsideBounds(m _ WorldWidth, m _ WorldHeight))
m _ AllBalls.DeleteItem(ball);
Listing 5.24. CModel::UpdateSimulation() Function (Tutorial 5.5).
Source file.
Mouse button
When compared with previous tutorials, Tutorial 5.5 supports more user ac-
tions, and the output is more graphically oriented (more displayed balls). How-
ever, to support these extra user actions and graphical outputs, we see that the
corresponding programming code has not much to do with the specific GUI API
or graphics API. This observation is true in general. As the complexity of our
application increases, we would be spending more programming efforts in devel-
oping and maintaining the model component, and in most cases, the programming
involved will be API-independent.
service
routines
are
defined
by
the
view/controller
pair
CDrawAndMouseHandler
class. The implemen-
tation can be found in
DrawAndMouseHandler.h/cpp
in the WindowHandler folder
of the D3D _ MultipleBalls
project.
Tutorial 5.6. The Ball-Shooting Program
Tutorial 5.6.
Project Name:
D3D _ BallShooting
Library Support:
UWBGL _ MFC _ Lib1
UWBGL _ D3D _ Lib3
Goals. Demonstrate the implementation of the ball-shooting program as
specified on p. 10.
Approach. Continue working with Tutorial 5.5 to complete the implemen-
tation of the ball-shooting program.
Search WWH ::




Custom Search