hello again um okay this video this this
this section of videos is going to be
all entirely about something called box
2D box 2D let's write that over here
box
2D now why are we talking about box 2D
okay so what have we been doing we have
been making all these examples they have
these mover objects the objects have
these vectors they have these functions
what do they they move around the screen
they respond to forces we've been
building our own physics engine bit by
bit Slowly by slowly looking at
different examples and scenarios for
simulating uh physics and motion on the
screen of course it's probably quite
obvious to you that we are not the first
people to have ever thought of this
problem and ever done this and in fact
physics simulation exists everywhere in
computer graphics and there are lots of
examples of of of ways of writing code
and libraries that you can use so
what we want to take a moment in this
nature of code experience to say okay
well there's value to us building our
own physics engine to learning the ins
and outs of it to kind of being creative
with what we're making but maybe there
is a time in place where we should just
use somebody else's physics engine
somebody else's physics library to
control the behavior and motion of
everything on the screen and so what I
want to look at in this video is a what
is what is a physics Library what what
is box where do I get box Tod and what
are the pros and cons of using something
like box Tod instead of um custom baking
your own
stuff okay so uh this is going to be
challenging I have I I made a list got
eight videos to do it would probably
turn into more honestly it's a huge
topic and it's not going to be easy but
so this first video which you know which
will just be a short hopefully I just
want to kind of talk through the basic
elements of box look at a couple
websites where you can get stuff I'll
include links below wherever you're
watching this on Vimeo or wherever um of
where you want to download the stuff and
then you know we'll get into the details
in in future videos so if you kind of
already if you know what box2d is and
you're already up and running you could
stop now and just go to the next video
okay so um box
2D let's think about why why is what
what is the sort of central reason why
you might want to use a library like box
Tod okay so I'm I'm sure this scenario
has come up for you before you you you
have all these circles moving around the
screen and you're programming them with
vectors and forces and they're all doing
all this exciting stuff but you want to
figure out you know you have got this
circle and this other Circle and they're
moving towards each other and you know
they're going to they're going to get
right next to each other and you're
going to want to detect the fact that
they're touching each other and they're
bouncing off each other you want to do
something with their
Collision if you have a program where
the collisions of objects matter to you
if you have this idea for something you
want to make and you're walking down the
street describing your idea to your
friend blah blah blah coll collisions
blah blah blah collisions this and that
and this and that and that and then they
Collide and blah blah blah if you're
using the word Collision over and over
again in your project description this
is a moment where probably you want to
use box Tod we could start to go through
the math for this and if with circles
it's not so bad we know first of all we
know how to detect if two circles are
intersecting or not right we can just
look at the distance between those two
circles and if the distance between
those two circles is greater than the
sum of their
radi then they're not overlapping if
it's less than the sum of their radi
they are overlapping and then we could
start to figure out okay well if if they
are overlapping what do we do with them
well we know their velocity vectors we
could probably do some Vector math and
reflect their vectors and bounce them
and rotate them and we could figure out
what direction they're going to go and
this would be a worthwhile exercise and
somebody someday should make a video
about how to do the scenario but this is
the moment this is the moment in life
where we are choosing not to go down
this road because this road leads to
other more complicated and stressful
problems like what if they aren't
circles what if these are strangely
shaped polygons and and what if those
strangely shaped polygons should like
are spinning and how do we know if
they're overlapping when they hit each
other how are they going to bounce off
each other and with friction and what if
they're kind of elastic or not very
elastic there's so many ways we could
make this problem so unbelievably
complicated we could suddenly find
ourselves dedicating the next several
years of our life to figuring out just
what to do about things colliding the
good news for us is somebody else
already spent many years of their life
dedicated to this problem and they
released the solution in an open source
Library called box Tod so one of the
central reasons why we want to use box
2D is to deal with stuff like collisions
into two Dimensions now if we're going
to get into 3D that we let's not we're
not even going to get in this in the
about box we're sticking in two
Dimensions you might this is brings up
an interesting point though which is
that is there ever you could be asking
yourself okay that's great why would I
never not use box to I mean that sounds
awesome I should just use that for
everything and you might choose to now
use it for everything but I I do want to
emphasize that this doesn't come without
any EXT any pain as well right using a
library you've got to learn the how the
library works you got to figure out how
to import stuff which functions which
classes there's a lot of overhead and as
we're going to see there's a lot of
stuff we have to kind of learn how to
use just to just to you know just to get
a circle moving on the screen with box
2D is a lot more effort than without it
but when we once we get to the effort of
having to deal with collisions it
becomes worth that effort to get box up
and running so it's this kind of
balancing act and and and I'm very
curious actually I don't I don't pretend
to have the answer to this you this is a
question you will have to wrestle with I
have this idea for this project I want
to make should I use this this Library
should I use this other Library should I
use no library and this is the question
we hope to as a community whoever we may
be kind of solve together and talk about
and discuss and and I would be
interested in hearing from you as to you
know what what's what's worked with box
and what hasn't so okay so this kind of
gets us over the hump of why we want to
use box Tod so there's two more
questions we need to answer in this
particular video one is where do I get
it and how can I even be up and running
with it and and then kind of what is the
overview what's the bigger picture here
what are the central elements that I
need to learn about so let's first take
a look at where it is that you get box
DD and what box DD really is the first
thing I should mention though um I'm G
to include this is so like kind of
analog of me but um here's a website
that you could go to box.org and I'm
going to include everything that I'm
going to show you I'm going to include
as links below wherever you're watching
this um you know probably on Vimeo um in
the description I'll include links Okay
so
uh where what is box actually what I
meant to write here I'm just kind of
rambling now is
C++ so one thing we should be aware of
is box2d is a C++ engine it's written in
C++ and if you go to box td.org that's
where you can download it you can find
the documentation there's a forum
there's information about the project um
it's a C++ engine it was created by
someone named Aaron Kato I believe it's
been around since 2007 something like
that it's probably in many ways most
famous for uh its use in the game Angry
Birds and many many many many many many
many mobile uh tablet games that you
play um are built with a physics engine
and box2d is a very popular one
especially for 2D games so one of the
things that I think is most useful about
this website that you might want to take
a look at is perhaps rather dry reading
but if you're if you're like me and you
like to find something to read you know
quietly at night with a flashlight while
you're about to go to bed you might go
here and look at the Box Tod manual so
the box manual is going to give you an
overview of kind of all what are all the
pieces of boxd if you look at this it's
all written for the C++ user now here's
the thing box is such an amazing and
incredible library that does so much uh
we are not the first people to discover
this it's been ported to just about
every language and environment you can
think of there's a JavaScript version
there's a uh a flash version there's
probably there's I I can't even anything
you can imagine there's probably a
version now processing is built as you
as you may well know is built on top of
java so if we could just find a Java
version of box Tod we could probably use
it in processing and in fact there is
one so if you go to jbox to.org you'll
find a Java physics engine this is a
port of the boxd library for Java now
you could we could be done here we could
just say ah this is perfect I found this
I'll download this I'll figure out I'll
somehow get processing to recognize it
and use it and I'll write all this Java
e code and that's essentially what we're
going to do but to make this a little
bit easier I have put together something
called P box DD which I realized is sort
of against the rules of Library making
because the p is sort of reserved for
official things so maybe I should change
the name of it but uh I don't know why
it just got just occurred to me now this
part out but anyway um this what this is
is it really isn't it's it's misleading
it looks like it's a processing Port of
boxd but what it really is is a little
it's it's really just a little um it's a
set of examples and a library that
allows you to sort of easily access jbox
Tod directly from within processing so
that's the details of this this is what
you know as I look through my list of
videos there's like eight of them all of
that's going to use this um Library
called pbox DD so you can see it's on
GitHub there's a link to download it
I'll include a link below um there's
lots and lots of examples I don't know
if I had the time and maybe I will could
probably go through all of them and
hours of content here but I'm going to
try to whittle this down to the basics
now I should mention that this is not
the only way to use box Tod in
processing in fact there are other
libraries if you go to the processing
libraries page you'll see a few um box
wrap 2D I think one is called but one
that I wanted to point out which I think
is particularly wonderful is called
fysica which is I don't know if I'm
pronouncing that right I say it with
enthusiasm though fysica um which is by
uh Richard marxer and this I think is
terrific I I'm not choosing to use it
because what I think it's useful for us
as an exercise here to really dive into
the guts of box fysica is a little bit
bit of a higher level layer in many ways
makes it it makes it a little bit easier
to use but um perhaps um not every I
actually don't know if this is accurate
but uh not everything in the entirety of
box 2D has been implemented so I want us
to kind of get into the raw box2d to
really learn about how it works so um
but you know maybe I need to reconsider
that because this is really a wonderful
library and I definitely recommend you
taking a look at it okay so this is the
picture of where where everything is now
let's just discuss for a moment though
um kind of looking at an overview of all
of the elements in box 2D you know what
actually that's going to be in the next
video this I think this is good here's
the thing so this is what you should do
you should go and you should download um
this Library pbox use the link below
download it open it get it running go
through all the examples and just run
them take a look at them and and sort of
just see if it makes sense to you that
this is something that you think you
might want to use that's going to have
add value to the stuff that you're
making and if that's the case then
continue and watch the next set of
videos if not you know go and have a
sandwich or a nice salad something you
know take take a take take take relax
and do something else okay so uh
hopefully that gives you kind of a basic
overview of what box duty is and when
you want to think about using it the
next video we're going to get into kind
of another overview but with more
details about the elements of boxid and
how they're used and then finally we'll
start digging into the code details as
well and see how to actually write code
that use boxd okay um goodbye