CUDA Lab 8. A simple particle animation in CUDA
1. Understand how to animate sphere in motion
2. Understand how to render different spheres in different colours
3. (optional) Design and implement a simple sphere-sphere collision detection algorithm
Copyright By PowCoder代写 加微信 powcoder
Exercise 1. Draw a box without front wall.
Built upon what you have achieved in Lab 6 and draw the following box. There are two ways to draw the walls of the box. One method is to implement a ray-box ray caster by calculating the ray-box intersection similar to the method provided in sphere.h. A more direct method is to regard the walls as the surfaces of very big spheres. For instance, the left wall can be directly defined as
*(d_list + 1) = new sphere(vec3(-10002.0, 0, -3), 10000);
Exercise 2. Free motion animation.
Draw a ball rotating by the centre of the box. One direct way to create this effect is to introduce a static variable corresponding to the rotation angle, for instance, locally as
static int ticks = 1; or globally as
__device__ static int ticks = 1;
and specify the position of a ball as.
new sphere(vec3(cos(0.01*(float)ticks++), sin(0.01*(float)ticks++), -1), 0.2); For more realistic animation, the ball position may need to be updated based on system time.
Exercise 3. Ball-box walls collision animation.
1. Animate a ball in motion inside the box with a given initial velocity, such that when it hits a wall, its velocity is reflected by the wall normal vector.
2. Change the ball colour once when it collides with a box wall.
3. Introduce two more balls and animate their motions within the box.
Exercise 4 (Optional). Ball-ball collision animation.
Introduce a few more balls with identical size inside the box and animate their motion with certain initial velocities. When the speeds of these balls are not high, the collision between two balls can be detected approximately by checking the distance between them. For identical balls with pure elasticity, the ball-ball collision response can be calculated directly based on their relative velocity of at the time of collision in the following way,
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com