Author Topic: car simulator  (Read 5864 times)

0 Members and 1 Guest are viewing this topic.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
car simulator
« on: November 14, 2021, 03:49:26 pm »
Hello !
I'm also trying to put a car in the flying game. I used to think about it, but I didn’t get anywhere. In fact, I'm still stuck. What is seen is not much different from the dynamics of the plane. we move an object in a plane that has velocity and direction. We modify the direction vector with the new direction created by the drift. But I got stuck.
I want you to travel in the mountains, on the hills, and the shock absorber would also be useful. I want you to tip over. This, in turn, is a much more complex approach. I would like to ask you for ideas, links, literature to see if anyone can help. where can i find writing about the physics of a car?
I created an environment for experimentation. You can try this, go with it, you can switch between 4 camera views with the C key, the current options will be displayed on the screen.



Code: QB64: [Select]
  1. CONST pip180 = 3.141592 / 180
  2. CONST perlin_pers = 0 '7 'amplitudo
  3. CONST perlin_level = 1 '5 'level of resolution wave
  4. CONST perlin_multiplier = 0.007
  5. CONST perlin_smooth_noise_interpolation_type = 0 '0-none '1-standard
  6. CONST perlin_flat_soil_limit_low = .8 'high value is low area (negate)
  7. CONST perlin_flat_soil_limit_high = .1
  8. CONST flight_array_size = 20: DIM flight_save(flight_array_size - 1)
  9. DIM SHARED rotating(2), cosrotz, sinrotz, cosrotx, sinrotx, map_zoom_xy, map_zoom_distance, see_point, flight(19, flight_array_size), me(19), rotx_bevel
  10. DIM SHARED mouse_sens_xy, mouse_sens_z, position_speed, clmn_rad
  11. DIM SHARED map_x, map_y, perl_setx, perl_sety, map_resolution, map_z, map_dimz, map_dimxy, flight_high_max
  12. monx = 1366 * .8: mony = monx / 16 * 9 'screen size
  13.  
  14. win_marg = monx / 25
  15. flight_high_max = -70
  16.  
  17. auto_precalc = 22
  18. auto_mouse_scale = 120
  19. auto_try_resolution = 22
  20. DIM flight_auto(auto_try_resolution - 1, flight_array_size - 1): DIM auto_efficiency(auto_try_resolution - 1, 5) '0- 1 if crash          '1- target-flight distance
  21.  
  22. pr_temp = 0 'temp pr
  23. text_deep = 30 'make deep shadow pictures
  24.  
  25.  
  26. map_center = 100000 'start of perlin-map
  27. 'text_field$ = "need\field2.bmp"
  28. text_field$ = "need\field1.bmp" 'field map texture
  29. text_multi = 40 'zoom to texture
  30.  
  31. position_speed = .3
  32. map_resolution = 50 'see map resolution
  33. DIM SHARED map_resper2: map_resper2 = INT(map_resolution / 2)
  34.  
  35.  
  36. DIM SHARED max_incli: max_incli = 65 'flight max rotation
  37.  
  38. map_dimxy = 1200 * .8
  39. map_dimz = 250 * .8
  40. DIM SHARED ee: ee = map_dimxy / map_resolution
  41.  
  42. map_zoom_xy = 6 * .2
  43. map_zoom_distance = 15 * .2
  44.  
  45.  
  46. mouse_sens_xy = 1.6
  47. mouse_sens_z = 1
  48.  
  49. me(6) = pip180 * 270
  50.  
  51. me(0) = map_center: me(1) = map_center
  52.  
  53. control_type$(0) = "walking": control_type$(1) = "flying": control_type$(2) = "flying/autopilot"
  54. DIM color_temp(9) AS _INTEGER64
  55. targ_text = _LOADIMAGE("need\target.jpg", 33)
  56.  
  57.  
  58.  
  59.  
  60.  
  61. DIM clmn(1999, 5): clmn_rad = 30: ration_column = 0.0003
  62. ration_column = 0.0003
  63.  
  64.  
  65. 'PREPARATION ---------------------------------------------------------------------------------------------------------------------------------------------------
  66.  
  67. 'create wheel texture
  68. whe_ts = 50: whe_marg = 7: temp = _NEWIMAGE(whe_ts, whe_ts, 32): _DEST temp: CLS , 0: marg = whe_ts * text_size_marg / 100
  69. PAINT (0, 0), _RGBA32(10, 10, 10, 255)
  70. LINE (whe_marg, whe_marg)-(whe_ts - whe_marg, whe_ts - whe_marg), _RGBA32(100, 100, 100, 255), BF
  71. whe_text = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  72.  
  73. 'create pseudo random buffer
  74. DIM SHARED noise_rand_c: noise_rand_c = 10000: DIM SHARED noise_rand(noise_rand_c - 1): FOR t = 0 TO noise_rand_c - 1: noise_rand(t) = RND(1): NEXT t
  75.  
  76. 'vehicle frame texture
  77. vhfr_ts = 30: marg = 5: temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(46, 88, 100, 255)
  78. LINE (marg, marg)-(vhfr_ts - marg, vhfr_ts - marg), _RGBA32(255, 166, 50, 255), BF: vhfr_text(0) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  79. temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(255 / 2, 166 / 2, 50 / 2, 255): vhfr_text(1) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  80. temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(150, 150, 255, 50): vhfr_text(2) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  81. temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(233, 94, 61, 255)
  82. marg = 5: LINE (marg, marg)-(vhfr_ts - marg, vhfr_ts - marg), _RGB32(255, 0, 0), BF: _SETALPHA 0, _RGB32(255, 0, 0) TO _RGB32(255, 0, 0)
  83. vhfr_text(3) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  84.  
  85.  
  86.  
  87. vp$ = "-01010-03010-01020-03020-00031-04031-01052-03052-01072-03072-00081-04081-00101-04101-00090-04090" 'points X(2),Y(2),Z(1)
  88. vl$ = "-0001-0002-0103-0203-0004-0105-0204-0305-0406-0507-0607-0410-0511-0608-0709-0809-0810-0911-1011-1012-1113-1213-1412-1513-1415-0405-0214-0315" '3d lines
  89. sq$ = "-0123-4567-0246-2367-3175-1054" 'cubes points make square
  90. vt$ = "-000102031-000104051-141512131-101112131-040012141-050113151-080910111-141502031" 'bodywork textures
  91. vt$ = vt$ + "-040610082-040509112-040506072-060708092" 'vehicle windows
  92. vp$ = vp$ + "-01081-01101-01092-01102-03081-03101-03092-03102-00092-04092-00102-04102": vt$ = vt$ + "-161718193-202122233-242526270" 'extension air deflector
  93.  
  94.  
  95. 'temporary terrain texture
  96. DIM temp_color(9) AS _INTEGER64
  97. f = 500
  98. terr = _NEWIMAGE(f, f, 32): _DEST terr
  99. PAINT (0, 0), _RGB32(50, 80, 50)
  100. r = 50 * RND(1)
  101. FOR t = 0 TO 200
  102.     x = f * RND(1): y = f * RND(1)
  103.     temp_color(0) = _RGB32(255 * RND(1), 255 * RND(1), 255 * RND(1))
  104.     CIRCLE (x, y), 20, temp_color(0)
  105.     PAINT (x, y), temp_color(0), temp_color(0)
  106.  
  107. text_multi = 20
  108.  
  109.  
  110.  
  111.  
  112.  
  113. 'create texture to map
  114. DIM SHARED mapz_min, mapz_max: DIM texture(text_deep - 1, 5): temp = terr '_LOADIMAGE(text_field$, 32)
  115. FOR t = 0 TO text_deep - 1: dark = (.6 - (1 / (text_deep - 1) * t)): transp = dark * 2000: IF transp > 255 THEN transp = 255
  116.     temp2 = _NEWIMAGE(_WIDTH(temp), _HEIGHT(temp), 32): _SOURCE temp: _DEST temp2: CLS 0, _RGBA32(0, 0, 0, transp)
  117.     FOR tx = 0 TO _WIDTH(temp) - 1: FOR ty = 0 TO _HEIGHT(temp) - 1: temp_color(0) = POINT(tx, ty)
  118.             c1 = _RED32(temp_color(0)) * dark: c2 = _GREEN32(temp_color(0)) * dark: c3 = _BLUE32(temp_color(0)) * dark
  119. PSET (tx, ty), _RGBA32(c1, c2, c3, transp): NEXT ty, tx: texture(t, 0) = _COPYIMAGE(temp2, 33): _FREEIMAGE temp2: NEXT t
  120.  
  121. 'find min/max Z
  122. DIM SHARED mapz_multiplier: mapz_min = 9999999: mapz_max = -mapz_min: FOR t = 0 TO 2999: c = Perlin2D_original(5000 * RND(1), 5000 * RND(1))
  123.     mapz_min = c * ABS(mapz_min > c) + mapz_min * (ABS(mapz_min > c) XOR 1): mapz_max = c * ABS(mapz_max < c) + mapz_max * (ABS(mapz_max < c) XOR 1)
  124. NEXT t: mapz_multiplier = 1 / (mapz_max - mapz_min)
  125.  
  126. 'fill map-buffer
  127. DIM SHARED map(map_resolution - 1, map_resolution - 1, 19): perl_setx = INT(me(0)): perl_sety = INT(me(1))
  128. FOR map_x = 0 TO map_resolution - 1: FOR map_y = 0 TO map_resolution - 1
  129.         map((map_x + perl_setx) MOD map_resolution, (map_y + perl_sety) MOD map_resolution, 0) = perlin2d(perl_setx + map_x, perl_sety + map_y)
  130. map((map_x + perl_setx) MOD map_resolution, (map_y + perl_sety) MOD map_resolution, 6) = noise(map_x, map_y) < ration_column: NEXT map_y, map_x
  131.  
  132. 'calculating shadows
  133. FOR map_x = 0 TO map_resolution - 1: FOR map_y = 0 TO map_resolution - 1
  134.         dis = INT((text_deep - 1) / map_resper2 * SQR((map_x - map_resper2) ^ 2 + (map_y - map_resper2) ^ 2)): IF dis < 0 OR dis > text_deep - 1 THEN _CONTINUE
  135. map(map_x, map_y, 9) = 1: map(map_x, map_y, 8) = dis: NEXT map_y, map_x
  136.  
  137.  
  138.  
  139.  
  140. 'MAP array
  141. '0-perlin Z-data
  142. '1-maptriangle calculate X
  143. '2-maptriangle calculate Y
  144. '3-maptriangle calculate Z
  145. '4-distance from me (color)
  146. '5-texture height scale
  147. '6-is there a column ?
  148. '7-is the point visible?
  149. '8-shadow-table
  150. '9-not used area signal
  151.  
  152. 'ME array
  153. '0-me X location
  154. '1-me Y location
  155. '2-me Z location
  156. '3-vector_x
  157. '4-vector_y
  158. '5-me XY angle CAM3
  159. '6-me XY CAM4
  160. '7-me kanyarodas merteke
  161.  
  162. 'FLIGHT array
  163. '0-active
  164. '1-rotx - kanyarodas merteke
  165. '2-rotx_bevel
  166. '3-location X
  167. '4-location Y
  168. '5-location Z
  169. '6-vector X
  170. '7-vector Y
  171. '8-W gas
  172. '9-S brake
  173. '10-mouseX
  174. '11-mouseZ
  175. '12 cam4  /me6
  176. '13 cam3 /me5
  177. '15 actual speed
  178. '16 column (XY) crash /last step
  179. '17 land (Z) crash /last step
  180.  
  181. 'PREPARATION END ------------------------------------------------------------------------------------------------------------------------------------------
  182. GOSUB new_target
  183. CLS , 0
  184. control_type = 0
  185.  
  186.  
  187.  
  188.  
  189. IF pr_temp THEN _PRINTSTRING (0, 0), "moving:mouse+WASD jump:space walking/fly: F"
  190. DIM wang(20, 2, 1, 1)
  191. veh_posx = map_center
  192. veh_posy = map_center
  193.  
  194. DIM veh(19, 49)
  195. me2_comp = 1.5
  196. old_camera_type = -1
  197. '-------------------------------------------------------- BOSS CYCLE -----------------------------------------------------------------------------------
  198.  
  199.     'keyboard/mouse inputs
  200.     kf = _KEYDOWN(102): k_space = _KEYDOWN(32)
  201.     kw = _KEYDOWN(119): ks = _KEYDOWN(115): mousex = 0: mousey = 0: mw = 0: WHILE _MOUSEINPUT: mousex = mousex + _MOUSEMOVEMENTX: mousey = mousey + _MOUSEMOVEMENTY
  202.         mw = mw + _MOUSEWHEEL
  203.     WEND
  204.     kw = _KEYDOWN(119): ks = _KEYDOWN(115): ka = _KEYDOWN(97): kd = _KEYDOWN(100)
  205.     k_space = _KEYDOWN(32)
  206.     k_left = _KEYDOWN(19200): k_right = _KEYDOWN(19712): k_up = _KEYDOWN(18432): k_down = _KEYDOWN(20480): veh_wheel_sens = 8
  207.     IF ut_kf = 0 AND kf THEN control_type = (control_type + 1) MOD 3
  208.     ut_kf = kf
  209.     me2_comp = me2_comp + mw * .1
  210.     IF _KEYDOWN(45) THEN me2_comp = me2_comp - .2
  211.     IF _KEYDOWN(43) THEN me2_comp = me2_comp + .2
  212.     IF _KEYDOWN(47) THEN dis_comp = dis_comp + .2
  213.     IF _KEYDOWN(42) THEN dis_comp = dis_comp - .2
  214.  
  215.  
  216.  
  217.     '    IF _KEYDOWN(52) THEN veh_rotate2 = veh_rotate2 - .1
  218.     '    IF _KEYDOWN(54) THEN veh_rotate2 = veh_rotate2 + .1
  219.     '    IF _KEYDOWN(56) THEN veh_rotate3 = veh_rotate3 - .1
  220.     '    IF _KEYDOWN(50) THEN veh_rotate3 = veh_rotate3 + .1
  221.  
  222.  
  223.  
  224.  
  225.     'contol
  226.     IF pr_temp THEN _PRINTSTRING (500, 0), "control type : " + control_type$(control_type) + "           "
  227.     control_type = 0
  228.     SELECT CASE control_type '(0-walking 1-flying)
  229.         CASE 0
  230.             walk_speed = .18
  231.             me(3) = 0: me(4) = 0: me(7) = 0: flight(0, 1) = 0
  232.             me(5) = me(5) + mousex * mouse_sens_xy / 200: me(6) = me(6) + mousey * mouse_sens_xy / 200
  233.             go = ABS(ka OR kd OR kw OR ks): direction = (-90 * ABS(ka) + 90 * ABS(kd) + 180 * ABS(ks)) * go * pip180
  234.             go_x = -(SIN(direction + me(5)) * walk_speed) * go: go_y = -(COS(direction + me(5)) * walk_speed) * go
  235.             me(0) = me(0) + go_x: me(1) = me(1) + go_y
  236.             ' me(2) = (map_deep(me(0), me(1)) - .18 + mapzd) * map_dimz
  237.             'IF k_space AND free_jump THEN jump_cf = 15
  238.             rotx_bevel = rotx_bevel * .95: me(2) = me(2) - jump_cf / 4: jump_cf = jump_cf - 1: IF jump_cf < 0 THEN jump_cf = 0
  239.     END SELECT
  240.  
  241.  
  242.     'camera control
  243.  
  244.     IF INKEY$ = "c" THEN camera_type = (camera_type + 1) MOD 4
  245.  
  246.  
  247.     IF camera_type <> old_camera_type THEN
  248.  
  249.  
  250.         LOCATE 1, 1: PRINT "VEHICLE CONTROL: arrow keys ,space-handbrake"
  251.  
  252.         c$(0) = "typical view, camera height adjustment mousewheel, camera distance /,* buttons , and mouse horisontal look"
  253.         c$(1) = "interior view and mouse look around"
  254.         c$(2) = "'cameraman' follows the car. camera height is mousewheel and mouse horisontal look"
  255.         c$(3) = "free walking. WASD + mouse arrow. camera height is mousewheel "
  256.         LOCATE 2, 1: PRINT "camera type :"; camera_type; "(change C button);  "
  257.         LOCATE 3, 1: PRINT c$(camera_type) + SPACE$(120 - LEN(c$(camera_type)))
  258.     END IF
  259.     old_camera_type = camera_type
  260.  
  261.  
  262.  
  263.     SELECT CASE camera_type
  264.         CASE 0
  265.             me(5) = me(5) + (veh_rotate1_counterforce - me(5)) / 20
  266.             dis = 5 + dis_comp
  267.             me(0) = SIN(veh_rotate1) * dis + veh_posx
  268.             me(1) = COS(veh_rotate1) * dis + veh_posy
  269.             me(2) = map_deep(veh_posx, veh_posy) * map_dimz - (.5 + me2_comp) * ee
  270.             ' me(5) = (degree(veh_posx - me(0), veh_posy - me(1)) + 180) * pip180
  271.  
  272.         CASE 1
  273.             me(5) = me(5) + (veh_rotate1_counterforce - me(5)) / 20
  274.             dis = 5 - 5.2 '    dis_comp = -5.2: me2_comp = 0.6
  275.             me(0) = SIN(veh_rotate1) * dis + veh_posx
  276.             me(1) = COS(veh_rotate1) * dis + veh_posy
  277.             me(2) = map_deep(veh_posx, veh_posy) * map_dimz - (.5 + .6) * ee
  278.             ' me(5) = (degree(veh_posx - me(0), veh_posy - me(1)) + 180) * pip180
  279.  
  280.         CASE 2
  281.             medismax = 8: medismin = 3: follow = .01
  282.  
  283.             DO WHILE SQR((me(0) - veh_posx) ^ 2 + (me(1) - veh_posy) ^ 2) > medismax
  284.             me(0) = me(0) + SGN(veh_posx - me(0)) * follow: me(1) = me(1) + SGN(veh_posy - me(1)) * follow: LOOP
  285.  
  286.             DO WHILE SQR((me(0) - veh_posx) ^ 2 + (me(1) - veh_posy) ^ 2) < medismin
  287.             me(0) = me(0) - SGN(veh_posx - me(0)) * follow: me(1) = me(1) - SGN(veh_posy - me(1)) * follow: LOOP
  288.  
  289.             me(5) = (degree(veh_posx - me(0), veh_posy - me(1)) + 180) * pip180
  290.             me(2) = map_deep(veh_posx, veh_posy) * map_dimz - (.5 + me2_comp) * ee
  291.  
  292.         CASE 3
  293.             medis = 25: follow = .01
  294.             IF me(0) <> veh_posx THEN DO WHILE ABS(me(0) - veh_posx) > medis: me(0) = me(0) + SGN(veh_posx - me(0)) * follow: LOOP
  295.             IF me(1) <> veh_posy THEN DO WHILE ABS(me(1) - veh_posy) > medis: me(1) = me(1) + SGN(veh_posy - me(1)) * follow: LOOP
  296.             me(2) = map_deep(veh_posx, veh_posy) * map_dimz - (.5 + me2_comp) * ee
  297.     END SELECT
  298.  
  299.  
  300.  
  301.  
  302.     cosrotz = COS(me(5)): sinrotz = SIN(me(5)): cosrotx = COS(me(6)): sinrotx = SIN(me(6)) 'to rotating angles
  303.  
  304.  
  305.     '------------------------------------------ TERRAIN DRAW --------------------------------------------------------------------------------------------------
  306.  
  307.     'replace the missing row in the buffer line Y
  308.     DO WHILE INT(INT(me(0))) <> perl_setx: dir = -SGN(INT(me(0)) - perl_setx): perl_setx = perl_setx - dir
  309.         temp = INT(perl_setx + ABS(dir = -1) * (map_resolution - 1)): temp_m = INT(temp MOD map_resolution)
  310.         FOR map_y = 0 TO map_resolution - 1: map(temp_m, INT(map_y + perl_sety) MOD map_resolution, 0) = perlin2d(temp, perl_sety + map_y)
  311.     map(temp_m, INT((map_y + perl_sety) MOD map_resolution), 6) = noise(temp, perl_sety + map_y) < ration_column: NEXT map_y: LOOP
  312.  
  313.     'replace the missing row in the buffer line X
  314.     DO WHILE INT(INT(me(1))) <> perl_sety: dir = -SGN(INT(me(1)) - perl_sety): perl_sety = perl_sety - dir
  315.         temp = perl_sety + ABS(dir = -1) * (map_resolution - 1): temp_m = INT(temp MOD map_resolution)
  316.         FOR map_x = 0 TO map_resolution - 1: map(INT((map_x + perl_setx) MOD map_resolution), temp_m, 0) = perlin2d(perl_setx + map_x, temp)
  317.     map(INT(map_x + perl_setx) MOD map_resolution, temp_m, 6) = noise(perl_setx + map_x, temp) < ration_column: NEXT map_x: LOOP
  318.  
  319.     'calculating position and textures
  320.     clmn(0, 0) = 0 'reset column counter
  321.     FOR map_x = 0 TO map_resolution - 1: px = -map_dimxy / 2 + map_dimxy / map_resolution * (map_x - (me(0) - INT(me(0))))
  322.         FOR map_y = 0 TO map_resolution - 1: IF map(map_x, map_y, 9) = 0 THEN _CONTINUE
  323.             py = -map_dimxy / 2 + map_dimxy / map_resolution * (map_y - (me(1) - INT(me(1))))
  324.             read_mapx = INT((map_x + perl_setx) MOD map_resolution): read_mapy = INT((map_y + perl_sety) MOD map_resolution): map_z = map(read_mapx, read_mapy, 0)
  325.             map(map_x, map_y, 7) = 0: pz2 = map_dimz * map_z - me(2): rotate px, py, pz2, 1: IF see_point = 0 THEN _CONTINUE
  326.             map(map_x, map_y, 1) = rotating(0): map(map_x, map_y, 2) = rotating(1): map(map_x, map_y, 3) = rotating(2): map(map_x, map_y, 7) = 1
  327.             map(map_x, map_y, 5) = INT(text_height_scale * map_z): IF map(map_x, map_y, 5) > text_height_scale - 1 THEN map(map_x, map_y, 5) = text_height_scale - 1
  328.             IF map(map_x, map_y, 5) < 0 THEN map(map_x, map_y, 5) = 0
  329.             IF map(read_mapx, read_mapy, 6) THEN clmn(clmn(0, 0) + 1, 2) = map(map_x, map_y, 8): clmn(clmn(0, 0) + 1, 0) = px: clmn(clmn(0, 0) + 1, 1) = py: clmn(0, 0) = clmn(0, 0) + 1
  330.     NEXT map_y, map_x
  331.  
  332.     'do maptriangle from squares !
  333.     FOR map_x = 0 TO map_resolution - 2: FOR map_y = 0 TO map_resolution - 2
  334.             IF (map(map_x, map_y, 7) AND map(map_x + 1, map_y, 7) AND map(map_x, map_y + 1, 7) AND map(map_x + 1, map_y + 1, 7)) = 0 THEN _CONTINUE
  335.             m0x = map(map_x, map_y, 1): m0y = map(map_x, map_y, 2): m0z = map(map_x, map_y, 3)
  336.             m1x = map(map_x + 1, map_y, 1): m1y = map(map_x + 1, map_y, 2): m1z = map(map_x + 1, map_y, 3)
  337.             m2x = map(map_x, map_y + 1, 1): m2y = map(map_x, map_y + 1, 2): m2z = map(map_x, map_y + 1, 3)
  338.             m3x = map(map_x + 1, map_y + 1, 1): m3y = map(map_x + 1, map_y + 1, 2): m3z = map(map_x + 1, map_y + 1, 3)
  339.             atexture = texture(map(map_x, map_y, 8), 0): sx1 = (perl_setx + map_x) * text_multi: sy1 = (perl_sety + map_y) * text_multi: sx2 = sx1 + text_multi: sy2 = sy1 + text_multi
  340.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), atexture TO(m0x, m0y, m0z)-(m1x, m1y, m1z)-(m2x, m2y, m2z)
  341.     _MAPTRIANGLE (sx2, sy2)-(sx2, sy1)-(sx1, sy2), atexture TO(m3x, m3y, m3z)-(m1x, m1y, m1z)-(m2x, m2y, m2z): NEXT map_y, map_x
  342.  
  343.     'TERRAIN DRAW END --------------------------------------------------------------------------------------------------------------------------------------------
  344.  
  345.  
  346.  
  347.  
  348.     'VEHICLE DRAW   -------------------------------------------------------------------------------------------------------
  349.  
  350.  
  351.     v_ratio = .5
  352.     veh_tengelytav = 4 * v_ratio
  353.     veh_kerektav = 4 * v_ratio
  354.     veh_kerekrad = 1 * v_ratio
  355.     veh_kerekszeles = .9 * v_ratio
  356.     veh_posz = map_deep(veh_posx, veh_posy) * map_dimz - veh_kerekrad * ee '- 2
  357.     veh_shockab_scale = .3
  358.     body_cx = .6 * v_ratio
  359.     body_cy = .6 * v_ratio
  360.     body_cz = .8 * v_ratio
  361.     frs = .08 * v_ratio
  362.  
  363.     frs_dis_c = 1.1: body_yadd = -5.5 'frame size (ratio to vp$)
  364.  
  365.     'draw wheel
  366.     wh_r(0) = veh_kerekrad: wh_r(1) = veh_kerekrad * .4: wh_div = 16 'wheel parameters
  367.     FOR a_wheel = 0 TO 3: wh_posy = (SGN(a_wheel AND 1) * 2 - 1) * veh_tengelytav / 2: wh_posx = (SGN(a_wheel AND 2) * 2 - 1) * veh_kerektav / 2
  368.         wheel_ang = (90 + ABS(a_wheel AND 1) * veh_wheel) * pip180
  369.         FOR awh = 0 TO wh_div - 1: ang = (-wheel(a_wheel, 0) + 360 / wh_div * awh) * pip180: x = SIN(ang): y = COS(ang)
  370.             FOR sz = 0 TO 1: wh_z = (sz * 2 - 1) * veh_kerekszeles / 2: FOR whr = 0 TO 1: r1 = x * wh_r(whr): r2 = wh_z: r3 = y * wh_r(whr)
  371.                     rotate_2d r2, r1, wheel_ang: r1 = r1 + wh_posx: r2 = r2 + wh_posy: r3 = r3 + veh_shockab_scale * shockab(a_wheel)
  372.                     rotate_vehicle r1, r2, r3, veh_rotate1, veh_rotate2, veh_rotate3: r1 = r1 + veh_posx: r2 = r2 + veh_posy: r3 = r3 * ee + veh_posz
  373.         rotate (r1 - me(0)) * ee, (r2 - me(1)) * ee, r3 - me(2), 0: FOR t = 0 TO 2: wang(awh, t, whr, sz) = rotating(t): NEXT t, whr, sz, awh
  374.         FOR t1 = 0 TO wh_div - 1: t2 = (t1 + 1) MOD wh_div: FOR t3 = 0 TO 1: FOR t4 = 0 TO 1
  375.                     p00 = t1: p01 = t4: p02 = t4: p10 = t2: p11 = t4: p12 = t4: p20 = t1: p21 = t3: p22 = t3 XOR 1: p30 = t2: p31 = t3: p32 = t3 XOR 1
  376.                     _MAPTRIANGLE (0, 0)-(whe_ts - 1, 0)-(0, whe_ts - 1), whe_text TO(wang(p00, 0, p01, p02), wang(p00, 1, p01, p02), wang(p00, 2, p01, p02))-(wang(p10, 0, p11, p12), wang(p10, 1, p11, p12), wang(p10, 2, p11, p12))-(wang(p20, 0, p21, p22), wang(p20, 1, p21, p22), wang(p20, 2, p21, p22))
  377.                     _MAPTRIANGLE (whe_ts - 1, whe_ts - 1)-(whe_ts - 1, 0)-(0, whe_ts - 1), whe_text TO(wang(p30, 0, p31, p32), wang(p30, 1, p31, p32), wang(p30, 2, p31, p32))-(wang(p10, 0, p11, p12), wang(p10, 1, p11, p12), wang(p10, 2, p11, p12))-(wang(p20, 0, p21, p22), wang(p20, 1, p21, p22), wang(p20, 2, p21, p22))
  378.     NEXT t4, t3, t1, a_wheel
  379.  
  380.     'draw vehicle frame
  381.     FOR t1 = 0 TO LEN(vl$) / 5 - 1: p1 = VAL(MID$(vl$, t1 * 5 + 2, 2)): p2 = VAL(MID$(vl$, t1 * 5 + 4, 2))
  382.         x1 = (VAL(MID$(vp$, p1 * 6 + 2, 2)) - 2) * body_cx: y1 = -(VAL(MID$(vp$, p1 * 6 + 4, 2)) + body_yadd) * body_cy: z1 = -(VAL(MID$(vp$, p1 * 6 + 6, 1))) * body_cz
  383.         x2 = (VAL(MID$(vp$, p2 * 6 + 2, 2)) - 2) * body_cx: y2 = -(VAL(MID$(vp$, p2 * 6 + 4, 2)) + body_yadd) * body_cy: z2 = -(VAL(MID$(vp$, p2 * 6 + 6, 1))) * body_cz
  384.         xc = (x1 + x2) / 2: yc = (y1 + y2) / 2: zc = (z1 + z2) / 2: dis = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2 + (z1 - z2) ^ 2) / 2 * frs_dis_c
  385.         angle1 = (-degree(x2 - x1, y2 - y1)) * pip180: angle2 = (degree(y2 - y1, z2 - z1) - 90) * pip180
  386.         FOR t2 = 0 TO 7: p(t2, 0) = (SGN(ABS(t2 AND 1)) * 2 - 1) * frs: p(t2, 1) = (SGN(ABS(t2 AND 2)) * 2 - 1) * dis: p(t2, 2) = (SGN(ABS(t2 AND 4)) * 2 - 1) * frs
  387.             rotate_2d p(t2, 0), p(t2, 1), angle1: rotate_2d p(t2, 1), p(t2, 2), -angle2: p(t2, 0) = p(t2, 0) + xc: p(t2, 1) = p(t2, 1) + yc: p(t2, 2) = p(t2, 2) + zc
  388.             rotate_vehicle p(t2, 0), p(t2, 1), p(t2, 2), veh_rotate1, veh_rotate2, veh_rotate3: r1 = p(t2, 0) + veh_posx: r2 = p(t2, 1) + veh_posy
  389.         r3 = (veh_posz + p(t2, 2) * ee) - me(2): rotate (r1 - me(0)) * ee, (r2 - me(1)) * ee, r3, 0: FOR t = 0 TO 2: p(t2, t) = rotating(t): NEXT t, t2
  390.         FOR t2 = 0 TO 5: FOR t3 = 0 TO 3: sq(t3) = VAL(MID$(sq$, 2 + t2 * 5 + t3, 1)): NEXT t3
  391.             _MAPTRIANGLE (0, 0)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), vhfr_text(0) TO(p(sq(0), 0), p(sq(0), 1), p(sq(0), 2))-(p(sq(1), 0), p(sq(1), 1), p(sq(1), 2))-(p(sq(2), 0), p(sq(2), 1), p(sq(2), 2))
  392.             _MAPTRIANGLE (vhfr_ts - 1, vhfr_ts - 1)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), vhfr_text(0) TO(p(sq(3), 0), p(sq(3), 1), p(sq(3), 2))-(p(sq(1), 0), p(sq(1), 1), p(sq(1), 2))-(p(sq(2), 0), p(sq(2), 1), p(sq(2), 2))
  393.     NEXT t2, t1
  394.  
  395.     'draw vehicle bodywork textures
  396.     FOR t1 = 0 TO LEN(vt$) / 10 - 1: FOR t = 0 TO 3: vtx(t) = VAL(MID$(vt$, t1 * 10 + (t + 1) * 2, 2)): NEXT t
  397.         FOR t2 = 0 TO 3: vt(t2, 0) = (VAL(MID$(vp$, vtx(t2) * 6 + 2, 2)) - 2) * body_cx: vt(t2, 1) = -(VAL(MID$(vp$, vtx(t2) * 6 + 4, 2)) + body_yadd) * body_cy
  398.             vt(t2, 2) = -(VAL(MID$(vp$, vtx(t2) * 6 + 6, 1))) * body_cz: rotate_vehicle vt(t2, 0), vt(t2, 1), vt(t2, 2), veh_rotate1, veh_rotate2, veh_rotate3
  399.             r1 = vt(t2, 0) + veh_posx: r2 = vt(t2, 1) + veh_posy: r3 = (veh_posz + vt(t2, 2) * ee) - me(2)
  400.         rotate (r1 - me(0)) * ee, (r2 - me(1)) * ee, r3, 0: FOR t = 0 TO 2: vt(t2, t) = rotating(t): NEXT t, t2: atexture = vhfr_text(VAL(MID$(vt$, t1 * 10 + 10, 1)))
  401.         _MAPTRIANGLE (0, 0)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), atexture TO(vt(0, 0), vt(0, 1), vt(0, 2))-(vt(1, 0), vt(1, 1), vt(1, 2))-(vt(2, 0), vt(2, 1), vt(2, 2))
  402.         _MAPTRIANGLE (vhfr_ts - 1, vhfr_ts - 1)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), atexture TO(vt(3, 0), vt(3, 1), vt(3, 2))-(vt(1, 0), vt(1, 1), vt(1, 2))-(vt(2, 0), vt(2, 1), vt(2, 2))
  403.     NEXT t1
  404.  
  405.  
  406.     'VEHICLE DRAW END ----------------------------------------------------------------------------------------------------------
  407.  
  408.  
  409.  
  410.  
  411.  
  412.     'vehicle control
  413.  
  414.  
  415.  
  416.     veh_speed_max = .3
  417.  
  418.     veh_wheel = veh_wheel + (k_left - k_right) * veh_wheel_sens '/ ((veh_speed + .01) * 5)
  419.     veh_wheel_max = 45: IF ABS(veh_wheel) > veh_wheel_max THEN veh_wheel = SGN(veh_wheel) * veh_wheel_max
  420.  
  421.     veh_speed = SQR(veh_vecx ^ 2 + veh_vecy ^ 2)
  422.  
  423.     IF k_space THEN gg = 3 ELSE gg = 1
  424.     veh_wheel = veh_wheel * (.85 - veh_speed / gg)
  425.  
  426.  
  427.     veh_rotate1 = veh_rotate1 + (veh_speed * veh_wheel) / 120
  428.  
  429.  
  430.     veh_rotate1_counterforce = veh_rotate1
  431.  
  432.     position_accel = .0091: ww = .98: szog_xy = veh_rotate1 '+ weh_wheel * pip180
  433.  
  434.     new_vec_x = SIN(szog_xy) * position_accel * k_up * ABS(k_space = 0)
  435.     new_vec_y = COS(szog_xy) * position_accel * k_up * ABS(k_space = 0)
  436.     vec_x = (veh_vecx * ww + new_vec_x)
  437.     vec_y = (veh_vecy * ww + new_vec_y)
  438.     vec_sum = SQR(vec_x * vec_x + vec_y * vec_y):
  439.     IF vec_sum > veh_speed_max THEN vec_sum = veh_speed_max / vec_sum ELSE vec_sum = 1
  440.  
  441.  
  442.     veh_vecx = vec_x * vec_sum
  443.     veh_vecy = vec_y * vec_sum
  444.     veh_speed = SQR(veh_vecx ^ 2 + veh_vecy ^ 2)
  445.     IF k_up = 0 AND veh_speed < .01 THEN veh_vecx = 0: veh_vecy = 0: veh_speed = 0
  446.     veh_posx = veh_posx + veh_vecx
  447.     veh_posy = veh_posy + veh_vecy
  448.  
  449.  
  450.     IF k_down THEN deacc = .96 ELSE deacc = .9993: IF kw THEN deacc = 1
  451.     IF k_space THEN deacc = .99
  452.     veh_vecx = veh_vecx * deacc
  453.     veh_vecy = veh_vecy * deacc
  454.  
  455.     '    IF INKEY$ = "u" THEN FOR t = 0 TO 3: shockab(t) = RND(1): NEXT t
  456.     '   LOCATE 3, 1: PRINT shockab(3)
  457.  
  458.     'wheels rotation
  459.     FOR a_wheel = 0 TO 3
  460.         wh_posy = (SGN(a_wheel AND 1) * 2 - 1) * veh_tengelytav / 2: wh_posx = (SGN(a_wheel AND 2) * 2 - 1) * veh_kerektav / 2
  461.         rotate_2d wh_posy, wh_posx, veh_rotate1: wheel_ang = (90 + ABS(a_wheel AND 1) * veh_wheel) * pip180
  462.         add = veh_speed: IF add > .2 THEN add = .2
  463.         IF k_space AND ((a_wheel AND 1) = 0) THEN add = 0
  464.     wheel(a_wheel, 0) = wheel(a_wheel, 0) + add * 50: NEXT a_wheel
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.     _DISPLAY: IF pr_temp THEN _PRINTSTRING (0, 20), SPACE$(160)
  472.  
  473.  
  474. '--------------------------------------------------------------------------- BOSS CYCLE END -------------------------------------------------
  475.  
  476.  
  477. rotating_draw:
  478. rd = .3
  479. _MAPTRIANGLE (0, 0)-(whe_ts - 1, 0)-(0, whe_ts - 1), whe_text TO(rotating(0), rotating(1), rotating(2))-(rotating(0) + rd, rotating(1), rotating(2))-(rotating(0), rotating(1) + rd, rotating(2))
  480.  
  481.  
  482.  
  483. new_target: l = 300: targ(0) = map_center + l / 2 + l * RND(1): targ(1) = map_center + l / 2 + l * RND(1): targ(2) = (map_deep(targ(0), targ(1)) - .1 - targ_size / 2)
  484. new_target_signal = 160: RETURN
  485.  
  486.  
  487.  
  488.  
  489. FUNCTION noise (x, y) 'reading pseudo random buffer
  490.     x2 = INT(x): y2 = INT(y): a = INT(ABS(x2) + ABS(y2)) MOD noise_rand_c: b = ABS(x2) MOD noise_rand_c: c = noise_rand(a) + noise_rand(b): noise = c - INT(c)
  491.  
  492. FUNCTION SmoothNoise (x, y)
  493.     SELECT CASE perlin_smooth_noise_interpolation_type
  494.         CASE 0: SmoothNoise = noise(x, y)
  495.         CASE 1: corners = (noise(x - 1, y - 1) + noise(x + 1, y - 1) + noise(x - 1, y + 1) + noise(x + 1, y + 1)) / 16
  496.             sides = (noise(x - 1, y) + noise(x + 1, y) + noise(x, y - 1) + noise(x, y + 1)) / 8: center = noise(x, y) / 4: SmoothNoise = corners + sides + center
  497.  
  498. FUNCTION Perlin2D_original (x, y): total = 0: FOR t = 0 TO perlin_level - 1: frequency = 2 ^ t * perlin_multiplier: amplitude = perlin_pers ^ t
  499.     total = total + InterpolatedNoise(x * frequency, y * frequency) * amplitude: NEXT t: Perlin2D_original = total
  500.  
  501. FUNCTION perlin2d (x, y): perlin2dx = mapz_multiplier * (Perlin2D_original(x, y) - mapz_min)
  502.     '    perlin2d = 0: EXIT FUNCTION
  503.     IF perlin2dx > perlin_flat_soil_limit_low THEN perlin2dx = perlin_flat_soil_limit_low
  504.     IF perlin2dx < perlin_flat_soil_limit_high THEN perlin2dx = perlin_flat_soil_limit_high
  505.     perlin2d = perlin2dx
  506.  
  507. FUNCTION InterpolatedNoise (x, y): integer_X = INT(x): fractional_X = x - integer_X: integer_y = INT(y): fractional_Y = y - integer_y
  508.     v1 = SmoothNoise(integer_X, integer_y): v2 = SmoothNoise(integer_X + 1, integer_y)
  509.     v3 = SmoothNoise(integer_X, integer_y + 1): v4 = SmoothNoise(integer_X + 1, integer_y + 1)
  510. i1 = Interpolate(v1, v2, fractional_X): i2 = Interpolate(v3, v4, fractional_X): InterpolatedNoise = Interpolate(i1, i2, fractional_Y): END FUNCTION
  511.  
  512. FUNCTION Interpolate (a, b, x): Interpolate = a * (1 - x) + b * x: END FUNCTION
  513.  
  514. SUB rotate (px, py, pz2, see_analysis)
  515.     px3 = px * cosrotz - py * sinrotz: py2 = px * sinrotz + py * cosrotz: py3 = py2 * cosrotx - pz2 * sinrotx: pz3 = -(py2 * sinrotx + pz2 * cosrotx)
  516.     see_point = pz3 < 200: IF see_point = 0 AND see_analysis THEN EXIT SUB
  517. rotate_2d px3, py2, rotx_bevel: rotating(0) = px3 * map_zoom_xy: rotating(1) = -py3 * map_zoom_xy: rotating(2) = pz3 * map_zoom_distance: END SUB
  518.  
  519. SUB rotate_2d (x, y, ang): x1 = -(x * COS(ang) - y * SIN(ang)): y1 = -(x * SIN(ang) + y * COS(ang)): x = x1: y = y1: END SUB
  520.  
  521. SUB flight_control (af)
  522.  
  523.     rotx = flight(af, 1): me0 = flight(af, 3): me1 = flight(af, 4): me2 = flight(af, 5): me3 = flight(af, 6): me4 = flight(af, 7): kw = ABS(flight(af, 8))
  524.     ks = ABS(flight(af, 9)): mousey = flight(af, 11): mousex = flight(af, 10): me6 = flight(af, 12): me5 = flight(af, 13): rotx_bevel3 = flight(af, 2)
  525.     rotx = (rotx + mousex * .005) * .95: IF ABS(rotx) > (max_incli * pip180) THEN rotx = max_incli * pip180 * SGN(rotx)
  526.  
  527.     actual_speed = 1 / position_speed * SQR(me3 * me3 + me4 * me4): rotx_bevel2 = rotx * actual_speed * kw
  528.     rotx_bevel3 = rotx_bevel3 + (rotx_bevel2 - rotx_bevel3) * .05: me5 = me5 + rotx / 20: me6 = me6 + mousey / 100: lim_fy = 65: temp = me6 / pip180
  529.     IF temp > 270 + lim_fy THEN temp = 270 + lim_fy
  530.     IF temp < 270 - lim_fy THEN temp = 270 - lim_fy
  531.     me6 = temp * pip180: me2 = me2 + COS(-me6) * actual_speed * 5 * kw + 1 * ABS(ks AND actual_speed < .05) 'calculating Z
  532.     actual_deep = (map_deep(me0, me1) - .1) * map_dimz
  533.     IF me2 > actual_deep - .1 THEN me2 = actual_deep - .1 - actual_speed / 4: me3 = me3 * .9: me4 = me4 * .9: flight(af, 17) = 1 ELSE flight(af, 17) = 0
  534.     IF me2 < flight_high_max THEN me2 = flight_high_max
  535.     position_accel = .02: ww = .9999: szog_xy = me5 + rotx 'calculating XY
  536.  
  537.     new_vec_x = -SIN(szog_xy) * position_accel * kw: new_vec_y = -COS(szog_xy) * position_accel * kw: vec_x = (me3 * ww + new_vec_x): vec_y = (me4 * ww + new_vec_y)
  538.     vec_sum = SQR(vec_x * vec_x + vec_y * vec_y): IF vec_sum > position_speed THEN vec_sum = position_speed / vec_sum ELSE vec_sum = 1
  539.     me3 = vec_x * vec_sum: me4 = vec_y * vec_sum: me0 = me0 + me3: me1 = me1 + me4: IF ks THEN deacc = .96 ELSE deacc = .99: IF kw THEN deacc = 1
  540.     me3 = me3 * deacc: me4 = me4 * deacc: flight(af, 16) = 0
  541.  
  542.     IF crash_to_column(me0, me1) THEN
  543.         IF ABS(me3 < .05) THEN me0 = flight(af, 3)
  544.         IF ABS(me4 < .05) THEN me1 = flight(af, 4)
  545.         flight(af, 16) = 1: me3 = -me3 * .7: me4 = -me4 * .7: DO: me0 = me0 + me3: me1 = me1 + me4: LOOP WHILE crash_to_column(me0, me1)
  546.     END IF
  547.     flight(af, 1) = rotx: flight(af, 3) = me0: flight(af, 4) = me1: flight(af, 5) = me2: flight(af, 6) = me3: flight(af, 7) = me4: flight(af, 2) = rotx_bevel3
  548.     flight(af, 12) = me6: flight(af, 13) = me5: flight(af, 15) = actual_speed
  549.  
  550.  
  551. FUNCTION map_deep (x, y)
  552.     read_mapx1 = INT(x + map_resper2) MOD map_resolution: read_mapx2 = INT(x + map_resper2 + 1) MOD map_resolution
  553.     read_mapy1 = INT(y + map_resper2) MOD map_resolution: read_mapy2 = INT(y + map_resper2 + 1) MOD map_resolution
  554.     mapx1 = Interpolate(map(read_mapx1, read_mapy1, 0), map(read_mapx2, read_mapy1, 0), x - INT(x))
  555.     mapx2 = Interpolate(map(read_mapx1, read_mapy2, 0), map(read_mapx2, read_mapy2, 0), x - INT(x))
  556. map_deep = Interpolate(mapx1, mapx2, y - INT(y)): END FUNCTION
  557.  
  558.  
  559. FUNCTION crash_to_column (x1, y1): EXIT FUNCTION
  560.     pixs_column = INT(map_dimxy / map_resolution / clmn_rad) + 2
  561.     FOR tx = -pixs_column TO pixs_column: FOR ty = -pixs_column TO pixs_column
  562.             read_mapx = INT(x1 + map_resper2 + tx) MOD map_resolution: read_mapy = INT(y1 + map_resper2 + ty) MOD map_resolution
  563.             IF map(read_mapx, read_mapy, 6) THEN crash_to_column = 1: EXIT FUNCTION
  564. NEXT ty, tx: END FUNCTION
  565.  
  566. FUNCTION degree (a, b): degreex = ATN((a + .00001) / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0)
  567. degree = degreex: END FUNCTION
  568.  
  569. SUB rotate_vehicle (p0, p1, p2, a1, a2, a3): rotate_2d p2, p1, a3 + 180 * pip180: rotate_2d p0, p2, a2 + 180 * pip180: rotate_2d p0, p1, -a1: END SUB
  570.  
  571.  
  572.  
  573.  

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: car simulator
« Reply #1 on: November 14, 2021, 05:41:51 pm »
MasterGy -

