-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAdjustableCamera.lua
More file actions
160 lines (136 loc) · 7.82 KB
/
AdjustableCamera.lua
File metadata and controls
160 lines (136 loc) · 7.82 KB
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
AdjustableCamera = {}
if AdjustableCamera.modName == nil then AdjustableCamera.modName = g_currentModName end
AdjustableCamera.offsetStep = 0.02
function AdjustableCamera:onLoad(savegame)
self.spec_adjustableCamera = self["spec_"..AdjustableCamera.modName..".AdjustableCamera"]
end
function AdjustableCamera.prerequisitesPresent(specializations)
return true
end
function AdjustableCamera.registerFunctions(vehicleType)
SpecializationUtil.registerFunction(vehicleType, "adjustCamera", AdjustableCamera.adjustCamera)
end
function AdjustableCamera:adjustCamera(offsetX, offsetY, offsetZ)
-- print("AdjustableCamera.adjustCamera");
if self.isClient then
-- print(offsetX, offsetY, offsetZ)
local spec = self.spec_adjustableCamera
local cam = self.spec_enterable.activeCamera
if cam ~= nil and (cam.hasExtraRotationNode == nil or cam.hasExtraRotationNode == false) then
if g_gameSettings:getValue("isHeadTrackingEnabled") and cam.headTrackingNode ~= nil then
spec.htCameraChanged = true
local htX, htY, htZ = getTranslation(cam.headTrackingNode)
if spec.origHtX == nil then spec.origHtX = htX end
if spec.origHtY == nil then spec.origHtY = htY end
if spec.origHtZ == nil then spec.origHtZ = htZ end
setTranslation(cam.headTrackingNode, htX + offsetX, htY + offsetY, htZ + offsetZ)
else
spec.cameraChanged = true
if spec.origTransX == nil then spec.origTransX = cam.transDirX end
if spec.origTransY == nil then spec.origTransY = cam.transDirY end
if spec.origTransZ == nil then spec.origTransZ = cam.transDirZ end
if spec.origZoom == nil then spec.origZoom = cam.zoom end
if spec.origZoomTarget == nil then spec.origZoomTarget = cam.zoomTarget end
-- Fix for crane cameras
if cam.zoom < 0.01 then
cam.zoom = 1
cam.zoomTarget = 1
end
cam.transDirX = cam.transDirX + offsetX
cam.transDirY = cam.transDirY + offsetY
cam.transDirZ = cam.transDirZ + offsetZ
cam.changedByAdjustableCameraMod = true
end
end
end
end
function AdjustableCamera:actionEventCameraForward(actionName, inputValue, callbackState, isAnalog)
-- print("AdjustableCamera.actionEventCameraForward");
if self.isClient then
self:adjustCamera(0, 0, AdjustableCamera.offsetStep)
end
end
function AdjustableCamera:actionEventCameraBackward(actionName, inputValue, callbackState, isAnalog)
-- print("AdjustableCamera.actionEventCameraBackward");
if self.isClient then
self:adjustCamera(0, 0, -AdjustableCamera.offsetStep)
end
end
function AdjustableCamera:actionEventCameraLeft(actionName, inputValue, callbackState, isAnalog)
-- print("AdjustableCamera.actionEventCameraLeft");
if self.isClient then
self:adjustCamera(AdjustableCamera.offsetStep, 0, 0)
end
end
function AdjustableCamera:actionEventCameraRight(actionName, inputValue, callbackState, isAnalog)
-- print("AdjustableCamera.actionEventCameraRight");
if self.isClient then
self:adjustCamera(-AdjustableCamera.offsetStep, 0, 0)
end
end
function AdjustableCamera:actionEventCameraDown(actionName, inputValue, callbackState, isAnalog)
-- print("AdjustableCamera.actionEventCameraDown");
if self.isClient then
self:adjustCamera(0, -AdjustableCamera.offsetStep, 0)
end
end
function AdjustableCamera:actionEventCameraUp(actionName, inputValue, callbackState, isAnalog)
-- print("AdjustableCamera.actionEventCameraDown");
if self.isClient then
self:adjustCamera(0, AdjustableCamera.offsetStep, 0)
end
end
function AdjustableCamera:actionEventCameraReset()
-- print("AdjustableCamera.actionEventCameraReset");
if self.isClient then
local spec = self.spec_adjustableCamera
local cam = self.spec_enterable.activeCamera
if cam ~= nil then
if g_gameSettings:getValue("isHeadTrackingEnabled") and cam.headTrackingNode ~= nil and spec.htCameraChanged ~=nil then
setTranslation(cam.headTrackingNode, spec.origHtX, spec.origHtY, spec.origHtZ)
elseif spec.cameraChanged ~= nil and cam.changedByAdjustableCameraMod ~= nil then
cam.transDirX = spec.origTransX
cam.transDirY = spec.origTransY
cam.transDirZ = spec.origTransZ
cam.zoom = spec.origZoom
cam.zoomTarget = spec.origZoomTarget
end
end
end
end
function AdjustableCamera:onRegisterActionEvents(isActiveForInput, isActiveForInputIgnoreSelection)
-- print("AdjustableCamera.onRegisterActionEvents");
if self.isClient then
local spec = self.spec_adjustableCamera
self:clearActionEventsTable(spec.actionEvents)
AdjustableCamera.actionEvents = {}
if self:getIsActiveForInput(true) and spec ~= nil then
local _, actionEventId = self:addActionEvent(AdjustableCamera.actionEvents, InputAction.ADJUSTABLE_CAMERA_FORWARD, self, AdjustableCamera.actionEventCameraForward, false, true, false, true, nil)
g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_LOW)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
_, actionEventId = self:addActionEvent(AdjustableCamera.actionEvents, InputAction.ADJUSTABLE_CAMERA_BACKWARD, self, AdjustableCamera.actionEventCameraBackward, false, true, false, true, nil)
g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_LOW)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
_, actionEventId = self:addActionEvent(AdjustableCamera.actionEvents, InputAction.ADJUSTABLE_CAMERA_LEFT, self, AdjustableCamera.actionEventCameraLeft, false, true, false, true, nil)
g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_LOW)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
_, actionEventId = self:addActionEvent(AdjustableCamera.actionEvents, InputAction.ADJUSTABLE_CAMERA_RIGHT, self, AdjustableCamera.actionEventCameraRight, false, true, false, true, nil)
g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_LOW)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
_, actionEventId = self:addActionEvent(AdjustableCamera.actionEvents, InputAction.ADJUSTABLE_CAMERA_RESET, self, AdjustableCamera.actionEventCameraReset, false, true, false, true, nil)
g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_LOW)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
_, actionEventId = self:addActionEvent(AdjustableCamera.actionEvents, InputAction.ADJUSTABLE_CAMERA_DOWN, self, AdjustableCamera.actionEventCameraDown, false, true, false, true, nil)
g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_LOW)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
_, actionEventId = self:addActionEvent(AdjustableCamera.actionEvents, InputAction.ADJUSTABLE_CAMERA_UP, self, AdjustableCamera.actionEventCameraUp, false, true, false, true, nil)
g_inputBinding:setActionEventTextPriority(actionEventId, GS_PRIO_LOW)
g_inputBinding:setActionEventTextVisibility(actionEventId, false)
end
end
end
function AdjustableCamera.registerEventListeners(vehicleType)
-- print("AdjustableCamera.registerEventListeners");
SpecializationUtil.registerEventListener(vehicleType, "onLoad", AdjustableCamera);
SpecializationUtil.registerEventListener(vehicleType, "onRegisterActionEvents", AdjustableCamera);
end