LZScene

Форк
0
/
GLVerletClasses.pas 
85 строк · 2.9 Кб
1
//
2
// This unit is part of the GLScene Engine https://github.com/glscene
3
//
4
{
5
   Classes and functions that make integration between verlets and glscene
6
   objects easy.
7

8
	 History :  
9
       23/08/10 - Yar - Added "VectorTypes.pas" unit to uses
10
       13/04/04 - MF - Verlet call now uses TVerletProgressTimes
11
       06/03/04 - MF - Creation
12
    
13
}
14
unit GLVerletClasses;
15

16
interface
17

18
uses
19
  GLVerletTypes, GLVectorGeometry, GLScene, GLObjects, GLVectorTypes;
20

21
type
22
  // TGLVerletNode
23
  //
24
  { Specialized verlet node that can be anchored to a GLScene object. If it's
25
     anchored and has the property "NailedDown" set, it will remain in the same
26
     relative position to the GLScene object.}
27
  TGLVerletNode = class(TVerletNode)
28
  private
29
    FRelativePosition: TAffineVector;
30
    FGLBaseSceneObject: TGLBaseSceneObject;
31
    procedure SetGLBaseSceneObject(const Value: TGLBaseSceneObject);
32
  protected
33
    procedure SetLocation(const Value: TAffineVector);override;
34
  public
35
    procedure Verlet(const vpt : TVerletProgressTimes); override;
36

37
    property GLBaseSceneObject : TGLBaseSceneObject read FGLBaseSceneObject write SetGLBaseSceneObject;
38
    property RelativePosition : TAffineVector read FRelativePosition write FRelativePosition;
39
  end;
40

41
  function CreateVCPlaneFromGLPlane(Plane : TGLPlane; VerletWorld : TGLVerletWorld; Offset : single) : TVCFloor;
42
//-------------------------------------------------------------------------------------------
43
//-------------------------------------------------------------------------------------------
44
implementation
45
//-------------------------------------------------------------------------------------------
46
//-------------------------------------------------------------------------------------------
47

48
function CreateVCPlaneFromGLPlane(Plane : TGLPlane; VerletWorld : TGLVerletWorld; Offset : single) : TVCFloor;
49
begin
50
  result := TVCFloor.Create(VerletWorld);
51
  with result do
52
  begin
53
    Normal := VectorNormalize(Plane.Direction.AsAffineVector);
54

55
    Location := VectorAdd(Plane.Position.AsAffineVector, VectorScale(Normal, Offset));
56
  end;
57
end;
58

59
{ TGLVerletNode }
60

61
procedure TGLVerletNode.SetGLBaseSceneObject(
62
  const Value: TGLBaseSceneObject);
63
begin
64
  FGLBaseSceneObject := Value;
65

66
  if Assigned(GLBaseSceneObject) and NailedDown then
67
    FRelativePosition := AffineVectorMake(GLBaseSceneObject.AbsoluteToLocal(VectorMake(FLocation, 1)));
68
end;
69

70
procedure TGLVerletNode.SetLocation(const Value: TAffineVector);
71
begin
72
  inherited;
73
  if Assigned(GLBaseSceneObject) and NailedDown then
74
    FRelativePosition := GLBaseSceneObject.AbsoluteToLocal(Value);
75
end;
76

77
procedure TGLVerletNode.Verlet(const vpt : TVerletProgressTimes);
78
begin
79
  if Assigned(GLBaseSceneObject) and NailedDown then
80
  begin
81
    FLocation := GLBaseSceneObject.LocalToAbsolute(FRelativePosition);
82
  end else
83
    inherited;
84
end;
85
end.
86

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.