Skip to content

Commit

Permalink
Merge pull request #20 from samcake/clouding
Browse files Browse the repository at this point in the history
Cleaning up the user inputs from the web page
  • Loading branch information
samcake committed Nov 12, 2019
2 parents 61c6447 + 6587a18 commit f2c6a01
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 86 deletions.
44 changes: 4 additions & 40 deletions plugins/cloudClient/resources/controller/cloudInput.json
@@ -1,25 +1,6 @@
{
"name": "CloudInput to Actions",
"channels": [
{ "from": { "makeAxis" : [
["CloudInput.PressLeft"],
["CloudInput.PressRight"]
]
},
"to": "Actions.Yaw"
},

{ "from": { "makeAxis" : [
["CloudInput.PressLeft"],
["CloudInput.PressRight"]
]
},
"to": "Actions.Yaw"
},

{ "from": "CloudInput.PressUp", "to": "Actions.LONGITUDINAL_FORWARD" },
{ "from": "CloudInput.PressDown", "to": "Actions.LONGITUDINAL_BACKWARD" },

{ "from": { "makeAxis" : ["CloudInput.CameraMoveUp", "CloudInput.CameraMoveDown"] },
"to": "Actions.DeltaPitch",
"filters":
Expand All @@ -35,26 +16,9 @@
]
},

{ "from": { "makeAxis" : ["CloudInput.AvatarMoveLeft", "CloudInput.AvatarMoveRight"] },
"to": "Actions.TRANSLATE_X",
"filters":
[
{ "type": "scale", "scale": 1.0 }
]
},
{ "from": { "makeAxis" : ["CloudInput.AvatarMoveDown", "CloudInput.AvatarMoveUp"] },
"to": "Actions.TRANSLATE_Y",
"filters":
[
{ "type": "scale", "scale": 1.0 }
]
},
{ "from": { "makeAxis" : ["CloudInput.AvatarMoveBack", "CloudInput.AvatarMoveForward"] },
"to": "Actions.TRANSLATE_Z",
"filters":
[
{ "type": "scale", "scale": 1.0 }
]
}
{"from": "CloudInput.AvatarMoveFront", "to": "Actions.LONGITUDINAL_FORWARD" },
{"from": "CloudInput.AvatarMoveBack", "to": "Actions.LONGITUDINAL_BACKWARD" },
{"from": "CloudInput.AvatarMoveRight", "to": "Actions.LATERAL_RIGHT" },
{"from": "CloudInput.AvatarMoveLeft", "to": "Actions.LATERAL_LEFT" }
]
}
4 changes: 0 additions & 4 deletions plugins/cloudClient/resources/web/index.html
Expand Up @@ -13,10 +13,6 @@
<br />

<input type="button" id="start" onclick="start(true)" value="Start Video"></input>
<input type="button" id="right" onclick="onRight()" value="Right"></input>
<input type="button" id="left" onclick="onLeft()" value="Left"></input>
<input type="button" id="up" onclick="onUp()" value="Up"></input>
<input type="button" id="down" onclick="onDown()" value="Down"></input>

<script type="text/javascript">
pageReady();
Expand Down
54 changes: 13 additions & 41 deletions plugins/cloudClient/resources/web/webrtc.js
Expand Up @@ -46,24 +46,7 @@ function pageReady() {
peerConnection.ontrack = gotRemoteStream;
// peerConnection.addStream(localStream);
peerConnection.ondatachannel = receiveChannelCallback;


/*
sendChannel = peerConnection.createDataChannel("sendChannel");
sendChannel.onopen = function () {
console.log("sendChannel.onopen");
console.log("sendChannel state=" + sendChannel.readyState);
sendChannel.send('Hi you!');
}
sendChannel.onclose = function () {
console.log("sendChannel.onclose");
console.log("sendChannel state=" + sendChannel.readyState);
}
sendChannel.onmessage = function (message) {
console.log("sendChannel got message: " + (message.data));
}*/



installUserInputHandler();

var desc = new RTCSessionDescription(signal);
Expand Down Expand Up @@ -265,19 +248,6 @@ function sendInput(inputEvent) {
sendChannel.send(m);
}

function onLeft() {
sendInput({"c": "PressLeft", "p": -1 })
}
function onRight() {
sendInput({"c": "PressRight", "p": -1 })
}
function onUp() {
sendInput({"c": "PressUp", "p": -1 })
}
function onDown() {
sendInput({"c": "PressDown", "p": -1 })
}

function onCameraMove(delta) {
sendInput({"c": "CameraMove", "p": delta })
}
Expand All @@ -286,28 +256,24 @@ function onAvatarMove(delta) {
sendInput({"c": "AvatarMove", "p": delta })
}

var mouseButtonDown = false;
var mouseDragLastPos = { x: 0, y:0};

var mouseDragLastPos = { x: 0, y:0 };

let handleMouseDown = (event) => {
if (event.buttons === 1) {
mouseButtonDown = true;
mouseDragLastPos = { x: event.x, y:event.y};
console.log("mouse down");
// console.log("mouse down");
}
};

let handleMouseUp = (event) => {
if (mouseButtonDown) {
mouseButtoDown = false;
onCameraMove({x: 0, y: 0});

console.log("mouse up");
}
// console.log("mouse up");
};

let handleMouseMove = (event) => {
if ((event.buttons === 1) && mouseButtonDown) {
if ((event.buttons === 1)) {
var newPos = { "x": event.x, "y": event.y};
var delta = { "x": (newPos.x - mouseDragLastPos.x), "y":(newPos.y - mouseDragLastPos.y)};
mouseDragLastPos = newPos;
Expand All @@ -318,7 +284,13 @@ let handleMouseMove = (event) => {
let handleKeyPress = (event) => {
var x = event.key;
if (x == "w" || x == "W") {
onAvatarMove({ x: 0, y: 0, z: 2 });
onAvatarMove({ x: 0, y: 0, z: 1 });
} else if (x == "s" || x == "S") {
onAvatarMove({ x: 0, y: 0, z: -1 });
} else if (x == "a" || x == "A") {
onAvatarMove({ x: -1, y: 0, z: 0 });
} else if (x == "d" || x == "D") {
onAvatarMove({ x: 1, y: 0, z: 0 });
}
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/cloudClient/src/CloudControllerManager.cpp
Expand Up @@ -88,7 +88,7 @@ void CloudControllerManager::onRemoteInputEvent(const json& args) {
_inputDevice->_axisStateMap[(AVATAR_MOVE_AXIS_Z_POS)] = { float(z > 0.0f ? z : 0.0f), now };
_inputDevice->_axisStateMap[(AVATAR_MOVE_AXIS_Z_NEG)] = { float(z < 0.0f ? -z : 0.0f), now };

qDebug() << "=== CloudControllerManager : CameraMove " << x << " - " << y;
qDebug() << "=== CloudControllerManager : AvatarMove " << x << " - " << y;
}
}
}
Expand Down

0 comments on commit f2c6a01

Please sign in to comment.