I was diging through a bunch of source codes sind 2012.
Something goes realy strange here...
In the D3DX10 library there is this function:
D3DXVECTOR3* D3DXVec3TransformCoord(
_Inout_ D3DXVECTOR3 *pOut,
_In_ const D3DXVECTOR3 *pV,
_In_ const D3DXMATRIX *pM
);
According to the documentation
https://docs.microsoft.com/en-us/windows/win32/direct3d9/d3dxvec3transformcoord
the result value is the same as the pOut Value.
So the translated header function in pascal looks like this:
function D3DXVec3TransformCoord(out pOut: TD3DXVECTOR3; const pV: TD3DXVECTOR3; const pM: TD3DXMATRIX): PD3DXVECTOR3; stdcall; external DLL_D3DX10;
Using this function
lookAt2 := D3DXVec3TransformCoord(lookAt, lookAt, rotationMatrix);
result in this assembly code:
# [116] lookAt2:=D3DXVec3TransformCoord(lookAt, lookAt, rotationMatrix);
leal -132(%ebp),%eax
pushl %eax
leal -40(%ebp),%eax
pushl %eax
leal -40(%ebp),%eax
pushl %eax
call _$dll$d3dx10_43$D3DXVec3TransformCoord
movl %eax,-56(%ebp)
.Ll55:
The problem is, that the application is crashing at this function.
The same pascal routine compiled in Delphi, works fine.
Looks like this:
cameraclass.pas.122: lookAt2 := D3DXVec3TransformCoord(lookAt, lookAt, rotationMatrix);
004F6A9A 8D857CFFFFFF lea eax,[ebp-$00000084]
004F6AA0 50 push eax
004F6AA1 8D45C8 lea eax,[ebp-$38]
004F6AA4 50 push eax
004F6AA5 8D45C8 lea eax,[ebp-$38]
004F6AA8 50 push eax
004F6AA9 E8C2D3FFFF call D3DXVec3TransformCoord
004F6AAE 8945F8 mov [ebp-$08],eax
I'm not a assembler guru, but the code looks equal to me.
I found a workaround
// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
{$IFDEF FPC}
pos4D := TD3DXVector4.Create(lookAt.x, lookAt.y, lookAt.z, 1);
d3dxvec4transform(pos4D, pos4D, rotationMatrix);
lookAt.x := pos4D.x;
lookAt.y := pos4D.y;
lookAt.z := pos4D.z;
pos4D := TD3DXVector4.Create(up.x, up.y, up.z, 1);
d3dxvec4transform(pos4D, pos4D, rotationMatrix);
up.x := pos4D.x;
up.y := pos4D.y;
up.z := pos4D.z;
{$ELSE}
D3DXVec3TransformCoord(lookAt, lookAt, rotationMatrix);
D3DXVec3TransformCoord(up, up, rotationMatrix);
{$ENDIF}
But I'm not very happy, with this, cause when comes the next problem...?
So whats the problem?