Recent

Author Topic: lazarus beginer quetions  (Read 10405 times)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: lazarus beginer quetions
« Reply #15 on: December 15, 2017, 09:57:56 pm »
Compared to what? classes? advanced records? It only complicates things.
to each other of course.
Maybe a handful of people here, you, me, Marco, Howardpc, molly, getmem, dev team, etc know how to handle the old object paradigm.
I like object, you know that (KOL) but do not give the secret away to new users.... 8-) O:-) O:-) O:-) :D

IMHO it must be considered a language feature for advanced users. And use at your own risk.
I agree it is far easier to phase out when very few people depend on it.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

bluatigro

  • New Member
  • *
  • Posts: 26
  • everybody is diferent therefore everybody is equal
Re: lazarus beginer quetions
« Reply #16 on: December 16, 2017, 10:45:45 am »
update :
i think i got it now

[ i use notepad for coding now ]

Code: Pascal  [Select][+][-]
  1. unit dbl3d ;
  2. type dbl3d = record
  3.   x , y , z : double ;
  4.   procedure fill( a , b , c : double )
  5. end ;
  6. procedure dbl3d.fill( a , b , c : double )
  7. begin
  8.   x := a ;
  9.   y := b ;
  10.   z := c ;
  11. end ;
  12. operator + ( a , b : dbl3d ) : dbl3d
  13. begin
  14.   Result.x := a.x + b.x ;
  15.   Result.y := a.y + b.y ;
  16.   Result.z := a.z + b.z ;
  17. end ;
  18. operator - ( a , b : dbl3d ) : dbl3d
  19. begin
  20.   Result.x := a.x - b.x ;
  21.   Result.y := a.y - b.y ;
  22.   Result.z := a.z - b.z ;
  23. end ;
  24. operator / ( a : dbl3d , b : double ) : dbl3d
  25. begin
  26.   Result.x := a.x / b ;
  27.   Result.y := a.y / b ;
  28.   Result.z := a.z / b ;
  29. end ;
  30. operator * ( a : dbl3d , b : double ) : dbl3d
  31. begin
  32.   Result.x := a.x * b ;
  33.   Result.y := a.y * b ;
  34.   Result.z := a.z * b ;
  35. end ;
  36. function cross( a , b : dbl3d ) : dbl3d
  37. begin
  38.   Result.x := a.y * b.z - a.z * b.y ;
  39.   Result.y := a.z * b.x - a.x * b.z ;
  40.   Result.z := a.x * b.y - a.y * b.x ;
  41. end ;
  42. function dot( a , b : dbl3d ) : double
  43. begin
  44.   Result := a.x * b.x + a.y * b.y + a.z * b.z ;
  45. end ;
  46. function len( a : dbl3d ) : double
  47. begin
  48.   Result := sqr( dot( a , a ) ) ;
  49. end ;
  50. function normalize( a : dbl3d ) : dbl3d
  51. begin
  52.   Result := a / len( a ) ;
  53. end ;
  54. function getangle( a , b : dbl3d ) : double
  55. var
  56.   d : double
  57. begin
  58.   a := normalize( a ) ;
  59.   b := normalize( b ) ;
  60.   d := dot( a , b ) :
  61.   Result := acos( d ) ;
  62. end ;
  63. function mix( a : dbl3d , f : double , b : dbl3d ) dbl3d
  64. begin
  65.   if f < 0.0 then
  66.     f := 0.0 ;
  67.   if f > 1.0 then
  68.     f := 1.0 ;
  69.   Result := a + b * ( b - a ) * f ;
  70. end ;
  71. function toColor( a : dbl3d ) : TColor
  72. begin
  73.   Result := RGBTOColor( a.x * 255 , a.y * 255 , a.z * 255 ) ;
  74. end ;
  75.  
  76.  

bluatigro

  • New Member
  • *
  • Posts: 26
  • everybody is diferent therefore everybody is equal
