Level Editor Should be stable (as of Sunday) Will be updating the source code if you want to make tweaks to it for your final
Spoooooky Three checkpoints due next week M III Tac V Final I
Good news! Playtesting requirements: Just your engine Primary requirements: Also just your engine Secondary requirements: Spoooooky Two extras for either tac or m
PDFs will be sent out soonish Final Requirements are somewhat vague and subjective Secondary requirements are just polished version of primary requirements Whatever you re planning to do now, that will change We want the rubric to be flexible enough to handle that If you want to change engine/game requirements that are listed on your pdf, you can do that, just check with us first!
Final I is due next week Final There will be a week-long break between Final III and Final IV for thanksgiving (we ll still have lecture, but nothing will be due) Everything is due by final V
Final Groups You can share code with your group members Please be honest with your submissions If you re missing m1, don t hand in your group member s m1 This is against Brown s academic policy
Special Topics We ll be posting ~4 slide decks each week, even if we only go over two per lecture This is so you can look over the slides if they re relevant to your final engine
Sound APPLICATIONS
Sound in Games In the real world, computers have sound Background music Sound effects Can be an important part of gameplay Listening for footsteps Dramatic music
Sound File Formats Many ways to encode and store sound Open standards Ogg Vorbis FLAC Closed standards mp3 m4a wav
Sampled Audio mp3, wav, and most other familiar extensions Usually recordings of live sounds Samples of sound wave at regular intervals Prevalent in modern games 1100100110101011011101011001000110101
Generated Audio MIDI File provides information on instruments and notes Similar to sheet music Sound cards translate from instruments/notes to sound Can instruct computer to play something even if you can t play it Used to be popular to save space, not as common now
Compressed vs. Uncompressed Compressed Sound Files Lossy or Lossless? Lossy remove least important parts of sound wave Lossless just use smart compression on raw wave Smaller file size (esp. lossy) Lossy is lower quality Slower to decode and play Often used for music Uncompressed Sound Files Record as much as possible of sound wave Much larger file size Usually high quality Faster to decode and play Often used for sound effects
Buffering Decompressing and decoding is slow Read sound into buffer, play back from buffer Size of buffer depends on speed of system Playback delay while buffer is filled Sound device Buffer Decoding Sound file
Sound EFFECTS
Positional Sound Manipulates left and right speaker volumes based on sound s source relative to player
Doppler Shifts Sounds moving toward you sound higher Sounds moving away from you sound lower Sounds traveling past you slide
A sound is made, and it bounces of an object at reduced volume Echo
A sound is made, and it lingers from repeatedly bouncing off objects Similar to echo Lasts longer Reverberation More scrambled/overlapped
Use a Library
Sound IMPLEMENTATION
javax.sound.sampled AudioSystem: Provides factory methods for loading audio sources Clip: Any audio that can be loaded prior to playback Line: Any source of streaming audio DataLine: An implementation of Line with helpful media functionality (start, stop, etc) Other classes for mixing, ports, and other utilities File file = new File( mysound.wav ); InputStream in = new BufferedInputStream( new FileInputStream(myFile) ); AudioInputStream stream = AudioSystem.getAudioInputStream(in); Clip clip = AudioSystem.getClip(); clip.open(stream); clip.start();
javax.sound.midi MidiSystem: The AudioSystem for MIDI files Sequencer: Plays MIDI sounds Other classes for manipulation of instruments, notes, and soundbanks So you can create MIDI sounds in realtime Much harder to manipulate samples Sequence song = MidiSystem.getSequence(new File( mysong.midi )); Sequencer midiplayer = MidiSystem.getSequencer(); midiplayer.open(); midiplayer.setsequence(song); midiplayer.setloopcount(0); midiplayer.start();
Some drawbacks of the built-in sound classes Imprecise control over exact playback start/stop positions Almost impossible to manipulate or even examine samples in realtime While Java offers pan and reverb, other libraries offer more varied effects But it s very effective for simple background music and sfx! Alternatives?
Cross-platform audio API modeled after OpenGL Pros: Built for positional sound (distance attenuation, Doppler shift, etc all built in) More fine-grain control available Cons: Modeled on OpenGL OpenAL
Most other libraries are platform-specific or wrappers for OpenAL except for synthesis libraries! Jsyn, Beads, etc Useful for composer programs and the like, not so much for sound playback Others
Sound QUESTIONS?
What is raycasting? Determine the first object that a ray hits A ray is like a ray of light, has a source and direction and goes on forever Think of it as shooting a laser in a particular direction
Raycasting Uses When would we need to raycast? Hitscan weapons Line of sight for AI Area of effect Rendering
A ray is a point (source) and a direction Point on ray given by: The Ray is the source point is the direction This must be normalized! is a scalar value (length) Ԧp መd t መd
Raycasting boils down to finding the intersection of a ray and shapes Kind of like collision detection all over again You want the point of collision as well Basics
If the source is outside Project center onto ray Check if the projection is positive and the projection point is within the circle Ray-Circle
Ray-Circle If the source is outside Project center onto ray Check if the projection is positive and the projection point is within the circle Point of intersection? Ԧp L
Ray-Circle If the source is outside Project center onto ray Check if the projection is positive and the projection point is within the circle Point of intersection? Ԧp + (L r 2 x 2 ) መd Ԧp r x
Ray-Circle If the source is outside: Project center onto ray Check if projection is positive Check if projection is in the circle Equation: p + d *( L - r *r - x * x) Ԧp r x
Ray-Circle If source is inside the circle: Project center onto ray Projection must be in the circle Projection can be negative Equation: Ԧp x r p + d *( L + r *r - x * x)
Ray-Polygon/AAB A polygon/aab is composed of edges We can check for intersection of ray by checking for intersection of all edges There is no shortcut for AABs this time
Ray-Edge Edge is defined by two end points, Ԧa and b We need some other vectors: m is direction of the segment (normalized) n is the perpendicular to the segment (normalized) Ԧp መd Ԧa m n b
Ray-Edge Firstly, determine if the segment straddles the ray Use cross products Ԧa m n and must be of opposite sign Ԧa Ԧp Therefore no intersection if Ԧp b Ԧp b መd
Ray-Edge Secondly, determine if the two lines intersect Point of intersection Ԧa m n Ԧq = Ԧp + t መd Ԧq Solve for t t must be nonnegative! Ԧp b መd
Ray-Edge Because lies on the segment Ԧa m n So plugging in: Ԧq Ԧp b መd
Intersect the ray with all the edges of the polygon Ray intersects polygon if it intersects at least 1 edge Keep track of the point that is closest to the source (the lowest value of t) Ray-Polygon
Raycasting: Putting it all together 1. Intersect ray with every shape in the world 1. For circles, use the circle-ray algorithm in the slides 2. For polygons and AABs, intersect each edge and use the closest 2. Keep track of closest intersection point from the source as well as the corresponding shape
Raycasting QUESTIONS?