Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
ViewOrientationTool.c
Go to the documentation of this file.
1[WorkbenchPluginAttribute("Set entity to view orientation", "Modifies position and rotation of selected entity to match that of editor view.", "", "", {"WorldEditor"},"",0xf21d)]
2class EntityOrientationTool: WorkbenchPlugin
3{
4 override void Run()
5 {
6 WorldEditor mod = Workbench.GetModule(WorldEditor);
7 if (!mod)
8 {
9 Print("World editor module is not available.", LogLevel.ERROR);
10 return;
11 }
12
13 WorldEditorAPI api = mod.GetApi();
14 int selectedCount = api.GetSelectedEntitiesCount();
15 if (selectedCount != 1)
16 {
17 Print("You can only set orientation of single entity, but you have " + selectedCount + " entities selected.", LogLevel.ERROR);
18 return;
19 }
20
21 vector mat[4];
22 IEntitySource src = api.GetSelectedEntity(0);
23 IEntity e = api.SourceToEntity(src);
24 e.GetWorld().GetCamera(19, mat);
25
26 IEntity parent = api.SourceToEntity(src.GetParent());
27 if (parent)
28 {
29 vector mat_parent[4];
30 parent.GetTransform(mat_parent);
31
32 vector mat_local[4];
33 Math3D.MatrixInvMultiply4(mat_parent, mat, mat_local);
34
35 mat = mat_local;
36 }
37
38 vector yawPitchRoll = Math3D.MatrixToAngles(mat);
39 vector pos = mat[3];
40
41 if ((e.GetFlags() & EntityFlags.RELATIVE_Y) != 0)
42 {
43 float y;
44 if (api.TryGetTerrainSurfaceY(pos[0], pos[2], y))
45 {
46 pos[1] = pos[1] - y;
47 }
48 }
49
50 api.BeginEntityAction("Set entity to view orientation script");
51 api.SetVariableValue(src, null, "coords", pos.ToString(false));
52 api.SetVariableValue(src, null, "angles", string.Format("%1 %2 %3", yawPitchRoll[1], yawPitchRoll[0], yawPitchRoll[2]));
53 api.EndEntityAction();
54 }
55
56 override void Configure() { }
57}
58
59[WorkbenchPluginAttribute(name: "Set camera orientation to entity", description: "Modifies position and rotation of editor view to match selected entity.", shortcut: "Ctrl+Shift+C", wbModules: {"WorldEditor"}, awesomeFontCode: 0xf083)]
60class CameraOrientationTool: WorkbenchPlugin
61{
62 override void Run()
63 {
64 WorldEditor mod = Workbench.GetModule(WorldEditor);
65 if (!mod)
66 {
67 Print("World editor module is not available.", LogLevel.ERROR);
68 return;
69 }
70
71 WorldEditorAPI api = mod.GetApi();
72 int selectedCount = api.GetSelectedEntitiesCount();
73 if (selectedCount != 1)
74 {
75 Print("You can only set orientation of single entity, but you have " + selectedCount + " entities selected.", LogLevel.ERROR);
76 return;
77 }
78
79 vector mat[4];
80 IEntity e = api.SourceToEntity(api.GetSelectedEntity(0));
81 e.GetTransform(mat);
82
83 api.SetCamera(mat[3], mat[2]);
84 }
85
86 override void Configure() { }
87}
override void Run()
override void Configure()
EntityOrientationTool WorkbenchPlugin WorkbenchPluginAttribute(name:"Set camera orientation to entity", description:"Modifies position and rotation of editor view to match selected entity.", shortcut:"Ctrl+Shift+C", wbModules:{"WorldEditor"}, awesomeFontCode:0xf083)
proto external EntityFlags GetFlags()
proto external BaseWorld GetWorld()
proto external void GetTransform(out vector mat[])
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14