Commit ff24005d authored by Jens-Christian Fischer's avatar Jens-Christian Fischer
Browse files

Send Orientation/Acceleration data on visuals channel

In order to update the boids, send back orientation/acceleration data to
the new VisualsChannel.
parent 135ec7b4
......@@ -3,7 +3,7 @@ defmodule Grains.Mixfile do
def project do
[app: :grains,
version: "0.0.39",
version: "0.0.40",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
......
......@@ -20,6 +20,7 @@ defmodule Grains.AccelerationChannel do
z: z
} )
Grains.Endpoint.broadcast "visual", "acceleration", %{user: uuid, force: z}
{:reply, :ok, socket}
......
......@@ -25,7 +25,10 @@ defmodule Grains.OrientationChannel do
Grengine.Performance.set_values(uuid, %{
pitch: pitch,
roll: roll,
} )
}
)
Grains.Endpoint.broadcast "visual", "velocity", %{user: uuid, dx: pitch, dy: roll}
# Grains.Endpoint.broadcast("osc", "orientation", %{user: socket.assigns.user_uuid,
# pitch: pitch,
......
......@@ -12,6 +12,7 @@ defmodule Grains.UserSocket do
channel "presence:*", Grains.PresenceChannel
channel "osc", Grains.OscChannel
channel "visual", Grains.VisualsChannel
## Transports
transport :websocket, Phoenix.Transports.WebSocket
......
defmodule Grains.VisualsChannel do
use Phoenix.Channel
require Logger
def join(_topic, _payload, socket) do
{:ok, socket}
end
def handle_info(_message, socket) do
{:noreply, socket}
end
def handle_in("ping", payload, socket) do
{:reply, {:ok, payload}, socket}
end
def handle_in(event, payload, socket) do
Logger.warn("unhandled event #{event} #{inspect payload}")
{:noreply, socket}
end
end
......@@ -101,6 +101,15 @@ room.join().receive("ok", resp => {
})
.receive("error", reason => console.log("presence join failed", reason))
let visuals = socket.channel("visuals", {});
visuals.on("velocity", state => {
console.log("velocity: ", state);
});
visuals.on("acceleratoin", state => {
console.log("acceleration: ", state);
});
// Import local files
//
......
......@@ -30,6 +30,9 @@ let OrientationPanel = {
.receive("error", reason => console.log("join failed", reason));
let a = new Interface.Panel({
container:document.getElementById(domId)
});
......
......@@ -15,6 +15,11 @@ function Boid(p, x, y) {
this.maxforce = 0.05; // Maximum steering force
};
Boid.prototype.set_velocity = function(dx, dy) {
this.velocity = this.p.createVector(dx, dy);
}
Boid.prototype.run = function(boids) {
this.flock(boids);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment