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

📄 oxnewtonutils.pas

📁 Newton Game Dynamic 1.52 Delphi下基于GLScene的OpenGL游戏开发控件。功能非常强大和易于使用。 Advanced physics engine for re
💻 PAS
📖 第 1 页 / 共 5 页
字号:
unit oxNewtonUtils;
{$I GLScene.inc}
{$I oxNewton2.inc}
{******************************************************************************}
// [15-9-2007]: oxNewtonUtils 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.55 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.

================================================================================}
// On this unit some Matrix code come from the Sascha Willems code mixed with the
// glscene vectorgeometry unit and it is based on the Newton SDK.
interface
{******************************************************************************}
// [15-9-2007]: oxNewtonUtils last change by Dave Gravel.                    //
{******************************************************************************}
uses
     // Windows
     Windows, Messages, SysUtils, Classes, Graphics, Controls, ExtCtrls,
     Dialogs, Math, StdCtrls,
     // GLScene
     GLScene, GLMisc, GLObjects, VectorGeometry, GLVectorFileObjects, VectorLists,
     PersistentClasses, OpenGL1x, GLTexture, GLGeomObjects, VectorTypes, GLContext,
     TGA, JPEG, oxNewtonImport, oxZLibEx, GLColor;
type
{$IFDEF NEWTON_DOUBLE_PRECISION}
  TOXVector3 = TVector3d;
  TOXVector4 = TVector4d;
  TOXMatrix = TMatrix4d;
  var InfoDllMode: string = 'oxNewton and Newton double precision dll enabled.';
  const oxDebugLine = 2;
{$else}
  TOXVector3 = TVector3f;
  TOXVector4 = TVector4f;
  TOXMatrix = TMatrix4f;
  var InfoDllMode: string = 'oxNewton and Newton single precision dll enabled.';
  const oxDebugLine = 1;
{$endif}
type
POXVector3 = ^TOXVector3;
POXVector3Array = array[0..0] of TOXVector3;
const
  WHmgVector: TOXVector4 = ( 0, 0, 0, 1 );
  oxNullV3 : TOXVector3 = ( 0, 0, 0 );
  oxNullV4 : TOXVector4 = ( 0, 0, 0, 0 );
  xX = 0;
  xY = 1;
  xZ = 2;
  xW = 3;
{******************************************************************************}
// [15-9-2007]: Type Proc & Func Utils last change by Dave Gravel.           //
{******************************************************************************}
type
  TOXWorldStep = ( mdNormalStep, mdCadencerStep, mdMultiplyStep, mdCustomStep );
  TOXWorldSolver = ( mdSolverExact, mdSolverAdaptive, mdSolverLinear );
  TOXWorldFriction = ( mdFrictionExact, mdFrictionAdaptive );
  TOXVehicleTraction = ( mdRear, mdFront, mdBoth );
  TOXObjectDynType = ( obDynCube, obDynSphere, obDynCylinder, obDynCCylinder, obDynChamferCylinder, obDynCone, obDynMesh );
  TOXObjectStaType = ( obStaCube, obStaSphere, obStaCylinder, obStaCCylinder, obStaChamferCylinder, obStaCone, obStaMesh );
  TOXMaterialSurfaceMode = ( mdNone, mdDefault, mdHard, mdSoft, mdSlide, mdStatic );
  TOXNewtonTreeCollisionCallback = procedure( const bodyWithTreeCollision : PNewtonBody; const body : PNewtonBody; const vertex : PFloat; vertexstrideInBytes : int; indexCount : int; const indexArray : PInt ) of object;
  TOXJointBallCallBack = procedure( ball: PNewtonJoint ) of object;
  TOXJointHingeCallBack = function( hinge: PNewtonJoint; desc: PNewtonHingeSliderUpdateDesc ): Unsigned_int of object;
  TOXJointSliderCallBack = function( slider: PNewtonJoint; desc: PNewtonHingeSliderUpdateDesc ): Unsigned_int of object;
  TOXJointCorkscrewCallBack = function( corkscrew: PNewtonJoint; desc: PNewtonHingeSliderUpdateDesc ): Unsigned_int of object;
  TOXJointUniversalCallBack = function( universal: PNewtonJoint; desc: PNewtonHingeSliderUpdateDesc ): Unsigned_int of object;
  TOXJointUserBilateralCallBack = function ( userJoint: PNewtonJoint ): unsigned_int of object;
  TOXJointPresetCallBack = function ( userJoint: PNewtonJoint; Mat0, Mat1: TOXMatrix; body0, body1: PNewtonBody ): unsigned_int of object;
  TOXJointCustomCreate = procedure( cBody, pBody: PNewtonBody; cPivot, cPin: TOXVector4 ) of object;
  TOXJointCustomBothCreate = procedure( cBody, pBody: PNewtonBody; cPivot, cPin, pPivot, pPin: TOXVector4 ) of object;
  TOXPhysicsApplyForceAndTorque = procedure( Body: PNewtonBody ) of object;
  TOXOnStepRender = procedure( dtime, ntime: double ) of object;
  TOXOnMultiStepRender = procedure( dtime, ntime: double ) of object;
  TOXOnCustomPhysicsStep = procedure( dtime, ntime: double ) of object;
  TOXOnCustomMass = procedure( Mass: Float; InertiaX, InertiaY, InertiaZ, OriginX, OriginY, OriginZ: Float ) of object;
  TOXOnFacesAttribute = procedure( const TriCount: int; FaceID: int; var Attribute: int ) of object;
  TOXOnContactBegin = function( material: PNewtonMaterial; body0: PNewtonBody; body1: PNewtonBody ): int of object;
  TOXOnContactProcess = function( material: PNewtonMaterial; body0: PNewtonBody; body1: PNewtonBody; contact: PNewtonContact ): int of object;
  TOXOnContactEnd = procedure( material: PNewtonMaterial; body0: PNewtonBody; body1: PNewtonBody ) of object;