This is such an excellent endeavor, and you've done an awesome job with the vehicle already! So car physics... we should be able to derive all that, if anyone wants to supply links that's their business.

As for the car flipping over... This can be intricate business to get exactly right, especially when in motion. Speed factors into whether you tip over or not, so how do we model all this? I'll start:

(1) Calculate (or convincingly estimate) the center of mass of your vehicle. This will be a 3d vector landing somewhere near the middle of it, basically. This number will have to change depending on what your shock absorbers are doing from moment to moment.

(2) When the car is in any given certain position on your terrain, place an imaginary point under each tire, and connect those imaginary points with imaginary lines to make a closed, 4-sided shape. In general, for bumpy terrain, this 4-sided wireframe won't be flat or level. (This frame can serve as the basis for determining the normal vector the vehicle and help render it at a slant.)

(3) View this wireframe shape from above (take the z-projection) and it flattens to a rectangle. If the ground was very slanted, you'll get a rather small rectangle. If the ground was perfectly flat, you get the biggest possible rectangle. The benefit of shock absorbers would be to increase the size of this projected rectangle.

(4) Project the center of mass vector onto the same plane, which will effectively place a dot either inside or outside the projected rectangle. If the dot lands outside the rectangle, the vehicle flips over.

This picture is actually not exactly what im describing but it does have the center of mass and you can imagine the "wireframe box"
 
