Sunday, October 3, 2010

BB, part 3, creating a 3d object


uses
  BB.Screen,
  BB.Screen.D3D, BB.Input.Keys, BB.Screen.Types, BB.Math.Vector, BB.Colors,
  BB.Math.Matrix, BB.E3D.Scene,
  BB.E3D.Ents, BB.E3D.Camera, BB.Screen.Surfaces, BB.Types, BB.E3D.Lights,
  BB.E3D.Objects, BB.Screen.Interfaces,
  BB.Factory;

procedure TfrmMain.FormActivate(Sender: TObject);
var
  s: TScene;
  main: TEnt;
  c: TCamera;
  t: ISurface;
  l: TLight;
  f: TFactory;
  gd: IGraphicsDriver;

begin
  f := TFactory.Create(WindowHandle);
  gd := f.SetProvider(gpD3D);
  gd.Initialize(ClientWidth, ClientHeight, 32, [sfClear, sfWait]);
  gd.GetInfo.SetBackgroundColor(TRGB.Blue.ToInt(32));

  s := f.GetScene;

  // Texture
  t := s.NewSurface;
  t.Load('dirt.bmp');
  t.SetFilter(sfLinear);

  // Light
  l := s.NewLight;
  l.Range := 1024;
  l.Position := TVector.Create(0, -100, 0);
  l.Diffuse := TRGB.Orange;

  // 3D
  main := TEnt.Create;
  main.FileName := 'castalia.asc';
  main.LoadFile;
  main.Position := TVector.Create(0, 0, 0);
  main.Parent := s;
  main.RenderMethod := rmTexture;
  main.SmoothShading := True;
  main.SetTexture(t);
  main.Shade := [sSpecular, sDiffuse];
  s.Ents.Add(main);

  // Camera
  c := s.NewCamera;
  c.Position := TVector.Create(0, 0, -150);

  repeat
    main.Rotate(0.1, 0.3, 0.6);

    gd.BeginRender;

    s.BeginScene;
    s.Render;
    gd.GetPrimitives.Rectangle(0, 0, gd.GetInfo.GetCurrentFPS, 16, TRGB.White);
    s.EndScene;

    gd.EndRender;

  until InKey(VK_ESCAPE);

  Close;
end;


This time I've used a factory rather than the driver directly, is just an option, as the library grows, I always add new stuff to make my life easier

No comments:

Post a Comment