11using Dalamud . Game . Command ;
22using Dalamud . IoC ;
33using Dalamud . Plugin ;
4- using System . IO ;
5- using System . Reflection ;
64using Dalamud . Interface . Windowing ;
75using ZoomTilt . Windows ;
86using Dalamud . Game ;
97using System ;
108using FFXIVClientStructs . FFXIV . Client . UI . Misc ;
11- using System . Diagnostics ;
12- using Dalamud . Logging ;
139using ZoomTilt . Structures ;
1410
1511namespace ZoomTilt {
@@ -26,15 +22,16 @@ public sealed unsafe class Plugin : IDalamudPlugin {
2622 private CameraManager * cameraManager { get ; init ; }
2723
2824 public Plugin (
29- [ RequiredVersion ( "1.0" ) ] DalamudPluginInterface pluginInterface ,
30- [ RequiredVersion ( "1.0" ) ] CommandManager commandManager ,
31- [ RequiredVersion ( "1.0" ) ] Framework framework ,
32- [ RequiredVersion ( "1.0" ) ] SigScanner sigScanner ) {
25+ [ RequiredVersion ( "1.0" ) ] DalamudPluginInterface pluginInterface ,
26+ [ RequiredVersion ( "1.0" ) ] CommandManager commandManager ,
27+ [ RequiredVersion ( "1.0" ) ] Framework framework ,
28+ [ RequiredVersion ( "1.0" ) ] SigScanner sigScanner
29+ ) {
3330 this . pluginInterface = pluginInterface ;
3431 this . commandManager = commandManager ;
3532 this . framework = framework ;
3633 this . configModule = ConfigModule . Instance ( ) ;
37- this . cameraManager = cameraManager = ( CameraManager * ) sigScanner . GetStaticAddressFromSig ( "4C 8D 35 ?? ?? ?? ?? 85 D2" ) ; // g_ControlSystem_CameraManager
34+ this . cameraManager = ( CameraManager * ) sigScanner . GetStaticAddressFromSig ( "4C 8D 35 ?? ?? ?? ?? 85 D2" ) ; // g_ControlSystem_CameraManager
3835
3936 Configuration = pluginInterface . GetPluginConfig ( ) as Configuration ?? new Configuration ( ) ;
4037 Configuration . Initialize ( pluginInterface ) ;
@@ -44,7 +41,6 @@ public Plugin(
4441 // var goatImage = pluginInterface.UiBuilder.LoadImage(imagePath);
4542
4643 WindowSystem . AddWindow ( new MainWindow ( this ) ) ;
47- // WindowSystem.AddWindow(new ConfigWindow(this));
4844
4945 commandManager . AddHandler ( CommandName , new CommandInfo ( OnCommand ) {
5046 HelpMessage = "A useful message to display in /xlhelp"
@@ -64,10 +60,8 @@ public void Dispose() {
6460 framework . Update -= Update ;
6561 }
6662
67- private float desiredTiltOffset ;
68- private float currentTiltOffset ;
6963
70- private static double Lerp ( double delta , double from , double to ) {
64+ public static double Lerp ( double delta , double from , double to ) {
7165 return from + ( ( to - from ) * delta ) ;
7266 }
7367 // private static double EaseInOutSine(double x) {
@@ -76,21 +70,18 @@ private static double Lerp(double delta, double from, double to) {
7670 // private static double EaseOutCubic(double x) {
7771 // return 1 - Math.Pow(1 - x, 3);
7872 // }
79- private static double EaseOutQuad ( double x ) {
80- return 1 - ( ( 1 - x ) * ( 1 - x ) ) ;
81- }
73+ public static double EaseOutQuad ( double x ) => 1 - ( ( 1 - x ) * ( 1 - x ) ) ;
8274
75+ private float desiredTiltOffset ;
76+ private float currentTiltOffset ;
8377 public void Update ( Framework framework ) {
8478 if ( ! Configuration . Enabled ) return ;
8579
86- // var now = (DateTime.Now - Process.GetCurrentProcess().StartTime).TotalMilliseconds;
87- // var tiltOffset = Math.Abs(Math.Sin(now * 0.005f)) * 100;
8880 var currentZoom = cameraManager ->WorldCamera ->CurrentZoom ;
8981 var minZoom = cameraManager ->WorldCamera ->MinZoom ;
9082 var maxZoom = cameraManager ->WorldCamera ->MaxZoom ;
9183 var minTilt = Configuration . MinZoomTilt ;
9284 var maxTilt = Configuration . MaxZoomTilt ;
93- // Calculate the tilt offset based on the current zoom level, raning from the min and max tilt values
9485 var tiltOffset = ( int ) (
9586 (
9687 ( maxTilt - minTilt ) * EaseOutQuad ( ( currentZoom - minZoom ) / ( maxZoom - minZoom ) )
@@ -99,59 +90,59 @@ public void Update(Framework framework) {
9990 ) ;
10091 desiredTiltOffset = tiltOffset ;
10192 currentTiltOffset = ( float ) Lerp (
102- framework . LastUpdate . TimeOfDay . TotalMilliseconds / DateTime . Now . TimeOfDay . TotalMilliseconds * 0.1875f ,
93+ framework . UpdateDelta . TotalMilliseconds / 100f ,
10394 currentTiltOffset , desiredTiltOffset
10495 ) ;
10596 configModule ->SetOption ( ConfigOption . TiltOffset , ( int ) Math . Round ( currentTiltOffset ) ) ;
10697 }
10798
108- // This didn't work
109-
110- // private readonly float minLookAtHeightOffset = -0.342871f ;
111- // private readonly float maxLookAtHeightOffset = -0.889871f;
112- // 3rd Person Camera Angle: 0
113- // Look at Height Offset: -0.342871
114-
115- // 3rd Person Camera Angle: 100
116- // Look at Height Offset: -0.891649
117- // -0.889871 is more accurate?
118- // public void Update(Framework framework ) {
119- // if (!Configuration.Enabled ) {
120- // if ( desiredLookAtHeightOffset ! = minLookAtHeightOffset) {
121- // desiredLookAtHeightOffset = minLookAtHeightOffset ;
122- // cameraManager->WorldCamera->LookAtHeightOffset = desiredLookAtHeightOffset;
123- // }
124- // return;
125- // }
126-
127- // var currentZoom = cameraManager->WorldCamera->CurrentZoom ;
128- // var minZoom = cameraManager->WorldCamera->MinZoom ;
129- // var maxZoom = cameraManager->WorldCamera->MaxZoom ;
130- // var minTilt = Configuration.MinZoomTilt ;
131- // var maxTilt = Configuration.MaxZoomTilt ;
132- // var currentTiltOffset = configModule->GetIntValue(ConfigOption.TiltOffset);
133- // var tiltOffset = (int) (
134- // (
135- // (currentZoom - minZoom) * (maxTilt - minTilt) / (maxZoom - minZoom )
136- // )
137- // + minTilt
138- // );
139- // var lookAtHeightOffset = (
140- // minLookAtHeightOffset
141- // + (maxLookAtHeightOffset - minLookAtHeightOffset )
142- // * (Math.Clamp(currentTiltOffset - 50, -50, 50) / 50f)
143- // * (float)tiltOffset / (float)maxTilt
144- // ) ;
145- // desiredLookAtHeightOffset = lookAtHeightOffset ;
146- // currentLookAtHeightOffset = (float)Lerp((DateTime.Now - framework.LastUpdate).TotalMilliseconds, currentLookAtHeightOffset, desiredLookAtHeightOffset );
147- // PluginLog.Log($"currentTiltOffset : {currentTiltOffset }");
148- // PluginLog.Log($"tiltOffset : {tiltOffset }");
149- // PluginLog.Log($"maxTilt : {maxTilt }");
150- // PluginLog.Log($"lookAtHeightOffset: {lookAtHeightOffset }");
151- // // PluginLog.Log($"ZoomTilt: tiltOffset: {tiltOffset}, currentLookAtHeightOffset: {currentLookAtHeightOffset}, desiredLookAtHeightOffset: {desiredLookAtHeightOffset}") ;
152- // cameraManager->WorldCamera->LookAtHeightOffset = currentLookAtHeightOffset ;
153- // PluginLog.Log($"camera: {cameraManager->WorldCamera->LookAtHeightOffset}");
154- // }
99+ /* This didn't work
100+ private readonly float minLookAtHeightOffset = -0.342871f;
101+ private readonly float maxLookAtHeightOffset = -0.889871f ;
102+ 3rd Person Camera Angle: 0
103+ Look at Height Offset: -0.342871
104+
105+ 3rd Person Camera Angle: 100
106+ Look at Height Offset: -0.891649
107+ -0.889871 is more accurate?
108+ public void Update(Framework framework) {
109+ if (!Configuration.Enabled ) {
110+ if (desiredLookAtHeightOffset != minLookAtHeightOffset ) {
111+ desiredLookAtHeightOffset = minLookAtHeightOffset;
112+ cameraManager->WorldCamera->LookAtHeightOffset = desiredLookAtHeightOffset ;
113+ }
114+ return;
115+ }
116+
117+ var currentZoom = cameraManager->WorldCamera->CurrentZoom;
118+ var minZoom = cameraManager->WorldCamera->MinZoom ;
119+ var maxZoom = cameraManager->WorldCamera->MaxZoom ;
120+ var minTilt = Configuration.MinZoomTilt ;
121+ var maxTilt = Configuration.MaxZoomTilt ;
122+ var currentTiltOffset = configModule->GetIntValue(ConfigOption.TiltOffset) ;
123+ var tiltOffset = (int)(
124+ (
125+ (currentZoom - minZoom) * (maxTilt - minTilt) / (maxZoom - minZoom)
126+ )
127+ + minTilt
128+ );
129+ var lookAtHeightOffset = (
130+ minLookAtHeightOffset
131+ + (maxLookAtHeightOffset - minLookAtHeightOffset)
132+ * (Math.Clamp(currentTiltOffset - 50, -50, 50) / 50f )
133+ * (float)tiltOffset / (float)maxTilt
134+ );
135+ desiredLookAtHeightOffset = lookAtHeightOffset ;
136+ currentLookAtHeightOffset = (float)Lerp((DateTime.Now - framework.LastUpdate).TotalMilliseconds, currentLookAtHeightOffset, desiredLookAtHeightOffset) ;
137+ PluginLog.Log($"currentTiltOffset: {currentTiltOffset}" );
138+ PluginLog.Log($"tiltOffset : {tiltOffset }");
139+ PluginLog.Log($"maxTilt : {maxTilt }");
140+ PluginLog.Log($"lookAtHeightOffset : {lookAtHeightOffset }");
141+ // PluginLog.Log($"ZoomTilt: tiltOffset: {tiltOffset}, currentLookAtHeightOffset: {currentLookAtHeightOffset}, desiredLookAtHeightOffset: {desiredLookAtHeightOffset }");
142+ cameraManager->WorldCamera->LookAtHeightOffset = currentLookAtHeightOffset;
143+ PluginLog.Log($"camera: { cameraManager->WorldCamera->LookAtHeightOffset}") ;
144+ }
145+ */
155146
156147 private void OnCommand ( string command , string args ) {
157148 // in response to the slash command, just display our main ui
0 commit comments