1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Physics constraint entities
//
// $NoKeywords: $
//===========================================================================//
#ifndef PHYSCONSTRAINT_H
#define PHYSCONSTRAINT_H
#ifdef _WIN32
#pragma once
#endif
#include "vphysics/constraints.h"
struct hl_constraint_info_t
{
hl_constraint_info_t()
{
pObjects[0] = pObjects[1] = NULL;
pGroup = NULL;
anchorPosition[0].Init();
anchorPosition[1].Init();
swapped = false;
massScale[0] = massScale[1] = 1.0f;
}
Vector anchorPosition[2];
IPhysicsObject *pObjects[2];
IPhysicsConstraintGroup *pGroup;
float massScale[2];
bool swapped;
};
abstract_class CPhysConstraint : public CLogicalEntity
{
DECLARE_CLASS( CPhysConstraint, CLogicalEntity );
public:
CPhysConstraint();
~CPhysConstraint();
DECLARE_DATADESC();
void Spawn( void );
void Precache( void );
void Activate( void );
void ClearStaticFlag( IPhysicsObject *pObj );
virtual void Deactivate();
void OnBreak( void );
void InputBreak( inputdata_t &inputdata );
void InputOnBreak( inputdata_t &inputdata );
void InputTurnOn( inputdata_t &inputdata );
void InputTurnOff( inputdata_t &inputdata );
int DrawDebugTextOverlays();
void DrawDebugGeometryOverlays();
void GetBreakParams( constraint_breakableparams_t ¶ms, const hl_constraint_info_t &info );
// the notify system calls this on the constrained entities - used to detect & follow teleports
void NotifySystemEvent( CBaseEntity *pNotify, notify_system_event_t eventType, const notify_system_event_params_t ¶ms );
// gets called at setup time on first init and restore
virtual void OnConstraintSetup( hl_constraint_info_t &info );
// return the internal constraint object (used by sound gadgets)
inline IPhysicsConstraint *GetPhysConstraint() { return m_pConstraint; }
string_t GetNameAttach1( void ){ return m_nameAttach1; }
string_t GetNameAttach2( void ){ return m_nameAttach2; }
protected:
void GetConstraintObjects( hl_constraint_info_t &info );
void SetupTeleportationHandling( hl_constraint_info_t &info );
bool ActivateConstraint( void );
virtual IPhysicsConstraint *CreateConstraint( IPhysicsConstraintGroup *pGroup, const hl_constraint_info_t &info ) = 0;
IPhysicsConstraint *m_pConstraint;
// These are "template" values used to construct the hinge
string_t m_nameAttach1;
string_t m_nameAttach2;
string_t m_breakSound;
string_t m_nameSystem;
float m_forceLimit;
float m_torqueLimit;
unsigned int m_teleportTick;
float m_minTeleportDistance;
COutputEvent m_OnBreak;
};
//-----------------------------------------------------------------------------
// Purpose: Fixed breakable constraint
//-----------------------------------------------------------------------------
class CPhysFixed : public CPhysConstraint
{
DECLARE_CLASS( CPhysFixed, CPhysConstraint );
public:
IPhysicsConstraint *CreateConstraint( IPhysicsConstraintGroup *pGroup, const hl_constraint_info_t &info );
// just for debugging - move to the position of the reference entity
void MoveToRefPosition()
{
if ( m_pConstraint )
{
matrix3x4_t xformRef;
m_pConstraint->GetConstraintTransform( &xformRef, NULL );
IPhysicsObject *pObj = m_pConstraint->GetReferenceObject();
if ( pObj && pObj->IsMoveable() )
{
Vector pos, posWorld;
MatrixPosition( xformRef, pos );
pObj->LocalToWorld(&posWorld, pos);
SetAbsOrigin(posWorld);
}
}
}
int DrawDebugTextOverlays()
{
if ( m_debugOverlays & OVERLAY_TEXT_BIT )
{
MoveToRefPosition();
}
return BaseClass::DrawDebugTextOverlays();
}
void DrawDebugGeometryOverlays()
{
if ( m_debugOverlays & (OVERLAY_BBOX_BIT|OVERLAY_PIVOT_BIT|OVERLAY_ABSBOX_BIT) )
{
MoveToRefPosition();
}
BaseClass::DrawDebugGeometryOverlays();
}
};
#endif // PHYSCONSTRAINT_H
|