CS525 Project 3 Page
0.Demo Video
1. Basic idea
For this project, basically using openCL to implement the collision detection part in 2D rigid body dynamics with Kinect controlling, so that you can use your hand to attract all the objects. Following is a general look of program itself.
2. 2D Polygon Collision Detect
The principle is very easy, and very simple to implement. The algorithm tries to determine is it is possible to fit a plane between two object. If such a plane exists, then the object are separated, and cannot intersect.
To determine if the objects are separated, it is simply a matter of projecting the objects onto the normal of the plane, and comparing the intervals and see if they overlap.
To determine if the objects are separated, it is simply a matter of projecting the objects onto the normal of the plane, and comparing the intervals and see if they overlap.
So, there is obviously an infinite number of planes that can fit between two separated objects. For boxes, from the picture above, we can see the plane normal is the major axis of Box B.
It can be shown that for boxes, the separation planes to be tested are the planes with normal equal to the axes of both boxes. So for 2 boxes, we only need to test 4 separation planes in total. Out of the 4 planes, once we found a separation plane that separates the boxes, then we know the box cannot intersect, and return a no collision flag.
If the 4 planes cannot separate the boxes, then the box must be intersection, and there is a collision.
To extend this to generic polygons, the algorithm remains the same. Only the number of planes to be tested changes.
It can be shown that for boxes, the separation planes to be tested are the planes with normal equal to the axes of both boxes. So for 2 boxes, we only need to test 4 separation planes in total. Out of the 4 planes, once we found a separation plane that separates the boxes, then we know the box cannot intersect, and return a no collision flag.
If the 4 planes cannot separate the boxes, then the box must be intersection, and there is a collision.
To extend this to generic polygons, the algorithm remains the same. Only the number of planes to be tested changes.
3. GPU Implement Using OpenCL
The number of threads equals to the number of objects on the screen, first transfer all the data of objects to GPU memory, then implement the kernel that, each thread of one object compare itself to all the other object to detect if there is a collision between these two polygons.
If a collision found, then the kernel calculate the contact point for them and add all the force together including gravity, then render the new position on the screen.
If a collision found, then the kernel calculate the contact point for them and add all the force together including gravity, then render the new position on the screen.
4. Kinect Control
Since kinect can give accurate and reasonably high res depth information for every pixel, and openNI can give a relatively good skeleton tracing, so it's not hard to get the position of right hand in realtime.
Unfortunately, I don't find anyway to implement openGL&openCL and openNI in a same project file, so I separate them into two different execute file.
Unfortunately, I don't find anyway to implement openGL&openCL and openNI in a same project file, so I separate them into two different execute file.
5. Program Control
For the program, first will create 15 random objects, there are a 20% possibility that a new object is a static object, which does not move. And the gravity is automatic add on.
Controls of the program:
+/-: add/delete new/old objects
Press G: enable/disable gravity
Push action: activate cursor attracting
Move right hand: move attracting center
P : Pause
Spacebar: reset
Enter: run from the begin
Controls of the program:
+/-: add/delete new/old objects
Press G: enable/disable gravity
Push action: activate cursor attracting
Move right hand: move attracting center
P : Pause
Spacebar: reset
Enter: run from the begin
6. Result
From the fig. we can see that, for more and more polygon in the screen, the GPU has higher and higher FPS than CPU.
7. Reference
http://75.98.78.94/default.aspx openNI: offical website of openNI which is a great depth sensors library that can make kinect control possible
http://openkinect.org/wiki/Main_Page openKINECT: another good library for kinect
http://www.kinecthacks.com/ kinecthacks: ideas and videos of kineck hacking form all over the world
http://www.kinectforwindows.org/ New offical SDK from Microsoft~~
http://chrishecker.com/Rigid_Body_Dynamics Every thing about rigid body dynamics, a lots maths...
http://openkinect.org/wiki/Main_Page openKINECT: another good library for kinect
http://www.kinecthacks.com/ kinecthacks: ideas and videos of kineck hacking form all over the world
http://www.kinectforwindows.org/ New offical SDK from Microsoft~~
http://chrishecker.com/Rigid_Body_Dynamics Every thing about rigid body dynamics, a lots maths...