forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimCamera.lua
210 lines (187 loc) · 6.3 KB
/
SimCamera.lua
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
--
-- SimCamera
--
-- SimCamera buffers control requests to push to the user layer at sync time. It provides facilities
-- for waiting on the camera to perform certain actions. At the moment, the facilities that wait can
-- not be used in multiplayer and are considered to finish immediately when running the simulation in
-- a headless mode. Thus the primary use for such features is in the single player campaign. We have
-- a plan to add multiplayer and headless support for these features but it may be some time before
-- this gets implemented.
--
-- Copyright © 2005 Gas Powered Games, Inc. All rights reserved.
---@class SimCameraEvent
---@field Name string
---@field Type string
---@field Exec string
local SyncCameraRequest = import("/lua/SimSyncUtils.lua").SyncCameraRequest
SingleEvent = import("/lua/system/singleevent.lua").SingleEvent
-- Name / Object table for cameras
Cameras = {}
-- The user layer calls this via SimCallback when the camera finishes moving to its target.
function OnCameraFinish(name)
--LOG('Signal')
Cameras[name]:EventSet()
end
---@class SimCamera : SingleEvent
SimCamera = Class(SingleEvent) {
__init = function(self,name)
self.CameraName = name
self.Callback = {
Func = "OnCameraFinish",
Args = name,
}
Cameras[name] = self
end,
ScaleMoveVelocity = function(self,val)
WARN('ScaleMoveVelocity is defunct. Please remove.')
end,
MoveTo = function(self,rectRegion,seconds)
--LOG('Camera:MoveTo ', repr(rectRegion), ' ',seconds)
request = {
Name = self.CameraName,
Type = 'CAMERA_MOVE',
Region = rectRegion,
Time = seconds or 0,
Callback = self.Callback
}
SyncCameraRequest(request)
end,
MoveToMarker = function(self,marker,seconds)
--LOG('Camera:MoveToMarker ', repr(marker.type), ' ',seconds)
request = {
Name = self.CameraName,
Type = 'CAMERA_MOVE',
Marker = marker,
Time = seconds or 0,
Callback = self.Callback
}
SyncCameraRequest(request)
end,
SyncPlayableRect = function(self,rectRegion)
LOG('Camera:SyncPlayableRect ', repr(rectRegion))
request = {
Name = self.CameraName,
Type = 'CAMERA_SYNC_PLAYABLE_RECT',
Region = rectRegion,
}
LOG('Request: ',repr(request))
SyncCameraRequest(request)
end,
SnapToMarker = function(self,marker)
--LOG('Camera:SnapToMarker('..repr(marker.type)..')')
request = {
Name = self.CameraName,
Type = 'CAMERA_SNAP',
Marker = marker,
}
SyncCameraRequest(request)
end,
TrackEntities = function(self, units, zoom, seconds)
--LOG('Camera:TrackEntities')
request = {
Name = self.CameraName,
Type = 'CAMERA_TRACK_ENTITIES',
Ents = {},
Time = seconds or 0,
Zoom = zoom,
Callback = self.Callback
}
for k,v in units do
table.insert( request.Ents, v:GetEntityId() )
end
SyncCameraRequest(request)
end,
NoseCam = function(self, ent, pitchAdjust, zoom, seconds, transition)
--LOG('Camera:NoseCam')
local idNum = false
if ent:GetAIBrain():GetArmyIndex() ~= ArmyBrains[1]:GetArmyIndex() then
local entBlip = ent:GetBlip(1)
if entBlip then
idNum = entBlip:GetEntityId()
end
else
idNum = ent:GetEntityId()
end
if idNum then
request = {
Name = self.CameraName,
Type = 'CAMERA_NOSE_CAM',
Entity = idNum,
PitchAdjust = pitchAdjust,
Time = seconds or 0,
Transition = transition or 0,
Zoom = zoom,
Callback = self.Callback
}
SyncCameraRequest(request)
else
error( '*CAMERA ERROR: Nose Cam not given valid unit or unit does not have a blip', 2 )
end
end,
SetAccMode = function(self,accModeName)
--LOG('Camera:SetAccMode')
request = {
Name = self.CameraName,
Type = 'CAMERA_SET_ACC_MODE',
Data = accModeName,
Callback = self.Callback
}
SyncCameraRequest(request)
end,
SetZoom = function(self,zoom,seconds)
--LOG('Camera:SetZoom')
request = {
Name = self.CameraName,
Type = 'CAMERA_SET_ZOOM',
Zoom = zoom,
Time = seconds or 0,
Callback = self.Callback
}
SyncCameraRequest(request)
end,
SpinAroundUnit = function(self, location, unitHeading, headingRate )
local marker = {
orientation = VECTOR3( unitHeading, .35, 0 ),
position = location,
zoom = FLOAT( 75 ),
}
request = {
Name = self.CameraName,
Type = 'CAMERA_UNIT_SPIN',
Marker = marker,
HeadingRate = headingRate,
Callback = self.Callback
}
SyncCameraRequest(request)
end,
Spin = function(self,headingRate,zoomRate)
request = {
Name = self.CameraName,
Type = 'CAMERA_SPIN',
HeadingRate = headingRate,
ZoomRate = zoomRate,
}
SyncCameraRequest(request)
end,
HoldRotation = function(self)
SyncCameraRequest({ Name = self.CameraName, Exec = 'HoldRotation' })
end,
RevertRotation = function(self)
SyncCameraRequest( { Name = self.CameraName, Exec = 'RevertRotation' } )
end,
UseGameClock = function(self)
SyncCameraRequest( { Name = self.CameraName, Exec = 'UseGameClock' } )
end,
UseSystemClock = function(self)
SyncCameraRequest( { Name = self.CameraName, Exec = 'UseSystemClock' } )
end,
EnableEaseInOut = function(self)
SyncCameraRequest( { Name = self.CameraName, Exec = 'EnableEaseInOut' } )
end,
DisableEaseInOut = function(self)
SyncCameraRequest( { Name = self.CameraName, Exec = 'DisableEaseInOut' } )
end,
Reset = function(self)
SyncCameraRequest( {Name=self.CameraName, Exec='Reset'} )
end,
}