4.PNG


... All that's true "At Rest" (or true enough for low speeds) ...

To do all this while in motion, you need Newton's second law to factor in. Friction, torque, centripetal stuff, oh my... Like for example, if you're driving along at a good speed, and then suddenly turn the wheel as hard as you can, the vehicle flips like crazy, even on flat ground. Do you want to capture all of those dynamics too?
« Last Edit: November 14, 2021, 07:24:44 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: car simulator
« Reply #2 on: November 15, 2021, 01:03:05 pm »
Once again really nice work @MasterGy

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: car simulator
« Reply #3 on: November 17, 2021, 06:16:06 am »
thanks for the advice and for checking it out. Good idea STxAxTIC what you wrote! I'm just drawing for now, I'm trying to understand. I hope you succeed one day.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: car simulator
« Reply #4 on: November 20, 2021, 04:41:24 am »
I'm getting up with this lately, I'm lying with this. Before I write the move for the game, I first try to understand the dynamics of the vehicle in 2d, it’s very complicated and by the time I get there, it’s false. The behavior is not realistic. Knowledge of solid body physics or rigid body physics would be required. In vain, there are many descriptions on the Internet, but so far they have not been applied effectively. No problem, I won't give up!

Code: QB64: [Select]
  1. CONST pip180 = 3.141592 / 180
  2. CONST perlin_pers = 7 '7 'amplitudo
  3. CONST perlin_level = 1 '5 'level of resolution wave
  4. CONST perlin_multiplier = 0.005
  5. CONST perlin_smooth_noise_interpolation_type = 0 '0-none '1-standard
  6. CONST perlin_flat_soil_limit_low = .99 'high value is low area (negate)
  7. CONST perlin_flat_soil_limit_high = .05
  8.  
  9.  
  10. 'create pseudo random buffer
  11. DIM SHARED noise_rand_c: noise_rand_c = 10000: DIM SHARED noise_rand(noise_rand_c - 1): FOR t = 0 TO noise_rand_c - 1: noise_rand(t) = RND(1): NEXT t
  12.  
  13. 'find min/max Z
  14. DIM SHARED mapz_min, mapz_max, dimz
  15. DIM SHARED mapz_multiplier: mapz_min = 9999999: mapz_max = -mapz_min: FOR t = 0 TO 2999: c = Perlin2D_original(5000 * RND(1), 100)
  16.     mapz_min = c * ABS(mapz_min > c) + mapz_min * (ABS(mapz_min > c) XOR 1): mapz_max = c * ABS(mapz_max < c) + mapz_max * (ABS(mapz_max < c) XOR 1)
  17. NEXT t: mapz_multiplier = 1 / (mapz_max - mapz_min)
  18.  
  19. 'vehicle 3d data
  20. vp$ = "-01010-03010-01020-03020-00031-04031-01052-03052-01072-03072-00081-04081-00101-04101-00090-04090" 'points X(2),Y(2),Z(1)
  21. vl$ = "-0001-0002-0103-0203-0004-0105-0204-0305-0406-0507-0607-0410-0511-0608-0709-0809-0810-0911-1011-1012-1113-1213-1412-1513-1415-0405-0214-0315" '3d lines
  22. sq$ = "-0123-4567-0246-2367-3175-1054" 'cubes points make square
  23. vt$ = "-000102031-000104051-141512131-101112131-040012141-050113151-080910111-141502031" 'bodywork textures
  24. vt$ = vt$ + "-040610082-040509112-040506072-060708092" 'vehicle windows
  25. vp$ = vp$ + "-01081-01101-01092-01102-03081-03101-03092-03102-00092-04092-00102-04102": vt$ = vt$
  26.  
  27.  
  28. monx = 1200: mony = 400: mon = _NEWIMAGE(monx, mony, 32): SCREEN mon: _SCREENMOVE _MIDDLE
  29. dimz = 200: veh_posx = 10000
  30. eltx = -monx / 8 'location vehicle on display
  31. DIM whz(1, 99, 9)
  32. 'shockab(0) = .5
  33.  
  34.  
  35. veh_posz = map_deep(veh_posx) + 150 'veh_kerekrad
  36.  
  37. '------------------------------------------------------------- BOSS CYCLE -------------------------------------------------------------------------------------
  38.     'controls input
  39.     k_space = _KEYDOWN(32): k_left = _KEYDOWN(19200): k_right = _KEYDOWN(19712): k_up = _KEYDOWN(18432): k_down = _KEYDOWN(20480)
  40.  
  41.  
  42.     'draw terrain
  43.     FOR tx = 0 TO monx - 1: az = perlin2d(tx + veh_posx - monx / 2 - eltx, 100) * dimz: LINE (tx, mony)-(tx, mony - az), _RGB32(50, 50, 50): NEXT tx
  44.  
  45.     v_ratio = 30
  46.     veh_tengelytav = 4 * v_ratio
  47.     veh_kerektav = 4 * v_ratio
  48.     veh_kerekrad = 1 * v_ratio
  49.     veh_kerekszeles = .9 * v_ratio
  50.     veh_shockab_scale = .7 * v_ratio
  51.     body_cx = .6 * v_ratio
  52.     body_cy = .6 * v_ratio
  53.     body_cz = .8 * v_ratio
  54.     frs = .08 * v_ratio
  55.     wh_div = 11
  56.     frs_dis_c = 1.1: body_yadd = -5.5 'frame size (ratio to vp$)
  57.     wh_r(0) = veh_kerekrad: wh_r(1) = veh_kerekrad * .4
  58.  
  59.     'draw wheel
  60.     FOR a_wheel = 0 TO 1: wh_posx = (a_wheel * 2 - 1) * veh_tengelytav / 2: wh_posy = veh_shockab_scale * shockab(a_wheel)
  61.         rotate_2d wh_posx, wh_posy, veh_rotx: wpx = wh_posx + monx / 2 + eltx: wpy = mony - wh_posy - veh_posz
  62.         CIRCLE (wpx, wpy), wh_r(0), _RGB32(255, 255, 255): CIRCLE (wpx, wpy), wh_r(1), _RGB32(255, 255, 255)
  63.         FOR t = 0 TO wh_div - 1: ang = (-wheel_rat(a_wheel) + 360 / wh_div * t) * pip180 + veh_rotx
  64.             x1 = SIN(ang) * wh_r(0) + wpx: y1 = COS(ang) * wh_r(0) + wpy: x2 = SIN(ang) * wh_r(1) + wpx: y2 = COS(ang) * wh_r(1) + wpy
  65.     LINE (x1, y1)-(x2, y2), _RGB32(200, 200, 200): NEXT t, a_wheel
  66.  
  67.     'draw vehicle frame
  68.     FOR t1 = 0 TO LEN(vl$) / 5 - 1: p1 = VAL(MID$(vl$, t1 * 5 + 2, 2)): p2 = VAL(MID$(vl$, t1 * 5 + 4, 2))
  69.         x1 = (VAL(MID$(vp$, p1 * 6 + 4, 2)) + body_yadd) * body_cy: y1 = -(VAL(MID$(vp$, p1 * 6 + 6, 1))) * body_cz
  70.         x2 = (VAL(MID$(vp$, p2 * 6 + 4, 2)) + body_yadd) * body_cy: y2 = -(VAL(MID$(vp$, p2 * 6 + 6, 1))) * body_cz
  71.         rotate_2d x1, y1, veh_rotx: rotate_2d x2, y2, veh_rotx
  72.         x1 = x1 + monx / 2 + eltx: y1 = mony - y1 - veh_posz: x2 = x2 + monx / 2 + eltx: y2 = mony - y2 - veh_posz
  73.     LINE (x1, y1)-(x2, y2), _RGB32(255, 255, 255): NEXT t1
  74.  
  75.     '--------------------------------------------------------------------- CONTROL --------------------------------------------------------
  76.     v_ratio = 3
  77.     gravity = v_ratio * 0.05
  78.  
  79.     veh_posx = veh_posx + veh_vecx * v_ratio
  80.     veh_posz = veh_posz + veh_vecz * v_ratio
  81.  
  82.     veh_vecx = COS(veh_rotx) * v_ratio
  83.     veh_vecz = veh_vecz - gravity + SIN(veh_rotx) * .3
  84.  
  85.     '    LOCATE 1, 1: PRINT veh_vecx, veh_vecz
  86.  
  87.     'utkozik-e valamelyik kerek ?
  88.     FOR a_wheel = 0 TO 1: whe_pos(a_wheel, 2) = 0
  89.         whe_pos(a_wheel, 0) = (veh_tengelytav / 2 * (a_wheel * 2 - 1)): whe_pos(a_wheel, 1) = veh_shockab_scale * shockab(a_wheel)
  90.         rotate_2d whe_pos(a_wheel, 0), whe_pos(a_wheel, 1), veh_rotx
  91.         whe_pos(a_wheel, 0) = whe_pos(a_wheel, 0) + veh_posx: whe_pos(a_wheel, 1) = whe_pos(a_wheel, 1) + veh_posz
  92.  
  93.         res = 100: twc = 0: twx = 0: twz = 0: FOR t2 = 0 TO res - 1: whz(a_wheel, t2, 2) = veh_rotx + (360 / (res - 1) * t2) * pip180 'angle
  94.             wangx = SIN(whz(a_wheel, t2, 2)) * veh_kerekrad: wangz = COS(whz(a_wheel, t2, 2)) * veh_kerekrad
  95.             whz(a_wheel, t2, 0) = wangx + whe_pos(a_wheel, 0): whz(a_wheel, t2, 1) = wangz + whe_pos(a_wheel, 1)
  96.             t3 = ABS(map_deep(whz(a_wheel, t2, 0)) > whz(a_wheel, t2, 1)) 'point in the terrain height
  97.         twc = twc + t3: twx = twx + wangz * t3: twz = twz - wangx * t3: NEXT t2: IF twc = 0 THEN _CONTINUE
  98.         whe_pos(a_wheel, 2) = 1 'van-e utkozes ?
  99.         whe_pos(a_wheel, 3) = degree(twx, twz) - 90 'hany fok ?
  100.         whe_pos(a_wheel, 4) = INT(whe_pos(a_wheel, 0) - twz / twc) 'melyik terep X ?
  101.         road_scan = 4 'road-wheel angle ,road scan widht
  102.         'az utfelulet szoge a kerekek alatt
  103.         whe_pos(a_wheel, 5) = degree((map_deep(whe_pos(a_wheel, 4) + road_scan) - map_deep(whe_pos(a_wheel, 4) - road_scan)), road_scan * 2) - 90
  104.     NEXT a_wheel
  105.  
  106.  
  107.     'draw help-lines
  108.     FOR a_wheel = 0 TO 1: IF whe_pos(a_wheel, 2) = 0 THEN _CONTINUE
  109.         FOR t = 0 TO 1
  110.             xm(t) = whe_pos(a_wheel, 0) + SIN(whe_pos(a_wheel, 5) * pip180) * 300 * (t * 2 - 1) + monx / 2 - veh_posx + eltx
  111.             ym(t) = mony - (whe_pos(a_wheel, 1) - COS(whe_pos(a_wheel, 5) * pip180) * 300 * (t * 2 - 1) - veh_kerekrad)
  112.         NEXT t
  113.         IF rajzolas THEN LINE (xm(0), ym(0))-(xm(1), ym(1)), _RGB32(0, 255, 0) 'a talaj kerek alatti szoge
  114.         ang = whe_pos(a_wheel, 3) * pip180: x1 = whe_pos(a_wheel, 0) - veh_posx + eltx + monx / 2: y1 = mony - whe_pos(a_wheel, 1)
  115.         x2 = x1 + SIN(ang) * 100: y2 = y1 - COS(ang) * 100: IF rajzolas THEN LINE (x1, y1)-(x2, y2) 'kerek esese a talajra
  116.         x1 = whe_pos(a_wheel, 4): y1 = mony - map_deep(x1): IF rajzolas THEN CIRCLE (x1 - veh_posx + eltx + monx / 2, y1), 20 'talajon kerek talalkozas
  117.     NEXT a_wheel
  118.  
  119.  
  120.     'draw mover calculation
  121.     dvc = 100: dvy = dvc + 10: dvx = monx - dvy: 'CIRCLE (dvx, dvy), dvc: mover_x = _MOUSEX - dvx: mover_y = _MOUSEY - dvy
  122.     IF SQR(mover_x ^ 2 + mover_y ^ 2) > dvc THEN mover_ang = mover_ang_last ELSE mover_ang = degree(mover_x, mover_y)
  123.     mover_ang_last = mover_ang: mover_str = .5
  124.     x1 = SIN(mover_ang * pip180) * dvc * mover_str + dvx: y1 = COS(mover_ang * pip180) * dvc * mover_str + dvy: 'LINE (dvx, dvy)-(x1, y1)
  125.  
  126.     'draw mover vector
  127.     FOR a_wheel = 0 TO 1: IF whe_pos(a_wheel, 2) = 0 THEN _CONTINUE
  128.         x = whe_pos(a_wheel, 0): y = whe_pos(a_wheel, 1): angx = SIN(mover_ang * pip180): angy = COS(mover_ang * pip180):
  129.         x1 = whe_pos(a_wheel, 4): y1 = mony - map_deep(x1): x1 = x1 + monx / 2 - veh_posx + eltx: x2 = x1 - angx * 200: y2 = y1 - angy * 200
  130.         IF rajzolas THEN LINE (x1, y1)-(x2, y2), _RGB32(255, 100, 100)
  131.  
  132.  
  133.         'az auto mozgasvektora, es a talaj szoge mekkora szoget zar be ?
  134.         whe_pos(a_wheel, 6) = (-mover_ang) + whe_pos(a_wheel, 5) + 90
  135.  
  136.         angx = SIN(whe_pos(a_wheel, 6) * pip180) * 200: angy = COS(whe_pos(a_wheel, 6) * pip180) * 200
  137.         x3 = x1 - angx: y3 = y1 - angy:
  138.         IF rajzolas THEN LINE (x1, y1)-(x3, y3), _RGB32(100, 100, 255)
  139.  
  140.         66:
  141.     NEXT a_wheel
  142.  
  143.  
  144.     'lengescsillapito control
  145.     FOR a_wheel = 0 TO 1
  146.         IF whe_pos(a_wheel, 2) THEN shockab(a_wheel) = shockab(a_wheel) - .1 * v_ratio ELSE shockab(a_wheel) = shockab(a_wheel) + .02 * v_ratio
  147.         IF shockab(a_wheel) > 1 THEN shockab(a_wheel) = 1
  148.         IF shockab(a_wheel) < 0 THEN shockab(a_wheel) = 0
  149.  
  150.         whe_posx(a_wheel) = (veh_tengelytav / 2 * (a_wheel * 2 - 1))
  151.         whe_posy(a_wheel) = veh_shockab_scale * shockab(a_wheel)
  152.         rotate_2d whe_posx(a_wheel), whe_posy(a_wheel), veh_rotx
  153.  
  154.     NEXT a_wheel
  155.  
  156.  
  157.     IF whe_pos(1, 2) OR whe_pos(0, 2) THEN
  158.         veh_rotx2 = -(degree(whe_posx(0) - whe_posx(1), whe_posy(0) - whe_posy(1)) - 90) * pip180
  159.         veh_rotx3 = (veh_rotx2 - veh_rotx) * .3
  160.     ELSE
  161.         '        veh_rotx2 = veh_rotx3
  162.     END IF
  163.  
  164.     veh_rotx = veh_rotx + veh_rotx3
  165.  
  166.  
  167.     '    veh_rotx = veh_rotx + veh_rotx2 / 80
  168.     '    veh_rotx = veh_rotx + (veh_rotx_v1 - veh_rotx) / 15 '+ (veh_rotx_v2 - veh_rotx) / 5
  169.  
  170.  
  171.     'elforgatas
  172.  
  173.     LOCATE 1, 1: PRINT "angles draw D button"
  174.     IF INKEY$ = "d" THEN rajzolas = rajzolas XOR 1
  175.  
  176.  
  177.     'talaj fole igazitas
  178.  
  179.  
  180.  
  181.     IF whe_pos(1, 2) OR whe_pos(0, 2) THEN veh_vecz = 1
  182.  
  183.  
  184.  
  185. _DISPLAY: CLS , _RGB32(25, 0, 0): LOOP
  186.  
  187. kerek_talajker:
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220. FUNCTION noise (x, y) 'reading pseudo random buffer
  221.     x2 = INT(x): y2 = INT(y): a = INT(ABS(x2) + ABS(y2)) MOD noise_rand_c: b = ABS(x2) MOD noise_rand_c: c = noise_rand(a) + noise_rand(b): noise = c - INT(c)
  222.  
  223. FUNCTION SmoothNoise (x, y)
  224.     SELECT CASE perlin_smooth_noise_interpolation_type
  225.         CASE 0: SmoothNoise = noise(x, y)
  226.         CASE 1: corners = (noise(x - 1, y - 1) + noise(x + 1, y - 1) + noise(x - 1, y + 1) + noise(x + 1, y + 1)) / 16
  227.             sides = (noise(x - 1, y) + noise(x + 1, y) + noise(x, y - 1) + noise(x, y + 1)) / 8: center = noise(x, y) / 4: SmoothNoise = corners + sides + center
  228.  
  229. FUNCTION Perlin2D_original (x, y): total = 0: FOR t = 0 TO perlin_level - 1: frequency = 2 ^ t * perlin_multiplier: amplitude = perlin_pers ^ t
  230.     total = total + InterpolatedNoise(x * frequency, y * frequency) * amplitude: NEXT t: Perlin2D_original = total
  231.  
  232. FUNCTION perlin2d (x, y): perlin2dx = mapz_multiplier * (Perlin2D_original(x, y) - mapz_min)
  233.     IF perlin2dx > perlin_flat_soil_limit_low THEN perlin2dx = perlin_flat_soil_limit_low
  234.     IF perlin2dx < perlin_flat_soil_limit_high THEN perlin2dx = perlin_flat_soil_limit_high
  235.     perlin2d = perlin2dx
  236.  
  237. FUNCTION InterpolatedNoise (x, y): integer_X = INT(x): fractional_X = x - integer_X: integer_y = INT(y): fractional_Y = y - integer_y
  238.     v1 = SmoothNoise(integer_X, integer_y): v2 = SmoothNoise(integer_X + 1, integer_y)
  239.     v3 = SmoothNoise(integer_X, integer_y + 1): v4 = SmoothNoise(integer_X + 1, integer_y + 1)
  240. i1 = Interpolate(v1, v2, fractional_X): i2 = Interpolate(v3, v4, fractional_X): InterpolatedNoise = Interpolate(i1, i2, fractional_Y): END FUNCTION
  241.  
  242. FUNCTION Interpolate (a, b, x): Interpolate = a * (1 - x) + b * x: END FUNCTION
  243.  
  244. SUB rotate_2d (x, y, ang): x1 = -(x * COS(ang) - y * SIN(ang)): y1 = -(x * SIN(ang) + y * COS(ang)): x = x1: y = y1: END SUB
  245.  
  246. FUNCTION map_deep (x): map_deep = perlin2d(x, 100) * dimz: END FUNCTION
  247.  
  248. FUNCTION degree (a, b): degreex = ATN((a + .00001) / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0)
  249. degree = degreex: END FUNCTION
  250.  

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: car simulator
« Reply #5 on: November 26, 2021, 02:05:10 pm »
The car goes in the field. Cheats a lot, it's not real physics. I’ve learned a lot from it by now, if I have the time and mood, I’ll do it all over again. I want it to roll over and use the shock absorber as it should and the whole car should have normal dynamics. Right now, the way I’ve solved things is a bit confusing.
4 camera views, can be switched with the C key. camera-car distance * / buttons, camera-height + - buttons.



