Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computation as an Expressive Medium Lab 12: Tools, Patterns, and Practices (and Collision Detection) Jason Alderman.

Similar presentations


Presentation on theme: "Computation as an Expressive Medium Lab 12: Tools, Patterns, and Practices (and Collision Detection) Jason Alderman."— Presentation transcript:

1 Computation as an Expressive Medium Lab 12: Tools, Patterns, and Practices (and Collision Detection) Jason Alderman

2 It’s FRIDAY! (Again, or for the first time!) Collision detection strategies! Collision detection strategies! Fun libraries and tools! (nifty things you could potentially add to your arsenal…) Fun libraries and tools! (nifty things you could potentially add to your arsenal…) Design Patterns Design Patterns What they are! What they are! How they can help you! How they can help you! Good coding practices Good coding practices

3 Collision Detection: shapes Basic Basic Rectangular bounds Rectangular bounds (sphere/cylinder in 3D) (sphere/cylinder in 3D) Advanced Advanced Subdivisions Subdivisions (looks like they’re colliding, but they’re not really touching!) (most likely a horribly inaccurate depiction, but you get the picture)

4 Collision Detection: method 1 Next step Next step Before moving object, check to see if space it will move to is occupied by another object (wall, for example) Before moving object, check to see if space it will move to is occupied by another object (wall, for example) Problem: Problem: What if the object is moving really fast? What if the object is moving really fast? (uh, yeah, it was moving so fast its molecules just…vibrated their way through the wall. yeah…)

5 Collision Detection: method 2 Distance calculation Distance calculation Before moving object, check to see its distance from objects in front of it: if next “step” is either inside one of the objects OR a negative distance, don’t do it Before moving object, check to see its distance from objects in front of it: if next “step” is either inside one of the objects OR a negative distance, don’t do it Problem: Problem: That initial issue with shapes… but we’re mixing apples and oranges here That initial issue with shapes… but we’re mixing apples and oranges here (from what I’ve read, this is how most collision detection works …but there’s a lot of wonky planar math! )

6 Collision detection: in the class Give each object a getBounds() or isCollided() or (whatever you want to call it) function that returns true or false if an x and y passed to it are within the bounds of the object Give each object a getBounds() or isCollided() or (whatever you want to call it) function that returns true or false if an x and y passed to it are within the bounds of the object Give each object instructions on what to do if it finds out that it has collided with something Give each object instructions on what to do if it finds out that it has collided with something

7 Collision Detection: managing Idea 1: Idea 1: Check collisions in draw(); Check collisions in draw(); Treats all moving objects as subclasses of an Actor class (e.g., Rob’s Drawable) Treats all moving objects as subclasses of an Actor class (e.g., Rob’s Drawable) Cycles through all actors to determine if two are overlapping Cycles through all actors to determine if two are overlapping Tells each that they have collided with an actor and what type of actor Tells each that they have collided with an actor and what type of actor Problem: Problem: Might be good for between moving actors, but not so good for actors and walls… Might be good for between moving actors, but not so good for actors and walls… Idea 2: Idea 2: Check collisions in moveMe(); of objects Check collisions in moveMe(); of objects Checks to see if it’s colliding with another object in next step; passes message to other object that it has collided as well Checks to see if it’s colliding with another object in next step; passes message to other object that it has collided as well Problem: Problem: Making sure that each object can somehow get pointers to the other objects (can be tricky) Making sure that each object can somehow get pointers to the other objects (can be tricky) What if two objects are moving to intercept? What if two objects are moving to intercept?

8 Collision detection: more info http://www.gamasutra.com/features/20000330/ bobic_01.htm http://www.gamasutra.com/features/20000330/ bobic_01.htm http://www.gamasutra.com/features/20000330/ bobic_01.htm http://www.gamasutra.com/features/20000330/ bobic_01.htm Username: noregister@mailinator.com Username: noregister@mailinator.com Password: noregister Password: noregister http://www.planetalia.com/cursos/Java- Invaders/JAVA-INVADERS-20.tutorial http://www.planetalia.com/cursos/Java- Invaders/JAVA-INVADERS-20.tutorial http://www.planetalia.com/cursos/Java- Invaders/JAVA-INVADERS-20.tutorial http://www.planetalia.com/cursos/Java- Invaders/JAVA-INVADERS-20.tutorial http://games-middleware.dev.java.net http://games-middleware.dev.java.net http://games-middleware.dev.java.net FYI, Most tutorials online appear to be for 3D FYI, Most tutorials online appear to be for 3D

