Calculating bounce angle (Kinect Pong)

Alright, so I'm programming a game of pong using the kinect, but I'm having a very hard time getting the ball to bounce at the right angle.

I am using the depth information to allow for me to set up a small area in which anything in that area will be drawn on the screen, so that hands are used in place of paddles. That means hands will be moving all directions and will be tilted at all sorts of angles, so I can't do the typical pong movement and just have it reverse x/y directions.

This is what I have right now in an attempt to calculate the x/y movement output.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
						/*the ball is drawn above, and I have mapped out points around the ball to check for collision
						once 7 points on the circle are touching, we get xNormal and yNormal.
						i add the coordinates of these points (relative to center of ball)
						and average them in order to get the best point from which to calculate the normal. 
						these numbers are calculated properly and return the desired numbers*/
						xNormal = -xNormal/7;
						yNormal = -yNormal/7;
						
						//velocity (it works)
						v = sqrt(xin*xin + yin*yin);
						printf("v: %f\n\n", v);
						//calculate theta
						theta = atan(yin/xin);
						printf("theta: %f\n\n", theta);
						//and beta...
						beta = atan(yNormal/xNormal);

						printf("beta: %f\n\n", beta);

						//A should be the angle at which to send the ball off
						A = 2*beta + theta;
						
						//calculate the velocity at which to send the ball in each direction, updated each frame
						yin = sin(A) * v;
						xin = cos(A) * v;





I guess this is more of a mathematical question, and unfortunately my math background isn't all that strong.
boolean rememberMaterial = false;

Keep in mind the coordinate plane is as follows...

(0, 0) ------------------------------------------- (640, 0)
|
|
|
|
|
|
|
|
|
|
(0, 480)


Any help would be appreciated!
Last edited on
I've never dealt with kinect so I don't understand. What input do you have? Also, how can you only have x;y coordinates? I'm sure the input is in 3 coordinates.. Do you just ignore y (height) of the hand? In that case, if you have two points on you hand, you can easily find a normal. If you have that, see http://mathworld.wolfram.com/Reflection.html
Topic archived. No new replies allowed.