diff --git a/SConstruct b/SConstruct index ff44f96..1635181 100644 --- a/SConstruct +++ b/SConstruct @@ -2,6 +2,11 @@ import os import sys +if not os.path.isdir("modules/mavlink"): + raise UserError("MAVLink sources missing, run git submodule update --init --recursive") +if not os.path.isdir("include/mavlink"): + raise UserError("MAVLink generated headers missing, run python update_mavlink.py") + env = SConscript("modules/godot-cpp/SConstruct") # For reference: diff --git a/project/aircraft.gd b/project/aircraft.gd new file mode 100644 index 0000000..ce15b7a --- /dev/null +++ b/project/aircraft.gd @@ -0,0 +1,6 @@ +extends Node3D + +@export var connector: MarshConnector + +func _process(_delta: float) -> void: + transform = connector.get_aircraft() diff --git a/project/aircraft.gd.uid b/project/aircraft.gd.uid new file mode 100644 index 0000000..35cf84a --- /dev/null +++ b/project/aircraft.gd.uid @@ -0,0 +1 @@ +uid://cx30pr7kn4c74 diff --git a/project/main.tscn b/project/main.tscn index eb44bf2..6163934 100644 --- a/project/main.tscn +++ b/project/main.tscn @@ -1,5 +1,38 @@ -[gd_scene format=3 uid="uid://cjrkxv8ix1h8s"] +[gd_scene load_steps=7 format=3 uid="uid://cjrkxv8ix1h8s"] -[node name="Node3D" type="Node3D"] +[ext_resource type="Script" uid="uid://cx30pr7kn4c74" path="res://aircraft.gd" id="1_ig7tw"] + +[sub_resource type="BoxMesh" id="BoxMesh_0xm2m"] + +[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_ig7tw"] + +[sub_resource type="Sky" id="Sky_0xm2m"] +sky_material = SubResource("ProceduralSkyMaterial_ig7tw") + +[sub_resource type="Environment" id="Environment_ig7tw"] +background_mode = 2 +sky = SubResource("Sky_0xm2m") + +[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_0xm2m"] + +[node name="Main" type="Node3D"] [node name="MarshConnector" type="MarshConnector" parent="."] +process_mode = 0 + +[node name="Aircraft" type="Node3D" parent="." node_paths=PackedStringArray("connector")] +script = ExtResource("1_ig7tw") +connector = NodePath("../MarshConnector") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="Aircraft"] +mesh = SubResource("BoxMesh_0xm2m") + +[node name="Camera3D" type="Camera3D" parent="."] +transform = Transform3D(-1, -2.26267e-08, 8.44439e-08, 0, 0.965926, 0.258819, -8.74228e-08, 0.258819, -0.965926, 0, 1, -3) + +[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] +transform = Transform3D(-0.707107, -0.683013, 0.183013, 0, 0.258819, 0.965926, -0.707107, 0.683013, -0.183013, 3, 3, 3) + +[node name="WorldEnvironment" type="WorldEnvironment" parent="."] +environment = SubResource("Environment_ig7tw") +camera_attributes = SubResource("CameraAttributesPractical_0xm2m") diff --git a/src/marshconnector.cpp b/src/marshconnector.cpp index 7dd2846..03cecbd 100644 --- a/src/marshconnector.cpp +++ b/src/marshconnector.cpp @@ -6,8 +6,10 @@ #include "godot_cpp/core/math.hpp" #include "godot_cpp/core/memory.hpp" #include "godot_cpp/core/print_string.hpp" +#include "godot_cpp/variant/basis.hpp" #include "godot_cpp/variant/packed_byte_array.hpp" #include "godot_cpp/variant/quaternion.hpp" +#include "godot_cpp/variant/transform3d.hpp" #include "godot_cpp/variant/vector3.hpp" #include "mavlink/all/mavlink.h" // IWYU pragma: keep; always include the mavlink.h file for selected dialect #include "mavlink/common/mavlink_msg_sim_state.h" @@ -21,6 +23,7 @@ using namespace godot; void MarshConnector::_bind_methods() { ClassDB::bind_method(D_METHOD("send_heartbeat"), &MarshConnector::send_heartbeat); + ClassDB::bind_method(D_METHOD("get_aircraft"), &MarshConnector::get_aircraft); } MarshConnector::MarshConnector() { @@ -123,14 +126,18 @@ float MarshConnector::get_parameter(const String &id) { return Math_NAN; } +Transform3D MarshConnector::get_aircraft() { + return Transform3D{Basis{last_rotation}, last_location}; +} + Vector2 MarshConnector::local_meters_from_global_degrees(double latitude, double longitude) { // Convert everything to radians const double lat = latitude * Math_PI / 180.0; const double lon = longitude * Math_PI / 180.0; - const double lat0 = parameters[LOCAL_FRAME_LAT] * M_PI / 180.0; - const double lon0 = parameters[LOCAL_FRAME_LON] * M_PI / 180.0; + const double lat0 = parameters[LOCAL_FRAME_LAT] * Math_PI / 180.0; + const double lon0 = parameters[LOCAL_FRAME_LON] * Math_PI / 180.0; double EARTH_RADIUS = 6371008.7714; // mean radius for WGS-84, in meters diff --git a/src/marshconnector.h b/src/marshconnector.h index d3dfff5..6e73112 100644 --- a/src/marshconnector.h +++ b/src/marshconnector.h @@ -5,6 +5,7 @@ #include "godot_cpp/classes/packet_peer_udp.hpp" #include "godot_cpp/classes/timer.hpp" #include "godot_cpp/variant/quaternion.hpp" +#include "godot_cpp/variant/transform3d.hpp" #include "godot_cpp/variant/vector2.hpp" #include "godot_cpp/variant/vector3.hpp" #include "mavlink/mavlink_types.h" @@ -32,6 +33,8 @@ public: Error set_parameter(const String &id, float value); // Get current parameter value float get_parameter(const String &id); + // Get current state of the aircraft + Transform3D get_aircraft(); // Convert from global coordinates to local position x=north, y=east // taking into account current configuration.