unit lacModel;
interface
Type
TDrip = Record
Height : Single ;
Speed : Single ;
End ;
TWater = Array[0..0] of TDrip ;
PWater = ^TWater ;
TLac = class
private
private m_width : Integer ; // Largeur du lac
private m_height : Integer ; // Hauteur du lac
private m_taille : Integer ; // Taille du tableau contenant le lac
private m_amortissement : Single ;
private lac1, lac2, lac, newLac : PWater ;
private lac_0_m1, Lac_0_0, Lac_0_p1, Lac_m1_0, Lac_p1_0 : PWater ;
public globalRefringeance : Single ;
public
constructor create(aWidth, aHeight : Integer) ;
destructor done() ;
procedure compute() ;
procedure setPoint(X, Y : Integer ; value : Single ) ;
function getPoint(x, y : Integer) : Single ;
End ;
implementation
// Contructor
constructor TLac.create(aWidth, aHeight : Integer) ;
Var
x : Integer ;
Begin
m_width := aWidth ;
m_height := aHeight ;
m_taille := (m_width+2)*(m_height+2) ;
GetMem(lac1, m_taille*sizeof(TWater)) ;
GetMem(lac2, m_taille*sizeof(TWater)) ;
lac := lac1 ;
newLac := lac2 ;
for x := 0 to m_taille-1 do Begin
lac1^[x].Height := 0 ;
lac1^[x].Speed := 0 ;
lac2^[x].Height := 0 ;
lac2^[x].Speed := 0 ;
End ;
m_Amortissement := 0.99 ;
globalRefringeance := 1 ;
setPoint(m_width div 2, m_height div 2, 250) ;
End ;
//********* Getters and Setters ****************
procedure TLac.setPoint(X, Y : Integer ; value : Single ) ;
var
position : Integer ;
Begin
position := (Y+1)*(m_width+2)+ X+1 ;
Lac[position].Height := value ;
Lac[position].Speed := 0 ;
End ;
function TLac.getPoint(x, y : Integer) : Single ;
var
position : Integer ;
Begin
position := (Y+1)*(m_width+2)+ X+1 ;
result := Lac[position].Height ;
End ;
//*** Compute a step
procedure TLac.compute() ;
Var
i : Integer ;
v : Single ;
Begin
// Initialisation
Lac_0_M1 := Lac;
inc(Lac_0_M1) ;
Lac_0_0 := Lac_0_M1 ;
inc(Lac_0_0, m_width+2) ;
Lac_0_p1 := Lac_0_0 ;
inc(Lac_0_p1, m_width+2) ;
Lac_M1_0 := Lac_0_0 ;
dec(Lac_M1_0, 1) ;
Lac_P1_0 := Lac_0_0 ;
inc(Lac_P1_0) ;
// Update Speeds ;
for i := m_width*m_height-1 downto 0 do Begin
v := Lac_0_0[0].Height / 4 ;
Lac_0_0[0].Speed := Lac_0_0[0].Speed - v*4 ;
Lac_0_M1[0].Speed := Lac_0_M1[0].Speed + v ;
Lac_M1_0[0].Speed := Lac_M1_0[0].Speed + v ;
Lac_P1_0[0].Speed := Lac_P1_0[0].Speed + v ;
Lac_0_P1[0].Speed := Lac_0_P1[0].Speed + v ;
inc(Lac_0_M1) ;
inc(Lac_M1_0) ;
inc(Lac_0_0) ;
inc(Lac_P1_0) ;
inc(Lac_0_P1) ;
End ;
// Update Heights
Lac_0_0 := Lac ;
inc(Lac_0_0, m_width+1) ;
for i := m_width*m_height-1 downto 0 do Begin
Lac_0_0[0].Height := Lac_0_0[0].Height + Lac_0_0[0].Speed ;
inc(Lac_0_0) ;
End ;
End ;
Destructor TLac.done() ;
Begin
dispose(lac1) ;
dispose(lac2) ;
End ;
end.