9 Fun libraries and tools! Lots of things out there, you just have to know what you’re looking for…and be prepared to read the documentation… Lots of things out there, you just have to know what you’re looking for…and be prepared to read the documentation… Processing libraries Processing libraries GUI widgets Webcams Carnivore, XML, etc. Physics Anaglyphs!* http://processing.org/reference/libraries/ http://processing.org/reference/libraries/ …and some nifty Java libraries …and some nifty Java libraries FreeTTS (Text-To-Speech): http://freetts.sourceforge.net FreeTTS (Text-To-Speech): http://freetts.sourceforge.net http://freetts.sourceforge.net Free speech recog(!): http://cmusphinx.sourceforge.net/sphinx4/ Free speech recog(!): http://cmusphinx.sourceforge.net/sphinx4/ http://cmusphinx.sourceforge.net/sphinx4/ …and remember that Wikipedia has (usually) good primers on computer science topics! …and remember that Wikipedia has (usually) good primers on computer science topics! * USC’s Todd Furmanski coded this in processing for his thesis Here Be Dragons …still trying to acquire his awesome code!

10 Design Patterns! A lot of you have been asking: what’s the best way to do _____ in code? A lot of you have been asking: what’s the best way to do _____ in code? Answer: look to design patterns! Answer: look to design patterns! Like best practices, written down… Like best practices, written down… American architect Christopher Alexander started the whole craze.

11 Design Patterns make OOP fun! Provide blueprints for classes that programmers use A LOT…all given funny nicknames! Provide blueprints for classes that programmers use A LOT…all given funny nicknames! Singleton! Factory! Decorator! Iterator! (sound familiar?) Patterns are a way to encode best practices …over 250 have been documented to date Patterns are a way to encode best practices …over 250 have been documented to date There are 25 original OOP design patterns, but the number continues to grow. There’s even a Head First book on it. (People have made design patterns for UI and HCI as well.)

12 Design Patterns resources Free Design Patterns for Java book: Free Design Patterns for Java book: http://www.patterndepot.com/put/8/JavaPatterns.htm http://www.patterndepot.com/put/8/JavaPatterns.htm http://www.patterndepot.com/put/8/JavaPatterns.htm Synopses of LOTS of design patterns in simple terms from another Java DP book Synopses of LOTS of design patterns in simple terms from another Java DP book http://www.mindspring.com/~mgrand/pattern_synopses.htm http://www.mindspring.com/~mgrand/pattern_synopses.htm http://www.mindspring.com/~mgrand/pattern_synopses.htm Design Patterns column (few years old) Design Patterns column (few years old) http://www.javaworld.com/columns/jw-java-design-patterns- index.shtml http://www.javaworld.com/columns/jw-java-design-patterns- index.shtml http://www.javaworld.com/columns/jw-java-design-patterns- index.shtml http://www.javaworld.com/columns/jw-java-design-patterns- index.shtml Someone liked a design pattern so much they wrote a song about it—very Schoolhouse Rock! Someone liked a design pattern so much they wrote a song about it—very Schoolhouse Rock! http://mikezornek.com/archives/2003/07/17/wwdcs_mvc_song.php http://mikezornek.com/archives/2003/07/17/wwdcs_mvc_song.php http://mikezornek.com/archives/2003/07/17/wwdcs_mvc_song.php (Model-View-Controller is a very useful pattern that we’ll probably study next year in LCC6313) (Model-View-Controller is a very useful pattern that we’ll probably study next year in LCC6313)

13 Other generic good practices Plan out what you’re going to do before you start Plan out what you’re going to do before you start Break things down into simple, computer-level- understandable steps Break things down into simple, computer-level- understandable steps Move this to this location, turn it towards that object, change its color to blue when pointed in the right direction, etc. Move this to this location, turn it towards that object, change its color to blue when pointed in the right direction, etc. Figure out the structure of what you’re coding…what kinds of classes you’ll need, what fields and methods they’ll need, and how they will “talk” to each other Figure out the structure of what you’re coding…what kinds of classes you’ll need, what fields and methods they’ll need, and how they will “talk” to each other Comment as you code! Comment as you code! Talk to your friends!! (You’ll generally waste less time searching online!) Talk to your friends!! (You’ll generally waste less time searching online!)

14 That’s it for this week. (And possibly the semester?) Good luck with your projects and finals! Good luck with your projects and finals! Preemptive warning: Lab hours next Friday afternoon will be shifted or cancelled Preemptive warning: Lab hours next Friday afternoon will be shifted or cancelled Also, will have more information about LCC6313 by beginning of Finals Week Also, will have more information about LCC6313 by beginning of Finals Week It’s way too early.


Download ppt "Computation as an Expressive Medium Lab 12: Tools, Patterns, and Practices (and Collision Detection) Jason Alderman."

Similar presentations


Ads by Google