Exemple #1
0
 private Vec2 transform(Vec2 p, Size size)
 {
     return(V.xy(
                size.Width / 2f + p.x,
                size.Height * 2f / 3f - p.y
                ));
 }
Exemple #2
0
        private void Calculate()
        {
            var frame_next = frame + 1;

            if (frame_next >= frames)
            {
                return;
            }
            for (var shape = 0; shape < shapes; shape++)
            {
                var radius_curr = radius_arr[shape];
                var pos_curr    = pos_arr[shape, frame];
                var vel_curr    = vel_arr[shape, frame];


                var vel_next = vel_curr + dt * gravity;
                var pos_next = pos_curr + (vel_next + vel_curr) * dt * 0.5f;

                var t = wall_normal * (pos_next - wall_point);
                if (t < radius_curr && vel_curr * wall_normal < 0f)
                {
                    pos_next = mirror(wall_point + radius_curr * wall_normal, wall_normal, pos_next);
                    vel_next = mirror(V.zero(), wall_normal, vel_next) * restitution;
                }

                pos_arr[shape, frame_next] = pos_next;
                vel_arr[shape, frame_next] = vel_next;
            }
        }
Exemple #3
0
        private V mirror(V mirror_point, V mirror_normal, V point)
        {
            var t = mirror_normal * (point - mirror_point);

            return(point - 2 * t * mirror_normal);
        }