Re: lazarus beginer quetions
« Reply #17 on: December 19, 2017, 11:23:24 am »
update :
try at opengl

code from :
http://wiki.freepascal.org/OpenGL_Tutorial#Creating_your_first_LCL_program

error :
fatal  cannot find gettext used by lazutf8 of pacage lazutils

how do activate dbl3d.pas in this ?

Code: Pascal  [Select][+][-]
  1. unit main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, OpenGLContext, gl;
  9.  
  10. type
  11.   { TForm1 }
  12.   TForm1 = class(TForm)
  13.     procedure FormCreate(Sender: TObject);
  14.     procedure GLboxPaint(Sender: TObject);
  15.   private
  16.     { private declarations }
  17.   public
  18.     { public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  var
  28.   GLBox:TOpenGLControl;
  29. { TForm1 }
  30.  
  31. procedure TForm1.GLboxPaint(Sender: TObject);
  32. begin
  33.   glClearColor(0.27, 0.53, 0.71, 1.0); //Set blue background
  34.   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  35.   glLoadIdentity;
  36.   glBegin(GL_TRIANGLES);
  37.     glColor3f(1, 0, 0);
  38.     glVertex3f( 0.0, 1.0, 0.0);
  39.     glColor3f(0, 1, 0);
  40.     glVertex3f(-1.0,-1.0, 0.0);
  41.     glColor3f(0, 0, 1);
  42.     glVertex3f( 1.0,-1.0, 0.0);
  43.   glEnd;
  44.   GLbox.SwapBuffers;
  45. end;
  46.  
  47. procedure TForm1.FormCreate(Sender: TObject);
  48. begin
  49.   GLbox:= TOpenGLControl.Create(Form1);
  50.   GLbox.AutoResizeViewport:= true;
  51.   GLBox.Parent := self;
  52.   GLBox.MultiSampling:= 4;
  53.   GLBox.Align := alClient;
  54.   GLBox.OnPaint := @GLboxPaint; //for "mode delphi" this would be "GLBox.OnPaint := GLboxPaint"
  55.   GLBox.invalidate;
  56. end;
  57.  
  58. end.
  59. [\code]
  60.  

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: lazarus beginer quetions
« Reply #18 on: December 19, 2017, 12:19:37 pm »
Your code works correctly on my test on my Linux computer.

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: lazarus beginer quetions
« Reply #19 on: December 19, 2017, 01:11:07 pm »
I recommend not to use OBJECT.  It is in just for backward comparability.  AFAIK there are some memory management issues with the way it was defined in the language (GetMem/FreMem, new/dispose et al.).

Use CLASS instead, and advanced RECORD only if you don't need constructor and destructor.

Also I really disagree with operator overloading.  It was a mess when I used C++ and it is in Pascal as well.  Use methods instead.

Please:  forget all that bad practices from C++.
« Last Edit: December 19, 2017, 01:12:53 pm by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: lazarus beginer quetions
« Reply #20 on: December 19, 2017, 04:41:04 pm »
New users should start with the current language, not with legacy support.
REAL newbies should use assembler.  ;)

piGrimm

  • Guest
Re: lazarus beginer quetions
« Reply #21 on: December 19, 2017, 05:18:13 pm »
REAL newbies should use assembler.  ;)
no no  no  :D push the logic!
newbies should start with a barrel organ, and let us throw some candy to their dressed monkeys...
Let us also aplaud, when the pieces of music are encoded the right way with bitholes, onto wooden barrels (or cylinders), which are analogous.
be patient! next step is a
texas instruments SR-52
2 centuries after newbies got solid basis
 :D  :D  :D
« Last Edit: December 19, 2017, 05:22:40 pm by piGrimm »

piGrimm

  • Guest
Re: lazarus beginer quetions
« Reply #22 on: December 19, 2017, 05:24:13 pm »
« Last Edit: December 19, 2017, 05:27:34 pm by piGrimm »

 

TinyPortal © 2005-2018