📄 oxnewtonmousecontrol.pas
字号:
unit oxNewtonMouseControl;
{******************************************************************************}
// [15-9-2007]: oxNewtonMouseControl 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
{******************************************************************************}
// [15-9-2007]: oxNewtonMouseControl last change by Dave Gravel. //
{******************************************************************************}
uses
// Windows
Forms, Windows, Classes, Messages, SysUtils, Graphics, Controls,
ExtCtrls, Dialogs,
// GLScene
GLScene, GLHUDObjects, GLMisc, GLObjects, VectorGeometry, GLVectorFileObjects,
PersistentClasses, OpenGL1x, GLTexture, GLMesh, MeshUtils, GLState, XCollection,
GLGeomObjects, GLVerletClothify, XOpenGL, GLTerrainRenderer, VectorTypes,
GLContext, GLSilhouette, TGA, GLFileSMD, JPEG, GLCadencer,
GLWin32Viewer, VectorLists,
// Newton
oxNewtonUtils, oxNewtonImport, oxNewtonManager, GLColor;
{******************************************************************************}
// [15-9-2007]: TOXMouseControler last change by Dave Gravel. //
{******************************************************************************}
type
TOXMouseControler = class( TGLUpdateAbleComponent )
private
FOrionX3D: byte;
FOXVisual: boolean;
FActived: boolean;
FViewer: TGLSceneViewer;
FRender: TGLDirectOpenGL;
FManager: TOXNewtonManager;
FColor: TGLColor;
FPParam: Float;
FRotFix: Float;
FPickedParam: Float;
FPickedForce: TOXVector4;
FPointerObject: TGLBaseSceneObject;
FAttachmentPointVec: TOXVector3;
FPickedBody: PNewtonBody;
FMousePickMode: Boolean;
FForce: Float;
FDx, FDy: integer;
FDampForce: Float;
FSaveAutoFreeMode: integer;
FQ: PgluQuadric;
FRadius: Float;
FSlices: integer;
FStacks: integer;
FRayLocalNormal: PFloat;
FChainForceCallBack: NewtonApplyForceAndTorque;
procedure SetViewer( val: TGLSceneViewer );
procedure SetManager( val: TOXNewtonManager );
procedure SetObject( val: TGLBaseSceneObject );
procedure SetColor( val: TGLColor );
procedure BuildList( Sender: TObject; var rci: TRenderContextInfo );
public
procedure InitNewton; virtual;
procedure Notification( AComponent: TComponent; Operation: TOperation ); override;
constructor Create( aOwner: TComponent ); override;
destructor Destroy; override;
procedure MouseMove( X, Y: Integer );
procedure MouseDown( X, Y: Integer );
procedure MouseUp( X, Y: Integer );
published
property OXVisual: boolean read FOXVisual write FOXVisual;
property PickColor: TGLColor read FColor write SetColor;
property Manager: TOXNewtonManager read FManager write SetManager;
property GLSceneViewer: TGLSceneViewer read FViewer write SetViewer;
property PickedParam: Float read FPickedParam write FPickedParam;
property PickForce: Float read FForce write FForce;
property PointerObject: TGLBaseSceneObject read FPointerObject write SetObject;
property PickDampForce: Float read FDampForce write FDampForce;
property PickRotationFix: Float read FRotFix write FRotFix;
property PickVisualRadius: Float read FRadius write FRadius;
property PickVisualSlices: integer read FSlices write FSlices;
property PickVisualStacks: integer read FStacks write FStacks;
end;
{******************************************************************************}
// [15-9-2007]: TOXMouseControler last change by Dave Gravel. //
{******************************************************************************}
{******************************************************************************}
// [15-9-2007]: RayCastPickPrefilter last change by Dave Gravel. //
{******************************************************************************}
function RayCastPickPrefilter( const body: PNewtonBody;
const collision: PNewtonCollision; UserData: Pointer ): integer;
{******************************************************************************}
// [15-9-2007]: PhysicsApplyPickForce last change by Dave Gravel. //
{******************************************************************************}
procedure PhysicsApplyPickForce( const Body: PNewtonBody ); cdecl;
{******************************************************************************}
// [15-9-2007]: RayCastPickingFilter last change by Dave Gravel. //
{******************************************************************************}
function RayCastPickingFilter( const body: PNewtonBody; const normal: PFloat;
collisionID: integer; UserData : Pointer; intersetParam: Float ): Float; cdecl;
{******************************************************************************}
// [15-9-2007]: OXMouseControler last change by Dave Gravel. //
{******************************************************************************}
var
VirtualMouseControler: TOXMouseControler = nil;
implementation
{******************************************************************************}
// [15-9-2007]: RayCastPickPrefilter last change by Dave Gravel. //
{******************************************************************************}
function RayCastPickPrefilter( const body: PNewtonBody; const collision: PNewtonCollision; UserData: Pointer ): integer;
begin
// alway cast the primitive
result:= 1;
end;
{******************************************************************************}
// [15-9-2007]: PhysicsApplyPickForce last change by Dave Gravel. //
{******************************************************************************}
procedure PhysicsApplyPickForce( const Body: PNewtonBody ); cdecl;
var
Mass: Float;
Ixx, Iyy, Izz: Float;
Veloc: TOXVector4;
Omega: TOXVector4;
Force: TOXVector4;
DampForce: TOXVector4;
Point: TOXVector3;
Torque: TOXVector4;
obj: TGLBaseSceneObject;
tMat: TOXMatrix;
begin
obj:= NewtonBodyGetUserData( Body );
NewtonBodyGetVelocity( Body, @Veloc[0] );
NewtonBodyGetOmega( Body, @omega[0] );
NewtonBodyGetVelocity( Body, @veloc[0] );
NewtonBodyGetMassMatrix( Body, @mass, @Ixx, @Iyy, @Izz );
Force:= oxVScale( VirtualMouseControler.FPickedForce,
mass * VirtualMouseControler.FForce );
if (VirtualMouseControler.FRotFix<0) then VirtualMouseControler.FRotFix:= 0;
omega:= oxV4Make( omega[0] / VirtualMouseControler.FRotFix,
omega[1] / VirtualMouseControler.FRotFix,
omega[2] / VirtualMouseControler.FRotFix );
DampForce:= oxVScale( veloc, VirtualMouseControler.FDampForce * mass );
Force:= oxVSubtract( Force, DampForce );
Point:= VirtualMouseControler.FAttachmentPointVec;
tMat:= oxMFToMD( obj.Matrix );
oxMRotateToV( tMat, Point );
Torque:= oxVCrossProduct( oxV4Make( Point ), Force );
NewtonBodyAddForce( Body, @Force[0] );
NewtonBodyAddTorque( Body, @Torque[0] );
NewtonBodySetOmega( Body, @omega[0] );
end;
{******************************************************************************}
// [15-9-2007]: RayCastPickingFilter last change by Dave Gravel. //
{******************************************************************************}
function RayCastPickingFilter( const body: PNewtonBody; const normal: PFloat;
collisionID: integer; UserData : Pointer; intersetParam: Float ): Float; cdecl;
var
mass: Float;
Ixx: Float;
Iyy: Float;
Izz: Float;
begin
NewtonBodyGetMassMatrix( body, @mass, @Ixx, @Iyy, @Izz );
if ( mass > 0 ) then
if ( intersetParam < VirtualMouseControler.FPickedParam ) then begin
VirtualMouseControler.FPickedParam:= intersetParam;
VirtualMouseControler.FPickedBody:= PNewtonBody( body );
VirtualMouseControler.FRayLocalNormal:= normal;
end;
result:= intersetParam;
end;
{******************************************************************************}
// [15-9-2007]: TOXMouseControler last change by Dave Gravel. //
{******************************************************************************}
constructor TOXMouseControler.Create( aOwner: TComponent );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -