HOME | DD

willmh93 — Tutorial - Ball+Band Collision

Published: 2010-06-05 12:22:17 +0000 UTC; Views: 4163; Favourites: 14; Downloads: 283
Redirect to original
Description Click DOWNLOAD

Someone suggested making a tutorial for this, so I thought I'd try it. It doesn't give quite the same effect as the original (doesn't work on both sides & doesn't bounce off the points) but it's the hard part done.

Contains a ZIP file including a Word 95-2003 document, flash source file and preview SWF file

Spent a good while on this, so please try it out!
Requires that you know a fair amount of maths and AS2.. so you may also need to be patient to get it working.

Original devation:
Related content
Comments: 32

Alextro [2013-09-01 23:05:34 +0000 UTC]

demand more on math stuff.

Really good stuff here

👍: 0 ⏩: 1

willmh93 In reply to Alextro [2013-09-21 23:21:25 +0000 UTC]

Thanks a lot! I appreciate it!

👍: 0 ⏩: 0

kinematrix-transhaul [2010-08-02 04:15:08 +0000 UTC]

hey... thats good!
can you make a as3 version?

👍: 0 ⏩: 1

willmh93 In reply to kinematrix-transhaul [2010-08-02 13:50:12 +0000 UTC]

thankyou sorry i haven't learnt as3 yet, but this tutorial basically focuses on the maths behind it, if you know as3, i can't imagine a conversion will be that difficult

👍: 0 ⏩: 0

seyns [2010-07-21 21:53:18 +0000 UTC]

omg the ball has gone mad !

👍: 0 ⏩: 1

willmh93 In reply to seyns [2010-08-05 13:05:39 +0000 UTC]

^^

👍: 0 ⏩: 0

seyns [2010-07-21 21:52:54 +0000 UTC]

the ball keeps getting fast...insanely fast!

👍: 0 ⏩: 1

willmh93 In reply to seyns [2010-08-05 13:06:02 +0000 UTC]

yeh, adding a speed limit might be a good idea xD

👍: 0 ⏩: 0

ken1171 [2010-06-06 02:00:30 +0000 UTC]

Good old trigonometry, works like a charm!

👍: 0 ⏩: 1

willmh93 In reply to ken1171 [2010-06-06 15:12:06 +0000 UTC]

hah yeh all those hours in class paid off.
thankyou!

👍: 0 ⏩: 1

ken1171 In reply to willmh93 [2010-06-06 19:25:42 +0000 UTC]

And then we have all this people complaining that leaning math accounts to nothing in real life - but that's because they didn't get into computer graphics like you and me. I used to hate math until I got into computer science. Now I think the complex number math on fractals and even the elegance in path finding algorithms is beautiful. The beauty is on finding the *simple* mathematical solutions for something that may look daunting at first. For my masters degree in computer science, I wrote an algorithm to seamlessly map discrete fractal textures over 3D geometry that can be seen from any distance without loss in details. As you can imagine, I am in love with math because of the implications in 3D graphics.

👍: 0 ⏩: 1

willmh93 In reply to ken1171 [2010-06-07 18:57:25 +0000 UTC]

It used to frustrate me a bit when people complained about learn trigonometry and all these theorms saying "it has no use in the real world", nobody even realised that it's all thanks to maths we even have video games, it shows how much people take for granted.

That sounds very impressive I think maths is beautiful in it's own way, as you can see from this catagory of my gallery [link] 3D interests me but I've still not made that step over from 2D to 3D, having that third axis seems to complicate things much more, but I definetely want to explore it, maybe you would be a useful contact to have if I ever needed any help I understand it abit already, I can understand vectors and the maths behind it, I just need to apply what i know.

👍: 0 ⏩: 1

ken1171 In reply to willmh93 [2010-06-07 19:22:32 +0000 UTC]

