Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
plugincharplacement.c
Go to the documentation of this file.
1 class PluginCharPlacement extends PluginBase
2 {
3  PluginDeveloper m_ModuleDeveloper;
4  PlayerBase m_Character;
5  ref Timer m_Timer;
6  bool m_Initialized;
7  vector m_cam_pos;
8  vector m_character_pos;
9  vector m_camera_dir;
10  vector m_cameraTrans[4];
11  vector m_demoPos;
12  vector m_demoRot;
13  vector m_camera_orientation;
14 
15  const float FOV = 0.5236;
16 
17  void CheckInit()
18  {
19  if ( m_Initialized )
20  {
21  Print("logging...");
22  Log(FOV.ToString(),"FOV");
23  Log(m_camera_dir.ToString(),"camera dir");
24  Log(m_cam_pos.ToString(),"camera pos");
25  Log(m_demoPos.ToString(),"character pos");
26 
27  return;
28  }
29 
30  if( FreeDebugCamera.GetInstance().IsActive() )
31  Init();
32  }
33 
34  void Init()
35  {
36  if(m_Character)
37  m_Character.Delete();
38 
39  m_Initialized = true;
40  m_Character = PlayerBase.Cast( GetGame().CreateObject("SurvivorF_Judy", FreeDebugCamera.GetInstance().GetPosition(), false, false/*ai*/) );
41 
42  FreeDebugCamera.GetInstance().SetFOV(FOV); //default scene FOV
43  m_demoRot = "0 0 0";
44  }
45 
46  override void OnUpdate(float delta_time)
47  {
48  if(!m_Initialized) return;
49  if(!FreeDebugCamera.GetInstance().IsActive()) return;
50  if(!m_Character) return;
51  m_camera_orientation = FreeDebugCamera.GetInstance().GetOrientation();
52  m_camera_orientation[1] = 1;
53  FreeDebugCamera.GetInstance().SetOrientation(m_camera_orientation); //remove to unlock vertical axis
54  m_cam_pos = FreeDebugCamera.GetInstance().GetPosition();
55  m_character_pos = m_Character.GetPosition();
56  m_camera_dir = FreeDebugCamera.GetInstance().GetDirection();
57 
58  m_camera_dir.Normalize();
59  m_Character.SetPosition(CalculatePos());//(FreeDebugCamera.GetInstance().GetPosition() + ( m_camera_dir * 2) );
60  m_demoRot[0] = Math.Atan2(-m_camera_dir[0], -m_camera_dir[2]) * Math.RAD2DEG;
61  m_Character.SetOrientation(m_demoRot);//(FreeDebugCamera.GetInstance().GetPosition() - m_demoPos);
62  }
63 
64  override void OnDestroy()
65  {
66  FreeDebugCamera.GetInstance().SetFOV(g_Game.GetUserFOV());
67  }
68 
69  vector CalculatePos()
70  {
71  vector cam_pos = FreeDebugCamera.GetInstance().GetPosition();
72  Math3D.MatrixIdentity4(m_cameraTrans);
73  Math3D.DirectionAndUpMatrix(m_camera_dir/* - SnapToGround(cam_pos)*/, "0 1 0", m_cameraTrans);
74  m_cameraTrans[3] = cam_pos;
75  m_demoPos = Vector(/*0.685547, -0.988281,*/0,0, 3.68823).Multiply4(m_cameraTrans);
76  m_demoPos[1] = GetGame().SurfaceY(m_demoPos[0], m_demoPos[2]);
77 
78  return m_demoPos;
79  }
80 }
GetGame
proto native CGame GetGame()
m_Timer
ref Timer m_Timer
Definition: dayzgame.c:690
Log
class LogTemplates Log(string message, LogTemplateID template_id=0)
Creates debug log (optional) from LogTemplate which are registred.
Definition: logtemplates.c:75
Print
proto void Print(void var)
Prints content of variable to console/log.
PluginBase
Definition: pluginadminlog.c:1
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
OnUpdate
proto native void OnUpdate()
Definition: tools.c:349
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
m_Initialized
protected bool m_Initialized
Definition: uihintpanel.c:23
Timer
Definition: dayzplayerimplement.c:62
Math
Definition: enmath.c:6
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
OnDestroy
override void OnDestroy()
Definition: plugindayzcreatureaidebug.c:113
Math3D
Definition: enmath3d.c:27