oxnewtonheightfield.pas
来自「Newton Game Dynamic 1.52 Delphi下基于GLSce」· PAS 代码 · 共 212 行
PAS
212 行
unit oxNewtonHeightField; // No more work about this object in this version.
// I try to make more on next version but it looking to come a hard stuff.
// ...
{******************************************************************************}
// [15-9-2007]: oxNewtonHeightField 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.
================================================================================}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, GLTexture,
Dialogs, GLScene, GLObjects, GLMisc, GLWin32Viewer, GLCadencer,
VectorGeometry, VectorLists, VectorTypes, StdCtrls, GLGeomObjects, GLGraph,
//
oxNewtonImport, oxNewtonUtils, oxNewtonManager, oxNewtondll;
const
MAX_COLLIDING_FACES = 128;
{******************************************************************************}
// [15-9-2007]: oxNewtonHeightField last change by Dave Gravel. //
{******************************************************************************}
type
TOXNewtonHeightField = class( TGLHeightField )
private
FOrionX3D: byte;
FManager: TOXNewtonManager;
FCollision: PNewtonCollision;
FBody: PNewtonBody;
FActived: boolean;
//procedure CalculateMinExtend3d( const p0: TVector3f; const p1: TVector3f; boxP0: TVector3f; boxP1: TVector3f );
public
property Manager: TOXNewtonManager read FManager;
procedure InitNewton; virtual;
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
published
end;
{******************************************************************************}
// [15-9-2007]: oxNewtonHeightField last change by Dave Gravel. //
{******************************************************************************}
procedure MeshCollisionCollideCallback( collideDesc: NewtonUserMeshCollisionCollideDesc );
function UserMeshCollisionRayHitCallback( rayDesc: NewtonUserMeshCollisionRayHitDesc ): float;
implementation
{******************************************************************************}
// [15-9-2007]: oxNewtonHeightField last change by Dave Gravel. //
{******************************************************************************}
procedure MeshCollisionCollideCallback( collideDesc: NewtonUserMeshCollisionCollideDesc );
{var
x: integer;
z: integer;
x0: integer;
x1: integer;
z0: integer;
z1: integer;
index: integer;
faceCount: integer;
vertexIndex: integer;
step: integer;
edgesIndex: array[0..MAX_COLLIDING_FACES-1] of integer;
boxP0: TVector3f;
boxP1: TVector3f;
map: TOXNewtonHeightField;
p0: TVector3f;
p1: TVector3f; }
begin
{ map:= collideDesc.m_userData;
p0:= AffineVectorMake( collideDesc.m_boxP0[0], collideDesc.m_boxP0[1], collideDesc.m_boxP0[2] );
p1:= AffineVectorMake( collideDesc.m_boxP1[0], collideDesc.m_boxP1[1], collideDesc.m_boxP1[2] );
//
// initialize the callback data structure
collideDesc.m_vertexStrideInBytes:= sizeof( TVector3f );
collideDesc.m_userAttribute:= nil;
collideDesc.m_faceIndexCount:= @GLHeightField1.TriangleCount;
collideDesc.m_faceVertexIndex:= @GLHeightField1.TriangleCount;
collideDesc.m_vertex:= @; }
end;
{******************************************************************************}
// [15-9-2007]: oxNewtonHeightField last change by Dave Gravel. //
{******************************************************************************}
function UserMeshCollisionRayHitCallback( rayDesc: NewtonUserMeshCollisionRayHitDesc ): float;
begin
result:= 1.2;
end;
{******************************************************************************}
// [15-9-2007]: oxNewtonHeightField last change by Dave Gravel. //
{******************************************************************************}
constructor TOXNewtonHeightField.create(aOwner: TComponent);
begin
inherited create( aOwner );
FOrionX3D:= 100;
FActived:= False;
end;
{******************************************************************************}
// [15-9-2007]: oxNewtonHeightField last change by Dave Gravel. //
{******************************************************************************}
(*procedure TOXNewtonHeightField.CalculateMinExtend3d( const p0: TVector3f; const p1: TVector3f; boxP0: TVector3f; boxP1: TVector3f );
{var
x0: single;
x1: single;
y0: single;
y1: single;
z0: single;
z1: single;}
begin
{ //XSamplingScale.Min
x0:= XSamplingScale.Min;
y0:= YSamplingScale.Min;
//z0:= min (p0.m_z, p1.m_z) - 1.0e-3f;
//x1:= max (p0.m_x, p1.m_x) + 1.0e-3f;
//y1:= max (p0.m_y, p1.m_y) + 1.0e-3f;
//z1:= max (p0.m_z, p1.m_z) + 1.0e-3f;
//x0:= CELL_SIZE * dFloor (x0 * (1.0f / CELL_SIZE));
//y0:= CELL_SIZE * dFloor (z0 * (1.0f / CELL_SIZE));
//z0:= CELL_SIZE * dFloor (z0 * (1.0f / CELL_SIZE));
//x1:= CELL_SIZE * dFloor (x1 * (1.0f / CELL_SIZE)) + CELL_SIZE;
//y1:= CELL_SIZE * dFloor (y1 * (1.0f / CELL_SIZE)) + CELL_SIZE;
//z1:= CELL_SIZE * dFloor (z1 * (1.0f / CELL_SIZE)) + CELL_SIZE;
//boxP0[0]:= max( x0, m_minBox[0] );
//boxP0[1]:= max( y0, m_minBox[1] );
//boxP0[2]:= max( z0, m_minBox[2] );
//boxP1[0]:= min( x1, m_maxBox[0] );
//boxP1[1]:= min( z1, m_maxBox[1] );
//boxP1[2]:= min( z1, m_maxBox[2] );}
end; *)
{******************************************************************************}
// [15-9-2007]: oxNewtonHeightField last change by Dave Gravel. //
{******************************************************************************}
procedure TOXNewtonHeightField.InitNewton;
var
m_minBox: TVector3f;
m_maxBox: TVector3f;
m_matrix: TMatrix;
boxP0: TVector3f;
boxP1: TVector3f;
begin
FManager:= TOXNewtonManager(Scene);
m_minBox:= AffineVectorMake( 1.0e10, 1.0e10, 1.0e10 );
m_maxBox:= AffineVectorMake( -1.0e10, -1.0e10, -1.0e10 );
FCollision:= NewtonCreateUserMeshCollision( FManager.World, @m_minBox[0], @m_maxBox[0], self, @MeshCollisionCollideCallback, @UserMeshCollisionRayHitCallback, nil );
// create the level rigid body
FBody:= NewtonCreateBody( FManager.World, FCollision );
// save the pointer to the graphic object with the body.
NewtonBodySetUserData( FBody, self );
oxPSetInitTransform( FBody, self );
// release the collision tree (this way the application does not have to do book keeping of Newton objects
NewtonReleaseCollision( FManager.World, FCollision );
// set the global position of this body
m_matrix:= Matrix;
NewtonBodySetMatrix( FBody, @m_matrix[0, 0] );
// get the position of the aabb of this geometry
NewtonCollisionCalculateAABB( FCollision, @m_matrix[0, 0], @boxP0[0], @boxP1[0] );
// set the destructor for this object
//NewtonBodySetDestructorCallback (m_level, destructor);
FActived:= True;
end;
{******************************************************************************}
// [15-9-2007]: oxNewtonHeightField last change by Dave Gravel. //
{******************************************************************************}
destructor TOXNewtonHeightField.destroy;
begin
inherited destroy;
end;
{******************************************************************************}
{$D '[15-9-2007]: TOXNewtonManager v1.55 by Dave Gravel under MPL-1.1 license.'}
{******************************************************************************}
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?