Code: QB64: [Select]
  1. CONST pip180 = 3.141592 / 180
  2. CONST perlin_pers = 8 '7 'amplitudo
  3. CONST perlin_level = 4 '5 'level of resolution wave
  4. CONST perlin_multiplier = 0.012
  5. CONST perlin_smooth_noise_interpolation_type = 0 '0-none '1-standard
  6. CONST perlin_flat_soil_limit_low = .6 'high value is low area (negate)
  7. CONST perlin_flat_soil_limit_high = .1
  8. CONST flight_array_size = 20: DIM flight_save(flight_array_size - 1)
  9. DIM SHARED rotating(2), cosrotz, sinrotz, cosrotx, sinrotx, map_zoom_xy, map_zoom_distance, see_point, flight(19, flight_array_size), me(19), rotx_bevel
  10. DIM SHARED mouse_sens_xy, mouse_sens_z, position_speed, clmn_rad
  11. DIM SHARED map_x, map_y, perl_setx, perl_sety, map_resolution, map_z, map_dimz, map_dimxy, flight_high_max
  12. monx = 1366 * .8: mony = monx / 16 * 9 'screen size
  13.  
  14. win_marg = monx / 25
  15. flight_high_max = -70
  16.  
  17. auto_precalc = 22
  18. auto_mouse_scale = 120
  19. auto_try_resolution = 22
  20. DIM flight_auto(auto_try_resolution - 1, flight_array_size - 1): DIM auto_efficiency(auto_try_resolution - 1, 5) '0- 1 if crash          '1- target-flight distance
  21.  
  22. pr_temp = 0 'temp pr
  23. text_deep = 30 'make deep shadow pictures
  24.  
  25.  
  26. map_center = 100000 'start of perlin-map
  27. 'text_field$ = "need\field2.bmp"
  28. text_field$ = "field1.bmp" 'field map texture
  29. text_multi = 40 'zoom to texture
  30.  
  31. position_speed = .3
  32. map_resolution = 50 'see map resolution
  33. DIM SHARED map_resper2: map_resper2 = INT(map_resolution / 2)
  34.  
  35.  
  36. DIM SHARED max_incli: max_incli = 65 'flight max rotation
  37.  
  38. map_dimxy = 1200 * .8
  39. map_dimz = 250 * .8
  40. DIM SHARED ee: ee = map_dimxy / map_resolution
  41.  
  42. map_zoom_xy = 6 * .2
  43. map_zoom_distance = 15 * .2
  44.  
  45.  
  46. mouse_sens_xy = 1.6
  47. mouse_sens_z = 1
  48.  
  49. me(6) = pip180 * 270
  50.  
  51. me(0) = map_center: me(1) = map_center
  52.  
  53. control_type$(0) = "walking": control_type$(1) = "flying": control_type$(2) = "flying/autopilot"
  54. DIM color_temp(9) AS _INTEGER64
  55. targ_text = _LOADIMAGE("need\target.jpg", 33)
  56.  
  57.  
  58.  
  59.  
  60.  
  61. DIM clmn(1999, 5): clmn_rad = 30: ration_column = 0.0003
  62. ration_column = 0.0003
  63.  
  64.  
  65. 'PREPARATION ---------------------------------------------------------------------------------------------------------------------------------------------------
  66.  
  67. 'create wheel texture
  68. whe_ts = 50: whe_marg = 7: temp = _NEWIMAGE(whe_ts, whe_ts, 32): _DEST temp: CLS , 0: marg = whe_ts * text_size_marg / 100
  69. PAINT (0, 0), _RGBA32(10, 10, 10, 255)
  70. LINE (whe_marg, whe_marg)-(whe_ts - whe_marg, whe_ts - whe_marg), _RGBA32(100, 100, 100, 255), BF
  71. whe_text = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  72.  
  73. 'create pseudo random buffer
  74. DIM SHARED noise_rand_c: noise_rand_c = 10000: DIM SHARED noise_rand(noise_rand_c - 1): FOR t = 0 TO noise_rand_c - 1: noise_rand(t) = RND(1): NEXT t
  75.  
  76. 'make sky
  77. da = 8: db = 8: sky_points = da * db: DIM sky_points(sky_points - 1, 9), sq(sky_points - 1, 7): sky_image = _LOADIMAGE("sky.jpg", 33)
  78. FOR da2 = 0 TO da - 1: dega = 360 / (da - 1) * da2 * pip180: FOR db2 = 0 TO db - 1: degb = 180 / (db - 1) * db2 * pip180: ss = 1400
  79. ap = da2 * db + db2: sky_points(ap, 0) = SIN(degb) * COS(dega) * ss: sky_points(ap, 1) = SIN(degb) * SIN(dega) * ss: sky_points(ap, 2) = COS(degb) * ss: NEXT db2, da2
  80. FOR da2 = 0 TO da - 2: FOR db2 = 0 TO db - 2: sqa = da2 * db + db2: sq(sqa, 0) = sqa: sq(sqa, 1) = sq(sqa, 0) + 1: sq(sqa, 2) = sq(sqa, 0) + db: sq(sqa, 3) = sq(sqa, 2) + 1
  81.         sq(sqa, 4) = _WIDTH(sky_image) - (_WIDTH(sky_image) / (da - 1) * da2) - 1: sq(sqa, 5) = _WIDTH(sky_image) - (_WIDTH(sky_image) / (da - 1) * (da2 + 1)) - 1
  82. sq(sqa, 6) = INT(_HEIGHT(sky_image) / (db - 1) * db2): sq(sqa, 7) = INT(_HEIGHT(sky_image) / (db - 1) * (db2 + 1)): NEXT db2, da2
  83.  
  84.  
  85.  
  86. 'vehicle frame texture
  87. vhfr_ts = 30: marg = 5: temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(46, 88, 100, 255)
  88. LINE (marg, marg)-(vhfr_ts - marg, vhfr_ts - marg), _RGBA32(255, 166, 50, 255), BF: vhfr_text(0) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  89. temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(255 / 2, 166 / 2, 50 / 2, 255): vhfr_text(1) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  90. temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(150, 150, 255, 50): vhfr_text(2) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  91. temp = _NEWIMAGE(vhfr_ts, vhfr_ts, 32): _DEST temp: PAINT (0, 0), _RGBA32(233, 94, 61, 255)
  92. marg = 5: LINE (marg, marg)-(vhfr_ts - marg, vhfr_ts - marg), _RGB32(255, 0, 0), BF: _SETALPHA 0, _RGB32(255, 0, 0) TO _RGB32(255, 0, 0)
  93. vhfr_text(3) = _COPYIMAGE(temp, 33): _FREEIMAGE temp
  94.  
  95.  
  96.  
  97. vp$ = "-01010-03010-01020-03020-00031-04031-01052-03052-01072-03072-00081-04081-00101-04101-00090-04090" 'points X(2),Y(2),Z(1)
  98. vl$ = "-0001-0002-0103-0203-0004-0105-0204-0305-0406-0507-0607-0410-0511-0608-0709-0809-0810-0911-1011-1012-1113-1213-1412-1513-1415-0405-0214-0315" '3d lines
  99. sq$ = "-0123-4567-0246-2367-3175-1054" 'cubes points make square
  100. vt$ = "-000102031-000104051-141512131-101112131-040012141-050113151-080910111-141502031" 'bodywork textures
  101. vt$ = vt$ + "-040610082-040509112-040506072-060708092" 'vehicle windows
  102. vp$ = vp$ + "-01081-01101-01092-01102-03081-03101-03092-03102-00092-04092-00102-04102": vt$ = vt$ + "-161718193-202122233-242526270" 'extension air deflector
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. DIM temp_color(0) AS _INTEGER64
  111. 'create texture to map
  112. DIM SHARED mapz_min, mapz_max: DIM texture(text_deep - 1, 5): temp = _LOADIMAGE(text_field$, 32)
  113. FOR t = 0 TO text_deep - 1: dark = (.6 - (1 / (text_deep - 1) * t)): transp = dark * 2000: IF transp > 255 THEN transp = 255
  114.     temp2 = _NEWIMAGE(_WIDTH(temp), _HEIGHT(temp), 32): _SOURCE temp: _DEST temp2: CLS 0, _RGBA32(0, 0, 0, transp)
  115.     FOR tx = 0 TO _WIDTH(temp) - 1: FOR ty = 0 TO _HEIGHT(temp) - 1: temp_color(0) = POINT(tx, ty)
  116.             c1 = _RED32(temp_color(0)) * dark: c2 = _GREEN32(temp_color(0)) * dark: c3 = _BLUE32(temp_color(0)) * dark
  117. PSET (tx, ty), _RGBA32(c1, c2, 0, transp): NEXT ty, tx: texture(t, 0) = _COPYIMAGE(temp2, 33): _FREEIMAGE temp2: NEXT t
  118.  
  119. 'find min/max Z
  120. DIM SHARED mapz_multiplier: mapz_min = 9999999: mapz_max = -mapz_min: FOR t = 0 TO 2999: c = Perlin2D_original(5000 * RND(1), 5000 * RND(1))
  121.     mapz_min = c * ABS(mapz_min > c) + mapz_min * (ABS(mapz_min > c) XOR 1): mapz_max = c * ABS(mapz_max < c) + mapz_max * (ABS(mapz_max < c) XOR 1)
  122. NEXT t: mapz_multiplier = 1 / (mapz_max - mapz_min)
  123.  
  124. 'fill map-buffer
  125. DIM SHARED map(map_resolution - 1, map_resolution - 1, 19): perl_setx = INT(me(0)): perl_sety = INT(me(1))
  126. FOR map_x = 0 TO map_resolution - 1: FOR map_y = 0 TO map_resolution - 1
  127.         map((map_x + perl_setx) MOD map_resolution, (map_y + perl_sety) MOD map_resolution, 0) = perlin2d(perl_setx + map_x, perl_sety + map_y)
  128. map((map_x + perl_setx) MOD map_resolution, (map_y + perl_sety) MOD map_resolution, 6) = noise(map_x, map_y) < ration_column: NEXT map_y, map_x
  129.  
  130. 'calculating shadows
  131. FOR map_x = 0 TO map_resolution - 1: FOR map_y = 0 TO map_resolution - 1
  132.         dis = INT((text_deep - 1) / map_resper2 * SQR((map_x - map_resper2) ^ 2 + (map_y - map_resper2) ^ 2)): IF dis < 0 OR dis > text_deep - 1 THEN _CONTINUE
  133. map(map_x, map_y, 9) = 1: map(map_x, map_y, 8) = dis: NEXT map_y, map_x
  134.  
  135.  
  136.  
  137.  
  138. 'MAP array
  139. '0-perlin Z-data
  140. '1-maptriangle calculate X
  141. '2-maptriangle calculate Y
  142. '3-maptriangle calculate Z
  143. '4-distance from me (color)
  144. '5-texture height scale
  145. '6-is there a column ?
  146. '7-is the point visible?
  147. '8-shadow-table
  148. '9-not used area signal
  149.  
  150. 'ME array
  151. '0-me X location
  152. '1-me Y location
  153. '2-me Z location
  154. '3-vector_x
  155. '4-vector_y
  156. '5-me XY angle CAM3
  157. '6-me XY CAM4
  158. '7-me kanyarodas merteke
  159.  
  160. 'FLIGHT array
  161. '0-active
  162. '1-rotx - kanyarodas merteke
  163. '2-rotx_bevel
  164. '3-location X
  165. '4-location Y
  166. '5-location Z
  167. '6-vector X
  168. '7-vector Y
  169. '8-W gas
  170. '9-S brake
  171. '10-mouseX
  172. '11-mouseZ
  173. '12 cam4  /me6
  174. '13 cam3 /me5
  175. '15 actual speed
  176. '16 column (XY) crash /last step
  177. '17 land (Z) crash /last step
  178.  
  179. 'PREPARATION END ------------------------------------------------------------------------------------------------------------------------------------------
  180. GOSUB new_target
  181. CLS , 0
  182. control_type = 0
  183.  
  184.  
  185.  
  186.  
  187. IF pr_temp THEN _PRINTSTRING (0, 0), "moving:mouse+WASD jump:space walking/fly: F"
  188. DIM wang(20, 2, 1, 1)
  189. veh_posx = map_center
  190. veh_posy = map_center
  191.  
  192. DIM veh(19, 49)
  193.  
  194. old_camera_type = -1
  195. camera_type = 0
  196.  
  197. gravity = .3
  198. veh_gra = gravity
  199.  
  200.  
  201. '-------------------------------------------------------- BOSS CYCLE -----------------------------------------------------------------------------------
  202.  
  203.  
  204.     'draw sky
  205.     FOR actual_point = 0 TO sky_points - 1: rotate sky_points(actual_point, 0), sky_points(actual_point, 1), sky_points(actual_point, 2), 0
  206.     sky_points(actual_point, 4) = rotating(0): sky_points(actual_point, 5) = rotating(1): sky_points(actual_point, 6) = rotating(2): NEXT actual_point
  207.     FOR asq = 0 TO sky_points - 1
  208.         wx0 = sky_points(sq(asq, 0), 4): wy0 = sky_points(sq(asq, 0), 5): wz0 = sky_points(sq(asq, 0), 6)
  209.         wx1 = sky_points(sq(asq, 1), 4): wy1 = sky_points(sq(asq, 1), 5): wz1 = sky_points(sq(asq, 1), 6)
  210.         wx2 = sky_points(sq(asq, 2), 4): wy2 = sky_points(sq(asq, 2), 5): wz2 = sky_points(sq(asq, 2), 6)
  211.         wx3 = sky_points(sq(asq, 3), 4): wy3 = sky_points(sq(asq, 3), 5): wz3 = sky_points(sq(asq, 3), 6)
  212.         sy0 = sq(asq, 6): sx0 = sq(asq, 4): sy1 = sq(asq, 7): sx1 = sq(asq, 4): sy2 = sq(asq, 6): sx2 = sq(asq, 5): sy3 = sq(asq, 7): sx3 = sq(asq, 5)
  213.         _MAPTRIANGLE (sx0, sy0)-(sx1, sy1)-(sx2, sy2), sky_image TO(wx0, wy0, wz0)-(wx1, wy1, wz1)-(wx2, wy2, wz2), , _SMOOTH
  214.         _MAPTRIANGLE (sx3, sy3)-(sx1, sy1)-(sx2, sy2), sky_image TO(wx3, wy3, wz3)-(wx1, wy1, wz1)-(wx2, wy2, wz2), , _SMOOTH
  215.     NEXT asq
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.     'keyboard/mouse inputs
  224.     kf = _KEYDOWN(102): k_space = _KEYDOWN(32)
  225.     kw = _KEYDOWN(119): ks = _KEYDOWN(115): mousex = 0: mousey = 0: mw = 0: WHILE _MOUSEINPUT: mousex = mousex + _MOUSEMOVEMENTX: mousey = mousey + _MOUSEMOVEMENTY
  226.         mw = mw + _MOUSEWHEEL
  227.     WEND
  228.     kw = _KEYDOWN(119): ks = _KEYDOWN(115): ka = _KEYDOWN(97): kd = _KEYDOWN(100)
  229.     k_space = _KEYDOWN(32)
  230.     k_left = _KEYDOWN(19200): k_right = _KEYDOWN(19712): k_up = _KEYDOWN(18432): k_down = _KEYDOWN(20480): veh_wheel_sens = 8
  231.     IF ut_kf = 0 AND kf THEN control_type = (control_type + 1) MOD 3
  232.     ut_kf = kf
  233.     me2_comp = me2_comp + mw * .1
  234.     IF _KEYDOWN(45) THEN me2_comp = me2_comp - .1
  235.     IF _KEYDOWN(43) THEN me2_comp = me2_comp + .1
  236.     IF _KEYDOWN(47) THEN dis_comp = dis_comp + 3
  237.     IF _KEYDOWN(42) THEN dis_comp = dis_comp - 3
  238.  
  239.  
  240.  
  241.     IF _KEYDOWN(52) THEN veh_rotate2 = veh_rotate2 - .1
  242.     IF _KEYDOWN(54) THEN veh_rotate2 = veh_rotate2 + .1
  243.     IF _KEYDOWN(56) THEN veh_rotate3 = veh_rotate3 - .1
  244.     IF _KEYDOWN(50) THEN veh_rotate3 = veh_rotate3 + .1
  245.  
  246.  
  247.  
  248.  
  249.     'contol
  250.     IF pr_temp THEN _PRINTSTRING (500, 0), "control type : " + control_type$(control_type) + "           "
  251.     control_type = 0
  252.     SELECT CASE control_type '(0-walking 1-flying)
  253.         CASE 0
  254.             walk_speed = .18
  255.             me(3) = 0: me(4) = 0: me(7) = 0: flight(0, 1) = 0
  256.             me(5) = me(5) + mousex * mouse_sens_xy / 200: me(6) = me(6) + mousey * mouse_sens_xy / 200
  257.             go = ABS(ka OR kd OR kw OR ks): direction = (-90 * ABS(ka) + 90 * ABS(kd) + 180 * ABS(ks)) * go * pip180
  258.             go_x = -(SIN(direction + me(5)) * walk_speed) * go: go_y = -(COS(direction + me(5)) * walk_speed) * go
  259.             me(0) = me(0) + go_x: me(1) = me(1) + go_y
  260.             ' me(2) = (map_deep(me(0), me(1)) - .18 + mapzd) * map_dimz
  261.             'IF k_space AND free_jump THEN jump_cf = 15
  262.             'rotx_bevel = rotx_bevel * .95
  263.             me(2) = me(2) - jump_cf / 4: jump_cf = jump_cf - 1: IF jump_cf < 0 THEN jump_cf = 0
  264.     END SELECT
  265.  
  266.  
  267.     'camera control
  268.  
  269.     IF INKEY$ = "c" THEN camera_type = (camera_type + 1) MOD 4
  270.  
  271.  
  272.     IF camera_type <> old_camera_type THEN
  273.         me2_comp = 0: dis_comp = 0
  274.  
  275.         LOCATE 1, 1: PRINT "VEHICLE CONTROL: arrow keys ,space-handbrake"
  276.  
  277.         q$ = "camera height :mousewheel or *,- button , camera distance /,* button"
  278.         c$(0) = "typical view -" + q$
  279.         c$(1) = "interior view and mouse look around"
  280.         c$(2) = "'camera follows the car - " + q$
  281.         c$(3) = "free walking - WASD + mouse arrow " + q$
  282.         LOCATE 2, 1: PRINT "camera type :"; camera_type; "(change C button);  "
  283.         LOCATE 3, 1: PRINT c$(camera_type) + SPACE$(120 - LEN(c$(camera_type)))
  284.     END IF
  285.     old_camera_type = camera_type
  286.  
  287.  
  288.  
  289.     SELECT CASE camera_type
  290.         CASE 0
  291.  
  292.             dis = (45 + dis_comp) / ee
  293.             me(0) = SIN(veh_rotate1) * dis + veh_posx
  294.             me(1) = COS(veh_rotate1) * dis + veh_posy
  295.             me(2) = map_deep(me(0), me(1)) * map_dimz - (2 + me2_comp) * ee
  296.  
  297.             me(5) = (degree(veh_posx - me(0), veh_posy - me(1)) + 180) * pip180
  298.             me(6) = (degree(-(me(2) - veh_posz), dis)) * pip180 - (180 - 45) * pip180
  299.  
  300.  
  301.         CASE 1
  302.             me(5) = me(5) + (veh_rotate1 - me(5)) / 10
  303.             dis = 5 - 5.4 '    dis_comp = -5.2: me2_comp = 0.6
  304.             me(0) = SIN(veh_rotate1) * dis + veh_posx
  305.             me(1) = COS(veh_rotate1) * dis + veh_posy
  306.             me(2) = veh_posz - 12
  307.             me(6) = -(veh_rotate3 + pip180 * -90) - pip180 * 180 + veh_rotate3_mass
  308.  
  309.  
  310.  
  311.         CASE 2
  312.             medismax = 3: medismin = 5: follow = .01
  313.  
  314.             DO WHILE SQR((me(0) - veh_posx) ^ 2 + (me(1) - veh_posy) ^ 2) > medismax
  315.             me(0) = me(0) + SGN(veh_posx - me(0)) * follow: me(1) = me(1) + SGN(veh_posy - me(1)) * follow: LOOP
  316.  
  317.             DO WHILE SQR((me(0) - veh_posx) ^ 2 + (me(1) - veh_posy) ^ 2) < medismin
  318.             me(0) = me(0) - SGN(veh_posx - me(0)) * follow: me(1) = me(1) - SGN(veh_posy - me(1)) * follow: LOOP
  319.  
  320.             me(5) = (degree(veh_posx - me(0), veh_posy - me(1)) + 180) * pip180
  321.             me(2) = map_deep(me(0), me(1)) * map_dimz - (.5 + me2_comp) * ee
  322.  
  323.         CASE 3
  324.             medis = 25: follow = .01
  325.             IF me(0) <> veh_posx THEN DO WHILE ABS(me(0) - veh_posx) > medis: me(0) = me(0) + SGN(veh_posx - me(0)) * follow: LOOP
  326.             IF me(1) <> veh_posy THEN DO WHILE ABS(me(1) - veh_posy) > medis: me(1) = me(1) + SGN(veh_posy - me(1)) * follow: LOOP
  327.             me(2) = map_deep(me(0), me(1)) * map_dimz - (1 + me2_comp) * ee
  328.  
  329.     END SELECT
  330.  
  331.  
  332.     '    LOCATE 3, 1: PRINT rotx_bevel
  333.     IF camera_type = 1 THEN
  334.         cosrotz = COS(me(5))
  335.         sinrotz = SIN(me(5))
  336.         cosrotx = COS(me(6) - veh_rotate3)
  337.         sinrotx = SIN(me(6) - veh_rotate3)
  338.         '        rotx_bevel = veh_rotate2
  339.         '       rotx_bevel = TIMER / 20 '* RND(1)
  340.     ELSE
  341.         cosrotz = COS(me(5)): sinrotz = SIN(me(5)): cosrotx = COS(me(6)): sinrotx = SIN(me(6)) 'to rotating angles
  342.     END IF
  343.     '------------------------------------------ TERRAIN DRAW --------------------------------------------------------------------------------------------------
  344.  
  345.     'replace the missing row in the buffer line Y
  346.     DO WHILE INT(INT(me(0))) <> perl_setx: dir = -SGN(INT(me(0)) - perl_setx): perl_setx = perl_setx - dir
  347.         temp = INT(perl_setx + ABS(dir = -1) * (map_resolution - 1)): temp_m = INT(temp MOD map_resolution)
  348.         FOR map_y = 0 TO map_resolution - 1: map(temp_m, INT(map_y + perl_sety) MOD map_resolution, 0) = perlin2d(temp, perl_sety + map_y)
  349.     map(temp_m, INT((map_y + perl_sety) MOD map_resolution), 6) = noise(temp, perl_sety + map_y) < ration_column: NEXT map_y: LOOP
  350.  
  351.     'replace the missing row in the buffer line X
  352.     DO WHILE INT(INT(me(1))) <> perl_sety: dir = -SGN(INT(me(1)) - perl_sety): perl_sety = perl_sety - dir
  353.         temp = perl_sety + ABS(dir = -1) * (map_resolution - 1): temp_m = INT(temp MOD map_resolution)
  354.         FOR map_x = 0 TO map_resolution - 1: map(INT((map_x + perl_setx) MOD map_resolution), temp_m, 0) = perlin2d(perl_setx + map_x, temp)
  355.     map(INT(map_x + perl_setx) MOD map_resolution, temp_m, 6) = noise(perl_setx + map_x, temp) < ration_column: NEXT map_x: LOOP
  356.  
  357.     'calculating position and textures
  358.     clmn(0, 0) = 0 'reset column counter
  359.     FOR map_x = 0 TO map_resolution - 1: px = -map_dimxy / 2 + map_dimxy / map_resolution * (map_x - (me(0) - INT(me(0))))
  360.         FOR map_y = 0 TO map_resolution - 1: IF map(map_x, map_y, 9) = 0 THEN _CONTINUE
  361.             py = -map_dimxy / 2 + map_dimxy / map_resolution * (map_y - (me(1) - INT(me(1))))
  362.             read_mapx = INT((map_x + perl_setx) MOD map_resolution): read_mapy = INT((map_y + perl_sety) MOD map_resolution): map_z = map(read_mapx, read_mapy, 0)
  363.             map(map_x, map_y, 7) = 0: pz2 = map_dimz * map_z - me(2): rotate px, py, pz2, 1: IF see_point = 0 THEN _CONTINUE
  364.             map(map_x, map_y, 1) = rotating(0): map(map_x, map_y, 2) = rotating(1): map(map_x, map_y, 3) = rotating(2): map(map_x, map_y, 7) = 1
  365.             map(map_x, map_y, 5) = INT(text_height_scale * map_z): IF map(map_x, map_y, 5) > text_height_scale - 1 THEN map(map_x, map_y, 5) = text_height_scale - 1
  366.             IF map(map_x, map_y, 5) < 0 THEN map(map_x, map_y, 5) = 0
  367.             IF map(read_mapx, read_mapy, 6) THEN clmn(clmn(0, 0) + 1, 2) = map(map_x, map_y, 8): clmn(clmn(0, 0) + 1, 0) = px: clmn(clmn(0, 0) + 1, 1) = py: clmn(0, 0) = clmn(0, 0) + 1
  368.     NEXT map_y, map_x
  369.  
  370.     'do maptriangle from squares !
  371.     FOR map_x = 0 TO map_resolution - 2: FOR map_y = 0 TO map_resolution - 2
  372.             IF (map(map_x, map_y, 7) AND map(map_x + 1, map_y, 7) AND map(map_x, map_y + 1, 7) AND map(map_x + 1, map_y + 1, 7)) = 0 THEN _CONTINUE
  373.             m0x = map(map_x, map_y, 1): m0y = map(map_x, map_y, 2): m0z = map(map_x, map_y, 3)
  374.             m1x = map(map_x + 1, map_y, 1): m1y = map(map_x + 1, map_y, 2): m1z = map(map_x + 1, map_y, 3)
  375.             m2x = map(map_x, map_y + 1, 1): m2y = map(map_x, map_y + 1, 2): m2z = map(map_x, map_y + 1, 3)
  376.             m3x = map(map_x + 1, map_y + 1, 1): m3y = map(map_x + 1, map_y + 1, 2): m3z = map(map_x + 1, map_y + 1, 3)
  377.             atexture = texture(map(map_x, map_y, 8), 0): sx1 = (perl_setx + map_x) * text_multi: sy1 = (perl_sety + map_y) * text_multi: sx2 = sx1 + text_multi: sy2 = sy1 + text_multi
  378.             _MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), atexture TO(m0x, m0y, m0z)-(m1x, m1y, m1z)-(m2x, m2y, m2z)
  379.     _MAPTRIANGLE (sx2, sy2)-(sx2, sy1)-(sx1, sy2), atexture TO(m3x, m3y, m3z)-(m1x, m1y, m1z)-(m2x, m2y, m2z): NEXT map_y, map_x
  380.  
  381.     'TERRAIN DRAW END --------------------------------------------------------------------------------------------------------------------------------------------
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.     'VEHICLE DRAW   -------------------------------------------------------------------------------------------------------
  396.  
  397.  
  398.     v_ratio = .4 'car relativ size
  399.     veh_tengelytav = 4 * v_ratio: veh_kerektav = 4 * v_ratio: veh_kerekrad = 1 * v_ratio: veh_kerekszeles = .9 * v_ratio: veh_shockab_scale = .3
  400.     body_cx = .6 * v_ratio: body_cy = .6 * v_ratio: body_cz = .7 * v_ratio: frs = .08 * v_ratio: frs_dis_c = 1.1: body_yadd = -5.5 'frame size (ratio to vp$)
  401.  
  402.     'draw wheel
  403.     wh_r(0) = veh_kerekrad: wh_r(1) = veh_kerekrad * .4: wh_div = 12 'wheel parameters
  404.     FOR a_wheel = 0 TO 3: wh_posy = (SGN(a_wheel AND 1) * 2 - 1) * veh_tengelytav / 2: wh_posx = (SGN(a_wheel AND 2) * 2 - 1) * veh_kerektav / 2
  405.         wheel_ang = (90 + ABS(a_wheel AND 1) * veh_wheel) * pip180
  406.         FOR awh = 0 TO wh_div - 1: ang = (-wheel(a_wheel, 0) + 360 / wh_div * awh) * pip180: x = SIN(ang): y = COS(ang)
  407.             FOR sz = 0 TO 1: wh_z = (sz * 2 - 1) * veh_kerekszeles / 2: FOR whr = 0 TO 1: r1 = x * wh_r(whr): r2 = wh_z: r3 = y * wh_r(whr)
  408.                     rotate_2d r2, r1, wheel_ang: r1 = r1 + wh_posx: r2 = r2 + wh_posy: r3 = r3 + veh_shockab_scale * shockab(a_wheel)
  409.                     rotate_vehicle r1, r2, r3, veh_rotate1, veh_rotate2, veh_rotate3: r1 = r1 + veh_posx: r2 = r2 + veh_posy: r3 = r3 * ee + veh_posz
  410.         rotate (r1 - me(0)) * ee, (r2 - me(1)) * ee, r3 - me(2), 0: FOR t = 0 TO 2: wang(awh, t, whr, sz) = rotating(t): NEXT t, whr, sz, awh
  411.         FOR t1 = 0 TO wh_div - 1: t2 = (t1 + 1) MOD wh_div: FOR t3 = 0 TO 1: FOR t4 = 0 TO 1
  412.                     p00 = t1: p01 = t4: p02 = t4: p10 = t2: p11 = t4: p12 = t4: p20 = t1: p21 = t3: p22 = t3 XOR 1: p30 = t2: p31 = t3: p32 = t3 XOR 1
  413.                     _MAPTRIANGLE (0, 0)-(whe_ts - 1, 0)-(0, whe_ts - 1), whe_text TO(wang(p00, 0, p01, p02), wang(p00, 1, p01, p02), wang(p00, 2, p01, p02))-(wang(p10, 0, p11, p12), wang(p10, 1, p11, p12), wang(p10, 2, p11, p12))-(wang(p20, 0, p21, p22), wang(p20, 1, p21, p22), wang(p20, 2, p21, p22))
  414.                     _MAPTRIANGLE (whe_ts - 1, whe_ts - 1)-(whe_ts - 1, 0)-(0, whe_ts - 1), whe_text TO(wang(p30, 0, p31, p32), wang(p30, 1, p31, p32), wang(p30, 2, p31, p32))-(wang(p10, 0, p11, p12), wang(p10, 1, p11, p12), wang(p10, 2, p11, p12))-(wang(p20, 0, p21, p22), wang(p20, 1, p21, p22), wang(p20, 2, p21, p22))
  415.     NEXT t4, t3, t1, a_wheel
  416.  
  417.     'draw vehicle frame
  418.     FOR t1 = 0 TO LEN(vl$) / 5 - 1: p1 = VAL(MID$(vl$, t1 * 5 + 2, 2)): p2 = VAL(MID$(vl$, t1 * 5 + 4, 2))
  419.         x1 = (VAL(MID$(vp$, p1 * 6 + 2, 2)) - 2) * body_cx: y1 = -(VAL(MID$(vp$, p1 * 6 + 4, 2)) + body_yadd) * body_cy: z1 = -(VAL(MID$(vp$, p1 * 6 + 6, 1))) * body_cz
  420.         x2 = (VAL(MID$(vp$, p2 * 6 + 2, 2)) - 2) * body_cx: y2 = -(VAL(MID$(vp$, p2 * 6 + 4, 2)) + body_yadd) * body_cy: z2 = -(VAL(MID$(vp$, p2 * 6 + 6, 1))) * body_cz
  421.         xc = (x1 + x2) / 2: yc = (y1 + y2) / 2: zc = (z1 + z2) / 2: dis = SQR((x1 - x2) ^ 2 + (y1 - y2) ^ 2 + (z1 - z2) ^ 2) / 2 * frs_dis_c
  422.         angle1 = (-degree(x2 - x1, y2 - y1)) * pip180: angle2 = (degree(y2 - y1, z2 - z1) - 90) * pip180
  423.         FOR t2 = 0 TO 7: p(t2, 0) = (SGN(ABS(t2 AND 1)) * 2 - 1) * frs: p(t2, 1) = (SGN(ABS(t2 AND 2)) * 2 - 1) * dis: p(t2, 2) = (SGN(ABS(t2 AND 4)) * 2 - 1) * frs
  424.             rotate_2d p(t2, 0), p(t2, 1), angle1: rotate_2d p(t2, 1), p(t2, 2), -angle2: p(t2, 0) = p(t2, 0) + xc: p(t2, 1) = p(t2, 1) + yc: p(t2, 2) = p(t2, 2) + zc
  425.             rotate_vehicle p(t2, 0), p(t2, 1), p(t2, 2), veh_rotate1, veh_rotate2 + veh_rotate2_mass, veh_rotate3 + veh_rotate3_mass
  426.             r1 = p(t2, 0) + veh_posx: r2 = p(t2, 1) + veh_posy
  427.         r3 = (veh_posz + p(t2, 2) * ee) - me(2): rotate (r1 - me(0)) * ee, (r2 - me(1)) * ee, r3, 0: FOR t = 0 TO 2: p(t2, t) = rotating(t): NEXT t, t2
  428.         FOR t2 = 0 TO 5: FOR t3 = 0 TO 3: sqv(t3) = VAL(MID$(sq$, 2 + t2 * 5 + t3, 1)): NEXT t3
  429.             _MAPTRIANGLE (0, 0)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), vhfr_text(0) TO(p(sqv(0), 0), p(sqv(0), 1), p(sqv(0), 2))-(p(sqv(1), 0), p(sqv(1), 1), p(sqv(1), 2))-(p(sqv(2), 0), p(sqv(2), 1), p(sqv(2), 2))
  430.             _MAPTRIANGLE (vhfr_ts - 1, vhfr_ts - 1)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), vhfr_text(0) TO(p(sqv(3), 0), p(sqv(3), 1), p(sqv(3), 2))-(p(sqv(1), 0), p(sqv(1), 1), p(sqv(1), 2))-(p(sqv(2), 0), p(sqv(2), 1), p(sqv(2), 2))
  431.     NEXT t2, t1
  432.  
  433.     'draw vehicle bodywork textures
  434.     FOR t1 = 0 TO LEN(vt$) / 10 - 1: FOR t = 0 TO 3: vtx(t) = VAL(MID$(vt$, t1 * 10 + (t + 1) * 2, 2)): NEXT t
  435.         FOR t2 = 0 TO 3: vt(t2, 0) = (VAL(MID$(vp$, vtx(t2) * 6 + 2, 2)) - 2) * body_cx: vt(t2, 1) = -(VAL(MID$(vp$, vtx(t2) * 6 + 4, 2)) + body_yadd) * body_cy
  436.             vt(t2, 2) = -(VAL(MID$(vp$, vtx(t2) * 6 + 6, 1))) * body_cz:
  437.             rotate_vehicle vt(t2, 0), vt(t2, 1), vt(t2, 2), veh_rotate1, veh_rotate2 + veh_rotate2_mass, veh_rotate3 + veh_rotate3_mass
  438.             r1 = vt(t2, 0) + veh_posx: r2 = vt(t2, 1) + veh_posy: r3 = (veh_posz + vt(t2, 2) * ee) - me(2)
  439.         rotate (r1 - me(0)) * ee, (r2 - me(1)) * ee, r3, 0: FOR t = 0 TO 2: vt(t2, t) = rotating(t): NEXT t, t2: atexture = vhfr_text(VAL(MID$(vt$, t1 * 10 + 10, 1)))
  440.         _MAPTRIANGLE (0, 0)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), atexture TO(vt(0, 0), vt(0, 1), vt(0, 2))-(vt(1, 0), vt(1, 1), vt(1, 2))-(vt(2, 0), vt(2, 1), vt(2, 2))
  441.         _MAPTRIANGLE (vhfr_ts - 1, vhfr_ts - 1)-(vhfr_ts - 1, 0)-(0, vhfr_ts - 1), atexture TO(vt(3, 0), vt(3, 1), vt(3, 2))-(vt(1, 0), vt(1, 1), vt(1, 2))-(vt(2, 0), vt(2, 1), vt(2, 2))
  442.     NEXT t1
  443.  
  444.  
  445.     'VEHICLE DRAW END ----------------------------------------------------------------------------------------------------------
  446.  
  447.  
  448.  
  449.  
  450.  
  451.     'vehicle shockabs control
  452.  
  453.     wheel_gc = 0: min_wh = 999999
  454.     FOR a_wheel = 0 TO 3
  455.         r2 = (SGN(a_wheel AND 1) * 2 - 1) * veh_tengelytav * .3: r1 = (SGN(a_wheel AND 2) * 2 - 1) * veh_kerektav * .3: r3 = veh_shockab_scale * shockab(a_wheel)
  456.         rotate_vehicle r1, r2, r3, veh_rotate1, veh_rotate2, veh_rotate3: r1 = r1 + veh_posx: r2 = r2 + veh_posy: r3 = r3 * ee + veh_posz
  457.         dis_wheel(a_wheel, 0) = map_deep(r1, r2) * map_dimz 'a kerekek alatti talaj magassaga
  458.         dis_wheel(a_wheel, 1) = r3 'a kerek helyzete Z
  459.         dis_wheel(a_wheel, 2) = (dis_wheel(a_wheel, 0) - dis_wheel(a_wheel, 1) - 10) '    shockab(2) = .5 '0-bal hatso '1-bal elso '2-jobb hatso '3-jobb elso
  460.         wheel_gc = wheel_gc + ABS(dis_wheel(a_wheel, 2) < 0): qw = -0.2
  461.         IF dis_wheel(a_wheel, 2) < -1 THEN dis_wheel(a_wheel, 3) = qw / 2 ELSE dis_wheel(a_wheel, 3) = 0
  462.         IF dis_wheel(a_wheel, 2) < 1 THEN
  463.             shockab(a_wheel) = shockab(a_wheel) - ABS(dis_wheel(a_wheel, 2)) * .02
  464.         ELSE
  465.             shockab(a_wheel) = shockab(a_wheel) + .05
  466.         END IF
  467.         shockab(a_wheel) = shockab(a_wheel) * 1.01
  468.         IF shockab(a_wheel) > 1 THEN shockab(a_wheel) = 1
  469.         IF shockab(a_wheel) < 0 THEN shockab(a_wheel) = 0
  470.         IF dis_wheel(a_wheel, 2) < min_wh THEN min_wh = dis_wheel(a_wheel, 2): w_rot_neg = a_wheel
  471.     NEXT a_wheel
  472.  
  473.     zact = map_deep(veh_posx, veh_posy) * map_dimz - veh_kerekrad * ee
  474.     IF zact < veh_posz THEN veh_posz = veh_posz + (zact - veh_posz) * .7: veh_vecz = 0 ELSE veh_vecz = veh_vecz + .06: veh_posz = veh_posz + .3
  475.     vfly = ABS(wheel_gc < 2 AND ABS(veh_speed) > .12): turn_rot = 1
  476.  
  477.     'vehicle Z-contol
  478.     ana_rad = 3 * v_ratio: ang = (veh_rotate1): x1 = veh_posx + SIN(ang) * ana_rad: y1 = veh_posy + COS(ang) * ana_rad: m1 = map_deep(x1, y1) * map_dimz / ee
  479.     x2 = veh_posx - SIN(ang) * ana_rad: y2 = veh_posy - COS(ang) * ana_rad: m2 = map_deep(x2, y2) * map_dimz / ee
  480.     nofly_veh_rotate3 = (-degree(m2 - m1, ana_rad * 2)) * pip180: veh_doles_power = SIN(nofly_veh_rotate3)
  481.     ang = (veh_rotate1) + 90 * pip180: x1 = veh_posx + SIN(ang) * ana_rad: y1 = veh_posy + COS(ang) * ana_rad: m1 = map_deep(x1, y1) * map_dimz / ee
  482.     x2 = veh_posx - SIN(ang) * ana_rad: y2 = veh_posy - COS(ang) * ana_rad: m2 = map_deep(x2, y2) * map_dimz / ee
  483.     nofly_veh_rotate2 = (degree(m2 - m1, ana_rad * 2)) * pip180
  484.  
  485.     qq_c = .022: fly_veh_rotate2 = SGN(veh_rotate2_v) * qq_c: fly_veh_rotate3 = SGN(veh_rotate3_v) * qq_c: fly_veh_rotate1 = SGN(veh_rotate1 - veh_rotate1_last) / 40
  486.  
  487.     IF vfly THEN
  488.         IF wheel_gc > 0 THEN ell = 1 ELSE ell = 1
  489.         new_rotate3 = veh_rotate3 + fly_veh_rotate3 * ell: new_rotate2 = veh_rotate2 + fly_veh_rotate2 * ell: veh_rotate1 = veh_rotate1 + fly_veh_rotate1
  490.     ELSE
  491.         veh_rotate2_v = dif_ang(veh_rotate2 / pip180, veh_rotate2_last / pip180, 360) * turn_rot
  492.         veh_rotate3_v = dif_ang(veh_rotate3 / pip180, veh_rotate3_last / pip180, 360) * turn_rot
  493.         veh_rotate3_last = veh_rotate3: veh_rotate2_last = veh_rotate2: veh_rotate1_last = veh_rotate1
  494.         new_rotate3 = nofly_veh_rotate3: new_rotate2 = nofly_veh_rotate2
  495.  
  496.     END IF
  497.     veh_rotate2 = veh_rotate2 + (dif_ang(new_rotate2 / pip180, veh_rotate2 / pip180, 360)) * .009
  498.     veh_rotate3 = veh_rotate3 + (dif_ang(new_rotate3 / pip180, veh_rotate3 / pip180, 360)) * .009
  499.  
  500.  
  501.  
  502.     'vehicle direction control
  503.  
  504.     veh_speed_max = .6: veh_speed_min = .3
  505.  
  506.     veh_wheel = veh_wheel + (k_left - k_right) * veh_wheel_sens
  507.     veh_wheel_max = 70: IF ABS(veh_wheel) > veh_wheel_max THEN veh_wheel = SGN(veh_wheel) * veh_wheel_max
  508.  
  509.     veh_speed = SQR(veh_vecx ^ 2 + veh_vecy ^ 2): IF k_space AND ABS(vfly = 0) THEN gg = 3 ELSE gg = 1
  510.     veh_wheel = veh_wheel * (.85 - veh_speed / gg): wheel_speed_meas = -dif_ang(degree(vec_y, -vec_x), veh_rotate1 / pip180, 360)
  511.  
  512.     IF vfly = 0 THEN
  513.  
  514.         IF k_space THEN veh_rotate1_v_new = vr1vn * 1.01 ELSE veh_rotate1_v_new = (veh_speed * veh_wheel) / 30 * SGN(wheel_speed_meas)
  515.         vr1vn = veh_rotate1_v_new: korm_bef = (1 - veh_speed / veh_speed_max): IF korm_bef < .05 THEN korm_bef = .05
  516.         veh_rotate1_v = veh_rotate1_v + (veh_rotate1_v_new - veh_rotate1_v) * korm_bef / 6
  517.         veh_rotate1_v = veh_rotate1_v * .999: veh_rotate1 = veh_rotate1 + veh_rotate1_v * veh_speed / veh_speed_max * 1
  518.  
  519.         doles = (1 - veh_doles_power * .2) ^ 2: position_accel = .0075 * 1 * (k_up - k_down) * ABS(k_space = 0)
  520.  
  521.         ww = .98: new_vec_x = SIN(veh_rotate1) * position_accel: new_vec_y = COS(veh_rotate1) * position_accel: vdp = (1 - veh_doles_power / 200) ^ 2
  522.         vec_x = (veh_vecx * ww + new_vec_x) * vdp: vec_y = (veh_vecy * ww + new_vec_y) * vdp: vec_sum = SQR(vec_x * vec_x + vec_y * vec_y)
  523.         IF vec_sum > veh_speed_max AND SGN(wheel_speed_meas) = 1 THEN vec_sum = veh_speed_max / vec_sum ELSE vec_sum = 1
  524.  
  525.         veh_vecx = vec_x * vec_sum: veh_vecy = vec_y * vec_sum: veh_speed = SQR(veh_vecx ^ 2 + veh_vecy ^ 2)
  526.         IF ((k_down = 0 AND k_up = 0) OR k_space) AND veh_speed < .02 THEN veh_vecx = 0: veh_vecy = 0: veh_speed = 0
  527.  
  528.         deacc = .999: IF k_space THEN deacc = .98
  529.         veh_vecx = veh_vecx * deacc: veh_vecy = veh_vecy * deacc
  530.  
  531.     END IF
  532.  
  533.     veh_posx = veh_posx + veh_vecx: veh_posy = veh_posy + veh_vecy: veh_posz = veh_posz + veh_vecz
  534.  
  535.  
  536.  
  537.     'mass center
  538.     ang = degree(veh_vecx, veh_vecy) * pip180 - veh_rotate1: dis = SQR(veh_vecx ^ 2 + veh_vecy ^ 2)
  539.     veh_rotate2_mass = -SIN(ang) * dis * .6: veh_rotate3_mass = -COS(ang) * dis * .6 + -4.5 * pip180
  540.  
  541.     'wheels rotation
  542.     FOR a_wheel = 0 TO 3: wh_posy = (SGN(a_wheel AND 1) * 2 - 1) * veh_tengelytav / 2: wh_posx = (SGN(a_wheel AND 2) * 2 - 1) * veh_kerektav / 2
  543.         rotate_2d wh_posy, wh_posx, veh_rotate1: wheel_ang = (90 + ABS(a_wheel AND 1) * veh_wheel) * pip180: add = veh_speed: IF add > .2 THEN add = .2
  544.         IF k_space AND ((a_wheel AND 1) = 0) THEN add = 0
  545.     wheel(a_wheel, 0) = wheel(a_wheel, 0) + add * 50 * SGN(wheel_speed_meas): NEXT a_wheel
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.     _DISPLAY: IF pr_temp THEN _PRINTSTRING (0, 20), SPACE$(160)
  554.  
  555.  
  556. '--------------------------------------------------------------------------- BOSS CYCLE END -------------------------------------------------
  557.  
  558.  
  559. rotating_draw:
  560. rd = .3
  561. _MAPTRIANGLE (0, 0)-(whe_ts - 1, 0)-(0, whe_ts - 1), whe_text TO(rotating(0), rotating(1), rotating(2))-(rotating(0) + rd, rotating(1), rotating(2))-(rotating(0), rotating(1) + rd, rotating(2))
  562.  
  563.  
  564.  
  565. new_target: l = 300: targ(0) = map_center + l / 2 + l * RND(1): targ(1) = map_center + l / 2 + l * RND(1): targ(2) = (map_deep(targ(0), targ(1)) - .1 - targ_size / 2)
  566. new_target_signal = 160: RETURN
  567.  
  568.  
  569.  
  570.  
  571. FUNCTION noise (x, y) 'reading pseudo random buffer
  572.     x2 = INT(x): y2 = INT(y): a = INT(ABS(x2) + ABS(y2)) MOD noise_rand_c: b = ABS(x2) MOD noise_rand_c: c = noise_rand(a) + noise_rand(b): noise = c - INT(c)
  573.  
  574. FUNCTION SmoothNoise (x, y)
  575.     SELECT CASE perlin_smooth_noise_interpolation_type
  576.         CASE 0: SmoothNoise = noise(x, y)
  577.         CASE 1: corners = (noise(x - 1, y - 1) + noise(x + 1, y - 1) + noise(x - 1, y + 1) + noise(x + 1, y + 1)) / 16
  578.             sides = (noise(x - 1, y) + noise(x + 1, y) + noise(x, y - 1) + noise(x, y + 1)) / 8: center = noise(x, y) / 4: SmoothNoise = corners + sides + center
  579.  
  580. FUNCTION Perlin2D_original (x, y): total = 0: FOR t = 0 TO perlin_level - 1: frequency = 2 ^ t * perlin_multiplier: amplitude = perlin_pers ^ t
  581.     total = total + InterpolatedNoise(x * frequency, y * frequency) * amplitude: NEXT t: Perlin2D_original = total
  582.  
  583. FUNCTION perlin2d (x, y): perlin2dx = mapz_multiplier * (Perlin2D_original(x, y) - mapz_min)
  584.     '    perlin2d = 0: EXIT FUNCTION
  585.     IF perlin2dx > perlin_flat_soil_limit_low THEN perlin2dx = perlin_flat_soil_limit_low
  586.     IF perlin2dx < perlin_flat_soil_limit_high THEN perlin2dx = perlin_flat_soil_limit_high
  587.     perlin2d = perlin2dx
  588.  
  589. FUNCTION InterpolatedNoise (x, y): integer_X = INT(x): fractional_X = x - integer_X: integer_y = INT(y): fractional_Y = y - integer_y
  590.     v1 = SmoothNoise(integer_X, integer_y): v2 = SmoothNoise(integer_X + 1, integer_y)
  591.     v3 = SmoothNoise(integer_X, integer_y + 1): v4 = SmoothNoise(integer_X + 1, integer_y + 1)
  592. i1 = Interpolate(v1, v2, fractional_X): i2 = Interpolate(v3, v4, fractional_X): InterpolatedNoise = Interpolate(i1, i2, fractional_Y): END FUNCTION
  593.  
  594. FUNCTION Interpolate (a, b, x): Interpolate = a * (1 - x) + b * x: END FUNCTION
  595.  
  596. SUB rotate (px, py, pz2, see_analysis)
  597.     px3 = px * cosrotz - py * sinrotz: py2 = px * sinrotz + py * cosrotz: py3 = py2 * cosrotx - pz2 * sinrotx: pz3 = -(py2 * sinrotx + pz2 * cosrotx)
  598.     see_point = pz3 < 200: IF see_point = 0 AND see_analysis THEN EXIT SUB
  599. rotate_2d px3, py2, rotx_bevel: rotating(0) = px3 * map_zoom_xy: rotating(1) = -py3 * map_zoom_xy: rotating(2) = pz3 * map_zoom_distance: END SUB
  600.  
  601. SUB rotate_2d (x, y, ang): x1 = -(x * COS(ang) - y * SIN(ang)): y1 = -(x * SIN(ang) + y * COS(ang)): x = x1: y = y1: END SUB
  602.  
  603.  
  604. FUNCTION map_deep (x, y)
  605.     read_mapx1 = INT(x + map_resper2) MOD map_resolution: read_mapx2 = INT(x + map_resper2 + 1) MOD map_resolution
  606.     read_mapy1 = INT(y + map_resper2) MOD map_resolution: read_mapy2 = INT(y + map_resper2 + 1) MOD map_resolution
  607.     mapx1 = Interpolate(map(read_mapx1, read_mapy1, 0), map(read_mapx2, read_mapy1, 0), x - INT(x))
  608.     mapx2 = Interpolate(map(read_mapx1, read_mapy2, 0), map(read_mapx2, read_mapy2, 0), x - INT(x))
  609.     map_deep = Interpolate(mapx1, mapx2, y - INT(y))
  610.  
  611.  
  612.  
  613.     '    map_deep = (SIN(x10 / 500) + 1) / 2
  614.  
  615.  
  616.  
  617. FUNCTION degree (a, b): degreex = ATN((a + .00001) / (b + .00001)) / pip180: degreex = degreex - 180 * ABS(0 > b): degreex = degreex - 360 * (degreex < 0)
  618. degree = degreex: END FUNCTION
  619.  
  620. SUB rotate_vehicle (p0, p1, p2, a1, a2, a3): rotate_2d p2, p1, a3 + 180 * pip180: rotate_2d p0, p2, a2 + 180 * pip180: rotate_2d p0, p1, -a1: END SUB
  621.  
  622. FUNCTION dif_ang (a, b, unit): a2 = a: b2 = b
  623.     DO WHILE ABS(a2 - b2) > ABS((a2 - unit) - b2): a2 = a2 - unit: LOOP: DO WHILE ABS(a2 - b2) > ABS((a2 + unit) - b2): a2 = a2 + unit: LOOP: dif_ang = a2 - b2
  624.  
  625.  
