Closed ghost closed 2 years ago
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.
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.
Ok, thanks for the support. I will be using Ray4Laz extensively and will try to help out wherever I can.
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.
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
No problem, thanks for the link. I just had this up where I reformatted it, but was meaning to update it anyway :)
When loading an animation and using DrawModelEx the model keeps pivoting around its root position. When I use DrawModel and DrawModelWiresEx the model stays where it should.
Thanks