unit MeshTest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, GLScene, GLMesh, GLMisc, GLObjects, GLWin32Viewer, StdCtrls, cGLCoordinateAxes, GLWindowsFont,
GLBitmapFont, GLTexture, GLState, VectorTypes, VectorGeometry, GLContext,
GLPolyhedron, GLGeomObjects, GLGraph;
type
TForm1 =
class(TForm)
GLSceneViewer1: TGLSceneViewer;
GLScene1: TGLScene;
DummyCube1: TGLDummyCube;
Mesh1: TGLMesh;
GLLightSource1: TGLLightSource;
GLCamera1: TGLCamera;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
procedure CreateTestMesh;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CreateTestMesh;
var
cResolution : integer;
x, y : Integer;
xs, ys : single;
invRes : single;
invRes2 : single;
pTopLeft, pTopRight, pBottomRight, pBottomLeft : TAffineVector;
function MakeVect(
const x, y : Single) : TAffineVector;
begin
SetVector(Result, x*invRes, sin((x*x+y*y)*invRes2), y*invRes);
end;
procedure AddTriangle(
const p1, p2, p3 : TAffineVector;
const color : TColorVector);
begin
with Mesh1.Vertices
do begin
AddVertex(p1, NullVector, color);
AddVertex(p2, NullVector, color);
AddVertex(p3, NullVector, color);
end;
end;
begin
// scaling precalcs for our math func
cResolution := 10;
invRes:=10/cResolution;
invRes2:=0.1*Sqr(invRes);
// Triangles
with Mesh1
do begin
Mode:=mmTriangles;
Vertices.Clear;
for y:=-cResolution
to cResolution
do begin
for x:=-cResolution
to cResolution
do begin
pTopLeft := MakeVect(x, y+1);
pTopRight := MakeVect(x+1, y+1);
pBottomRight:= MakeVect(x+1, y);
pBottomLeft := MakeVect(x, y);
// top left triangle
AddTriangle(pBottomLeft, pTopLeft, pTopRight, clrBlue);
// bottom right triangle
AddTriangle(pTopRight, pBottomRight, pBottomLeft, clrRed);
end;
//for x ...
end;
//for y ...
CalcNormals(fwCounterClockWise);
end;
end;
{------------------------------------------------------------------------------}
procedure TForm1.FormCreate(Sender: TObject);
begin
CreateTestMesh;
end;
{------------------------------------------------------------------------------}
procedure TForm1.Button1Click(Sender: TObject);
begin
glLightSource1.Shining :=
not glLightSource1.Shining;
end;
{------------------------------------------------------------------------------}
end.