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

📄 oxnewtonopenal.pas

📁 Newton Game Dynamic 1.52 Delphi下基于GLScene的OpenGL游戏开发控件。功能非常强大和易于使用。 Advanced physics engine for re
💻 PAS
📖 第 1 页 / 共 2 页
字号:
// This unit is deprecated and need update to come compatible with oxNewton v1.50..
unit oxNewtonOpenAL;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
{===============================================================================

 Version: MPL 1.1

 The contents of this file are subject to the Mozilla Public License Version
 1.1 (the "License"); you may not use this file except in compliance with
 the License. You may obtain a copy of the License at
 http://www.mozilla.org/MPL/


 Software distributed under the License is distributed on an "AS IS" basis,
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 for the specific language governing rights and limitations under the
 License.

 The Original Code is "oxNewton opengl-Dynamics-delphi-component".

 The Initial Developer of the Original Code is
 Dave Gravel, OrionX3D Opengl & Delphi Programming, dave.gravel@cgocable.ca.
                       http://www.Dave.ServeUsers.com
                       http://www.k00m.sexidude.com

 Portions created by Dave Gravel are Copyright (C) 2004 - 2006.
 Dave Gravel. All Rights Reserved.

 Contributor(s): GLScene (http://www.glscene.org) -
 Julio Jerez and Alain Suero (http://www.newtondynamics.com) -
 Sascha Willems (www.delphigl.de)

================================================================================
 oxNewton v1.50 by Dave Gravel.

PS: I request only one thing from the users of my oxNewton Component,
it is to put on your about or your help a comment saying you using the
oxNewton Component with my name Dave Gravel and my
e-mail: dave.gravel@cgocable.ca
Don't modify or remove any comment or information on my file
if you do some modification on my code please contact me.
Read the Newton license too, it is realy important.

================================================================================}
interface
  uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
       //
       al, altypes, alut, EAX, GLScene, GLObjects, VectorGeometry, VectorTypes,
       oxNewtonVehicle4Wheels;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
type
  TOXSimpleOpenAL = class
    private
      FActived: boolean;
      FName: string;
      FSource: TGLBaseSceneObject;
      FListener: TGLBaseSceneObject;
      Fbuffer: TALuint;
      FData: TALuint;
      Fpitch: TALFloat;
      Fgain: TALFloat;
      Flooping: TALInt;
      Fplaying: boolean;
    public
      procedure update;
      procedure LoadFromFile(filename: string);
      procedure Play;
      procedure Pause;
      procedure Stop;
      constructor Create;
      destructor Destroy; override;
    published
      property Name: string read FName write FName;
      property Source: TGLBaseSceneObject read FSource write FSource;
      property Listener: TGLBaseSceneObject read FListener write FListener;
      property pitch: TALFloat read Fpitch write Fpitch;
      property gain: TALFloat read Fgain write Fgain;
      property loop: TALInt read Flooping write Flooping;
      property playing: boolean read Fplaying write Fplaying;
  end;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
type
  TOXVehicleOpenAL = class
    private
      FActived: boolean;
      FName: string;
      FSource: TGLBaseSceneObject;
      FListener: TGLBaseSceneObject;
      Fbuffer: TALuint;
      FData: TALuint;
      Fpitch: TALFloat;
      Fgain: TALFloat;
      Flooping: TALInt;
      Fplaying: boolean;
      FMotor: boolean;
      FIdle: single;
      FRevolution: single;
    public
      procedure update;
      procedure LoadFromFile(filename: string);
      procedure Play;
      procedure Pause;
      procedure Stop;
      constructor Create;
      destructor Destroy; override;
    published
      property Motor: boolean read FMotor write FMotor;
      property Name: string read FName write FName;
      property Source: TGLBaseSceneObject read FSource write FSource;
      property Listener: TGLBaseSceneObject read FListener write FListener;
      property pitch: TALFloat read Fpitch write Fpitch;
      property gain: TALFloat read Fgain write Fgain;
      property loop: TALInt read Flooping write Flooping;
      property playing: boolean read Fplaying write Fplaying;
  end;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
 type
  TOXManagerOpenAL = class(TComponent)
    private
      FActived: boolean;
      FVSList: TList;
      FVSCount: integer;
      FSSList: TList;
      FSSCount: integer;
      FVehicleSound: array of TOXVehicleOpenAL;
      FSimpleSound: array of TOXSimpleOpenAL;
    public
      function VehicleSound(name: string): TOXVehicleOpenAL;
      function SimpleSound(name: string): TOXSimpleOpenAL;
      procedure AddVehicleSound(name: string; soundfile:string; ssource, slistener: TGLBaseSceneObject);
      procedure AddSimpleSound(name: string; soundfile:string; ssource, slistener: TGLBaseSceneObject);
      procedure RemoveSound(name: string);
      constructor Create(aOwner: TComponent); override;
      destructor Destroy; override;
    published

  end;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
implementation
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
constructor TOXSimpleOpenAL.Create;
begin
  FActived:= false;
  Fplaying:= false;
  gain:= 1.0;
  pitch:= 1.0;
  AlGenBuffers(1, @Fbuffer);
  AlGenSources(1, @FData);
  FActived:= True;
end;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
procedure TOXSimpleOpenAL.LoadFromFile(filename: string);
var
  size: TALSizei;
  freq: TALSizei;
  Data: TALVoid;
  format: TALEnum;
  floop: TALInt;
  listenerori: array [0..5] of TALfloat;
  //FnName: PALubyte;
  //Env: TAluInt;
begin
  AlutLoadWavFile(filename, format, data, size, freq, floop);
  AlBufferData(Fbuffer, format, data, size, freq);
  AlutUnloadWav(format, data, size, freq);
  loop:= floop;
  AlSourcei(FData, AL_BUFFER, Fbuffer);
  AlSourcef(FData, AL_PITCH, Fpitch);
  AlSourcef(FData, AL_GAIN, Fgain);
  AlSourcefv(FData, AL_POSITION, @FSource.Position.AsVector);
  //AlSourcefv(FData, AL_VELOCITY, @Fvelocity);
  AlSourcei(FData, AL_LOOPING, Flooping);
  //Listener
  AlListenerfv ( AL_POSITION, @FListener.Position.AsVector);
  //AlListenerfv ( AL_VELOCITY, @Flvelocity);
  with FListener.Up do begin listenerori[0]:= X; listenerori[1]:= Y; listenerori[2]:= Z; end;
  with FListener.Direction do begin listenerori[3]:= X; listenerori[4]:= Y; listenerori[5]:= Z; end;
  AlListenerfv ( AL_ORIENTATION, @listenerori);
  {alIsExtensionPresent('EAX2.0');
  FnName := 'EAXSet';
  eaxSet := alGetProcAddress(FnName);
  FnName := 'EAXGet';
  eaxGet := alGetProcAddress(FnName);
  //set the effect
  Env := 0;
  eaxSet(DSPROPSETID_EAX20_ListenerProperties,
         DSPROPERTY_EAXLISTENER_ENVIRONMENT or
         DSPROPERTY_EAXLISTENER_DEFERRED,
         0, @Env, sizeof(TALuint));
  // Commit settings on source 0
  eaxSet(DSPROPSETID_EAX20_BufferProperties,
         DSPROPERTY_EAXBUFFER_COMMITDEFERREDSETTINGS,
         FData, nil, 0);
  // Commit Listener settings
  eaxSet(DSPROPSETID_EAX20_ListenerProperties,
         DSPROPERTY_EAXLISTENER_COMMITDEFERREDSETTINGS, 0, nil, 0);}  
end;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
procedure TOXSimpleOpenAL.Play;
begin
  AlSourcePlay(FData);
  Update;
  Fplaying:=true;
end;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
procedure TOXSimpleOpenAL.Pause;
begin
  AlSourcePause(FData);
end;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
procedure TOXSimpleOpenAL.Stop;
begin
  Fplaying:=false;
  AlSourceStop(FData);
end;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
procedure TOXSimpleOpenAL.update;
var
  listenerori: array [0..5] of TALfloat;
begin
     { FActived: boolean;
      FName: string;
      FSource: TGLBaseSceneObject;
      FListener: TGLBaseSceneObject;
      Fbuffer: TALuint;
      FData: TALuint;
      Fpitch: TALFloat;
      Fgain: TALFloat;
      Flooping: TALInt;
      Fplaying: boolean; }
  if FActived = false then exit;
  //Source
  AlSourcef(FData, AL_PITCH, Fpitch);
  AlSourcef(FData, AL_GAIN, Fgain);
  AlSourcefv(FData, AL_POSITION, @FSource.Position.AsVector);
  //AlSourcefv(FData, AL_VELOCITY, @Fvelocity);
  AlSourcei(FData, AL_LOOPING, Flooping);
  //Listener
  AlListenerfv ( AL_POSITION, @FListener.Position.AsVector);
  //AlListenerfv ( AL_VELOCITY, @Flvelocity);
  with FListener.Up do begin listenerori[0]:= X; listenerori[1]:= Y; listenerori[2]:= Z; end;
  with FListener.Direction do begin listenerori[3]:= X; listenerori[4]:= Y; listenerori[5]:= Z; end;
  AlListenerfv ( AL_ORIENTATION, @listenerori);
end;
{******************************************************************************}
// [05-25-2007]: TOXManagerOpenAL last change by Dave Gravel.                 //
{******************************************************************************}
destructor TOXSimpleOpenAL.Destroy;

⌨️ 快捷键说明

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