* neverend_land_vehicle.zip (Filesize: 1.44 MB, Downloads: 127)

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: car simulator
« Reply #6 on: November 27, 2021, 09:23:03 am »
there were problems with the camera, it works fine now

* veh_proba2.zip (Filesize: 1.44 MB, Downloads: 125)

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: car simulator
« Reply #7 on: November 27, 2021, 07:09:02 pm »
you’ve been thinking about what if you go fast in a car and lower the steering wheel as fast as you know, what happens. the car starts to spin. but what is it worth doing then? it is very interesting that this problem has come to light, because from here on, it is hard to imagine what a good position the wheel is to dampen the spin. it is interesting how this problem returned in mathematics because it was unable to turn greater than 180 degrees. very interesting. or just me? it was hard to imagine even in reality, but I could solve it. now really good! try it out and enjoy the car drifting back and forth.
* car_veh_02.zip (Filesize: 1.83 MB, Downloads: 120)

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: car simulator
« Reply #8 on: December 02, 2021, 08:59:00 pm »
I really want to make something out of it. car, flying with approximate dynamics, and automatic control. you just have to give them a goal and do everyone’s thing. I'll show you soon.


Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: car simulator
« Reply #9 on: December 14, 2021, 03:03:38 pm »
It will be ready soon, I will not give up now.
The gameplay will be easy and I hope it’s fun.


Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: car simulator
« Reply #10 on: December 14, 2021, 03:07:39 pm »
MasterGy, this is (going to be) already amazing, looks so good.

