📄 q_shared.pas
字号:
case p^.signbits of
0: begin
dist1 := p^.normal[0]*emaxs[0] + p^.normal[1]*emaxs[1] + p^.normal[2]*emaxs[2];
dist2 := p^.normal[0]*emins[0] + p^.normal[1]*emins[1] + p^.normal[2]*emins[2];
end;
1: begin
dist1 := p^.normal[0]*emins[0] + p^.normal[1]*emaxs[1] + p^.normal[2]*emaxs[2];
dist2 := p^.normal[0]*emaxs[0] + p^.normal[1]*emins[1] + p^.normal[2]*emins[2];
end;
2: begin
dist1 := p^.normal[0]*emaxs[0] + p^.normal[1]*emins[1] + p^.normal[2]*emaxs[2];
dist2 := p^.normal[0]*emins[0] + p^.normal[1]*emaxs[1] + p^.normal[2]*emins[2];
end;
3: begin
dist1 := p^.normal[0]*emins[0] + p^.normal[1]*emins[1] + p^.normal[2]*emaxs[2];
dist2 := p^.normal[0]*emaxs[0] + p^.normal[1]*emaxs[1] + p^.normal[2]*emins[2];
end;
4: begin
dist1 := p^.normal[0]*emaxs[0] + p^.normal[1]*emaxs[1] + p^.normal[2]*emins[2];
dist2 := p^.normal[0]*emins[0] + p^.normal[1]*emins[1] + p^.normal[2]*emaxs[2];
end;
5: begin
dist1 := p^.normal[0]*emins[0] + p^.normal[1]*emaxs[1] + p^.normal[2]*emins[2];
dist2 := p^.normal[0]*emaxs[0] + p^.normal[1]*emins[1] + p^.normal[2]*emaxs[2];
end;
6: begin
dist1 := p^.normal[0]*emaxs[0] + p^.normal[1]*emins[1] + p^.normal[2]*emins[2];
dist2 := p^.normal[0]*emins[0] + p^.normal[1]*emaxs[1] + p^.normal[2]*emaxs[2];
end;
7: begin
dist1 := p^.normal[0]*emins[0] + p^.normal[1]*emins[1] + p^.normal[2]*emins[2];
dist2 := p^.normal[0]*emaxs[0] + p^.normal[1]*emaxs[1] + p^.normal[2]*emaxs[2];
end;
else begin
dist1:=0;
dist2:=0; // shut up compiler
assert(false,'BoxOnPlaneSide error: invalid sign bits, (Carl Kenner)');
end;
end;
sides := 0;
if dist1 >= p^.dist then
sides := 1;
if dist2 < p^.dist then
sides := sides or 2;
assert(sides<>0,'BoxOnPlaneSide error: sides must be zero, (Carl Kenner)');
result:= sides;
end;
// CAK - There was an assembly language version here too, but I didn't
// CAK - bother converting it. Sorry.
// MACRO - Calls the original function
function BOX_ON_PLANE_SIDE(var emins, emaxs: vec3_t; p: cplane_p): Integer;
begin
Result:=BoxOnPlaneSide(emins,emaxs,p);
end;
procedure ClearBounds(out mins, maxs: vec3_t);
begin
mins[0] := 99999;
mins[1] := 99999;
mins[2] := 99999;
maxs[0] := -99999;
maxs[1] := -99999;
maxs[2] := -99999;
end;
procedure AddPointToBounds (const v: vec3_t; var mins,maxs: vec3_t);
Var i: Integer; val: vec_t;
begin
for i:=0 to 2 do begin
val := v[i];
if val < mins[i] then
mins[i] := val;
if val > maxs[i] then
maxs[i] := val;
end;
end;
function VectorCompare (const v1,v2: vec3_t): integer;
begin
if (v1[0] <> v2[0]) or (v1[1] <> v2[1]) or (v1[2] <> v2[2]) then
result:=0
else
result:=1;
end;
function VectorNormalize(var v: vec3_t): vec_t;
Var length, ilength: single;
begin
length := v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
length := sqrt (length); // FIXME
if length<>0 then begin
ilength := 1/length;
v[0] := v[0] * ilength;
v[1] := v[1] * ilength;
v[2] := v[2] * ilength;
end;
result := length;
end;
function VectorNormalize2 (const v: vec3_t; out _out: vec3_t): vec_t;
var length, ilength: single;
begin
length := v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
length := sqrt (length); // FIXME
if length<>0 then begin
ilength := 1/length;
_out[0] := v[0]*ilength;
_out[1] := v[1]*ilength;
_out[2] := v[2]*ilength;
end;
result:= length;
end;
procedure VectorMA (const veca: vec3_t; scale: single; const vecb: vec3_t; out vecc: vec3_t);
begin
vecc[0] := veca[0] + scale*vecb[0];
vecc[1] := veca[1] + scale*vecb[1];
vecc[2] := veca[2] + scale*vecb[2];
end;
function _DotProduct(const v1,v2: vec3_t): vec_t;
begin
result:=v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
end;
function DotProduct(const v1,v2: vec3_t): vec_t;
begin
result:=v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
end;
procedure _VectorSubtract (const veca,vecb: vec3_t; out _out: vec3_t);
begin
_out[0] := veca[0]-vecb[0];
_out[1] := veca[1]-vecb[1];
_out[2] := veca[2]-vecb[2];
end;
procedure VectorSubtract (const veca,vecb: vec3_t; out _out: vec3_t);
begin
_out[0] := veca[0]-vecb[0];
_out[1] := veca[1]-vecb[1];
_out[2] := veca[2]-vecb[2];
end;
procedure _VectorAdd (const veca,vecb: vec3_t; out _out: vec3_t);
begin
_out[0] := veca[0]+vecb[0];
_out[1] := veca[1]+vecb[1];
_out[2] := veca[2]+vecb[2];
end;
procedure VectorAdd (const veca,vecb: vec3_t; out _out: vec3_t);
begin
_out[0] := veca[0]+vecb[0];
_out[1] := veca[1]+vecb[1];
_out[2] := veca[2]+vecb[2];
end;
procedure _VectorCopy (const _in: vec3_t; out _out: vec3_t);
begin
_out[0] := _in[0];
_out[1] := _in[1];
_out[2] := _in[2];
end;
procedure VectorCopy (const _in: vec3_t; out _out: vec3_t);
begin
_out[0] := _in[0];
_out[1] := _in[1];
_out[2] := _in[2];
end;
procedure CrossProduct(const v1,v2: vec3_t; out cross: vec3_t);
begin
cross[0] := v1[1]*v2[2] - v1[2]*v2[1];
cross[1] := v1[2]*v2[0] - v1[0]*v2[2];
cross[2] := v1[0]*v2[1] - v1[1]*v2[0];
end;
//double sqrt(double x);
function VectorLength(const v: vec3_t): vec_t;
Var i: Integer; length: single;
begin
length := 0;
for i:=0 to 2 do
length:=length + v[i]*v[i];
length:=sqrt(length); // FIXME
result:=length;
end;
procedure VectorInverse(var v: vec3_t);
begin
v[0] := -v[0];
v[1] := -v[1];
v[2] := -v[2];
end;
procedure VectorScale(const _in: vec3_t; const scale: vec_t; out _out: vec3_t);
begin
_out[0] := _in[0]*scale;
_out[1] := _in[1]*scale;
_out[2] := _in[2]*scale;
end;
function Q_log2(val: Integer): Integer;
begin
result:=0;
val:=val shr 1;
while val<>0 do
inc(result);
end;
//====================================================================================
(*
============
COM_SkipPath
============
*)
function COM_SkipPath(pathname: PChar): PChar;
Var last: PChar;
begin
last:=pathname;
while pathname^<>#0 do begin
if pathname^='/' then begin
last:=pathname;
inc(last);
end;
inc(pathname);
end;
result:=last;
end;
(*
============
COM_StripExtension
============
*)
procedure COM_StripExtension(_in, _out: PChar);
begin
while (_in^<>#0) and (_in^<>'.') do begin
_out^:=_in^;
inc(_in);
inc(_out);
end;
_out^:=#0;
end;
(*
============
COM_FileExtension
============
*)
Var exten: array[0..7] of char;
function COM_FileExtension(_in: PChar): PChar;
Var i: Integer;
begin
while (_in^<>#0) and (_in^<>'.') do
inc(_in);
if (_in^=#0) then begin
Result:='';
exit;
end;
inc(_in);
i:=0;
while (i<7) and (_in^<>#0) do begin
exten[i]:=_in^;
inc(i);
inc(_in);
end;
exten[i]:=#0;
Result:=@exten;
end;
function strncmp(s1, s2: PChar; count: Integer): Integer;
Var z1, z2: String;
begin
z1:=s1;
z2:=s2;
z1:=Copy(z1,1,count);
z2:=Copy(z2,1,count);
if z1>z2 then Result:=-1
else if z1<z2 then Result:=1
else Result:=0;
end;
function strncpy(dest, source: PChar; count: Integer): PChar;
Var len, i: Integer;
begin
Result:=dest;
len:=strlen(source);
if count<=len then begin
move(source^,dest^,count);
end else begin
for i:=1 to len do begin
dest^:=source^;
inc(dest);
inc(source);
dec(count);
end;
for i:=1 to count do begin
dest^:=#0;
inc(dest);
end;
end;
end;
(*
============
COM_FileBase
============
*)
procedure COM_FileBase(_in, _out: PChar);
Var s, s2: PChar;
begin
s:= _in;
inc(s,strlen(_in)-1);
while (s<>_in) and (s^<>'.') do
dec(s);
s2:=s;
while (s2<>_in) and (s2^<>'/') do
dec(s2);
if LongInt(s)-LongInt(s2) < 2 then
_out^:=#0
else begin
dec(s);
strncpy(_out,PChar(LongInt(s2)+1),LongInt(s)-LongInt(s2));
_out[LongInt(s)-LongInt(s2)]:=#0;
end;
end;
(*
============
COM_FilePath
Returns the path up to, but not including the last /
============
*)
procedure COM_FilePath(_in, _out: PChar);
Var s: PChar;
begin
s:=_in;
inc(s,strlen(_in)-1);
while (s<>_in) and (s^<>'/') do
dec(s);
strncpy(_out,_in,LongInt(s)-LongInt(_in));
_out[LongInt(s)-LongInt(_in)]:=#0;
end;
(*
==================
COM_DefaultExtension
==================
*)
procedure COM_DefaultExtension(path, extension: PChar);
Var src: PChar;
begin
//
// if path doesn't have a .EXT, append extension
// (extension should include the .)
//
src := path;
inc(src, strlen(path) - 1);
while (src^ <> '/') and (src <> path) do begin
if (src^ = '.') then
exit; // it has an extension
dec(src);
end;
strcat(path, extension);
end;
(*
============================================================================
BYTE ORDER FUNCTIONS
============================================================================
*)
var bigendien: qboolean; // NOTE SPELLING!!!!
// can't just use function pointers, or dll linkage can
// mess up when qcommon is included in multiple places
var _BigShort: function(L: SmallInt): SmallInt;
var _LittleShort: function(L: SmallInt): SmallInt;
var _BigLong: function(L: LongInt): LongInt;
var _LittleLong: function(L: LongInt): LongInt;
var _BigFloat: function(L: Single): Single;
var _LittleFloat: function(L: Single): Single;
function BigShort(L: SmallInt): SmallInt;
begin
Result:=_BigShort(L);
end;
function LittleShort(L: SmallInt): SmallInt;
begin
Result:=_LittleShort(L);
end;
function BigLong(L: LongInt): LongInt;
begin
Result:=_BigLong(L);
end;
function LittleLong(L: LongInt): LongInt;
begin
Result:=_LittleLong(L);
end;
function BigFloat(L: Single): Single;
begin
Result:=_BigFloat(L);
end;
function LittleFloat(L: Single): Single;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -