Assignment 2:
Kinect Controlled Monkey Cannon
Hurray, a Video Game!
Your task: Using JMonkey, create a Cannon that
can rotate on its base around the y and x axis (that is: pitch and yaw, that
is: what you would expect from an old style artillery weapon). This cannon is controlled by your left and right arm:
·
The cannon's pitch
takes the angle of your right arm vs. the ground (i.e. if you hold your right
hand out straight to the right, the cannon points horizontally)
·
The cannon rotates
around its Y axis (changing the N,S,E,W direction, so to say) depending on your relative position of hand
and shoulderline: hand > 10cm in front: cannon rotates +, >10cm behind:
cannon rotates - .
·
Your left arm
controls a firing mechanism: if you move your left hand from above your
shoulders below your shoulders, the cannon fires.
We then let the cannon-ball fly and see if
it hits a target-box, which is placed somewhere.
Oh, the cannon and the target will be
replaced randomly after each shot.
The goal of the game is to shoot the box 5
times, as fast as possible.
What is assignment about?
·
Starting with
JMonkey
·
Thinking about
coordinate systems and transforms
·
impressing other
students
(you can easily extend this game: two
cannons are placed into a fractal environment with targets behind the
mountains, two player game with TCP connection, ...ideas welcome!)
For those who panic easily:
·
The TA will explain
a lot during the lab
·
We will talk very
detailed about this assignment in class
·
it's a group
assignment
·
The example codes
example1, example2 are at least a start with JMonkey (see class website)
·
We will NOT use any
JMonkey physics in here! (that will come later and add a lot of joy to the
project!)
·
You have an entire
week! :-)
·
I do help, if you
come to my office hours/office any time
The task in steps:
1.
setup a ground
area, which is a box of 20 x 0.1 x 20 meters (Box b = new Box(10,0.05,10))
2.
create the cannon.
The cannon should just consist of a Cylinder, as the cannon itself (excuse my
lack of military terminology, as I am a convinced pacifist, only firing virtual
cannons), and its base, e.g. a box.
3.
Think about the
Geometry and Node objects. You need to organize your cannon into an appropriate
scene graph structure. When rotating the cylinder up/down, the base does not
change. When rotating around the y-axis, the base AND the cylinder rotate!
4.
Connect to the
Kinect input. Determine the angle between right wrist and right shoulder
(simple approach: just assuming an arm length of 1 meter (1000 millimeter), and
defining the height difference between wrist and shoulder by "dy",
the horizontal angle is atan2(dy, 1000.0)). Determine the z-distance between
right wrist and shoulder.
5.
Animation:
animations in JMonkey are very easily achieved: the graphic output is
automatically updated (usually with something like 100fps). Before the update,
the method "public void simpleUpdate(float tpf)" is called. This is a
method of SimpleApplication, which you inherit your own class from. Hence,
overriding this method gives you your own animation thread. Please read about
the tpf ("time per frame") parameter in there to adjust your game's
speed to your computer's abilities.
6.
When all this
works, you should see a cannon, which rotates depending on your right arm
position.
7.
The firing
mechanism: each time your left hand moves from above to below your shoulder,
you create a Sphere inside of the cannon (coordinate system? transformations?),
and with it, you create variables for its position and speed (3D!). The initial
speed is given by the cylinder's axis direction (how do you compute that?)
8.
some self made
physics: update your cannon-balls position based on its speed (i'll talk about
that in class), and its speed based on gravity.
9.
create the game
logic around your system: add a box, test collision of sphere and box (your own
collision test, not JMonkey physics)
10.
play.
It's a group project. Help each other.
Bonus:
are you able to connect two computers via
TCP to play against each other? the target would then be the enemy cannon.