stylet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +4 -0
- data/.yardopts +2 -0
- data/Gemfile +16 -0
- data/README.org +19 -0
- data/Rakefile +17 -0
- data/bin/setup +63 -0
- data/bin/stylet +8 -0
- data/examples/.ruby-version +1 -0
- data/examples/00100_lib_hello_world.rb +8 -0
- data/examples/00110_lib_sge_check.rb +6 -0
- data/examples/00120_lib_/343/202/254/343/203/263/343/203/236/345/200/244/343/201/256/345/244/211/346/233/264.rb +22 -0
- data/examples/00130_lib_window_title.rb +8 -0
- data/examples/00140_lib_callbacks.rb +8 -0
- data/examples/00150_lib_vector.rb +5 -0
- data/examples/00160_lib_run.rb +4 -0
- data/examples/00170_lib_frame.rb +4 -0
- data/examples/00180_lib_config/347/242/272/350/252/215.rb +7 -0
- data/examples/00190_lib_/343/201/231/343/201/271/343/201/246/345/220/214/343/201/230/343/202/252/343/203/226/343/202/270/343/202/247/343/202/257/343/203/210.rb +10 -0
- data/examples/00200_lib_/343/203/254/343/202/267/343/203/274/343/203/220/343/203/274/343/202/222/347/234/201/347/225/245/343/201/231/343/202/213/346/226/271/346/263/225/343/201/256/343/203/206/343/202/271/343/203/210.rb +28 -0
- data/examples/00210_lib_delegators.rb +7 -0
- data/examples/00220_lib_template_method.rb +13 -0
- data/examples/00230_lib_/350/203/214/346/231/257/347/224/273/345/203/217/350/241/250/347/244/272.rb +9 -0
- data/examples/00240_lib_/350/203/214/346/231/257/347/224/273/345/203/217/343/202/222/346/232/227/343/201/2171_/351/273/222/343/201/256/344/270/212/343/201/253/350/203/214/346/231/257.rb +18 -0
- data/examples/00250_lib_/350/203/214/346/231/257/347/224/273/345/203/217/343/202/222/346/232/227/343/201/2172_/350/203/214/346/231/257/343/201/256/344/270/212/343/201/253/351/273/222.rb +17 -0
- data/examples/00260_lib_/350/203/214/346/231/257/347/224/273/345/203/217/343/202/222/346/232/227/343/201/2173_/350/203/214/346/231/257/343/201/256/344/270/212/343/201/253/351/273/222_/347/224/273/351/235/242/343/202/265/343/202/244/343/202/272/343/203/225/343/202/243/343/203/203/343/203/210_/351/207/215/343/201/204.rb +27 -0
- data/examples/00270_lib_/350/203/214/346/231/257/347/224/273/345/203/217/343/202/222/346/232/227/343/201/2173_/350/203/214/346/231/257/343/201/256/344/270/212/343/201/253/351/273/222_/347/224/273/351/235/242/343/202/265/343/202/244/343/202/272/343/203/225/343/202/243/343/203/203/343/203/210_/351/253/230/351/200/237/345/214/226.rb +44 -0
- data/examples/00280_lib_/347/211/271/345/256/232/343/201/256/343/202/250/343/203/252/343/202/242/343/201/240/343/201/221/345/276/220/343/200/205/343/201/253/346/266/210/343/201/231.rb +26 -0
- data/examples/00290_lib_/350/203/214/346/231/257/350/211/262/345/244/211/346/233/264.rb +5 -0
- data/examples/00300_lib_/343/202/255/343/203/243/343/203/251/343/202/257/343/202/277/347/224/273/345/203/217/343/202/222/350/241/250/347/244/272/343/201/231/343/202/213/344/276/213.rb +17 -0
- data/examples/00310_lib_/343/202/255/343/203/243/343/203/251/343/202/257/343/202/277/347/224/273/345/203/217/343/201/256/343/202/242/343/203/213/343/203/241/343/203/274/343/202/267/343/203/247/343/203/263.rb +18 -0
- data/examples/00320_lib_/343/202/255/343/203/243/343/203/251/343/202/257/343/202/277/346/213/241/345/244/247/347/270/256/345/260/217/345/233/236/350/273/242.rb +21 -0
- data/examples/00330_joystick.rb +5 -0
- data/examples/00340_joystick_PS3/343/202/242/343/203/212/343/203/255/343/202/260/343/203/254/343/203/220/343/203/274/343/201/256/345/213/225/343/201/215/343/201/214/345/206/205/351/203/250/343/201/247/343/201/257/345/233/233/350/247/222.rb +30 -0
- data/examples/00350_joystick_PS3/343/202/242/343/203/212/343/203/255/343/202/260/343/203/254/343/203/220/343/203/274/343/201/256/350/252/277/346/225/264/346/270/210/343/201/277/343/203/231/343/202/257/343/203/210/343/203/253.rb +12 -0
- data/examples/00360_lib_mouse.rb +5 -0
- data/examples/00370_lib_input.rb +29 -0
- data/examples/00380_lib_vputs_align.rb +8 -0
- data/examples/00390_/343/203/225/343/202/251/343/203/263/343/203/210/344/270/200/350/246/247.rb +15 -0
- data/examples/00400_lib_draw_circle.rb +8 -0
- data/examples/00410_SDL/343/201/256draw_rect/343/201/2571/343/203/224/343/202/257/343/202/273/343/203/253/344/275/231/345/210/206/343/201/253/346/217/217/347/224/273/343/201/225/343/202/214/343/202/213/343/201/256/343/201/247/346/263/250/346/204/217.rb +7 -0
- data/examples/00420_circle_on_circle.rb +10 -0
- data/examples/00430_rotate.rb +16 -0
- data/examples/00440_draw_triangle.rb +7 -0
- data/examples/00450_parabora_triangle.rb +37 -0
- data/examples/00460_ice_hockey.rb +88 -0
- data/examples/00470_collision_block_vs_block.rb +120 -0
- data/examples/00480_simple_circle_controll.rb +37 -0
- data/examples/00490_/347/255/211/351/200/237/347/247/273/345/213/225_uniform_velocity_rain.rb +51 -0
- data/examples/00500_/345/212/240/351/200/237/346/224/276/347/211/251/347/267/232_parabora_volcano.rb +94 -0
- data/examples/00510_3d.rb +53 -0
- data/examples/00520_/343/203/210/343/203/253/343/203/215/343/201/256/343/203/241/343/203/213/343/203/245/343/203/274/351/242/250/343/201/256/345/213/225/343/201/215.rb +77 -0
- data/examples/00530_curve_2/346/254/241/343/203/231/343/202/270/343/202/247/346/233/262/347/267/232/343/201/250/347/233/264/347/267/232/343/201/250/343/201/256/344/272/244/347/202/271.rb +43 -0
- data/examples/00540_curve_3/346/254/241/343/203/231/343/202/270/343/202/247/346/233/262/347/267/232.rb +40 -0
- data/examples/00550_curve_N/346/254/241/343/203/231/343/202/270/343/202/247/346/233/262/347/267/232.rb +92 -0
- data/examples/00560_curve_/343/202/271/343/203/227/343/203/251/343/202/244/343/203/263/346/233/262/347/267/232.rb +113 -0
- data/examples/00570_/345/206/206/351/201/213/345/213/225_circle_jet_coaster.rb +52 -0
- data/examples/00580_/345/206/206/343/202/222/346/212/274/343/201/231/343/201/262/343/201/243/343/201/261/343/202/213_collision_circle_vs_circle_push_or_pull.rb +56 -0
- data/examples/00590_/350/212/213/350/231/253/343/202/264/343/203/240/347/264/220/343/203/207/343/203/242_collision_demo_circle_worm.rb +104 -0
- data/examples/00600_/346/214/257/343/202/212/345/255/220_swing.rb +145 -0
- data/examples/00610_/345/206/205/347/251/215/343/201/250/345/244/226/347/251/215_inner_product.rb +36 -0
- data/examples/00620_/346/263/225/347/267/232/343/203/231/343/202/257/343/203/210/343/203/253.rb +23 -0
- data/examples/00630_/345/206/206/343/201/250/345/206/206/343/201/256/345/217/215/345/260/204_collision_reflect_circle_vs_circle.rb +222 -0
- data/examples/00640_/347/202/271/343/201/250/347/267/232/345/210/206/343/201/256/344/272/244/345/267/256/345/210/244/345/256/232_collision_ray_circle_vs_line.rb +261 -0
- data/examples/00650_/345/206/206/343/201/250/347/202/271/343/201/256/345/217/215/345/260/204_collision_circle_vs_dot.rb +36 -0
- data/examples/00660_/345/206/206/343/201/250/345/206/206/343/201/250/347/267/232/345/210/206/343/201/256/345/217/215/345/260/204/343/203/207/343/203/242_collision_demo.rb +305 -0
- data/examples/00670_/343/203/251/343/202/244/343/203/225/343/202/262/343/203/274/343/203/240.rb +86 -0
- data/examples/00680_2/347/202/271/343/202/222/351/200/232/343/202/213/347/233/264/347/267/232/343/201/256/346/226/271/347/250/213/345/274/217.rb +81 -0
- data/examples/00690_/343/203/222/343/203/253/343/203/231/343/203/253/343/203/210/346/233/262/347/267/232.rb +77 -0
- data/examples/00700_/343/202/263/343/203/203/343/203/233/346/233/262/347/267/232.rb +79 -0
- data/examples/00710_/343/202/267/343/202/260/343/203/242/343/202/244/343/203/211/346/233/262/347/267/232.rb +40 -0
- data/examples/00720_/343/202/267/343/203/200/346/244/215/347/211/251.rb +44 -0
- data/examples/00730_/343/202/257/343/203/252/343/203/225/343/202/251/343/203/274/343/203/211/343/202/242/343/203/210/343/203/251/343/202/257/343/202/277_/345/237/272/346/234/254.rb +29 -0
- data/examples/00740_/343/202/257/343/203/252/343/203/225/343/202/251/343/203/274/343/203/211/343/202/242/343/203/210/343/203/251/343/202/257/343/202/277_/346/224/271/350/211/257_/350/211/262/344/273/230/343/201/215.rb +68 -0
- data/examples/00750_/343/202/257/343/203/252/343/203/225/343/202/251/343/203/274/343/203/211/343/202/242/343/203/210/343/203/251/343/202/257/343/202/277_/343/203/211/343/203/274/343/203/212/343/203/204/345/236/213.rb +44 -0
- data/examples/00760_/347/201/253/350/212/261.rb +42 -0
- data/examples/00770_atan/343/201/247atan2/343/202/222/346/233/270/343/201/217.rb +26 -0
- data/examples/00780_/346/250/231/346/272/226/343/203/251/343/202/244/343/203/226/343/203/251/343/203/252/343/201/256atan2_sin_cos/343/202/222/344/275/277/343/201/206.rb +15 -0
- data/examples/00790_/350/247/222/345/272/246/343/201/250/343/203/251/343/202/270/343/202/242/343/203/263/343/201/256/347/233/270/344/272/222/345/244/211/346/217/233.rb +22 -0
- data/examples/00800_/347/220/203/343/201/214/347/233/264/347/267/232/347/232/204/343/201/253/345/213/225/343/201/204/343/201/246/343/201/204/343/202/213/343/201/240/343/201/221/343/201/247/345/233/236/350/273/242/343/201/227/343/201/246/343/201/204/343/202/213/343/202/210/343/201/206/343/201/253/350/246/213/343/201/210/343/202/213.rb +27 -0
- data/examples/00810_/343/202/267/343/203/237/343/203/245/343/203/254/343/203/274/343/202/267/343/203/247/343/203/263_/350/273/212.rb +75 -0
- data/examples/00820_/343/202/267/343/203/237/343/203/245/343/203/254/343/203/274/343/202/267/343/203/247/343/203/263_/346/210/246/350/273/212.rb +90 -0
- data/examples/00830_/350/247/222/345/272/246/345/267/256.rb +36 -0
- data/examples/00840_/346/224/276/347/211/251/347/267/232/343/201/247/347/213/231/346/222/203_/346/231/202/351/226/223/345/233/272/345/256/232.rb +61 -0
- data/examples/00850_/346/224/276/347/211/251/347/267/232/343/201/247/347/213/231/346/222/203_/350/247/222/345/272/246/345/233/272/345/256/232.rb +84 -0
- data/examples/00860_/346/224/276/347/211/251/347/267/232/343/201/247/347/213/231/346/222/203_/351/200/237/345/272/246/345/233/272/345/256/232.rb +66 -0
- data/examples/00870_/350/247/222/345/272/246/350/243/234/346/255/243_/345/212/240/351/200/237/343/203/237/343/202/265/343/202/244/343/203/253.rb +60 -0
- data/examples/00880_/345/210/235/351/200/237/343/201/214/351/200/237/343/201/204/343/203/237/343/202/265/343/202/244/343/203/253.rb +51 -0
- data/examples/00890_/346/255/243/350/246/217/344/271/261/346/225/260/343/201/250/346/250/231/346/272/226/345/201/217/345/267/256/343/201/256/345/217/257/350/246/226/345/214/226.rb +72 -0
- data/examples/00900_/345/220/221/345/277/203/345/212/233/343/201/247/345/233/236/350/273/242/343/200/220/350/247/222/345/272/2460/345/272/246/343/201/213/343/202/211/343/200/221.rb +23 -0
- data/examples/00910_/345/220/221/345/277/203/345/212/233/343/201/247/345/233/236/350/273/242/343/200/220/344/273/273/346/204/217/343/201/256/350/247/222/345/272/246/343/201/213/343/202/211/343/200/221.rb +33 -0
- data/examples/00920_/343/203/236/343/203/252/343/202/252/343/203/226/343/203/251/343/202/266/343/203/274/343/202/272/351/242/250/343/201/253/347/224/273/351/235/242/344/270/241/347/253/257/343/201/214/347/271/213/343/201/243/343/201/246/343/201/204/343/202/213/344/276/213.rb +29 -0
- data/examples/00930_/345/212/271/346/236/234/351/237/263.rb +17 -0
- data/examples/00940_/343/203/236/343/203/203/343/203/227/343/203/201/343/203/203/343/203/227/343/201/256/343/203/236/343/203/203/343/203/227/351/205/215/347/275/256.rb +71 -0
- data/examples/00950_/343/203/236/343/203/203/343/203/227/343/203/201/343/203/203/343/203/227/343/201/256/350/241/250/347/244/272/344/276/213.rb +28 -0
- data/examples/00960_/343/203/236/343/203/203/343/203/227/343/203/201/343/203/203/343/203/227/343/201/250/345/215/230/344/270/200/347/224/273/345/203/217/343/201/256/351/201/225/343/201/204/343/202/222/345/220/270/345/217/216/343/201/231/343/202/213/344/276/213.rb +47 -0
- data/examples/00970_observer_/343/201/235/343/201/2561_/347/233/264/346/216/245.rb +28 -0
- data/examples/00980_observer_/343/201/235/343/201/2562_/346/231/256/351/200/232/343/201/253Singleton/347/211/210.rb +30 -0
- data/examples/00990_observer_/343/201/235/343/201/2563_SimpleDelegator/347/211/210.rb +28 -0
- data/examples/01000_observer_/343/201/235/343/201/2564_/351/200/206/343/201/253/343/203/253/343/203/274/343/203/227/344/270/273/345/260/216.rb +28 -0
- data/examples/01010_observer_/343/201/235/343/201/2565_/343/201/204/343/202/215/343/202/223/343/201/252/346/211/200/343/201/213/343/202/211/345/221/274/343/202/223/343/201/247/343/201/204/343/202/213/343/201/221/343/201/251Singleton/343/201/252/343/201/256/343/201/247/345/256/211/345/205/250.rb +37 -0
- data/examples/01020_observer_/343/201/235/343/201/2566_/343/201/204/343/202/215/343/202/223/343/201/252/346/211/200/343/201/213/343/202/211/345/221/274/343/201/266/345/240/264/345/220/210callbacks/343/202/222/344/275/277/343/202/217/343/201/252/343/201/204/343/202/210/343/201/206/343/201/253.rb +30 -0
- data/examples/01030_observer_/343/201/235/343/201/2567_/343/202/250/343/203/225/343/202/247/343/202/257/343/203/210/343/202/277/343/202/271/343/202/257/343/202/222/345/233/236/343/201/231/344/276/213.rb +57 -0
- data/examples/01040_/343/203/236/343/202/246/343/202/271/343/201/256/344/275/215/347/275/256/343/201/253/343/203/224/343/202/257/343/202/273/343/203/253/343/202/222/346/211/223/343/201/244.rb +18 -0
- data/examples/01050_/343/203/224/343/202/257/343/202/273/343/203/253/345/205/250/344/275/223/343/202/222/346/233/270/343/201/215/350/276/274/343/202/200.rb +27 -0
- data/examples/01060_effect_/347/224/273/345/203/217/343/201/256/343/202/263/343/203/263/343/203/234/343/203/252/343/203/245/343/203/274/343/203/210/346/263/225/343/201/253/343/202/210/343/202/213/343/202/250/343/203/225/343/202/247/343/202/257/343/203/210/345/207/246/347/220/206.rb +116 -0
- data/examples/01070_effect_FF7/343/201/256/346/210/246/351/227/230/343/201/253/345/205/245/343/202/213/343/201/250/343/201/215/343/201/256/343/202/250/343/203/225/343/202/247/343/202/257/343/203/210.rb +33 -0
- data/examples/01080_effect_/350/203/214/346/231/257/343/202/222/347/267/251/343/201/217/346/266/210/343/201/227/343/201/246/343/201/204/343/201/217/343/201/250/343/202/271/343/203/240/343/203/274/343/202/272/343/201/253/343/201/252/343/202/213.rb +16 -0
- data/examples/01090_/347/224/273/345/203/217/343/201/256/343/202/257/343/203/255/343/202/271/343/203/225/343/202/247/343/203/274/343/203/211.rb +37 -0
- data/examples/01100_/343/202/271/343/202/257/343/203/252/343/203/274/343/203/263/346/203/205/345/240/261.rb +8 -0
- data/examples/01110_lib_contrib_menu.rb +19 -0
- data/examples/01120_/351/233/233/345/236/213_2P/345/257/276/346/210/246/351/242/250STG.rb +109 -0
- data/examples/01130_/351/233/233/345/236/213_/346/210/246/350/273/212/345/257/276/346/210/246.rb +396 -0
- data/examples/01140_/351/233/233/345/236/213_2P/345/257/276/346/210/246.rb +60 -0
- data/examples/01150_/351/233/233/345/236/213_/343/202/271/343/203/274/343/203/221/343/203/274/343/203/236/343/203/252/343/202/252/351/242/250/343/202/242/343/202/257/343/202/267/343/203/247/343/203/263.rb +1251 -0
- data/examples/01160_2D/343/202/242/343/203/225/343/202/243/343/203/263/345/244/211/346/217/233.rb +40 -0
- data/examples/01170_stackprof.rb +10 -0
- data/examples/01180_sdl_/343/202/242/343/203/253/343/203/225/343/202/241/343/203/226/343/203/254/343/203/263/343/203/207/343/202/243/343/203/263/343/202/260/343/201/247/351/207/215/343/201/255/345/220/210/343/201/233/345/241/227/343/202/212/346/275/260/343/201/227.rb +11 -0
- data/examples/01190_/343/203/221/343/203/274/343/203/206/343/202/243/343/202/257/343/203/253/345/220/214/345/243/253/343/201/247/344/270/255/345/244/256/343/201/253/345/220/221/343/201/213/343/201/206.rb +79 -0
- data/examples/01200_lib_OpenGL.rb +55 -0
- data/examples/bezier.rb +202 -0
- data/examples/cursor.rb +50 -0
- data/examples/helper.rb +38 -0
- data/examples/lifegame_patterns.rb +102 -0
- data/examples/movable_point.rb +64 -0
- data/examples/mtx33.rb +294 -0
- data/examples/setup.rb +5 -0
- data/examples/stage_infos.rb +1 -0
- data/examples/start.sh +2 -0
- data/examples/test_all.rb +5 -0
- data/examples/testgl.rb +228 -0
- data/examples/trash/__0060_shooting2.rb +37 -0
- data/examples/trash/__0090_collision_circle1.rb +50 -0
- data/examples/trash/__0125_circle_collision.rb +103 -0
- data/examples/trash/__0130_circle_collision2.rb +60 -0
- data/examples/trash/__0270_circle_cycle_shift.rb +29 -0
- data/examples/trash/__bullet_algos.rb +224 -0
- data/examples/trash/gunship.rb +39 -0
- data/examples//343/203/227/343/203/255/343/202/270/343/202/247/343/202/257/343/202/277/343/203/274/343/201/253/350/241/250/347/244/272/343/201/231/343/202/213/343/201/250/343/201/215.sh +2 -0
- data/lib/stylet.rb +1 -0
- data/lib/stylet/application_memory_record.rb +33 -0
- data/lib/stylet/audio.rb +455 -0
- data/lib/stylet/axis_support.rb +62 -0
- data/lib/stylet/base.rb +76 -0
- data/lib/stylet/callbacks.rb +62 -0
- data/lib/stylet/cli.rb +54 -0
- data/lib/stylet/collision_support.rb +56 -0
- data/lib/stylet/config.rb +39 -0
- data/lib/stylet/contrib/menu.rb +508 -0
- data/lib/stylet/contrib/shared_pad.rb +32 -0
- data/lib/stylet/contrib/sprity.rb +149 -0
- data/lib/stylet/core.rb +118 -0
- data/lib/stylet/cpu_stat.rb +58 -0
- data/lib/stylet/delegators.rb +54 -0
- data/lib/stylet/draw.rb +256 -0
- data/lib/stylet/draw_support/arrow.rb +56 -0
- data/lib/stylet/draw_support/circle.rb +63 -0
- data/lib/stylet/draw_support/polygon.rb +22 -0
- data/lib/stylet/font.rb +172 -0
- data/lib/stylet/fps_adjust.rb +23 -0
- data/lib/stylet/fps_stat.rb +41 -0
- data/lib/stylet/input.rb +8 -0
- data/lib/stylet/input/base.rb +105 -0
- data/lib/stylet/input/hardware_bindings.rb +65 -0
- data/lib/stylet/input/key_one.rb +162 -0
- data/lib/stylet/input/support.rb +72 -0
- data/lib/stylet/joystick.rb +31 -0
- data/lib/stylet/joystick_adapter.rb +130 -0
- data/lib/stylet/joystick_adapters/buffalo_snes_adapter.rb +47 -0
- data/lib/stylet/joystick_adapters/elecom_usb_pad_adapter.rb +30 -0
- data/lib/stylet/joystick_adapters/hori_rap_v3_sa_adapter.rb +46 -0
- data/lib/stylet/joystick_adapters/ps3_standard_adapter.rb +40 -0
- data/lib/stylet/joystick_adapters/unknown_adapter.rb +13 -0
- data/lib/stylet/keyboard.rb +15 -0
- data/lib/stylet/logger.rb +12 -0
- data/lib/stylet/mouse.rb +58 -0
- data/lib/stylet/palette.rb +17 -0
- data/lib/stylet/rect.rb +113 -0
- data/lib/stylet/shortcut.rb +8 -0
- data/lib/stylet/state.rb +87 -0
- data/lib/stylet/stylet.rb +44 -0
- data/lib/stylet/system_pause.rb +24 -0
- data/lib/stylet/version.rb +3 -0
- data/log/.gitkeep +0 -0
- data/stylet.gemspec +31 -0
- data/test/test_helper.rb +6 -0
- data/test/test_input_base.rb +12 -0
- data/test/test_input_key_one.rb +43 -0
- data/test/test_input_support.rb +47 -0
- data/test/test_sample.rb +13 -0
- data/test/test_state.rb +26 -0
- data/tips.org +16 -0
- metadata +391 -0
data/examples/00610_/345/206/205/347/251/215/343/201/250/345/244/226/347/251/215_inner_product.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# 内積
|
3
|
+
#
|
4
|
+
require_relative "helper"
|
5
|
+
|
6
|
+
class App < Stylet::Base
|
7
|
+
include Helper::CursorWithObjectCollection
|
8
|
+
include Helper::MovablePoint
|
9
|
+
|
10
|
+
setup do
|
11
|
+
@points = []
|
12
|
+
@points << vec2.angle_at(Stylet::Magic.clock(3)).scale(100)
|
13
|
+
@points << vec2.angle_at(Stylet::Magic.clock(0)).scale(100)
|
14
|
+
self.title = "内積と外積"
|
15
|
+
end
|
16
|
+
|
17
|
+
update do
|
18
|
+
update_movable_points(@points, :origin => srect.center)
|
19
|
+
@points.each.with_index {|e, i| draw_vector(e, :origin => srect.center, :label => "P#{i} #{e.round(2)}") }
|
20
|
+
|
21
|
+
a, b = @points
|
22
|
+
# Bを動かしているときにはAをnormalizeした方がわかりやすい
|
23
|
+
dot_product = vec2.dot_product(a.normalize, b)
|
24
|
+
cross_product = vec2.cross_product(a.normalize, b)
|
25
|
+
|
26
|
+
vputs "内積(横): #{dot_product.round(2)}"
|
27
|
+
vputs "外積(縦): #{cross_product.round(2)}"
|
28
|
+
|
29
|
+
vC = a.normalize * dot_product
|
30
|
+
vD = a.normalize.rotate(Stylet::Magic.r90) * cross_product
|
31
|
+
draw_vector(vC, :origin => srect.center, :color => :orange)
|
32
|
+
draw_vector(vD, :origin => vC + srect.center, :color => :orange)
|
33
|
+
end
|
34
|
+
|
35
|
+
run
|
36
|
+
end
|
data/examples/00620_/346/263/225/347/267/232/343/203/231/343/202/257/343/203/210/343/203/253.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# 法線ベクトル
|
3
|
+
#
|
4
|
+
require_relative "helper"
|
5
|
+
|
6
|
+
class App < Stylet::Base
|
7
|
+
include Helper::CursorWithObjectCollection
|
8
|
+
include Helper::MovablePoint
|
9
|
+
|
10
|
+
setup do
|
11
|
+
@point = vec2.rand.normalize * 100
|
12
|
+
self.title = "法線ベクトル"
|
13
|
+
end
|
14
|
+
|
15
|
+
update do
|
16
|
+
update_movable_points([@point], :origin => srect.center)
|
17
|
+
[@point, @point.prep].each.with_index {|e, i| draw_vector(e, :origin => srect.center, :label => "P#{i} #{e.round(2)}") }
|
18
|
+
draw_vector(@point, :origin => srect.center)
|
19
|
+
draw_vector(@point.prep, :origin => srect.center, :color => :orange)
|
20
|
+
end
|
21
|
+
|
22
|
+
run
|
23
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
#
|
2
|
+
# 円と円の反射
|
3
|
+
#
|
4
|
+
# 反射係数の関係(正面衝突したとする)
|
5
|
+
#
|
6
|
+
# -(反射B - 反射A) / (衝突B - 衝突A) #=> 1.0
|
7
|
+
#
|
8
|
+
# 速度と質量を乗算すると運動量
|
9
|
+
#
|
10
|
+
# 運動量 = 質量 * 速度
|
11
|
+
#
|
12
|
+
# 運動量保存の法則により、衝突前の円の運動量の合計値と、衝突後の円の運動量の合計値は等しくなる
|
13
|
+
#
|
14
|
+
# 運動量保存の法則
|
15
|
+
# 質量A * 衝突A + 質量B * 衝突B = 質量A * 反射A + 質量B * 反射B
|
16
|
+
#
|
17
|
+
require_relative "helper"
|
18
|
+
|
19
|
+
class App < Stylet::Base
|
20
|
+
include Helper::CursorWithObjectCollection
|
21
|
+
|
22
|
+
attr_reader :reflect_mode
|
23
|
+
|
24
|
+
setup do
|
25
|
+
self.title = "円と円の反射"
|
26
|
+
cursor.vertex = 3
|
27
|
+
|
28
|
+
@modes = ["reflect", "move", "none"]
|
29
|
+
@reflect_mode = @modes.first
|
30
|
+
|
31
|
+
@pA = srect.center.clone + vec2[80, -70]
|
32
|
+
@sA = vec2.angle_at(Stylet::Magic.clock(6, 15)).scale(1.0)
|
33
|
+
@a_radius = 100
|
34
|
+
@am = @a_radius**2
|
35
|
+
|
36
|
+
@pB = srect.center.clone + vec2[-120, -80]
|
37
|
+
@sB = vec2.angle_at(Stylet::Magic.clock(4)).scale(1.0)
|
38
|
+
@b_radius = 60
|
39
|
+
@bm = @b_radius**2 # 質量
|
40
|
+
|
41
|
+
@s_radius = 100 # 速度ベクトル 1.0 を画面上では何ドットで表わすか?
|
42
|
+
@vertex = 32
|
43
|
+
@reflect_ratio = 1.0 # 反射係数
|
44
|
+
end
|
45
|
+
|
46
|
+
update do
|
47
|
+
if key_down?(SDL::Key::S)
|
48
|
+
@reflect_mode = @modes[@modes.index(@reflect_mode).next.modulo(@modes.size)]
|
49
|
+
end
|
50
|
+
|
51
|
+
vputs "S:reflect=#{@reflect_mode}"
|
52
|
+
vputs "Z:ray++ X:ray-- C:drag V:angle"
|
53
|
+
|
54
|
+
# 操作
|
55
|
+
begin
|
56
|
+
# AとBで速度ベクトルの反映
|
57
|
+
@pA += @sA.scale(button.btA.repeat_0or1) + @sA.scale(-button.btB.repeat_0or1)
|
58
|
+
@pB += @sB.scale(button.btA.repeat_0or1) + @sB.scale(-button.btB.repeat_0or1)
|
59
|
+
# Cボタンおしっぱなし + マウスで自機位置移動
|
60
|
+
if button.btC.press?
|
61
|
+
@pA = cursor.point.clone
|
62
|
+
end
|
63
|
+
# Dボタンおしっぱなし + マウスで自機角度変更
|
64
|
+
if button.btD.press?
|
65
|
+
if cursor.point != @pA
|
66
|
+
@sA = (cursor.point - @pA).normalize * @sA.magnitude
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# @pA += @sA
|
72
|
+
# @pB += @sB
|
73
|
+
|
74
|
+
@diff = @pB - @pA
|
75
|
+
@rdiff = (@a_radius + @b_radius) - @diff.magnitude
|
76
|
+
vputs "magnitude=#{@diff.magnitude}"
|
77
|
+
vputs "rdiff=#{@rdiff}"
|
78
|
+
|
79
|
+
# AとBをお互い離す
|
80
|
+
if reflect_mode == "move"
|
81
|
+
if @rdiff > 0
|
82
|
+
@pA -= @diff.normalize * @rdiff / 2
|
83
|
+
@pB += @diff.normalize * @rdiff / 2
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# 反射する
|
88
|
+
if reflect_mode == "reflect"
|
89
|
+
if @rdiff > 0
|
90
|
+
begin
|
91
|
+
# 反射するモードでもいったんお互いを引き離さないと絡まってしまう
|
92
|
+
@pA -= @diff.normalize * @rdiff * 0.5
|
93
|
+
@pB += @diff.normalize * @rdiff * 0.5
|
94
|
+
|
95
|
+
# (am.x,am.y) 円Aから円Bへ移動運動を発生させるベクトル
|
96
|
+
# (ar.x,ar.y) 円Aから円Bへ回転運動を発生させるベクトル
|
97
|
+
# (bm.x,bm.y) 円Bから円Aへ移動運動を発生させるベクトル
|
98
|
+
# (br.x,br.y) 円Bから円Aへ回転運動を発生させるベクトル
|
99
|
+
|
100
|
+
# 速度ベクトルを重心方向と垂直な方向に分離する
|
101
|
+
_denominator = (@diff.x**2 + @diff.y**2)
|
102
|
+
|
103
|
+
# A
|
104
|
+
# A→B 回転運動
|
105
|
+
t = -(@diff.x * @sA.x + @diff.y * @sA.y) / _denominator
|
106
|
+
|
107
|
+
ar = @sA + @diff.scale(t)
|
108
|
+
|
109
|
+
# A→B 移動運動
|
110
|
+
t = -(-@diff.y * @sA.x + @diff.x * @sA.y) / _denominator
|
111
|
+
am = vec2[
|
112
|
+
@sA.x - @diff.y * t,
|
113
|
+
@sA.y + @diff.x * t,
|
114
|
+
]
|
115
|
+
|
116
|
+
# B
|
117
|
+
# B→A 回転運動
|
118
|
+
t = -(@diff.x * @sB.x + @diff.y * @sB.y) / _denominator
|
119
|
+
br = @sB + @diff.scale(t)
|
120
|
+
|
121
|
+
# B→A 移動運動
|
122
|
+
t = -(-@diff.y * @sB.x + @diff.x * @sB.y) / _denominator
|
123
|
+
bm = vec2[
|
124
|
+
@sB.x - @diff.y * t,
|
125
|
+
@sB.y + @diff.x * t,
|
126
|
+
]
|
127
|
+
|
128
|
+
# x 方向と y 方向それぞれの衝突後の速度を計算する
|
129
|
+
ad = vec2[
|
130
|
+
(@am * am.x + @bm * bm.x + bm.x * @reflect_ratio * @bm - am.x * @reflect_ratio * @bm) / (@am + @bm),
|
131
|
+
(@am * am.y + @bm * bm.y + bm.y * @reflect_ratio * @bm - am.y * @reflect_ratio * @bm) / (@am + @bm),
|
132
|
+
]
|
133
|
+
bd = vec2[
|
134
|
+
-@reflect_ratio * (bm.x - am.x) + ad.x,
|
135
|
+
-@reflect_ratio * (bm.y - am.y) + ad.y,
|
136
|
+
]
|
137
|
+
|
138
|
+
# 回転運動を発生させるベクトルを加算して衝突後の速度を計算
|
139
|
+
@sA.x = ad.x + ar.x
|
140
|
+
@sA.y = ad.y + ar.y
|
141
|
+
@sB.x = bd.x + br.x
|
142
|
+
@sB.y = bd.y + br.y
|
143
|
+
|
144
|
+
# @pA += @sA
|
145
|
+
# @pB += @sB
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
draw_circle(@pA, :vertex => @vertex, :radius => @a_radius)
|
151
|
+
vputs "A(#{@am})", :vector => @pA
|
152
|
+
draw_vector(@sA.scale(@s_radius), :origin => @pA, :label => @sA.magnitude)
|
153
|
+
|
154
|
+
draw_circle(@pB, :vertex => @vertex, :radius => @b_radius)
|
155
|
+
vputs "B(#{@bm})", :vector => @pB
|
156
|
+
draw_vector(@sB.scale(@s_radius), :origin => @pB, :label => @sB.magnitude)
|
157
|
+
|
158
|
+
vputs "#{@sA.magnitude} + #{@sA.magnitude} = #{(@sA + @sB).magnitude}"
|
159
|
+
|
160
|
+
if false
|
161
|
+
if @resp = compute(@pA, @sA, @a_radius, @pB, @sB, @b_radius)
|
162
|
+
vputs @resp.inspect
|
163
|
+
vputs c_state(@resp)
|
164
|
+
end
|
165
|
+
|
166
|
+
if @resp
|
167
|
+
@pA2 = @pA + @sA.normalize.scale(@resp[:f0])
|
168
|
+
draw_circle(@pA2, :vertex => @vertex, :radius => @a_radius)
|
169
|
+
|
170
|
+
@pB2 = @pB + @sB.normalize.scale(@resp[:f0])
|
171
|
+
draw_circle(@pB2, :vertex => @vertex, :radius => @b_radius)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# hakuhin.jp/as/collide.html#COLLIDE_02
|
177
|
+
#
|
178
|
+
# 値 状態
|
179
|
+
# f0 と f1 がどちらもプラス 円同士は近づいている
|
180
|
+
# f0 と f1 どちらもマイナス 円同士は離れている
|
181
|
+
# f0 と f1 の符号が反転 円同士はめり込んでいる
|
182
|
+
# f0 が 0 以上、 1 以下の値 現在のフレームで衝突する (この状態が発生しない。衝突は f0 == 0.0 && f1 > 0 のときっぽい←ちがう)
|
183
|
+
#
|
184
|
+
# Math.sqrt でエラーがでる
|
185
|
+
# はなれすぎているとエラーになるみたい
|
186
|
+
#
|
187
|
+
def compute(ap, as, ar, bp, bs, br)
|
188
|
+
_a = (as.x * as.x) - 2 * (as.x * bs.x) + (bs.x * bs.x) + (as.y * as.y) - 2 * (as.y * bs.y) + (bs.y * bs.y)
|
189
|
+
_b = 2 * (ap.x * as.x) - 2 * (ap.x * bs.x) - 2 * (as.x * bp.x) + 2 * (bp.x * bs.x) + 2 * (ap.y * as.y) - 2 * (ap.y * bs.y) - 2 * (as.y * bp.y) + 2 * (bp.y * bs.y)
|
190
|
+
_c = (ap.x * ap.x) - 2 * (ap.x * bp.x) + (bp.x * bp.x) + (ap.y * ap.y) - 2 * (ap.y * bp.y) + (bp.y * bp.y) - (ar + br) * (ar + br)
|
191
|
+
_d = Math.sqrt(_b * _b - 4 * _a * _c)
|
192
|
+
|
193
|
+
if _d <= 0
|
194
|
+
# 当たりなし
|
195
|
+
return
|
196
|
+
end
|
197
|
+
|
198
|
+
f0 = (- _b - _d) / (2 * _a) # 接触する瞬間
|
199
|
+
f1 = (- _b + _d) / (2 * _a) # 離れる瞬間
|
200
|
+
|
201
|
+
{:f0 => f0, :f1 => f1}
|
202
|
+
rescue Errno::EDOM => error
|
203
|
+
return
|
204
|
+
end
|
205
|
+
|
206
|
+
def c_state(resp)
|
207
|
+
return unless resp
|
208
|
+
# return if resp.is_a? StandardError
|
209
|
+
if resp[:f0] > 0 && resp[:f1] > 0
|
210
|
+
"tikazuki"
|
211
|
+
elsif resp[:f0] < 0 && resp[:f1] < 0
|
212
|
+
"hanare"
|
213
|
+
elsif resp[:f0] >= 0 && resp[:f1] <= 1
|
214
|
+
"collision"
|
215
|
+
# elsif (resp[:f0] < 0 && resp[:f1] >= 0) || (resp[:f1] < 0 && resp[:f0] >= 0)
|
216
|
+
elsif (resp[:f0] * resp[:f1]) < 0
|
217
|
+
"merikomi"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
run
|
222
|
+
end
|
@@ -0,0 +1,261 @@
|
|
1
|
+
#
|
2
|
+
# 点と線分の交差判定と反射
|
3
|
+
#
|
4
|
+
require_relative "helper"
|
5
|
+
|
6
|
+
class App < Stylet::Base
|
7
|
+
include Helper::CursorWithObjectCollection
|
8
|
+
|
9
|
+
attr_reader :ray_mode
|
10
|
+
attr_reader :reflect_mode
|
11
|
+
|
12
|
+
setup do
|
13
|
+
self.title = "点と線分の交差判定と反射"
|
14
|
+
cursor.vertex = 3
|
15
|
+
|
16
|
+
@ray_mode = false # true:ドット false:円
|
17
|
+
@reflect_mode = true # true:反射する
|
18
|
+
|
19
|
+
@p0 = srect.center.clone # 自機の位置ベクトル
|
20
|
+
@dot_radius = 3 # 点の大きさ
|
21
|
+
@vertex = 32
|
22
|
+
@vS = vec2[0.84, -0.10].normalize # 速度ベクトル
|
23
|
+
|
24
|
+
# 線分AB
|
25
|
+
@pA = srect.center + vec2[srect.w * 0.3, -srect.h * 0.30]
|
26
|
+
@pB = srect.center + vec2[srect.w * 0.0, +srect.h * 0.30]
|
27
|
+
|
28
|
+
mode_init
|
29
|
+
end
|
30
|
+
|
31
|
+
update do
|
32
|
+
if key_down?(SDL::Key::A)
|
33
|
+
@ray_mode = !@ray_mode
|
34
|
+
mode_init
|
35
|
+
end
|
36
|
+
if key_down?(SDL::Key::S)
|
37
|
+
@reflect_mode = !@reflect_mode
|
38
|
+
end
|
39
|
+
|
40
|
+
# 操作説明
|
41
|
+
vputs "A:ray=#{@ray_mode} S:reflect=#{@reflect_mode}"
|
42
|
+
vputs "Z:ray++ X:ray-- C:drag V:angle"
|
43
|
+
end
|
44
|
+
|
45
|
+
def mode_init
|
46
|
+
if ray_mode
|
47
|
+
@radius = 1 # 自機の大きさ
|
48
|
+
else
|
49
|
+
@radius = 50 # 自機の大きさ
|
50
|
+
end
|
51
|
+
@vS = @vS.normalize.scale(@radius * 0.5) # 自機の速度ベクトル制限
|
52
|
+
end
|
53
|
+
|
54
|
+
update do
|
55
|
+
# 操作
|
56
|
+
begin
|
57
|
+
# AとBで速度ベクトルの反映
|
58
|
+
@p0 += @vS.scale(button.btA.repeat_0or1) + @vS.scale(-button.btB.repeat_0or1)
|
59
|
+
# Cボタンおしっぱなし + マウスで自機位置移動
|
60
|
+
if button.btC.press?
|
61
|
+
@p0 = cursor.point.clone
|
62
|
+
end
|
63
|
+
# Dボタンおしっぱなし + マウスで自機角度変更
|
64
|
+
if button.btD.press?
|
65
|
+
if cursor.point != @p0
|
66
|
+
@vS = (cursor.point - @p0).normalize * @vS.magnitude
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
begin
|
72
|
+
# 法線取得
|
73
|
+
@normal = @pA.normal(@pB).normalize
|
74
|
+
# vputs "Normal: #{@normal.magnitude}"
|
75
|
+
|
76
|
+
# 線分ABの法線を見える化(長さに意味はない)
|
77
|
+
vN = @normal.normalize.scale(64)
|
78
|
+
origin = vec2.pos_vector_ratio(@pA, @pB, 0.5)
|
79
|
+
draw_vector(vN, :origin => origin, :arrow_size => 8)
|
80
|
+
vputs "vN", :vector => origin + vN
|
81
|
+
end
|
82
|
+
|
83
|
+
# t と C1 の取得
|
84
|
+
begin
|
85
|
+
# スピードベクトルをt倍したら線に衝突するかを求める
|
86
|
+
# 自機の原点・速度ベクトル・法線の原点(pAでもpBでもよい)・法線ベクトルを渡すと求まる
|
87
|
+
@t1 = vec2.collision_power_scale(@p0, @vS, @pA, @normal)
|
88
|
+
|
89
|
+
# 裏面(通りすぎている) <= 0.0 < 衝突 <= 1.0 < 表面(まだあたっていない)
|
90
|
+
vputs "C1 t1: #{@t1} (#{ps_state(@t1)})"
|
91
|
+
|
92
|
+
# スピードを t 倍したとき本当にラインに接触するのかを見える化
|
93
|
+
# draw_vector(@vS.scale(@t1), :origin => @p0)
|
94
|
+
|
95
|
+
# 交差点の取得
|
96
|
+
@pC1 = @p0 + @vS.scale(@t1)
|
97
|
+
|
98
|
+
# 交差点の視覚化
|
99
|
+
draw_triangle(@pC1, :radius => @dot_radius, :angle => @vS.angle)
|
100
|
+
vputs "C1", :vector => @pC1
|
101
|
+
|
102
|
+
# 線分ABの中に衝突しているか調べる方法
|
103
|
+
# 内積の取得
|
104
|
+
@ac1 = @pC1 - @pA
|
105
|
+
@bc1 = @pC1 - @pB
|
106
|
+
if @ac1.nonzero? && @bc1.nonzero?
|
107
|
+
@ip1 = vec2.dot_product(@ac1, @bc1)
|
108
|
+
vputs "C1 dot_product(AC1, BC1): #{@ip1} (#{dot_product_state(@ip1)})"
|
109
|
+
|
110
|
+
draw_vector(@ac1.normalize.scale(20), :origin => @pA + @normal.scale(-20 * 1), :arrow_size => 8)
|
111
|
+
draw_vector(@bc1.normalize.scale(20), :origin => @pB + @normal.scale(-20 * 1), :arrow_size => 8)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# t2 と C2 の取得
|
116
|
+
begin
|
117
|
+
# 自機から面と垂直な線を出して面と交差するか調べる(ここが点の場合と違う)
|
118
|
+
@vP = vec2.angle_at(@normal.reverse.angle).scale(@radius) # スケールは半径と同じ長さとする
|
119
|
+
draw_vector(@vP, :origin => @p0)
|
120
|
+
vputs "vP", :vector => @vP + @p0
|
121
|
+
|
122
|
+
# 自機の原点・逆法線ベクトル・法線の原点(pAでもpBでもよい)・法線ベクトルを渡すと求まる
|
123
|
+
# @t2 = vec2.collision_power_scale(@p0, @vP, @pA, @normal)
|
124
|
+
@t2 = vec2.collision_power_scale(@p0, @vP, @pA, @normal)
|
125
|
+
vputs "C2 t2: #{@t2} (#{ps_state(@t2)})"
|
126
|
+
|
127
|
+
# 交差点の取得
|
128
|
+
@pC2 = @p0 + @vP.scale(@t2)
|
129
|
+
|
130
|
+
# 交差点の視覚化
|
131
|
+
draw_triangle(@pC2, :radius => @dot_radius, :angle => @vP.angle)
|
132
|
+
vputs "C2", :vector => @pC2
|
133
|
+
|
134
|
+
# 内積の取得
|
135
|
+
@ac2 = @pC2 - @pA
|
136
|
+
@bc2 = @pC2 - @pB
|
137
|
+
if @ac2.nonzero? && @bc2.nonzero?
|
138
|
+
@ip2 = vec2.dot_product(@ac2, @bc2)
|
139
|
+
vputs "C2 dot_product(AC2, BC2): #{@ip2} (#{dot_product_state(@ip2)})"
|
140
|
+
|
141
|
+
# 二つのベクトルがどちらを向いているか視覚化(お互いが衝突していたら線の中にいることがわかる)
|
142
|
+
draw_vector(@ac2.normalize.scale(20), :origin => @pA + @normal.scale(-20 * 2), :arrow_size => 8)
|
143
|
+
draw_vector(@bc2.normalize.scale(20), :origin => @pB + @normal.scale(-20 * 2), :arrow_size => 8)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# 線の表裏どちらにいるか。また衝突しているか? (この時点では無限線)
|
148
|
+
if reflect_mode
|
149
|
+
if ray_mode && false
|
150
|
+
# レイモードの反射は難しい
|
151
|
+
# Zで通りすぎてXボタンでバックして再び突進すると線を通りすぎてしまう。
|
152
|
+
# これは「移動距離 < 半径」の法則が慣りたってないから。
|
153
|
+
# 半径を0.1などと考えて円にして反射させるのがいいのかも
|
154
|
+
|
155
|
+
# _radius = 0.5
|
156
|
+
#
|
157
|
+
# if 0.0 < @t2 && @t2 <= 1.0 # めり込んでいる
|
158
|
+
# if @ip2 < 0 # 線の中で
|
159
|
+
# # 円を押し戻す
|
160
|
+
# @p0 = @pC2 + @normal.normalize.scale(_radius)
|
161
|
+
# @vS += @vS.reflect(@normal).scale(1.0)
|
162
|
+
# end
|
163
|
+
# end
|
164
|
+
#
|
165
|
+
# # 速度制限(円が線から飛び出さないようにする)
|
166
|
+
# if @vS.radius > _radius
|
167
|
+
# @vS = @vS.normalize.scale(_radius)
|
168
|
+
# end
|
169
|
+
|
170
|
+
# # Zで通りすぎてXボタンでバックして再び突進すると線を通りすぎてしまう。
|
171
|
+
# # これは「移動距離 < 半径」の法則が慣りたってないから。
|
172
|
+
# if 0.0 < @t && @t <= 1.0
|
173
|
+
# if @ip < 0
|
174
|
+
# @p0 = @pC1.clone
|
175
|
+
# # @p0 = @pC1 + @normal.normalize.scale(1.1)
|
176
|
+
# @vS += @vS.reflect(@normal)
|
177
|
+
# end
|
178
|
+
# end
|
179
|
+
else
|
180
|
+
# レイの場合は半径がないので t1 と C1 を使っても同じ
|
181
|
+
|
182
|
+
if 0.0 < @t2 && @t2 <= 1.0 # めり込んでいる
|
183
|
+
if @ip2 < 0 # 線の中で
|
184
|
+
# 円を押し戻す
|
185
|
+
@p0 = @pC2 + @normal.normalize.scale(@radius)
|
186
|
+
@vS += @vS.reflect(@normal).scale(1.0)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
# 速度制限(円が線から飛び出さないようにする)
|
191
|
+
if @vS.magnitude > @radius
|
192
|
+
@vS = @vS.normalize.scale(@radius)
|
193
|
+
end
|
194
|
+
|
195
|
+
# 点Aと点Bに円がめり込んでいたら押す
|
196
|
+
[@pA, @pB].each do |pX|
|
197
|
+
diff = @p0 - pX
|
198
|
+
if diff.magnitude > 0
|
199
|
+
if diff.magnitude < @radius
|
200
|
+
@p0 = pX + diff.normalize.scale(@radius)
|
201
|
+
if true
|
202
|
+
# 跳ね返す
|
203
|
+
@vS = diff.normalize.scale(@vS.magnitude)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
begin
|
212
|
+
if ray_mode
|
213
|
+
# 自機(ドット)の表示
|
214
|
+
draw_triangle(@p0, :radius => @dot_radius, :angle => @vS.angle)
|
215
|
+
else
|
216
|
+
# 自機(円)の表示
|
217
|
+
draw_circle(@p0, :radius => @radius, :vertex => @vertex, :angle => @vS.angle)
|
218
|
+
end
|
219
|
+
vputs "p0", :vector => @p0
|
220
|
+
|
221
|
+
# 自機の速度ベクトルの可視化(長さに意味はない)
|
222
|
+
pS = @vS
|
223
|
+
draw_vector(pS, :origin => @p0)
|
224
|
+
vputs "vS", :vector => @p0 + pS
|
225
|
+
vputs "Speed Vector: #{@vS.magnitude}"
|
226
|
+
|
227
|
+
# 線分ABの視覚化
|
228
|
+
draw_line(@pA, @pB)
|
229
|
+
vputs "A", :vector => @pA
|
230
|
+
vputs "B", :vector => @pB
|
231
|
+
|
232
|
+
if button.btC.press? || button.btD.press?
|
233
|
+
draw_line(@p0, @pC1)
|
234
|
+
draw_line(@p0, @pC2)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def ps_state(t)
|
240
|
+
if t > 1.0
|
241
|
+
"FACE"
|
242
|
+
elsif 0.0 < t && t <= 1.0
|
243
|
+
"COLLISION"
|
244
|
+
else # t <= 0.0
|
245
|
+
"REVERSE"
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# 1. ←← or →→ 正 (0.0 < v) お互いだいたい同じ方向を向いている
|
250
|
+
# 2. →← 負 (v < 0.0) お互いだいたい逆の方向を向いている
|
251
|
+
# 3. →↓ →↑ 零 (0.0) お互いが直角の関係
|
252
|
+
def dot_product_state(v)
|
253
|
+
if v < 0
|
254
|
+
"IN"
|
255
|
+
else
|
256
|
+
"OUT"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
run
|
261
|
+
end
|