From 12f5714b37fd178468b6c8138bad922f90f6796e Mon Sep 17 00:00:00 2001 From: mfranz Date: Wed, 7 Feb 2007 22:13:51 +0000 Subject: [PATCH] add support for x/y/z axes. The built-in function is (still) a NOOP, but aircraft can plug a custom function. This function can access all internal variables of the ViewManager class. It can set me.{x,y,z}_offset, and also add offsets to me.{heading,pitch,roll}_offset. Example: dynamic_view.register_headshake(func { me.x_offset = rand() * 0.02; # Parkinson effect }); The advantage of this implementation is that it doesn't break MMB drag functionality, and that is can be frozen by mouse movements. --- Nasal/dynamic_view.nas | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Nasal/dynamic_view.nas b/Nasal/dynamic_view.nas index 54bb9de1e..5fbb092b1 100644 --- a/Nasal/dynamic_view.nas +++ b/Nasal/dynamic_view.nas @@ -61,7 +61,10 @@ var Input = { var ViewAxis = { new : func(prop) { var m = { parents : [ViewAxis] }; - m.prop = props.globals.getNode(prop, 0); + m.prop = props.globals.getNode(prop, 1); + if (m.prop.getType() == "NONE") { + m.prop.setDoubleValue(0); + } m.reset(); return m; }, @@ -110,6 +113,10 @@ var ViewManager = { m.pitch_axis = ViewAxis.new("/sim/current-view/goal-pitch-offset-deg"); m.roll_axis = ViewAxis.new("/sim/current-view/goal-roll-offset-deg"); + m.x_axis = ViewAxis.new("/sim/current-view/x-offset-m"); + m.y_axis = ViewAxis.new("/sim/current-view/y-offset-m"); + m.z_axis = ViewAxis.new("/sim/current-view/z-offset-m"); + # accelerations are converted to G (Earth gravitation is omitted) m.ax = Input.new("/accelerations/pilot/x-accel-fps_sec", 0.03108095, 0, 0.58, 0); m.ay = Input.new("/accelerations/pilot/y-accel-fps_sec", 0.03108095, 0, 0.95); @@ -167,6 +174,7 @@ var ViewManager = { me.roll = me.rollN.getValue(); me.calculate(); + me.headshake(); var b = me.blendN.getValue(); var B = 1 - b; @@ -177,6 +185,10 @@ var ViewManager = { me.heading_axis.apply(me.heading); me.pitch_axis.apply(me.pitch); me.roll_axis.apply(me.roll); + + me.x_axis.apply(me.x_offset); + me.y_axis.apply(me.y_offset); + me.z_axis.apply(me.z_offset); }, lookat : func(heading = nil, pitch = nil, roll = nil) { if (heading == nil) { @@ -258,6 +270,13 @@ ViewManager.default_helicopter = func { +# default headshaking code (NOOP) +# +ViewManager.headshake = func { + me.x_offset = me.y_offset = me.z_offset = 0; +} + + # Update loop for the whole dynamic view manager. It only runs if # /sim/view[0]/dynamic/enabled is true. # @@ -285,6 +304,10 @@ var register = func(f) { view_manager.calculate = f; } +var register_headshake = func(f) { + view_manager.headshake = f; +} + var reset = func { view_manager.reset(); }