Hi,
i am also doing a game engine using pascal + directx.
This is my code for checking if sphere is inside frustum:
Code:
function FexDX_frustumSphereInside(_c : t_Vec;
_r : single;
_f : tFrustum): single;
// _c - sphere's center
// _r - sphere's radius
// Returns 0 if it's not inside or
// the distance to the NEAR plane if it's inside.
var _i : longint;
_d : single;
begin
for _i := 0 to 5 do
begin
_d := _f[_i].a * _c[0] + _f[_i].b * _c[1] + _f[_i].c * _c[2] + _f[_i].d;
if (_d <= -_r) then
begin
Result := 0;
exit;
end;
end;
Result := _d + _r;
end;
Please revise your FRUSTUM_BACK plane extraction, mine its different:
// Extract the NEAR plane
Result[5].a := _clip._14 + _clip._13;
Result[5].b := _clip._24 + _clip._23;
Result[5].c := _clip._34 + _clip._33;
Result[5].d := _clip._44 + _clip._43;
Nice to see someone coding a pascal engine using directx, i dont known why the norm here is using opengl.
I have 5 months on in now and there is a lot things to code yet, :cry:
tp.
Bookmarks