Looks like we're getting a game for Christmas bois... or maybe for New Years?
You're not done when it works, you're done when it's right.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: car simulator
« Reply #11 on: December 14, 2021, 03:13:42 pm »
I want to finish as soon as possible because I’m slowly going crazy. Get a simple storyline that makes it playable and expose. I want my brain cleared for the holidays before Christmas.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: car simulator
« Reply #12 on: December 17, 2021, 03:48:11 pm »
Hi !
Almost finished. Sounds are still missing (collision, wheel squeak), but both the car and the plane managed to give a speed-proportional, real sound. Balance okay, stereo.
In principle, there are no faults in physics or collisions.
The first half of the video (until 4:20) shows a complete fight, with each player controlled by a computer. The point is to get the bullet from the other and take it to the tornado. That’s where a pretty exciting chase begins.
In the video, after 4:20, I show that if I move the mouse over the object in the list, we see the world from his point of view. If I don’t bring the mouse to anyone, the cinema-mode camera remains, which doesn’t even take its eyes off the bullet.
If, on the other hand, I click on one, it gives me control and I control it.
For a few more days, I’ll make a menu, a simple interface, and expose the game.
I recorded the video in an audio multichanel and made sure it stayed that way when converting. Unfortunately, I don’t think you’re going to play 4 speakers in anyone, just stereo.