////////////////////////////////////////////////////////////////////////////////
// Attention
// Read the readme coming with the version oxNewton 1.48
// Because you can't use oxNewton normaly same as before with vector.
// It is very important to use helper coming from oxNewton...
// Surely more helper in coming on next version it is the first implementation.
// oxNewton double and single helper, important to use this helper now.
//
// Vector4f to TOXVector4 double and single.
function oxV4FToV4D( const fVec: TVector ): TOXVector4;
// TOXVector4 to Vector4f double and single.
function oxV4DToV4F( const dVec: TOXVector4 ): TVector;
// Vector3f to TOXVector3 double and single.
function oxV3FToV3D( const fVec: TVector3f ): TOXVector3;
// TOXVector3 to Vector3f double and single.
function oxV3DToV3F( const dVec: TOXVector3 ): TVector3f;
// Scale Vector double and single.
procedure oxScaleV( var v : TOXVector3; factor : Float ); overload;
procedure oxScaleV( var v : TOXVector3; const factor : TOXVector3 ); overload;
procedure oxScaleV( var v : TOXVector4; factor : Float ); overload;
procedure oxScaleV( var v : TOXVector4; const factor : TOXVector4 ); overload;
// Vector Normalize double and single.
function oxVNormalize( const v : TOXVector3 ) : TOXVector3; overload;
function oxVNormalize( const v : TOXVector4 ) : TOXVector4; overload;
procedure oxNormalizeV( var v : TOXVector3 ); overload;
procedure oxNormalizeV( var v : TOXVector4 ); overload;
function oxVNorm(const x, y : Float) : Float; overload;
function oxVNorm(const v : TOXVector3) : Float; overload;
function oxVNorm(const v : TOXVector4) : Float; overload;
function oxVNorm(var V: array of Float) : Float; overload;
// Vector Rotate around Y double and single.
procedure oxVAroundY( var v: TOXVector3; alpha: Float );
// Vector Transform double and single.
function oxVTransform( const V: TOXVector4; const M: TOXMatrix ): TOXVector4; overload;
function oxVTransform( const V: TOXVector3; const M: TOXMatrix ): TOXVector3; overload;
// Vector Negate double and single.
function oxVNegate(const v : TOXVector3) : TOXVector3;
// Vector Length double and single.
function oxVLength(const x, y : Float) : Float; overload;
function oxVLength(const x, y, z : Float) : Float; overload;
function oxVLength(const v : TOXVector3) : Float; overload;
function oxVLength(const v : TOXVector4) : Float; overload;
function oxVLength(const v : array of Float) : Float; overload;
// Vector CrossProduct double and single.
function oxVCrossProduct( const V1, V2 : TOXVector4 ): TOXVector4; overload;
function oxVCrossProduct( const V1, V2 : TOXVector3 ): TOXVector3; overload;
procedure oxVCrossProduct( const v1, v2 : TOXVector3; var vr : TOXVector3 ); overload;
// Vector DotProduct double and single.
function oxVDotProduct( const V1, V2 : TOXVector4 ) : Float; overload;
function oxVDotProduct( const V1, V2 : TOXVector3 ) : Float; overload;
// Vector Scale double and single.
function oxVScale( const v: TOXVector4; factor : Float ): TOXVector4; overload;
function oxVScale(const v : TOXVector3; factor : Float) : TOXVector3; overload;
// Vector4 Make double and single.
function oxV4Make( const x, y, z: Float; w : Float = 0 ): TOXVector4; overload;
function oxV4Make(const v : TOXVector3; w : Float = 0) : TOXVector4; overload;
// Vector3 Make double and single.
function oxV3Make( const x, y, z : Float): TOXVector3; overload;
function oxV3Make( const v : TOXVector4 ): TOXVector3; overload;
// Vector Subtract double and single.
function oxVSubtract( const V1, V2 : TOXVector4 ): TOXVector4; overload;
function oxVSubtract( const V1, V2 : TOXVector3 ) : TOXVector3; overload;
// Vector Add double and single.
function oxVAdd( const v1, v2 : TOXVector4 ) : TOXVector4; overload;
function oxVAdd( const v1, v2 : TOXVector3 ) : TOXVector3; overload;
// Vector Is Null double and single.
function oxVIsNull( const v : TOXVector4 ) : Boolean; overload;
function oxVIsNull( const v : TOXVector3 ) : Boolean; overload;
// MatrixF to MatrixD double and single.
function oxMFToMD( const fMat: TMatrix ): TOXMatrix;
// MatrixD to MatrixF double and single.
function oxMDToMF( const dMat: TOXMatrix ): TMatrix;
// Set Matrix double and single.
procedure oxSetM( var dest: TOXMatrix; const src : TOXMatrix );
// Translate Matrix double and single.
procedure oxTranslateM( var M : TOXMatrix; const v : TOXVector3 ); overload;
procedure oxTranslateM( var M : TOXMatrix; const v : TOXVector4 ); overload;
// Invert Matrix double and single.
procedure oxInvertM( var M : TOXMatrix );
// Matrix Multiply double and single.
function oxMMultiply( const M1, M2: TOXMatrix ): TOXMatrix;
// Matrix Determinant double and single.
function oxMDeterminant( const M: TOXMatrix ): Float;
// Matrix Normalize double and single.
procedure oxNormalizeM( var M : TOXMatrix );
// Create Rotation Matrix double and single.
function oxCreateRotationM( const anAxis : TOXVector3; angle : Float ) : TOXMatrix; overload;
function oxCreateRotationM( const anAxis : TOXVector4; angle : Float ) : TOXMatrix; overload;
// Adjoint Matrix double and single.
procedure oxAdjointM( var M : TOXMatrix );
// Scale Matrix double and single.
procedure oxScaleM( var M: TOXMatrix; const factor: Float );
// Matrix DetInternal double and single.
function oxMDetInternal( const a1, a2, a3, b1, b2, b3, c1, c2, c3: Float ): Float;
// Matrix Rotate To Vector double and single.
procedure oxMRotateToV( const M: TOXMatrix; var pVect: TOXVector3 );
// Matrix Set Transform double and single.
procedure oxMSetTransform( var M: TOXMatrix; V: TOXVector3 );
// Matrix Rotate Vector double and single.
function oxMRotateV( const M : TOXMatrix; pVect : TOXVector3 ): TOXVector3;
// Matrix Untransform Vector double and single.
function oxMUntransformV( const M: TOXMatrix; V: TOXVector3 ): TOXVector3;
// Matrix Tansform Vector double and single.
function oxMTansformV( const M: TOXMatrix; V: TOXVector3 ): TOXVector3;
// Matrix Set Column Vector double and single.
procedure oxMSetColumn( var M: TOXMatrix; pColumn: Byte; pVect: TOXVector4 );
// Matrix GrammSchmidt double and single.
function oxMGrammSchmidt( const aDir : TOXVector3 ): TOXMatrix;
// Matrix UnRotate Vector double and single.
function oxMUnRotateV( const M : TOXMatrix; pVect : TOXVector3 ): TOXVector3;
// Matrix Set Rotation double and single.
procedure oxMSetRotation( var M : TOXMatrix; V : TOXVector3 );
// Matrix Set Compound double and single.
function oxMSetCompound( obj1: TGLBaseSceneObject; obj2: TGLBaseSceneObject ): TOXMatrix;
//
var
  oxIdentityM: TOXMatrix = ( ( 1, 0, 0, 0 ), ( 0, 1, 0, 0 ), ( 0, 0, 1, 0 ), ( 0, 0, 0, 1 ) );
  oxEmptyHmgM: TOXMatrix = ( ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ), ( 0, 0, 0, 0 ) );
{******************************************************************************}
// [15-9-2007]: TOXNewtonBoneCylinder Utils last change by Dave Gravel.      //
{******************************************************************************}
  type
  TOXNewtonBoneCylinder = class( TGLCylinder )
    public
      procedure BuildList( var rci: TRenderContextInfo ); override;
  end;
  type
  TCompoundCube = class( TGLCube )
    private

    public
      procedure BuildList( var rci: TRenderContextInfo ); override;
  end;
  TCompoundSphere = class( TGLSphere )
    private
      FExtentScale: boolean;
    public
      constructor Create(aOwner: TComponent); override;
      procedure BuildList( var rci: TRenderContextInfo ); override;
      property ExtentScale: boolean read FExtentScale write FExtentScale;
  end;
  TCompoundCapsule = class( TGLCylinder )
    private
      FCap1: TGLSphere;
      FCap2: TGLSphere;
    public
      procedure InitCaps;
      procedure BuildList( var rci: TRenderContextInfo ); override;
  end;
  TCompoundCylinder = class( TGLCylinder )
    private

    public
      procedure BuildList( var rci: TRenderContextInfo ); override;
  end;
  TCompoundCone = class( TGLCone )
    private

    public
      procedure BuildList( var rci: TRenderContextInfo ); override;
  end;
  TCompoundChamferCylinder = class( TGLTorus )
    private

    public
      procedure BuildList( var rci: TRenderContextInfo ); override;
  end;
  TCompoundMesh = class( TGLFreeForm )
    private

    public
      procedure BuildList( var rci: TRenderContextInfo ); override;
  end;
  type
  TOXNewtonBoneSphere = class( TGLSphere )
    public
  end;
  type

⌨️ 快捷键说明

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