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

📄 oxnewtonbsp.pas

📁 Newton Game Dynamic 1.52 Delphi下基于GLScene的OpenGL游戏开发控件。功能非常强大和易于使用。 Advanced physics engine for re
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  tmp.Position[1]:= v1.Position[1] + v2.Position[1];
  tmp.Position[2]:= v1.Position[2] + v2.Position[2];
  tmp.TextureCoord[0]:= v1.TextureCoord[0] + v2.TextureCoord[0];
  tmp.TextureCoord[1]:= v1.TextureCoord[1] + v2.TextureCoord[1];
  tmp.LightmapCoord[0]:= v1.LightmapCoord[0] + v2.LightmapCoord[0];
  tmp.LightmapCoord[1]:= v1.LightmapCoord[1] + v2.LightmapCoord[1];
  Normal[0]:= v1.Normal[0] + v2.Normal[0];
  Normal[1]:= v1.Normal[1] + v2.Normal[1];
  Normal[2]:= v1.Normal[2] + v2.Normal[2];
  tmp.Normal:= Normal;
  result:= tmp;
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
procedure SwapTransparent( e1, e2: word ); far;
var
  s: TOXBSPFaceSort;
begin
  s:= TransparentFaces[e1];
  TransparentFaces[e1]:= TransparentFaces[e2];
  TransparentFaces[e2]:= s;
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
procedure SwapAdditive( e1, e2: word ); far;
var
  s: TOXBSPFaceSort;
begin
  s:= AdditiveFaces[e1];
  AdditiveFaces[e1]:= AdditiveFaces[e2];
  AdditiveFaces[e2]:= s;
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
function CompareAdditive( e1, e2: word ): integer; far;
begin
  if AdditiveFaces[e1].distance < AdditiveFaces[e2].distance then
    result := -1
  else if AdditiveFaces[e1].distance > AdditiveFaces[e2].distance then
    result := 1
  else
    result := 0;
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
procedure SwapSolid( e1, e2: word ); far;
var
  s: TOXBSPFaceSort;
begin
  s:= SolidFaces[e1];
  SolidFaces[e1]:= SolidFaces[e2];
  SolidFaces[e2]:= s;
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
function CompareSolid( e1, e2: word ): integer; far;
begin
  if SolidFaces[e1].distance < SolidFaces[e2].distance then
    result:= -1
  else if SolidFaces[e1].distance > SolidFaces[e2].distance then
    result:= 1
  else
    result:= 0;
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
function LookUp( name: string ): integer;
begin
  result:= -1;
  if ( Copy( name, 1, 1 ) >= '0' ) and ( Copy( name, 1, 1 ) <= '9' ) then begin
    result:= StrToInt( name );
    exit;
  end;
  try
    if ValueList.Exists( name ) then
      result:= ValueList[name]
  except
    ShowMessage( 'value ' + name + ' not found in lookup list!' );
    result:= -1;
  end;
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
procedure ChangeGamma( var color: array of byte; factor: single );
var
  scale, r, g, b: single;
begin
  scale:= 1;
  r:= color[0];
  g:= color[1];
  b:= color[2];
  r:= r * factor / 255.0;
  g:= g * factor / 255.0;
  b:= b * factor / 255.0;
  if ( r > 1.0 ) and ( ( 1.0 / r ) < scale ) then scale:= ( 1.0 / r );
  if ( g > 1.0 ) and ( ( 1.0 / g ) < scale ) then scale:= ( 1.0 / g );
  if ( b > 1.0 ) and ( ( 1.0 / b ) < scale ) then scale:= ( 1.0 / b );
  scale:= scale * 255.0;
  r:= r * scale;
  g:= g * scale;
  b:= b * scale;
  color[0]:= Trunc( r );
  color[1]:= Trunc( g );
  color[2]:= Trunc( b );
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
procedure TOXNewtonStaBSP.SetWorldSpawn( l: TStringList );
var
  i, channel, snd, pi: integer;
  v, p, fn: string;
