Git Product home page Git Product logo

Comments (6)

 avatar commented on July 16, 2024 1

Following code using DrawModelEx fixes the spinning for me on Windows:

unit frm1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
  ray_header;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private

  public
    FCamera:TCamera;
    FModel:TModel;
    FTexture:TTexture2D;
    FPosition:TVector3;
    FAnimationCount, FAnimationFrameCounter:Integer;
    FAnimations:PModelAnimation;
  end;

var
  Form1: TForm1;

procedure DrawModel(AModel:TModel; APosition:TVector3; AAxis:TVector3; AAngle:Single; AScale:Single; ATint:TColor);

implementation

{$R *.lfm}

procedure DrawModel(AModel:TModel; APosition:TVector3; AAxis:TVector3; AAngle:Single; AScale:Single; ATint:TColor);
var
  Scale, Axis:TVector3;
begin
  Scale:=Vector3Create(AScale,AScale,AScale);
  DrawModelEx(AModel, APosition, AAxis, AAngle, Scale, ATint);
end;

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
  I:Integer;
begin
  InitWindow(1280, 720, 'Animation Test');
  FCamera.Position:=Vector3Create(15.0, 15.0, 15.0);
  FCamera.Target:=Vector3Create(0.0,0.0,0.0);
  FCamera.Up:=Vector3Create(0.0, 1.0, 0.0);
  FCamera.FoVY:=45;
  FCamera.Projection:=CAMERA_PERSPECTIVE;
  FModel:=LoadModel('guy.iqm');
  FTexture:=LoadTexture('guytex.png');
  SetMaterialTexture(@FModel.Materials[0], MATERIAL_MAP_DIFFUSE, FTexture);
  FPosition:=Vector3Create(0,0,0);
  FAnimationCount:=0;
  FAnimations:=LoadModelAnimations('guy.iqm', @FAnimationCount);
  FAnimationFrameCounter:=0;
  WriteLn('animation count: ', FAnimationCount);
  SetCameraMode(FCamera, CAMERA_FREE);
  SetTargetFPS(60);
  while not WindowShouldClose() do
  begin
  UpdateCamera(@FCamera);
  if IsKeyDown(KEY_SPACE)
  then
  begin
    Inc(FAnimationFrameCounter);
    UpdateModelAnimation(FModel, FAnimations[0], FAnimationFrameCounter);
  if FAnimationFrameCounter>=FAnimations[0].FrameCount
  then
    FAnimationFrameCounter:=0;
  end;
  BeginDrawing();
  ClearBackground(RAYWHITE);
    BeginMode3d(FCamera);
      DrawModel(FModel, FPosition, Vector3Create(1.0, 0.0, 0.0), -45, 1, WHITE);
      for I:=0 to FModel.BoneCount - 1 do
      begin
      DrawCube(FAnimations[0].FramePoses[FAnimationFrameCounter][I].Translation, 0.2, 0.2, 0.2, RED);
      end;
      DrawGrid(10,1);
    EndMode3D();
  DrawFPS(10,10);
  EndDrawing();
  end;
  UnloadTexture(FTexture);
  for I:=0 to FAnimationCount - 1 do
  UnloadModelAnimation(FAnimations[I]);
  UnloadModel(FModel);
  CloseWindow();
end;


end.    

from ray4laz.

GuvaCode avatar GuvaCode commented on July 16, 2024

Yes, I know that. But this behavior is only on Windows. In Linux ase everything works fine. As soon as I get a chance I will try to solve it.

from ray4laz.

GuvaCode avatar GuvaCode commented on July 16, 2024

There is probably an error in raylib. You need to compile examples from raylib in Windows and check. For example there was a bug loading voxel models on linux.

from ray4laz.

 avatar commented on July 16, 2024

Ok, thanks for the support. I will be using Ray4Laz extensively and will try to help out wherever I can.

from ray4laz.

GuvaCode avatar GuvaCode commented on July 16, 2024

Thank you.
but why are you using this to create a form?
If you need it to be OOP style, look here

https://github.com/GuvaCode/Ray4Laz-Extras

https://github.com/GuvaCode/Ray4Laz-Extras/blob/master/source/ray_application.pas

from ray4laz.

 avatar commented on July 16, 2024

No problem, thanks for the link. I just had this up where I reformatted it, but was meaning to update it anyway :)

from ray4laz.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.