⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q_shared.pas

📁 雷神之锤2(Quake2)Delphi源码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  Result := BoxOnPlaneSide(emins,emaxs,p);
end;



procedure ClearBounds(var 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; var _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; var 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; var _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; var _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: array of smallint; var _out: array of integer);
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; var _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; var _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; var _out: vec3_t);
begin
  _out[0] := _in[0];
  _out[1] := _in[1];
  _out[2] := _in[2];
end;

procedure VectorCopy (const _in: vec3_t;  var _out: vec3_t);
begin
  _out[0] := _in[0];
  _out[1] := _in[1];
  _out[2] := _in[2];
end;

procedure VectorCopy (const _in: vec3_t; var _out: array of smallint);
begin
  _out[0] := round(_in[0]);
  _out[1] := round(_in[1]);
  _out[2] := round(_in[2]);
end;

procedure VectorCopy (const _in: array of smallint; var _out: array of smallint);
begin
  _out[0] := _in[0];
  _out[1] := _in[1];
  _out[2] := _in[2];
end;

procedure VectorCopy (const _in: array of smallint; var _out: vec3_t);
begin
  _out[0] := _in[0];
  _out[1] := _in[1];
  _out[2] := _in[2];
end;

procedure CrossProduct(const v1,v2: vec3_t; var 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; var _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;
var
  answer: Integer;
begin
  answer := 0;
  val := val shr 1;
  while val<>0 do begin
    inc(answer);
    val := val shr 1;
  end;
  Result := answer;
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;

(*
============
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, Pointer(Cardinal(s2) + 1), Cardinal(s) - Cardinal(s2));
    _out[Cardinal(s) - Cardinal(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
  _BigShort: function(L: SmallInt): SmallInt;
  _LittleShort: function(L: SmallInt): SmallInt;
  _BigLong: function(L: LongInt): LongInt;
  _LittleLong: function(L: LongInt): LongInt;
  _BigFloat: function(L: Single): Single;
  _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
  Result:=_LittleFloat(L);
end;

function ShortSwap(L: SmallInt): SmallInt;
var
  b1, b2: Byte;
begin
  b1:=L and 255;
  b2:=(L shr 8) and 255;
  result:=(b1 shl 8) + b2;
end;

function ShortNoSwap(L: SmallInt): SmallInt;
begin
  result:=L
end;

function LongSwap(L: LongInt): LongInt;
var
  b1, b2, b3, b4: Byte;
begin
  b1:=L and 255;
  b2:=(L shr 8) and 255;
  b3:=(L shr 16) and 255;
  b4:=(L shr 24) and 255;
  result := (LongInt(b1) shl 24) + (LongInt(b2) shl 16) + (LongInt(b3) shl 8) +b4;
end;

function LongNoSwap(L: LongInt): LongInt;
begin
  result:=L
end;

function FloatSwap(f: Single): Single;
Type
  ba = array[0..3] of byte;
var
  dat1, dat2: ^ba;
begin
  dat1:=Pointer(@f);
  dat2:=Pointer(@result);
  dat2[0] := dat1[3];
  dat2[1] := dat1[2];
  dat2[2] := dat1[1];
  dat2[3] := dat1[0];
end;

function FloatNoSwap(f: Single): Single;
begin
  Result:=f;
end;

(*
================
Swap_Init
================
*)
procedure Swap_Init;
var
  swaptest: array[0..1] of byte;
begin
  swaptest[0]:=1;
  swaptest[1]:=0;

  // set the byte swapping variables in a portable manne

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -