here is my code.
unit uMain;
interface
// Add the TV3D65 Type Library into the uses clause. (TV3D65_TLB).
uses
Windows, Messages, SysUtils, Classes, Forms, Dialogs, TV3D65_TLB, Controls,
StdCtrls,deneform, ExtCtrls,math;
type
TfrmMain = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
// Declare the TV Variables:
TV : TVEngine;
Scene : TVScene;
Input : TVInputEngine;
Lights: TVLightEngine;
Globals : TVGlobals;
Land: TVLandscape;
fizik: TVPhysics;
ikide: TVScreen2DText;
x,y,z: extended;
xx,yy,zz,xxx,yyy,p: integer;
b1,b2,b3,b4: WordBool;
sfont,badi,odam: integer;
pick: TVCollisionResult;
vektor2: tv_3dvector;
yer: TVLandscape;
// atmosfer: TVAtmosphere;
texturefactory: TVTextureFactory;
yerresmi: integer;
vektor,playerpos,bumu: TV_3DVector;
sorfeys: TVRenderSurface;
efek: TVGraphicEffect;
plane: tv_plane;
shader : TVShader;
yazilar : string;
ai : TVAI;
yol: TVPath;
button1,button2,yuruyor : boolean;
matematik: TVMathLibrary;
Procedure AppIdle(sender : TObject; var done : boolean);
end;
var
frmMain: TfrmMain;
Mesh1,mesh2,oda : TVMesh;
aktor1 : TVActor;
git: tv_3dvector;
implementation
{$R *.dfm}
procedure TfrmMain.FormCreate(Sender: TObject);
begin
// Create the TV Interface first:
TV := CoTVEngine.Create;
// Set the debug file/options.
// Do this before the 3D init so it can log any errors found during init.
TV.SetDebugMode(true, true, true, true);
TV.SetDebugFile(ExtractFilePath(Application.ExeName) + 'debugfile.txt');
// After setting the beta-key/license its time to init the engine:
texturefactory := COTVtexturefactory.Create();
// TV.Init3DWindowed(panel1.Handle, true);
TV.Init3DWindowed(frmMain.Handle, true);
// Something good to do is to enable the auto-resize feature:
// Get the default viewport and set autoresize to true for it:
TV.GetViewport.SetAutoResize(true);
// Lets display the FPS:
TV.DisplayFPS(true, -1);
// Set the prefered angle system:
TV.SetAngleSystem(TV_ANGLE_DEGREE);
// Now after we are done initializing the TVEngine component lets continue:
// Create any other components after TV init.
Scene := CoTVScene.Create;
Globals := CoTVGlobals.Create;
// Input has an additional init method to call.
Input := CoTVInputEngine.Create;
// Lets init both keyboard and mouse:
Input.Initialize(true, true);
// Now we have setup the most basic of components.
// Something to think about, if the component has a diffrent ATL init method
// then the CoTV<NAME>.Create, use that one instead.
ikide := CoTVScreen2DText.Create();
// For example:
// Mesh : TVMesh;
Land := COTVLandscape.Create();
mesh2 := Scene.CreateMeshBuilder('MyMesh2');
oda := scene.CreateMeshBuilder('Oda');
oda.LoadTVM('C:\Users\Teknik\Documents\3dsmax\export\oda.tvm',true,true);
oda.SetPosition(0,-500,400);
oda.SetLightingMode(TV_LIGHTING_NORMAL,1,1);
oda.SetScale(10,10,10);
oda.SetCollisionEnable(TRUE,4,TV_TESTTYPE_ACCURATETESTING);
scene.SetBackgroundColor(0.2,0.1,0.3,4);
Mesh1 := Scene.CreateMeshBuilder('MyMesh');
aktor1 := Scene.CreateActor('actor');
aktor1.LoadTVA('C:\Users\Teknik\Documents\3dsmax\export\actor.tva',true,true);
//aktor1.LoadXFile('C:\Users\TVNET Teknik\Documents\3dsmax\export\al5.x',true,true);
aktor1.SetPosition(0,0,500);
aktor1.SetLightingMode(TV_LIGHTING_NORMAL,1,1);
aktor1.SetCollisionEnable(true,2,TV_TESTTYPE_ACCURATETESTING);
mesh1.LoadTVM('C:\Users\Teknik\Documents\3dsmax\export\actor.tvm',true,true);
mesh1.SetPosition(0,200,0);
mesh1.SetLightingMode(TV_LIGHTING_NORMAL,1,1);
mesh1.SetCollisionEnable(true,3,TV_TESTTYPE_ACCURATETESTING);
scene.SetViewFrustum(45,10000);
// mesh1.SetScale(0.1,0.1,0.1);
// mesh1.SetMaterial(0,0);
// mesh1.SetLightingMode(0,0,0);
x:= 0;
y:= 0;
z:= 200;
// mesh1.Render;
// Same goes for RenderSurface, Viewport etc.
tv.SetAntialiasing(true,TV_MULTISAMPLE_4_SAMPLES);
Lights := COTVLightEngine.Create();
lights.CreatePointLight(aktor1.GetPosition,0.1,0.1,0.1,10000,'isik',1);
vektor2.x := 0;
vektor2.y := -1;
vektor2.z := 0;
fizik := COTVPhysics.Create();
fizik.Initialize;
fizik.SetGlobalGravity(vektor2);
badi := fizik.CreateBody(2);
fizik.AddMesh(badi,MESH1,TV_BODY_SPHERE,true);
yerresmi := texturefactory.LoadTexture( 'C:\Users\TVNET Teknik\Documents\tv3d\deneme1\heightmap.jpg','yer resmi',10,10,$FFFFFFFF,true);
// yer := COTVLandscape.Create();
//yer.SetTextureScale(10,10,-1);
//yer.SetScale(5,5,5);
//yer.CreateEmptyTerrain(TV_PRECISION_LOW, 1, 1, 0, 0, 0);
fizik.CreateActorBody(1,aktor1,TV_BODY_SPHERE);
fizik.CreateStaticMeshBody(oda,true,true);
// Lets setup the Loop:
//sorfeys := scene.CreateRenderSurface(256,256,true,1,'sorfeys');
//plane.Dist := -16.2;
//plane.Normal.x := 0;
//plane.Normal.y := 1;
//plane.Normal.z := 0;
//efek := coTVGraphicEffect.Create();
//efek.SetWaterReflection(oda,sorfeys,sorfeys,0,plane);
shader := scene.CreateShader('shader');
shader.CreateFromEffectFile('D:\tv3d\Bloom_HDR\Bloom_HDR\Media\Shaders\blur.fx');
//oda.SetShader(shader);
//Atmosfer := CoTVAtmosphere.Create();
//Atmosfer.SkySphere_Enable(true);
//Atmosfer.SkySphere_SetTexture(TextureFactory.LoadTexture('sky1.dds', 'Sky',1000,1000,$0000FFFF,true));
//Atmosfer.SkySphere_SetRadius(5000);
//Atmosfer.SkySphere_SetRotation(180, 0, 0);
yazilar := '999';
ai := cotvai.Create;
ai.InitNodeSystem();
ai.SetNodeSystemParameters(3000,4);
ai.AddNode(aktor1.GetPosition.x,aktor1.GetPosition.y,aktor1.GetPosition.z,10);
ai.EnableNode(0,true);
ai.SetNodeWeight(0,10);
ai.AddNode(0,0,0,10);
ai.EnableNode(1,true);
ai.SetNodeWeight(1,10);
yol := coTVPath.Create();
matematik := COTVMathLibrary.Create;
Application.OnIdle := AppIdle;
end;
procedure TfrmMain.FormShow(Sender: TObject);
begin
//deneform.Form1.Show();
//deneform.ali := 10;
end;
procedure TfrmMain.AppIdle(sender : TObject; var done : boolean);
var
coll : TV_COLLISIONRESULT;
yoluzunlugu,yolnoktasayisi: integer;
gecici1,gecici2: tv_3dvector;
playerdirection: tv_3dvector;
begin
// Check if the application has focus, if yes thats when we process the loop.
if frmMain.Focused then
begin
// This tells Windows it isnt done, so it will continue to loop.
done := false;
// The actual render loop:
TV.Clear(false);
Application.ProcessMessages;
// sorfeys.StartRender(false);
Scene.RenderAll(true, true);
//atmosfer.SkySphere_Render();
ikide.Action_BeginText(false);
ikide.TextureFont_DrawText(yazilar, 5, 30, $FFFFFFFF, sFont);
ikide.TextureFont_DrawBillboardText('Hello bill board', 5, 5, 40, $FFFFFFFF, sFont, 5, 5);
ikide.Action_EndText;
// sorfeys.EndRender;
TV.RenderToScreen;
// Lets check if the user presses ESC key, if yes we will quit the app.
If Input.IsKeyPressed(TV_KEY_ESCAPE) then Close();
Application.ProcessMessages;
// Process any messages Windows has for the application, do this last:
If Input.IsKeyPressed(TV_KEY_0) then begin
x := 0;
Z := 200;
y := 0;
end;
input.GetMouseState(xx,yy,b1,b2,b3,b4,p);
// input.GetAbsMouseState(xx,yy,b1,b2,b3,b4,p);
input.GetMousePosition(xxx,yyy);
if (not b1) and button1 then button1 := false;
if (b1) and (not button1) then begin
button1 := true;
//yol := nil;
Pick := scene.MousePick(xxx,yyy,TV_OBJECT_MESH,TV_TESTTYPE_ACCURATETESTING);
if pick.IsCollision then begin
git := pick.GetCollisionImpact;
git.y := git.y+2;
playerpos := aktor1.GetPosition;
playerpos.y := playerpos.y;
aktor1.ResetPath(0);
ai.SetNodePosition(0,playerpos.x,playerpos.y,playerpos.z);
ai.SetNodePosition(1,git.x,git.y,git.z);
// showmessage(pick.GetCollisionMesh.GetMeshName +' : ' + inttostr(trunc(git.y)));
yol := ai.FindNodePath(playerpos,git,yolnoktasayisi);
ai.CreateNodeGraph(true);
// aktor1.EnableMotionBlur(true);
if yol <> nil then begin
aktor1.SetPathSpeed(30,true);
aktor1.SetPath(yol,true);
//yol.SetPathType(TV_PATH_SPLINE);
//yol.EnableLooping(true);
yuruyor := true;
end;
// ai.CreateNodeGraph(true);
// yol.GetNodeCount
// yol.SetPathType(TV_PATH_SPLINE);
// yoluzunlugu := yol.GetNodeCount;
yoluzunlugu := ai.GetNodeCount;
// showmessage('uzunluk: '+inttostr(yolnoktasayisi)+':'+inttostr(yoluzunlugu));
end;
end;
// playerdirection := matematik.VNormalize(matematik.VSubtract(git, aktor1.GetPosition));
// PlayerPos := matematik.vAdd(aktor1.GetPosition, matematik.VScale(playerdirection, 3));
// aktor1.SetPosition(playerpos.x,playerpos.y,playerpos.z);
// If Input.IsKeyPressed(TV_KEY_SPACE) then aktor1.SetPath(ai.FindNodePath(aktor1.GetPosition,aktor1.GetPosition,yolnoktasayisi));
gecici1:=aktor1.GetPosition;
gecici2 :=git;
yazilar := inttostr(trunc(sqrt(abs((gecici1.x-gecici2.x))*2+abs((gecici1.y-gecici2.y))*2+abs((gecici1.z-gecici2.z))*2)));
if (strtoint(yazilar)<5) and (yuruyor = true) then begin
aktor1.SetPath(ai.FindNodePath(git,git,yolnoktasayisi),false);
gecici1 := yol.GetNode(yol.GetNodeCount-1);
aktor1.SetPosition(gecici1.x,gecici1.y,gecici1.z);
yuruyor := false;
end;
if (not b2) and button2 then button2 := false;
if (b2) and (not button2) then begin
button2 := true;
Pick := scene.MousePick(xxx,yyy,TV_OBJECT_MESH,TV_TESTTYPE_ACCURATETESTING);
if pick.IsCollision then begin
git := pick.GetCollisionImpact;
ai.EnableNode(ai.AddNode(git.x,git.y,git.z,0),true);
end;
fizik.AddImpulse( badi, Globals.Vector(0, 0.1, 0),true );
end;
{
vektor := mesh1.GetPosition;
If Input.IsKeyPressed(TV_KEY_UP) then vektor.z := mesh1.GetPosition.z+5;
If Input.IsKeyPressed(TV_KEY_DOWN) then vektor.z := mesh1.GetPosition.z-5;
If Input.IsKeyPressed(TV_KEY_LEFT) then vektor.x := mesh1.GetPosition.x-5;
If Input.IsKeyPressed(TV_KEY_RIGHT) then vektor.x := mesh1.GetPosition.x+5;
mesh1.SetPosition(vektor.x,mesh1.GetPosition.y,vektor.z);
// if (vektor.x <> 0) or (vektor.y <> 0) or (vektor.z <> 0) then fizik.SetBodyLinearVelocity(badi,vektor,false);
}
if (Input.IsKeyPressed(TV_KEY_W)) then scene.GetCamera().MoveRelative( tv.TimeElapsed() * 1, 0, 0,true);
if (Input.IsKeyPressed(TV_KEY_S)) then scene.GetCamera().MoveRelative(-tv.TimeElapsed() * 1, 0, 0,true);
if (Input.IsKeyPressed(TV_KEY_A)) then scene.GetCamera().MoveRelative(0, 0, -tv.TimeElapsed() * 1,true);
if (Input.IsKeyPressed(TV_KEY_D)) then scene.GetCamera().MoveRelative(0, 0, tv.TimeElapsed() * 1,true);
scene.GetCamera().SetRotation(scene.GetCamera().GetRotation().x + yy * 0.1, scene.GetCamera().GetRotation().y + xx * 0.1, 0);
fizik.Simulate( tv.AccurateTimeElapsed * 0.04 );
vektor.x := 0;
vektor.y := 0;
vektor.z := 0;
if(b1) then begin
zz:=10
end
else if (b2) then zz := -10
else zz:=0;
// tv.GetCamera.SetRotation(xx,yy,zz);
// scene.SetCamera(mesh1.getposition.x+200,mesh1.getposition.y+100,mesh1.getposition.z,scene.GetCamera.GetRotation.x+(xx),scene.GetCamera.GetRotation.y-(yy),scene.GetCamera.GetRotation.z);
// scene.SetCamera(scene.GetCamera.GetPosition.x,scene.GetCamera.GetPosition.y,scene.GetCamera.GetPosition.z-(zz*tv.AccurateTimeElapsed),xx,yy,scene.GetCamera.GetLookAt.z);
{ If Input.IsKeyPressed(TV_KEY_L) then begin
aktor1.SetAnimationID(2);
aktor1.PlayAnimation(0.1);
end;
}
Application.ProcessMessages;
end;
end;
procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
// Additional Info:
{
Normally you dont have to keep track of the TV component and free it on closing.
Delphi will free the ATL Interface on close and thus automatically all the internal
objects will be free'd. Such as Mesh's, Textures etc.
Though it might be good to know you do have the ability to destroy and nil objects
for re-creation or cleanup during runtime if you want that.
TV := Nil;
Will free all of the internal objects automatically.
There are several other Destroy methods such as:
TV<NAME>.Destroy , DestroyAll exists for some objects aswell if it is a Factory of some sort.
Some other good destroy methods are:
TVScene.DestroyAllMeshs.
TVTextureFactory.DeleteAllTextures.
And others...
}
// aktor1.Destroy;
// scene.DestroyMesh(mesh1);
// Scene.DestroyAllMeshes;
// TV := nil;
end;
end.