fNewtonWalkCarryD.pas 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. unit fNewtonWalkCarryD;
  2. interface
  3. uses
  4. Winapi.Windows,
  5. System.SysUtils,
  6. System.Variants,
  7. System.Classes,
  8. System.Math,
  9. Vcl.Graphics,
  10. Vcl.Controls,
  11. Vcl.Forms,
  12. Vcl.Dialogs,
  13. Vcl.StdCtrls,
  14. Vcl.ExtCtrls,
  15. Vcl.Imaging.Jpeg,
  16. Stage.VectorGeometry,
  17. Stage.Keyboard,
  18. Stage.VectorTypes,
  19. Stage.Utils,
  20. GLS.Scene,
  21. GLS.PersistentClasses,
  22. GLS.Material,
  23. GLS.Cadencer,
  24. GLS.SceneViewer,
  25. GLS.VectorFileObjects,
  26. GLS.Octree,
  27. GLS.GeomObjects,
  28. GLS.BaseClasses,
  29. GLS.BitmapFont,
  30. GLS.WindowsFont,
  31. GLS.Objects,
  32. GLS.Coordinates,
  33. GLS.File3DS,
  34. GLS.Navigator,
  35. GLS.XCollection,
  36. GLS.Color,
  37. GLS.HUDObjects,
  38. GLS.Texture,
  39. GLS.NGDManager;
  40. type
  41. TMap = record
  42. mdl: TGLFreeForm;
  43. dyn: boolean;
  44. end;
  45. TFormNewtonWalkCarry = class(TForm)
  46. GLScene1: TGLScene;
  47. GLSceneViewer1: TGLSceneViewer;
  48. GLNGDManager1: TGLNGDManager;
  49. GLCadencer1: TGLCadencer;
  50. GLMaterialLibrary1: TGLMaterialLibrary;
  51. Player_Cam: TGLCamera;
  52. Cam_Cube: TGLDummyCube;
  53. Player_Cube: TGLDummyCube;
  54. Scene_Objects: TGLDummyCube;
  55. Game_Menu: TGLDummyCube;
  56. OpenDialog1: TOpenDialog;
  57. GLWindowsBitmapFont1: TGLWindowsBitmapFont;
  58. Player_Capsule: TGLCapsule;
  59. GLLightSource1: TGLLightSource;
  60. GLCube2: TGLCube;
  61. GLNavigator1: TGLNavigator;
  62. GLUserInterface1: TGLUserInterface;
  63. GLNavigator2: TGLNavigator;
  64. TIPickTimer: TTimer;
  65. GLHUDSprite1: TGLHUDSprite;
  66. GLSphere1: TGLSphere;
  67. Memo1: TMemo;
  68. GLCube3: TGLCube;
  69. Jump_Timer: TTimer;
  70. GLHUDText1: TGLHUDText;
  71. Timer_OnVelocity: TTimer;
  72. On_Drop: TTimer;
  73. GLLines1: TGLLines;
  74. procedure FormCreate(Sender: TObject);
  75. procedure GLCadencer1Progress(Sender: TObject;
  76. const deltaTime, newTime: Double);
  77. procedure TIPickTimerTimer(Sender: TObject);
  78. procedure GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState;
  79. X, Y: Integer);
  80. procedure Jump_TimerTimer(Sender: TObject);
  81. procedure Timer_OnVelocityTimer(Sender: TObject);
  82. procedure On_DropTimer(Sender: TObject);
  83. private
  84. public
  85. procedure Menu_Load;
  86. procedure Game_Load;
  87. end;
  88. var
  89. FormNewtonWalkCarry: TFormNewtonWalkCarry;
  90. maps: array of TMap;
  91. currentPick: TGLCustomSceneObject;
  92. FPickedSceneObject: TGLBaseSceneObject;
  93. NGDDynamicBehav: TGLNGDDynamic;
  94. point3d, FPaneNormal: TGLVector;
  95. M_X, M_Y: Integer;
  96. Maps_Count: Integer;
  97. OnAir, OnGround: boolean;
  98. OnMouse_Click, OnDrop, OnPick: boolean;
  99. pickjoint: TGLNGDJoint;
  100. implementation
  101. {$R *.dfm}
  102. procedure TFormNewtonWalkCarry.FormCreate(Sender: TObject);
  103. begin
  104. // Switch to English keyboard layout
  105. LoadKeyboardLayout('00000409', KLF_ACTIVATE);
  106. Menu_Load;
  107. GLHUDText1.Text :=
  108. 'Walk - WASD'+#13+
  109. 'Jump - Space'+#13+
  110. 'Pick/Drop - Left mouse'+#13+
  111. 'Push - Right mouse';
  112. end;
  113. procedure TFormNewtonWalkCarry.GLCadencer1Progress(Sender: TObject;
  114. const deltaTime, newTime: Double);
  115. var
  116. I, D: TVector4f;
  117. F: TVector4f;
  118. peak_Up, peak_Down: boolean;
  119. ray, GP3D, result_GP3D: TVector4f;
  120. j: Integer;
  121. point2d, GotoPoint3d: TGLVector;
  122. key_space: boolean;
  123. cp: TPoint;
  124. visible_cursor: boolean;
  125. ScObj, FScObj: TGLBaseSceneObject;
  126. targetColor: TGLColorVector;
  127. picked: TGLCustomSceneObject;
  128. mm: TMatrix4f;
  129. begin
  130. GetCursorPos(cp);
  131. cp := GLSceneViewer1.ScreenToClient(cp);
  132. for j := 0 to Scene_Objects.Count - 1 do
  133. begin
  134. with Scene_Objects[j] as TGLCustomSceneObject do
  135. begin
  136. if Tag = 1 then
  137. Material.FrontProperties.Emission.Color := clrBlack;
  138. end;
  139. end;
  140. if Assigned(currentPick) then
  141. if currentPick.Tag = 1 then
  142. begin
  143. with currentPick do
  144. begin
  145. if currentPick.DistanceTo(Player_Capsule) <= 3.5 then
  146. begin
  147. targetColor := clrRed;
  148. end;
  149. // Set new color at 66% between current and target color
  150. with Material.FrontProperties.Emission do
  151. Color := targetColor; // VectorLerp(targetColor, Color, 0.66)
  152. end;
  153. end;
  154. GLUserInterface1.MouseLook;
  155. GLUserInterface1.MouseUpdate;
  156. TIPickTimer.Enabled := True;
  157. Player_Cube.Position := Player_Capsule.Position;
  158. if Assigned(FPickedSceneObject) and Assigned(GetNGDDynamic(FPickedSceneObject)) and OnMouse_Click then
  159. begin
  160. GP3D.X := Player_Cube.AbsolutePosition.X +
  161. Player_Cube.AbsoluteDirection.X * -2;
  162. GP3D.Y := Player_Capsule.AbsolutePosition.Y + 1.6 +
  163. Player_Cam.AbsoluteDirection.Y;
  164. GP3D.Z := Player_Cube.AbsolutePosition.Z +
  165. Player_Cube.AbsoluteDirection.Z * -2;
  166. if (roundto((point3d.X), -3) <> roundto((GP3D.X), -3)) or
  167. (roundto((point3d.Y), -3) <> roundto((GP3D.Y), -3)) or
  168. (roundto((point3d.Z), -3) <> roundto(GP3D.Z, -3)) then
  169. begin
  170. GP3D.X := point3d.X - GP3D.X;
  171. GP3D.Y := point3d.Y - GP3D.Y;
  172. GP3D.Z := point3d.Z - GP3D.Z;
  173. NormalizeVector(GP3D);
  174. GotoPoint3d.X := point3d.X + GP3D.X * -6 * deltaTime;
  175. GotoPoint3d.Y := point3d.Y + GP3D.Y * -6 * deltaTime;
  176. GotoPoint3d.Z := point3d.Z + GP3D.Z * -6 * deltaTime;
  177. point3d := GotoPoint3d;
  178. end
  179. else
  180. begin
  181. GotoPoint3d.X := Player_Cube.AbsolutePosition.X +
  182. Player_Cube.AbsoluteDirection.X * -2;
  183. GotoPoint3d.Y := Player_Capsule.AbsolutePosition.Y + 1.6 +
  184. Player_Cam.AbsoluteDirection.Y;
  185. GotoPoint3d.Z := Player_Cube.AbsolutePosition.Z +
  186. Player_Cube.AbsoluteDirection.Z * -2;
  187. end;
  188. pickjoint.KinematicControllerPick(point3d, paMove);
  189. end;
  190. if IsKeyDown(VK_LBUTTON) then
  191. begin
  192. point3d := VectorMake(GLSceneViewer1.Buffer.PixelRayToWorld(cp.X, cp.Y));
  193. if not(OnMouse_Click) and OnPick then
  194. begin
  195. FPickedSceneObject := GLSceneViewer1.Buffer.GetPickedObject(cp.X, cp.Y);
  196. if Assigned(FPickedSceneObject) then
  197. if FPickedSceneObject.DistanceTo(Player_Capsule) <= 3.5 then
  198. begin
  199. if Assigned(FPickedSceneObject) and Assigned(GetNGDDynamic(FPickedSceneObject)) and (FPickedSceneObject.Tag=1) then // If the user click on a glSceneObject
  200. begin
  201. // point3d is the global space point of the body to attach
  202. pickjoint.ParentObject := FPickedSceneObject;
  203. pickjoint.KinematicControllerPick(point3d, paAttach);
  204. OnMouse_Click := True;
  205. GotoPoint3d := point3d;
  206. On_Drop.Tag := 1;
  207. On_Drop.Enabled := True;
  208. end
  209. else
  210. FPickedSceneObject := nil;
  211. // We save the normal to create a plane parallel to camera in mouseMove Event.
  212. FPaneNormal := Player_Cam.AbsoluteDirection;
  213. end;
  214. end
  215. else
  216. begin
  217. if Assigned(FPickedSceneObject) and Assigned(GetNGDDynamic(FPickedSceneObject)) and OnDrop then
  218. begin
  219. pickjoint.KinematicControllerPick(point3d, paDetach);
  220. NGDDynamicBehav := nil;
  221. FPickedSceneObject := nil;
  222. OnMouse_Click := False;
  223. On_Drop.Tag := 0;
  224. On_Drop.Enabled := True;
  225. end;
  226. end;
  227. end;
  228. if Assigned(FPickedSceneObject) then
  229. begin
  230. ScObj := FPickedSceneObject;
  231. end;
  232. if not(OnMouse_Click) then
  233. begin
  234. // Detach the body
  235. if Assigned(NGDDynamicBehav) then
  236. begin
  237. Timer_OnVelocity.Enabled := True;
  238. end;
  239. end;
  240. if Assigned(FPickedSceneObject) and Assigned(GetNGDDynamic(FPickedSceneObject)) and IsKeyDown(VK_RBUTTON) then
  241. begin
  242. I:=Player_Cam.AbsoluteDirection;
  243. i.X:=I.X*20;
  244. i.Y:=I.Y*20;
  245. i.Z:=I.Z*20;
  246. with TGLNGDDynamic(FPickedSceneObject.Behaviours.GetByClass(TGLNGDDynamic)) do
  247. SetVelocity(I);
  248. pickjoint.KinematicControllerPick(point3d, paDetach);
  249. NGDDynamicBehav := nil;
  250. FPickedSceneObject := nil;
  251. OnMouse_Click:=false;
  252. On_Drop.Tag:=0;
  253. On_Drop.Enabled:=true;
  254. end;
  255. for j := 0 to Maps_Count - 1 do
  256. begin
  257. OnGround := maps[j].mdl.OctreeAABBIntersect
  258. (GLCube3.AxisAlignedBoundingBox(), GLCube3.AbsoluteMatrix,
  259. GLCube3.InvAbsoluteMatrix);
  260. if OnGround then
  261. break;
  262. end;
  263. if IsKeyDown(VK_SPACE) and OnGround and not(OnAir) then
  264. begin
  265. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  266. begin
  267. I := Player_Cube.AbsoluteDirection;
  268. if IsKeyDown('w') then
  269. begin
  270. i.X:=-i.X*6;
  271. i.X:=10;
  272. i.X:=-i.Z*6;
  273. SetVelocity(i);
  274. end
  275. else SetVelocity(VectorMake(0,10,0));
  276. OnGround := False;
  277. end;
  278. OnAir := True;
  279. Jump_Timer.Enabled := True;
  280. end;
  281. if Assigned(currentPick) then
  282. if currentPick.Material.FrontProperties.Emission.Color.X = 1 then
  283. begin
  284. GLHUDSprite1.Visible := True;
  285. end
  286. else
  287. begin
  288. GLHUDSprite1.Visible := False;
  289. end;
  290. if IsKeyDown('w') and OnGround and not(IsKeyDown(VK_SPACE)) then
  291. begin
  292. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  293. begin
  294. I := Player_Cube.AbsoluteDirection;
  295. i.X:=-I.X*4;
  296. i.Y:=AppliedVelocity.y;
  297. i.Z:=-I.Z*4;
  298. SetVelocity(i);
  299. end;
  300. end;
  301. if IsKeyDown('s') and OnGround then
  302. begin
  303. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  304. begin
  305. I := Player_Cube.AbsoluteDirection;
  306. i.X:=I.X*4;
  307. i.Y:=AppliedVelocity.y;
  308. i.Z:=I.Z*4;
  309. SetVelocity(i);
  310. end;
  311. end;
  312. if IsKeyDown('a') and OnGround then
  313. begin
  314. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  315. begin
  316. I := Player_Cam.AbsoluteRight;
  317. i.X:=I.X*4;
  318. i.Y:=AppliedVelocity.y;
  319. i.Z:=I.Z*4;
  320. SetVelocity(i);
  321. end;
  322. end;
  323. if IsKeyDown('d') and OnGround then
  324. begin
  325. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  326. begin
  327. I := Player_Cam.AbsoluteLeft;
  328. i.X:=I.X*4;
  329. i.Y:=AppliedVelocity.y;
  330. i.Z:=I.Z*4;
  331. SetVelocity(i);
  332. end;
  333. end;
  334. if IsKeyDown('d') and IsKeyDown('w') and OnGround then
  335. begin
  336. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  337. begin
  338. I := VectorAdd(Player_Cube.AbsoluteLeft, Player_Cube.AbsoluteDirection);
  339. i.X:=-I.X*4;
  340. i.Y:=AppliedVelocity.y;
  341. i.Z:=-I.Z*4;
  342. SetVelocity(i);
  343. end;
  344. end;
  345. if IsKeyDown('a') and IsKeyDown('w') and OnGround then
  346. begin
  347. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  348. begin
  349. I := VectorAdd(Player_Cube.AbsoluteRight, Player_Cube.AbsoluteDirection);
  350. i.X:=-I.X*4;
  351. i.Y:=AppliedVelocity.y;
  352. i.Z:=-I.Z*4;
  353. SetVelocity(i);
  354. end;
  355. end;
  356. if IsKeyDown('a') and IsKeyDown('s') and OnGround then
  357. begin
  358. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  359. begin
  360. I := VectorAdd(Player_Cube.AbsoluteLeft, Player_Cube.AbsoluteDirection);
  361. i.X:=I.X*4;
  362. i.Y:=AppliedVelocity.y;
  363. i.Z:=I.Z*4;
  364. SetVelocity(i);
  365. end;
  366. end;
  367. if IsKeyDown('d') and IsKeyDown('s') and OnGround then
  368. begin
  369. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  370. begin
  371. I := VectorAdd(Player_Cube.AbsoluteRight, Player_Cube.AbsoluteDirection);
  372. i.X:=I.X*4;
  373. i.Y:=AppliedVelocity.y;
  374. i.Z:=I.Z*4;
  375. SetVelocity(i);
  376. end;
  377. end;
  378. GLSceneViewer1.Invalidate;
  379. GLNGDManager1.Step(deltaTime);
  380. if Player_Capsule.Position.Y < -10 then
  381. begin
  382. with TGLNGDDynamic(Player_Capsule.Behaviours.GetByClass(TGLNGDDynamic)) do
  383. begin
  384. mm := NewtonBodyMatrix;
  385. mm.W := VectorMake(0, 0, 0, 1);
  386. NewtonBodyMatrix := mm;
  387. end;
  388. end;
  389. if IsKeyDown(VK_ESCAPE) then
  390. close;
  391. end;
  392. procedure TFormNewtonWalkCarry.GLSceneViewer1MouseMove(Sender: TObject; Shift: TShiftState;
  393. X, Y: Integer);
  394. begin
  395. M_X := X;
  396. M_Y := Y;
  397. end;
  398. procedure TFormNewtonWalkCarry.Menu_Load;
  399. begin
  400. FormNewtonWalkCarry.Width := 1280;
  401. FormNewtonWalkCarry.Height := 1024;
  402. GLHUDSprite1.Position.X := 640;
  403. GLHUDSprite1.Position.Y := 512;
  404. GLSceneViewer1.Height := 1024;
  405. GLSceneViewer1.Width := 1280;
  406. (*
  407. GLMaterialLibrary1.AddTextureMaterial('brick_b','brick_b.jpg');
  408. with GLMaterialLibrary1.Materials.GetLibMaterialByName('brick_b') do
  409. begin
  410. Material.Texture.Disabled:=false;
  411. end;
  412. GLMaterialLibrary1.AddTextureMaterial('mat1','Finishes.jpg');
  413. with GLMaterialLibrary1.Materials.GetLibMaterialByName('mat1') do
  414. begin
  415. Material.Texture.Disabled:=false;
  416. end;
  417. *)
  418. pickjoint := TGLNGDJoint(GLNGDManager1.NewtonJoint.Items[1]);
  419. OnPick := True;
  420. GLUserInterface1.MouseLookActivate;
  421. Game_Load;
  422. end;
  423. procedure TFormNewtonWalkCarry.Game_Load;
  424. var
  425. X, j, dyns: Integer;
  426. Models: string;
  427. PX, PY, PZ: Integer;
  428. RX, RY, RZ: Integer;
  429. DX, DY, DZ: Integer;
  430. Nam, end1, end2: Integer;
  431. b_ti1, b_ti2, b_ti3, ML_col: Integer;
  432. begin
  433. var Path: TFileName := GetCurrentAssetPath();
  434. // Memo1.Lines.Clear;
  435. // memo1.Lines.LoadFromFile('level.txt');
  436. SetLength(maps, Memo1.Lines.Count);
  437. For X := 0 to Memo1.Lines.Count - 1 do
  438. begin
  439. if copy(Memo1.Lines.Strings[X], 0, 8) = '[Model]=' then
  440. begin
  441. Models := Memo1.Lines.Strings[X];
  442. for j := 0 to Length(Models) do
  443. begin
  444. if copy(Models, j, 3) = 'PX_' then
  445. PX := j + 3;
  446. if copy(Models, j, 3) = 'PY_' then
  447. PY := j + 3;
  448. if copy(Models, j, 3) = 'PZ_' then
  449. PZ := j + 3;
  450. if copy(Models, j, 3) = 'RX_' then
  451. RX := j + 3;
  452. if copy(Models, j, 3) = 'RY_' then
  453. RY := j + 3;
  454. if copy(Models, j, 3) = 'RZ_' then
  455. RZ := j + 3;
  456. if copy(Models, j, 3) = 'DX_' then
  457. DX := j + 3;
  458. if copy(Models, j, 3) = 'DY_' then
  459. DY := j + 3;
  460. if copy(Models, j, 3) = 'DZ_' then
  461. DZ := j + 3;
  462. if copy(Models, j, 7) = '[Name]=' then
  463. Nam := j + 7;
  464. if copy(Models, j, 10) = '[Dynamic]=' then
  465. dyns := j + 10;
  466. if copy(Models, j, 1) = ':' then
  467. end1 := j - 1;
  468. if copy(Models, j, 3) = 'DM=' then
  469. b_ti1 := j + 3;
  470. if copy(Models, j, 3) = 'NM=' then
  471. b_ti2 := j + 3;
  472. if copy(Models, j, 3) = 'LM=' then
  473. b_ti3 := j + 3;
  474. if copy(Models, j, 1) = ';' then
  475. end2 := j - 1;
  476. end;
  477. if StrToBool(copy(Models, dyns, b_ti1 - dyns - 4 { end1-dyns+1 } ))
  478. = False then
  479. begin
  480. with maps[X] do
  481. begin
  482. mdl := TGLFreeForm.CreateAsChild(Scene_Objects);
  483. mdl.MaterialLibrary := GLMaterialLibrary1;
  484. mdl.LoadFromFile(copy(Models, Nam, dyns - Nam - 10));
  485. mdl.Position.X := StrToFloat(copy(Models, PX, PY - PX - 3));
  486. mdl.Position.Y := StrToFloat(copy(Models, PY, PZ - PY - 3));
  487. mdl.Position.Z := StrToFloat(copy(Models, PZ, RX - PZ - 3));
  488. mdl.RollAngle := StrToFloat(copy(Models, RX, RY - RX - 3));
  489. mdl.TurnAngle := StrToFloat(copy(Models, RY, RZ - RY - 3));
  490. mdl.PitchAngle := StrToFloat(copy(Models, RZ, DX - RZ - 3));
  491. mdl.Direction.X := StrToFloat(copy(Models, DX, DY - DX - 3));
  492. mdl.Direction.Y := StrToFloat(copy(Models, DY, DZ - DY - 3));
  493. mdl.Direction.Z := StrToFloat(copy(Models, DZ, Nam - DZ - 7));
  494. mdl.BuildOctree();
  495. mdl.Behaviours.GetOrCreate(TGLNGDStatic);
  496. Maps_Count := Maps_Count + 1;
  497. with TGLNGDStatic(mdl.Behaviours.GetByClass(TGLNGDStatic)) do
  498. begin
  499. Manager:=GLNGDManager1;
  500. NGDNewtonCollisions:=nc_Tree;
  501. end;
  502. end;
  503. end
  504. else
  505. begin
  506. with maps[X] do
  507. begin
  508. mdl := TGLFreeForm.CreateAsChild(Scene_Objects);
  509. mdl.LoadFromFile(copy(Models, Nam, dyns - Nam - 10));
  510. mdl.Position.X := StrToFloat(copy(Models, PX, PY - PX - 3));
  511. mdl.Position.Y := StrToFloat(copy(Models, PY, PZ - PY - 3));
  512. mdl.Position.Z := StrToFloat(copy(Models, PZ, RX - PZ - 3));
  513. mdl.RollAngle := StrToFloat(copy(Models, RX, RY - RX - 3));
  514. mdl.TurnAngle := StrToFloat(copy(Models, RY, RZ - RY - 3));
  515. mdl.PitchAngle := StrToFloat(copy(Models, RZ, DX - RZ - 3));
  516. mdl.Direction.X := StrToFloat(copy(Models, DX, DY - DX - 3));
  517. mdl.Direction.Y := StrToFloat(copy(Models, DY, DZ - DY - 3));
  518. mdl.Direction.Z := StrToFloat(copy(Models, DZ, Nam - DZ - 7));
  519. Maps_Count := Maps_Count + 1;
  520. mdl.Behaviours.GetOrCreate(TGLNGDDynamic);
  521. with TGLNGDDynamic(mdl.Behaviours.GetByClass(TGLNGDDynamic)) do
  522. begin
  523. Manager:=GLNGDManager1;
  524. NGDNewtonCollisions:=nc_Mesh;
  525. Density:=1;
  526. //NGDSurfaceItem:=GLNGDManager1.NewtonSurfaceItem.Items[3] as TNGDSurfaceItem;
  527. end;
  528. mdl.Tag := 1;
  529. mdl.OnProgress := GLCube2.OnProgress;
  530. mdl.BuildOctree();
  531. end;
  532. end;
  533. end;
  534. end;
  535. end;
  536. procedure TFormNewtonWalkCarry.Jump_TimerTimer(Sender: TObject);
  537. begin
  538. OnAir := False;
  539. Jump_Timer.Enabled := False;
  540. end;
  541. procedure TFormNewtonWalkCarry.On_DropTimer(Sender: TObject);
  542. begin
  543. if On_Drop.Tag = 1 then
  544. begin
  545. OnDrop := True;
  546. OnPick := False;
  547. On_Drop.Enabled := False;
  548. end
  549. else
  550. begin
  551. OnDrop := False;
  552. OnPick := True;
  553. On_Drop.Enabled := False;
  554. end;
  555. end;
  556. procedure TFormNewtonWalkCarry.Timer_OnVelocityTimer(Sender: TObject);
  557. begin
  558. pickjoint.KinematicControllerPick(point3d,paDetach);
  559. NGDDynamicBehav := nil;
  560. FPickedSceneObject := nil;
  561. Timer_OnVelocity.Enabled := False;
  562. On_Drop.Tag := 0;
  563. On_Drop.Enabled := True;
  564. end;
  565. procedure TFormNewtonWalkCarry.TIPickTimerTimer(Sender: TObject);
  566. var
  567. cp: TPoint;
  568. begin
  569. GetCursorPos(cp);
  570. cp := GLSceneViewer1.ScreenToClient(cp);
  571. currentPick := (GLSceneViewer1.Buffer.GetPickedObject(cp.X, cp.Y)
  572. as TGLCustomSceneObject);
  573. TIPickTimer.Enabled := False;
  574. end;
  575. end.