begin
  if l.Count > 0 then begin
    i:= 0;
    while i < l.Count do begin
      v:= l[i];
      p:= l[i + 1];
      if v = 'music' then begin
        pi := Pos( #32, p );
        if pi > 0 then p:= RightStr( p, Length( p ) -pi );
        fn:= FPath + p
      end
      else
      if v = 'message' then
        FManager.AddLog( 'Bsp MESSAGE: ' + p, 1, ':Info Object' );
      inc( i, 2 );
    end;
    i:= Pos( #32, fn );
    if i > 0 then
      fn:= RightStr( fn, Length( fn ) -i ); // music
    snd:= FSoundEngine.LoadSample( fn, true, false );
    channel:= FSoundEngine.NewEmitter( snd, Q3SetVector( 0, 0, 0 ), false, false );
    if (channel>=0) and (snd>=0) then
    FSOUND_PlaySoundEX( channel, FSoundEngine.FSoundLib[ snd ].SamplePtr, nil, false ); // sound can play directly from begin
    // commented sound playing only when the level is load...
  end;
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
procedure TOXNewtonStaBSP.SetSoundEmitters( l: TStringList );
var
  i, flags ,channel, snd: integer;
  pos: TVector3f;
  v, p, fn: string;
  UsePosition, Loop: boolean;
  h, cnt: integer;
begin
  if l.Count > 0 then begin
    i:= 0;
    flags:= 0;
    while i < l.Count do begin
      v:= l[i];
      p:= l[i+1];
      if v = 'origin' then
        Pos:= StrToVector3f( p )
      else
      if v = 'noise' then
        fn:= FPath + p
      else
      if v = 'spawnflags' then
        flags:= StrToInt( p )
      else
      if v = 'targetname' then begin
        FManager.AddLog( 'Bsp skipped target name!', 1, ':Info Object' );
        exit;
      end;
      inc(i, 2)
    end;
    cnt:= Length( fn );
    for h:= 1 to cnt do begin
      if fn[h] = '/' then fn[h]:= '\';
    end;
    FManager.AddLog( Format( 'FX: %s (%f/%f/%f), %d',[fn, pos[0], pos[1], pos[2], Flags] ), 1, ':Info Object' );
    UsePosition:= ( Flags and 4 ) = 0;
    Loop:= ( ( Flags and 1 ) = 1 ) or ( ( Flags and 4 ) = 4 );
    snd:= FSoundEngine.LoadSample( fn, Loop, UsePosition );
    channel:= FSoundEngine.NewEmitter( snd, Pos, UsePosition, false );
    if UsePosition then
      FSOUND_3D_SetAttributes( channel, @pos, nil );
  end;
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
function TOXNewtonStaBSP.GetSurfaceType( brushIndex: integer ): string;
var
  texId: integer;
begin
  result:= '';
  texId:= FBrushes[brushIndex].Texture;
  if ( FTextureInfo[texId].surface and oxSURF_METALSTEPS ) = oxSURF_METALSTEPS then
    result:= 'METAL'
  else
  if ( FTextureInfo[texId].contents and oxCONTENTS_WATER ) = oxCONTENTS_WATER then
    result:= 'WATER'
  else
  if ( FTextureInfo[texId].contents and oxMASK_PLAYERSOLID ) <> 0 then
    result:= 'NORMAL';
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
constructor TOXNewtonStaBSP.Create( AOwner: TComponent );
begin // External data, You can't create multiple TOXNewtonStaBSP in the same scene sorry.
      // I looking to fix this problem because it can come interesting to load multiple little bsp.
  BSPLeaves:= 0;
  renderedLeaves:= 0;
  PVSLeaves:= 0;
  FrustumLeaves:= 0;
  VisibleTriangles:= 0;
  nextLeaf:= 0;
  inherited Create( aOwner );
  FQ3DefaultCollision:= false;
  FQ3IsSplash:= False;
  FOnFree:= False;
  FBSPFileName:= '';
  FQ3LevelName:= '';
  FQ3LevelSplashName:= '';
  FQ3LevelSplashId:= 0;
  FTexturesDeleted:= False;
  FSoundEngine:= nil;
  FManager:= TOXNewtonManager( Scene );
  FFrust:= TQ3Frustum.Create;
  FActived:= False;
  FCanRender:= False;
  FFreeTexture:= False;
  FEntitiesLoaded:= False;
  FSkyboxShader:= -1;
  FNumOfOldTextures:= 0;
  FNumOfOldLightmaps:= 0;
  FNumOfVerts:= 0;
  FNumOfFaces:= 0;
  FNumOfTextures:= 0;
  FNumOfLightmaps:= 0;
  FNumOfNodes:= 0;
  FNumOfLeafs:= 0;
  FNumOfLeafFaces:= 0;
  FNumOfPlanes:= 0;
  FNumOfMeshVerts:= 0;
  FNumOfModels:= 0;
  FNumOfBrushes:= 0;
  FNumOfBrushSides:= 0;
  FNumOfLeafBrushes:= 0;
  FNumOfEffects:= 0;
  FNumOfFogVolumes:= 0;
  FNumOfEntities:= 0;
  FCurPosition:= 0;
  FCurrentName:= '';
  FDov:= 0;
  FDist:= 0;
  FRenderNoTexture:= False;
  FRenderSky:= True;
  FSky:= TQ3Skybox.Create;
  FSky.FBsp:= self;
  FEntityList:= TStringList.Create;
  FVecList:= TAffineVectorList.Create;
  FPlayerDummy:= TGLDummyCube( AddNewChild( TGLDummyCube ) );
  FSoundEngine:= TQ3SoundEngine.Create( FManager, self );
end;
{******************************************************************************}
 // [09/05/07]: TOXNewtonStaBSP last change by Dave Gravel.
{******************************************************************************}
procedure TOXNewtonStaBSP.RenderSky;
var
  shader: TShader;
  i, numOfVerts: integer;
  texId: Cardinal;
begin
  glCullFace( GL_BACK );
  shader:= FShaderManager[FSkyBoxShader];
  if ( shader = nil ) then exit;
  if shader.SkyboxType = 2 then begin
    glActiveTextureARB( GL_TEXTURE1_ARB );
    glDisableClientState( GL_COLOR_ARRAY );
    glClientActiveTextureARB( GL_TEXTURE1_ARB );
    glDisable( GL_TEXTURE_2D );
    glActiveTextureARB( GL_TEXTURE0_ARB );
    glDisableClientState( GL_COLOR_ARRAY );
    glClientActiveTextureARB( GL_TEXTURE0_ARB );
    glDisable( GL_TEXTURE_2D );
    FSky.DrawBox( FManager.CurrentGLCamera.AbsoluteAffinePosition );
    SetDefaults;
    exit;
  end;
  if MultiTexture then begin
    glActiveTextureARB( GL_TEXTURE1_ARB );
    glDisable( GL_TEXTURE_2D );
    glActiveTextureARB( GL_TEXTURE0_ARB );
  end;
  glDisable( GL_TEXTURE_2D );
  try
    FSky.CalcRenderPoints( FManager.CurrentGLCamera.AbsoluteAffinePosition );
    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    glColor3ub( 255, 255, 255 );
    FSky.CopyData( FInputBuffer );
    numOfVerts:= FSky.TriangleCount * 3;
    SetVertexCoords( nil, FSkyBoxShader, numOfVerts );
    glVertexPointer( 3, GL_FLOAT, sizeof( TOXBSPVertex ), @FInputBuffer[0].Position );
    if shader.numOfLayers > 0 then begin
      for i:= 0 to shader.numOfLayers -1 do begin
        SetVertexColors( nil, FSkyBoxShader, i, numOfVerts );
        glColorPointer( 4, GL_UNSIGNED_BYTE, 0, @FColorBuffer[0] );
        glDisableClientState( GL_COLOR_ARRAY );
        SetTextureCoordinates( FSkyBoxShader, i, numOfVerts );
        if multiTexture then
          glClientActiveTextureARB( GL_TEXTURE0_ARB );
        glTexCoordPointer( 2, GL_FLOAT, 0,  @FTexCoordBuffer[0] );
        texId:= shader.Layers[i].TextureId[shader.Layers[i].curText

⌨️ 快捷键说明

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