When jumping from 2D to 3D, a different kind of math is used. Instead of trigonometry, you will operate point coordinates using 4x4 matrices. This math can also work with 2D graphics without much change, because 2D is actually a subset of 3D. By using rather simple matrix math, you can translate, rotate and scale a 3D point in space (called "vertex"), and all 3D graphics are calculated this way. By creating 2 vertexes and connecting them with a line, you create a 3D "edge". You can then create 3D polygons (called "facets") using connected edges. Finally, 3D objects are created using connected facets. Facets can be filled with textures, creating fully realized 3D models that can move in 3D space and do whatever you want.

If you break things down to simple terms, it's not really that complicated. ^^

👍: 0 ⏩: 1

willmh93 In reply to ken1171 [2010-06-07 19:37:00 +0000 UTC]

When I stupidly said 'vectors', I meant to say matricies, I had a couple of lessons on them, I know how to add, subtract and multiply them and all that, I just never saw its connection to 3D. Your explanation helped, the problem I have is getting started, I would use C++ for anything 3D, but i've never had much luck setting up OpenGL or DirectX. My problem is I love doing things from scratch, when I'm given a huge development kit I struggle to find the motivation to learn how to use each function correctly.

I'll have a go at getting it all set up now

👍: 0 ⏩: 1

ken1171 In reply to willmh93 [2010-06-07 20:23:17 +0000 UTC]

If you are already familiar with matrix operations, you probably already know most of what you need to know to perform 3D vertex operations. All you need is to know how to multiply 4x4 matrices, and you are all set for a lot of fun. You can even do this directly in Flash, since AS3 comes with X, Y and Z coordinates built in!

But before you can use this rather simple math to operate points in 3D space, you will need to have a look on the principles of Cartesian coordinates, like local and global coordinates. For matrix calculus to work properly, your 3D points need to be converted to local space, and then converted back to global space after the matrix operation. This is related to what Flash display objects know as the "hot spot", or center of rotation. It's nothing complicated, but it's something you have to do. ^^

👍: 0 ⏩: 1

willmh93 In reply to ken1171 [2010-06-10 11:36:47 +0000 UTC]

Too bad I haven't learnt AS3 yet I'm still with AS2, and I don't particularly feel
like learning a new programming language even if it's only an upgrade from thr previous.
I'm interested in how matricies apply to 3D, I've installed the new DirectX development kit,
so I'll try learning how to use it. Your description was very useful, I already have a
book that applies all this to DirectX 10, but I think it's for s slightly more advanced level.

Thanks

👍: 0 ⏩: 1

ken1171 In reply to willmh93 [2010-06-10 22:44:03 +0000 UTC]

I personally find DirectX way too complicated for what it does. This is common to Microsoft products, where at times it looks like they complicate things on purpose.

👍: 0 ⏩: 1

willmh93 In reply to ken1171 [2010-06-10 23:41:49 +0000 UTC]

I know what you mean! but I think it ultimately boils down to speed, the more work the programmer has to do - usually the faster the code will be. When everything's managed for you, there's alot of excess code which slows things down. That wouldn't be too much of a problem for me, I just need to learn how to use it first... then maybe I can make my own class to wrap up all the code and speed development up in future.

👍: 0 ⏩: 1

ken1171 In reply to willmh93 [2010-06-11 00:05:38 +0000 UTC]

I think computers are so fast nowadays that things like this are not such an issue like it used to be when I was a programmer back in the 1980s and 90s. I used to write DirectX code in those days, but now it has lost its appeal to me because it is tied up to Windows-only, and that's never going to change. I think the future will be 3D on the web, and I have already written a small interactive 3D program [link] that runs on a web browser using Flash. Note this is *really* real time 3D on a browser, not 2D sprite simulations. Its multi-browser and multi-platform, something DirectX can only dream about...

👍: 0 ⏩: 1

willmh93 In reply to ken1171 [2010-06-11 00:20:32 +0000 UTC]

I agree with the fact that they're fast enough for games you would commonly find for the PC, but I think something like DirectX is needed when it comes to producing high-performance XBOX or PS3 games, where a single instruction repeated hundreds of thousands times per second makes all the difference when you sum them all up. Some people's aim is to achieve fun portable games, others are to make specific powerful games/applications.

