diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..612a613 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +nodejs 14.12.0 diff --git a/assets/js/app.js b/assets/js/app.js index 9dfad66..7f070b9 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -26,6 +26,7 @@ import { LiveSocket } from "phoenix_live_view" import topbar from "../vendor/topbar" import { mountMap, updateMap } from "./map" import { mountView, updateView } from "./view" +import { mountVR, updateVR} from "./vr" function extractLocation(element) { return { @@ -34,11 +35,13 @@ function extractLocation(element) { alt: element.getAttribute("data-alt"), bearing: element.getAttribute("data-bearing"), pitch: element.getAttribute("data-pitch"), + roll: element.getAttribute("data-roll") } } const mapState = {} const viewState = {} +const vrState = {} let Hooks = {} Hooks.Map = { @@ -46,11 +49,13 @@ Hooks.Map = { const location = extractLocation(this.el) mountMap(mapState, location) mountView(viewState, location) + mountVR(vrState, location) }, updated() { const location = extractLocation(this.el) updateMap(mapState, location) updateView(viewState, location) + updateVR(vrState, location) }, } diff --git a/assets/js/vr.js b/assets/js/vr.js new file mode 100644 index 0000000..2491c67 --- /dev/null +++ b/assets/js/vr.js @@ -0,0 +1,36 @@ +export function mountVR(state, location) { + let pos = { + lat: parseFloat(location.lat), + lng: parseFloat(location.lng), + alt: parseFloat(location.alt), + pitch: parseFloat(location.pitch), + yaw: parseFloat(location.bearing), + roll: parseFloat(location.roll)}; + + state.camera = { + rigElement: document.getElementById('vr-rig'), + cameraElement: document.getElementById('vr-camera'), + pos: pos + } +} + +export function updateVR(state, location) { + let cam = state.camera.cameraElement; + let rig = state.camera.rigElement; + let pos = { lat: parseFloat(location.lat), + lng: parseFloat(location.lng), + alt: parseFloat(location.alt), + pitch: parseFloat(location.pitch), + roll: parseFloat(location.roll), + yaw: parseFloat(location.bearing)} + state.pos = pos; + rig.setAttribute('position', {x: pos.lat , y: pos.alt , z: pos.lng}); + cam.setAttribute('rotation', { + x: pos.pitch, + y: -pos.yaw, + z: -pos.roll + }); + + console.log( pos); + +} diff --git a/assets/package-lock.json b/assets/package-lock.json index 7474c83..96d0ac8 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -1,39 +1,6 @@ { - "name": "assets", - "lockfileVersion": 2, "requires": true, - "packages": { - "": { - "dependencies": { - "@googlemaps/js-api-loader": "^1.13.10", - "arcgis-js-api": "^4.15.2", - "esri-loader": "^3.4.0" - } - }, - "node_modules/@googlemaps/js-api-loader": { - "version": "1.13.10", - "resolved": "https://registry.npmjs.org/@googlemaps/js-api-loader/-/js-api-loader-1.13.10.tgz", - "integrity": "sha512-11AF8SdXca1+trN7kDYiPqwxcjQjet/e/A20PPR2hMHQIZ0ktxd4VsqbsSDLj1BZW1bke0FnZ4zY0KYmgWZ9cg==", - "dependencies": { - "fast-deep-equal": "^3.1.3" - } - }, - "node_modules/arcgis-js-api": { - "version": "4.23.0", - "resolved": "https://registry.npmjs.org/arcgis-js-api/-/arcgis-js-api-4.23.0.tgz", - "integrity": "sha512-+mLcXsFRycXvLdNA9XbnFLyb5NeLK/oeIG9uQALhgorxxaasGjYMWq5CMRaLbmQUnrevrzZS0OJOp9A4UVUF7w==" - }, - "node_modules/esri-loader": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/esri-loader/-/esri-loader-3.4.0.tgz", - "integrity": "sha512-iS3SbBmrnr4TlUdAjyyVZD2yCud8AMZkyJcmYEVzTiE5wVUtdN8d9USp7XYtilgwkJe/eWR2f2G1+S58ESqLuQ==" - }, - "node_modules/fast-deep-equal": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" - } - }, + "lockfileVersion": 1, "dependencies": { "@googlemaps/js-api-loader": { "version": "1.13.10", diff --git a/config/dev.exs b/config/dev.exs index 931da3b..42e2d93 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -9,7 +9,13 @@ import Config config :flight_simulator, FlightSimulatorWeb.Endpoint, # Binding to loopback ipv4 address prevents access from other machines. # Change to `ip: {0, 0, 0, 0}` to allow access from other machines. - http: [ip: {127, 0, 0, 1}, port: 4000], + http: [ip: {0, 0, 0, 0}, port: 4000], + https: [ + port: 4001, + cipher_suite: :strong, + keyfile: "priv/cert/selfsigned_key.pem", + certfile: "priv/cert/selfsigned.pem" + ], check_origin: false, code_reloader: true, debug_errors: true, diff --git a/lib/flight_simulator.ex b/lib/flight_simulator.ex index 67aaa7f..447f677 100644 --- a/lib/flight_simulator.ex +++ b/lib/flight_simulator.ex @@ -13,20 +13,20 @@ defmodule FlightSimulator do """ @pitch_delta 1.0 - @max_pitch_angle 20.0 - @min_pitch_angle -20.0 + @max_pitch_angle 89.0 + @min_pitch_angle -89.0 @roll_delta 1.0 - @max_roll_angle 50.0 - @min_roll_angle -50.0 + @max_roll_angle 90.0 + @min_roll_angle -90.0 @yaw_delta 1.0 - @speed_delta 5.0 - @min_speed 5.0 + @speed_delta 0.2 + @min_speed 2.0 @max_speed 120.0 - @min_altitude 10.0 + @min_altitude 0.0 @reset_factor 1.1 @@ -237,10 +237,15 @@ defmodule FlightSimulator do http://www.movable-type.co.uk/scripts/latlong.html#dest-point """ def update_location(%{lat: lat, lng: lng}, bearing, distance) do - {:ok, [lat_new, lng_new]} = - destination_point({lat, lng}, degrees_to_radians(bearing), distance) - - %{lat: lat_new, lng: lng_new} + #{:ok, [lat_new, lng_new]} = + #destination_point({lat, lng}, degrees_to_radians(bearing), distance) + + #%{lat: lat_new, lng: lng_new} + theta = degrees_to_radians(bearing) + %{ + lat: lat - :math.sin(theta) * distance, + lng: lng - :math.cos(theta) * distance + } end defp sin(a), do: :math.sin(degrees_to_radians(a)) diff --git a/lib/flight_simulator_web/flight_simulator/flight_simulator_live.ex b/lib/flight_simulator_web/flight_simulator/flight_simulator_live.ex index d4c1972..0ecbc15 100644 --- a/lib/flight_simulator_web/flight_simulator/flight_simulator_live.ex +++ b/lib/flight_simulator_web/flight_simulator/flight_simulator_live.ex @@ -4,8 +4,8 @@ defmodule FlightSimulatorWeb.FlightSimulatorLive do alias FlightSimulatorWeb.Instrument @initial_state %FlightSimulator{ - location: %{lat: -33.964592291602244, lng: 151.18069727924058}, - bearing: 347.0 + location: %{lat: 0, lng: 10}, + bearing: 0.0 } @tick 30 diff --git a/lib/flight_simulator_web/flight_simulator/flight_simulator_live.html.heex b/lib/flight_simulator_web/flight_simulator/flight_simulator_live.html.heex index dfcaef8..f091638 100644 --- a/lib/flight_simulator_web/flight_simulator/flight_simulator_live.html.heex +++ b/lib/flight_simulator_web/flight_simulator/flight_simulator_live.html.heex @@ -5,6 +5,7 @@ data-lng={@simulator.location.lng} data-alt={@simulator.altitude} data-bearing={@simulator.bearing} + data-roll={@simulator.roll_angle} data-pitch={@simulator.pitch_angle} /> @@ -15,12 +16,31 @@ altitude={@simulator.altitude} speed={@simulator.speed} /> - - - + - +
+ + + + + + + + + + + + + + + + +
+ + + +
diff --git a/lib/flight_simulator_web/flight_simulator/instrument.ex b/lib/flight_simulator_web/flight_simulator/instrument.ex index a8cfd8c..1b06e61 100644 --- a/lib/flight_simulator_web/flight_simulator/instrument.ex +++ b/lib/flight_simulator_web/flight_simulator/instrument.ex @@ -6,7 +6,7 @@ defmodule FlightSimulatorWeb.Instrument do """ def panel(assigns) do ~H""" -