-
Notifications
You must be signed in to change notification settings - Fork 0
/
GravityMarker.es
177 lines (154 loc) · 5.36 KB
/
GravityMarker.es
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
212
%{
#include "StdH.h"
%}
uses "Entities/Marker";
uses "Entities/GravityRouter";
enum GravityType {
0 LT_PARALLEL "Parallel",
1 LT_CENTRAL "Central",
2 LT_CYLINDRICAL "Cylindirical",
3 LT_TORUS "Torus",
};
class CGravityMarker: CMarker {
name "Gravity Marker";
thumbnail "Thumbnails\\GravityMarker.tbn";
features "IsImportant";
properties:
1 enum GravityType m_gtType "Type" 'Y' =LT_PARALLEL,
2 FLOAT m_fStrength "Strength" 'S' = 1,
3 RANGE m_rFallOff "FallOff" 'F' = 50,
4 RANGE m_rHotSpot "HotSpot" 'H' = 50,
5 RANGE m_rTorusR "Torus Radius" 'R' = 100,
10 FLOAT m_fAcc = 0,
11 FLOAT m_fSign = 1,
12 FLOAT m_fStep = 0,
20 ANGLE3D m_aForceDir "Forcefield Direction" 'F' = ANGLE3D(0,0,0),
21 FLOAT m_fForceA "Forcefield Acceleration" = 0.0f,
22 FLOAT m_fForceV "Forcefield Velocity" = 0.0f,
23 FLOAT3D m_vForceDir = FLOAT3D(1,0,0),
components:
1 model MODEL_MARKER "Models\\Editor\\GravityMarker.mdl",
2 texture TEXTURE_MARKER "Models\\Editor\\GravityMarker.tex"
functions:
// find strength at given distance
inline FLOAT StrengthAtDistance(FLOAT fDistance)
{
FLOAT fStrength = (m_rFallOff-fDistance)*m_fStep;
return Clamp(fStrength, 0.0f, m_fAcc);
}
/* Get force type name, return empty string if not used. */
const CTString &GetForceName(INDEX i)
{
return m_strName;
}
/* Get force in given point. */
void GetForce(INDEX i, const FLOAT3D &vPoint,
CForceStrength &fsGravity, CForceStrength &fsField)
{
const FLOATmatrix3D &m = GetRotationMatrix();
switch (m_gtType) {
case LT_PARALLEL: {
fsGravity.fs_vDirection(1) = -m(1,2) * m_fSign;
fsGravity.fs_vDirection(2) = -m(2,2) * m_fSign;
fsGravity.fs_vDirection(3) = -m(3,2) * m_fSign;
FLOAT fDistance = (vPoint-GetPlacement().pl_PositionVector)%fsGravity.fs_vDirection;
fsGravity.fs_fAcceleration = StrengthAtDistance(fDistance);
fsGravity.fs_fVelocity = 70;
} break;
case LT_CENTRAL: {
fsGravity.fs_vDirection = (GetPlacement().pl_PositionVector-vPoint)*m_fSign;
FLOAT fDistance = fsGravity.fs_vDirection.Length();
if (fDistance>0.01f) {
fsGravity.fs_vDirection/=fDistance;
}
fsGravity.fs_fAcceleration = StrengthAtDistance(fDistance);
fsGravity.fs_fVelocity = 70;
} break;
case LT_CYLINDRICAL: {
FLOAT3D vDelta = GetPlacement().pl_PositionVector-vPoint;
FLOAT3D vAxis;
vAxis(1) = m(1,2);
vAxis(2) = m(2,2);
vAxis(3) = m(3,2);
GetNormalComponent(vDelta, vAxis, fsGravity.fs_vDirection);
fsGravity.fs_vDirection*=m_fSign;
FLOAT fDistance = fsGravity.fs_vDirection.Length();
if (fDistance>0.01f) {
fsGravity.fs_vDirection/=fDistance;
}
fsGravity.fs_fAcceleration = StrengthAtDistance(fDistance);
fsGravity.fs_fVelocity = 70;
} break;
case LT_TORUS: {
// get referent point
FLOAT3D vDelta = vPoint-GetPlacement().pl_PositionVector;
FLOAT3D vAxis;
vAxis(1) = m(1,2);
vAxis(2) = m(2,2);
vAxis(3) = m(3,2);
FLOAT3D vR;
GetNormalComponent(vDelta, vAxis, vR);
vR.Normalize();
fsGravity.fs_vDirection = (vDelta-vR*m_rTorusR)*m_fSign;
FLOAT fDistance = fsGravity.fs_vDirection.Length();
if (fDistance>0.01f) {
fsGravity.fs_vDirection/=fDistance;
}
fsGravity.fs_fAcceleration = StrengthAtDistance(fDistance);
fsGravity.fs_fVelocity = 70;
} break;
default:
fsGravity.fs_fAcceleration = m_fAcc;
fsGravity.fs_fVelocity = 70;
fsGravity.fs_vDirection = FLOAT3D(0,-1,0);
}
// calculate forcefield influence
fsField.fs_fAcceleration = m_fForceA;
fsField.fs_fVelocity = m_fForceV;
fsField.fs_vDirection = m_vForceDir;
}
/* Handle an event, return false if the event is not handled. */
BOOL HandleEvent(const CEntityEvent &ee)
{
if( ee.ee_slEvent==EVENTCODE_ETrigger)
{
EChangeGravity eChangeGravity;
eChangeGravity.penNewGravity = this;
m_penTarget->SendEvent( eChangeGravity);
return TRUE;
}
return FALSE;
}
procedures:
Main()
{
InitAsEditorModel();
SetPhysicsFlags(EPF_MODEL_IMMATERIAL);
SetCollisionFlags(ECF_IMMATERIAL);
// set appearance
SetModel(MODEL_MARKER);
SetModelMainTexture(TEXTURE_MARKER);
// set name
if (m_strName=="Marker") {
m_strName = "Gravity Marker";
}
// precalc fast gravity parameters
m_fAcc = Abs(30*m_fStrength),
m_fSign = SgnNZ(m_fStrength),
m_fStep = m_fAcc/(m_rFallOff-m_rHotSpot);
AnglesToDirectionVector(m_aForceDir, m_vForceDir);
return;
}
};