Sunday, July 09, 2006

Direct X Version Bouncing Ball !

3D Bouncing Ball 1.0

Oh yea! I did it! Hehe, after today of hard work (almost 5 hours spent) for this my "weekend's plan", I did this simple 3D Bouncing Ball with Direct X! I planed to make a bouncing ball in this weekend on Thursday because I found that it's been too long since I touch my Direct X. So I came out this plan to test my skill. Still remember while I just join Hatchlings, my first programmer task is to code a 2D Bouncing Ball. So I guess this is a good topic to test a game programmer skill?

This is not a hard thing to code while someone might laughing at me :"What? Until now you just did this stupid bouncing ball program? People coding World of Starcraft already!". By the way, just kidding :P I don't think anyone will care what a N00b did anyway. Hehe. For 1 month + few days of Direct X learning and I did this thing, for myself, it's good enough :) This just a starting anyway, will do more research and try to improve and make real thing. I start to love 3D programming. lol.

Working Report

Well, please allow me to share my humble making this Bouncing Ball expenrience (After all, just wanna mark my History page, wuahahaha). After some years of programming, I learn an important pre-work before I actually code which is "scracth and draw on paper with pencil". It's not UML, too formal for me alone to refer. I just simply clip some last year notes together and use the back side to draw and write everything I plan to do. Brainstorm whatever method came across my brain and just write it down, online google some useful formula and not familiar function. Then start to filter out and conclude the last method.

In this demo, I divide it to 2 stages. 1st stage is drawing a sphere manually in Direct x. Most of the code I reuse from my previous Dx pratice (CodeName : Dx 3.2) to save duplicated works. So I just need to do the Ball class with built mesh and render method. It took me some times to figure out the right way to draw a sphere in 3D graphic. I knew it's dumb to twisting my brain while this solution float every where in the internet, but thats me :) What's the point to copy people code for such a simple work anyway... So my solution is using Triangle Strip to draw the body of the ball and Fan to end it's top. I drew one hemisphere, the other half will copy the 1st one and rotate 180 degree to form a complete ball. (The picture show my ball)




Getting the rigth vertex and rigth index arrangement to draw a complete ball is tedius work, many trials and error run used to finally made one ball. 2nd stage is relative easy compare to 1st stage. 2nd stage just need to add one extra function, animate() in my ball class and make my balls instance is a large array so that many balls flying around. Animate() just simply moving function with translate my balls around the space and reflect when it hit the wall. No gravity, No ball to ball collision detection, and No friction in Demo 1. Hehe. (The picture is 500 balls flying around and knocking the wall).

I leant a lot of thing by doing this demo such as how to use strip and fan, how to translate and rotate the mesh. I will improve this once I get my free time again. Or may be I continue learning my Direct x lesson which I stuck somewhere in the Terrain engine.

RM1,000 Codematch!?

Codemath is a Programming Contest orgranize by MMU's programming lecturer which test mainly on programming algorithm. Solid and I went to the training today but half of the time is wathcing and listen because there is no electricity. 10 teams joined the match, each team with 3 members in it. Me, Solid and Josh formed a team named SJK. We are a good team in my opinion, both of their programming skill is good. But the thing is... our opponents are not here to play too :P Victor joined this contest too, so I guess the rest of us are going for the RM 500 or RM 300. RM 1K already reserved by Victor. LOL. Victor is a famous good programming student in MMU, heard of his skill around the campus several times. Well, we SJK are here to testing only, no big deal, but we still going to try our best!

Waoh...Today blog's all about programming? That's my objective of making this blog anyway :P Don't worry, gonna share more experince afterward. My body is bugging me to sleep now. hehe. Tommorow have a CyberJaya -> KLIA -> Sunway -> CyberJaya Drive.

Today Feeling ~|~ Filled with success, but there's a empty space, I guess it's a place for the bee to sleep.