Home » Community » Forums » » The Water Effect Explained
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 The Water Effect Explained
Post Reply 
Yes, I remember my highschool physics, do you really?

"If you remember your highschool physics, you know that...
...where the refraction index is that of water: 2.0."

Actually water has a refraction index of 1.33, no liquids have a value of 2.0! For instance, glass have 1.5, quarts like 1.7 and diamond is worst by a value of 2.6. Anyway, its a great tutorial, i learnt alot from it! Huge thanks!

[edited by - nights on April 27, 2003 9:31:07 AM]

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

This article is really helpful. But if you write the code in C language, i think it'll be more helpful.

 User Rating: 1015    Report this Post to a Moderator | Link

Hi ,
I read ur code ..its great..

If at any time u r going to write the Code in C or C++..let me know..


 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Hi ,
I read ur code ..its great..

If at any time u r going to write the Code in C or C++..let me know..

Even the Rainfall efect is great.



 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by nights
Yes, I remember my highschool physics, do you really?

"If you remember your highschool physics, you know that...
...where the refraction index is that of water: 2.0."

Actually water has a refraction index of 1.33, no liquids have a value of 2.0! For instance, glass have 1.5, quarts like 1.7 and diamond is worst by a value of 2.6. Anyway, its a great tutorial, i learnt alot from it! Huge thanks!

[edited by - nights on April 27, 2003 9:31:07 AM]


Woops... That must've slipped in during a late-night coding session. I probably used 2 as 1.33 wasn't "watery" enough for the simulation. Sorry :$


Roy Willemse.

 User Rating: 1015    Report this Post to a Moderator | Link

For anyone who is interested (or too lazy) here is a link to the article.

 User Rating: 1620   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Does anyone has an idea, how to avoid the wave reflection at the boundings ?

Seems not that simple for me..

 User Rating: 1015    Report this Post to a Moderator | Link

i want to ask to every body in forum. can you help me. i was create the water effect in delphi7 but it's not work i confused because the color broken.
can you help me because it's my homework. thx every body. i give the program in dephi7 was i created.
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtDlgs, ExtCtrls,math;

type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
OpenPictureDialog1: TOpenPictureDialog;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Image3: TImage;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure updatewavemap;
procedure init;
procedure initize;
procedure gambar;
procedure gambar1;
procedure RenderWaveToDIB;
procedure WaveMapDrop(x,y,w,MulFactor: integer);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

const MAXX=300;
MAXY=300;
DAMP = 4;
rIndex = 4.0;
var
Form1: TForm1;
CT,NW:byte;
WaveMap: Array[0..1, 0..MAXX, 0..MAXY] of integer;
dispLut: Array[0..511] of byte;
keluar:boolean;
implementation

{$R *.dfm}

procedure tform1.initize;
var c,d:integer;
begin
for c:=-256 to 255 do begin
d:=c div 4;
dispLut[c+256] := Byte(Trunc(Tan(ArcSin((Sin(ArcTan(d))/rIndex)))*d));
end;
end;

procedure tform1.WaveMapDrop(x,y,w,MulFactor: integer);
var
u,v:integer;
sqrx,sqry,sqrw: integer;
begin
sqrw := sqr(w);
if (x>w) and (x<MAXX-w) and (y>w) and (y<MAXY-w) then begin
for v:=y-w to y+w do begin
sqry := sqr(v-y);
for u:=x-w to x+w do begin
sqrx := sqr(u-x);
if (sqrx+sqry)<=sqrw then begin
WaveMap[CT,u,v] := MulFactor*Trunc(w-sqrt(sqrx+sqry));
end;
end;
end;
end;
end;

procedure Tform1.RenderWaveToDIB;
var
x,y,newcolor,xDiff,yDiff,xDisp,yDisp: Smallint;
begin
for y:=0 to MAXY do begin
for x:=0 to MAXX do begin
xDiff := WaveMap[NW,x+1,y] - WaveMap[NW,x,y];
yDiff := WaveMap[NW,x,y+1] - WaveMap[NW,x,y];
xDisp := dispLut[xDiff+256];
yDisp := dispLut[yDiff+256];

if xDiff<0 then begin
// Current position is higher - Clockwise rotation
if (yDiff<0) then
newcolor := image1.canvas.Pixels[x-xDisp,y-yDisp]
else
newcolor := image1.canvas.Pixels[x-xDisp,y+yDisp]
end else begin
if (yDiff<0) then
newcolor := image1.canvas.Pixels[x+xDisp,y-yDisp]
else
newcolor := image1.canvas.Pixels[x+xDisp,y+yDisp]
end;
image2.canvas.pixels[x,y] := newcolor;
end;
end;
end;

procedure tform1.updatewavemap;
var y,x:integer;
n:integer;
begin
for y:=2 to MAXY-2 do begin
for x:=2 to MAXX-2 do begin
{ n:=( WaveMap[CT,x-1,y] +
WaveMap[CT,x-2,y] +
WaveMap[CT,x+1,y] +
WaveMap[CT,x+2,y] +
WaveMap[CT,x,y-1] +
WaveMap[CT,x,y-2] +
WaveMap[CT,x,y+1] +
WaveMap[CT,x,y+2] +
WaveMap[CT,x-1,y-1] +
WaveMap[CT,x+1,y-1] +
WaveMap[CT,x-1,y+1] +
WaveMap[CT,x+1,y+1]
) div 6 - WaveMap[NW,x,y];}
n := ( WaveMap[CT,x-1,y] +
WaveMap[CT,x+1,y] +
WaveMap[CT,x,y-1] +
WaveMap[CT,x,y+1] ) div 2 -
WaveMap[NW,x,y];
n:= n - (n div damp);
{asm
push bx
mov bx, n
sar bx, DAMP
sub n, bx
pop bx
end; }
WaveMap[NW,x,y] := n; // Store result
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var x,y,i,j:integer;
totr,totg,totb:integer;
tmp:integer;

begin
CT:=0;
NW:=1;

x := 40 + random(MAXX-40);
y := 40 + random(MAXY-40);
WaveMapDrop(x,y,10,25);

UpdateWaveMap;
RenderWaveToDIB;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
CT:=0;
NW:=1;

end;

end.

 User Rating: 1011   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: