Presentation is loading. Please wait.

Presentation is loading. Please wait.

Moving Car Case Study © Allan C. Milne Abertay University v14.2.28.

Similar presentations


Presentation on theme: "Moving Car Case Study © Allan C. Milne Abertay University v14.2.28."— Presentation transcript:

1

2 Moving Car Case Study © Allan C. Milne Abertay University v14.2.28

3 Agenda.  Requirements.  OO design.  Calculating position.  Rendering as audio.  Realism.

4 Requirements. Simulate a moving car through audio rendering of the sound of the engine … –… with the user (listener) being at some fixed point and orientation … –… as the car moves along one of a set of pre-defined tracks. The user should be able to select the track and adjust the car speed.

5 Technology. C++. DirectX XAudio2. AllanMilne and AllanMilne::Audio frameworks. Use pan and volume to simulate position.

6 User interface. Keyboard control: –space : start/stop car movement. –up/down : increase/decrease car speed. –1, 2, … : select different tracks. –I : display instructions & available tracks. –escape : end application.

7 OO architecture. IState interface frame processing MovingCarControl manage UI control car select track Track interface compute position on a track concrete tracks … compute position for a specific track MovingCar real-time car movement modify speed render as audio Updateable interface single frame handshaking XASound manage single XAudio2 source voice WinCore Windows handshaking

8 Class designs. Classes can be designed through defining their header files. –As long as you include relevant commentary on the meaning and requirements of the member fields and functions. review these to identify the state and exposed behaviour of the classes: –MovingCarControl.hppMovingCarControl.hpp –Track.hppTrack.hpp –MovingCar.hpp

9 Calculating position. Track interface exposes method –MovePosition(&x, &y, deltaTime, speed) this updates the in/out x,y position for travelling at speed for deltaTime on a track. A concrete class implements this method for a specific track layout.

10 void DiagonalStraight::MovePosition (float& inOutX, float& inOutY, const float deltaTime, const float speed) const { // Calculate how far the car has travelled in delta time. const float distance = speed / 3600.0f * deltaTime; // convert to Km/sec. // Calculate how far this is in X and Y axis directions using Pythagoras; since 45 degrees x=y. const float axisIncrement = sqrt (distance * distance / 2.0f); inOutX += axisIncrement; inOutY += axisIncrement; } // end MovePosition function. This is for a 45 degree diagonal straight line track layout. class DiagonalStraight : Track { … … … }; // end DiagonalStraight class.

11 Updating position. A MovingCar object includes state for –current (x,y) position; –current speed; –pointer to concrete Track object. MovingCar::Update(deltaTime) is called every frame. this can call Track::MovePosition(…) to update the current (x,y) position.

12 Rendering as audio. The protected MovingCar::RenderAudio() function –is called from MovingCar::Update(…) –after Update() has updated the current position. RenderAudio() modifies the attributes of the looped.wav file playback to reflect the current position of the car. –This implementation uses pan and volume to provide positional rendering.

13 void MovingCar::RenderAudio () { // angle from user; does not reflect being behind. // XASound pan representation between -1.0 and 1.0 float pan = 0.0f; if (!nearEqual (mXPos, 0.0)) { // Not close to straight ahead or behind. // calculate angle from Y-axis as ratio of 90 DEGREES (in radians). pan = atan (mXPos / mYPos) / kHalfPi; // handle sign of atan return value. // We don't need quadrant - only whether to right or left of Y- axis. if (mYPos < 0.0f) pan = -pan; } // Calculate volume as dB ATTENUATION relative to full volume. // Note this uses a linear distance to volume map. // Calculate distance using Pythagoras. const float volume = sqrt (mXPos*mXPos + mYPos*mYPos) * kVolumeDbPerKm; // Apply values to the XASound object. mCarEngine->SetPan (pan); mCarEngine->SetVolume (volume); } // end RenderAudio function.

14 How realistic is the sound? Depends on quality of soundcard, amplifier, speakers, hearing, room acoustics. Some audio issues to consider: –inverse square law; –attenuation of different frequencies over distance; –Doppler effect; –head relative transfer function (HRTF).

15 Designed for flexibility. Any Track object can be set to be used by a MovingCar. New track layouts can be added; –create a concrete Track class. Alternative audio rendering can be implemented: –subclass MovingCar; and –override RenderAudio().

16 Full implementation. See the application index page for further information and a link to a zipped Visual Studio solution.application index page


Download ppt "Moving Car Case Study © Allan C. Milne Abertay University v14.2.28."

Similar presentations


Ads by Google