I've seen alot of debate on these sorts of topics, even people suggesting C++ will soon die out and Java will take over entirely. But I think each language has its own use, low level or slow systems will usually be made with C/C++.

My first DirectX game used DirectX version 4, I made a game of breakout. Hell - that took me nearly 700 lines of painful C code, where in flash that could have been done in 40-50 lines, so I guess I see your point

👍: 0 ⏩: 1

ken1171 In reply to willmh93 [2010-06-11 06:57:23 +0000 UTC]

I don't believe Java could ever take over C++, because Java was designed for a specific purpose, usually where C++ cannot go, and vice-versa. They are both necessary depending on the target platform. Java is at home on the web, while C++ is everywhere else.

What caught my attention was the meeting between Adobe and Intel, where there seems to be plans for a new chip that will run ActionScript on hardware. This will have a multitude of applications on portable devices, and there are rumors that PC motherboards should all come with the chip built-in on a near future. This would finally allow true hardware accelerated Flash applications, to include 3D.

As for DirectX, Sony uses a custom version of Linux to power the PS3, so that should make it impossible for DX to ever enter that market. This only leaves XBOX and Windows to use DirectX, which is quite a limited market. In the same way, Microsoft's Silverlight only works under Windows, while Flash can run anywhere. Apple has recently tried to kill Flash, but the public didn't receive that very well, considering that HTML5 cannot actually replace it.

Things are changing a lot nowadays, and I am eager to see what will come out of it.

👍: 0 ⏩: 0

TidalNight [2010-06-06 01:14:01 +0000 UTC]

Awesome application of trig and math, I'm currently on a break from flash, but have been thinking about getting back into it, this certainly would be something I'd look through to refresh my memory on things.

Thanks for posting this!

👍: 0 ⏩: 1

willmh93 In reply to TidalNight [2010-06-06 12:54:36 +0000 UTC]

thankyou! i think that's a good idea i quit flash for a fair while, i'm also trying to get back into it more.
thanks again, and you're welcome ^^

👍: 0 ⏩: 0

faraz622 [2010-06-05 20:49:18 +0000 UTC]

wow perfect
thank you

👍: 0 ⏩: 1

willmh93 In reply to faraz622 [2010-06-05 21:59:23 +0000 UTC]

you're welcome! glad you like it

👍: 0 ⏩: 0

wonderwhy-ER [2010-06-05 19:28:40 +0000 UTC]

Heh elegant and simple. Though I wonder how complex it could become if you add more balls...

👍: 0 ⏩: 1

willmh93 In reply to wonderwhy-ER [2010-06-05 21:59:12 +0000 UTC]

Adding more balls isn't too complex i don't think.. but it's very confusing.. and although im sure i could manage it with some time, I just can't be bothered ^^

thankyou :]

👍: 0 ⏩: 1

wonderwhy-ER In reply to willmh93 [2010-06-05 22:15:54 +0000 UTC]

I see

👍: 0 ⏩: 0

waltzy [2010-06-05 18:44:58 +0000 UTC]

Ill check this out when I get a mo, the preview make this look like just the thing I need. The code I can do, but the math always eludes me. Very useful

👍: 0 ⏩: 1

willmh93 In reply to waltzy [2010-06-05 21:58:04 +0000 UTC]

hm, well then the code and comments should make some sense to you, but maybe some practice in trigonometry would help if you're not too good with the maths.. its mainly reading diagrams and resolving variables with trig.

Thanks

👍: 0 ⏩: 0

ZaneAsylum [2010-06-05 14:28:26 +0000 UTC]

Intensive! A must have. Thanks so much for taking the time to make this and share it.

👍: 0 ⏩: 1

willmh93 In reply to ZaneAsylum [2010-06-05 15:03:25 +0000 UTC]

thankyou! that means alot and actually I say i spent a while making this, I only started it yesterday but i spend a good few hours on it.

I'm glad you like it

👍: 0 ⏩: 0