repo: janusweb
action: commit
revision: 
path_from: 
revision_from: 95ae896dc47a0ba56e51f55131efe50897b1186d:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit 95ae896dc47a0ba56e51f55131efe50897b1186d
Author: James Baicoianu 
Date:   Wed Mar 28 00:42:06 2018 -0700

    room.referrer, better spawnpoint handling

diff --git a/scripts/room.js b/scripts/room.js
index 4e50036bf11db01c64861f1bba0f1c96630cb87e..
index ..ac4b99fc79c744b08e94b205b7cabf3ca9cd1ddd 100644
--- a/scripts/room.js
+++ b/scripts/room.js
@@ -11,6 +11,7 @@ elation.require([
       this.defineProperties({
         'janus': { type: 'object' },
         'url': { type: 'string', default: false },
+        'referrer': { type: 'string' },
         'deferload': { type: 'boolean', default: false },
         'roomid': { type: 'string' },
         'corsproxy': { type: 'string', default: false },
@@ -57,8 +58,6 @@ elation.require([
         '^error$': elation.janusweb.translators.error({janus: this.janus}),
         '^default$': elation.janusweb.translators.default({janus: this.janus})
       };
-      this.playerstartposition = [0,0,0];
-      this.playerstartorientation = new THREE.Quaternion();
       this.spawnpoint = new THREE.Object3D();
       this.roomsrc = '';
       this.changes = {};
@@ -172,8 +171,8 @@ elation.require([
     }
     this.setPlayerPosition = function(pos, orientation) {
       if (!pos) {
-        pos = this.playerstartposition;
-        orientation = this.playerstartorientation;
+        pos = this.spawnpoint.position;
+        orientation = this.spawnpoint.orientation;
       }
       var player = this.engine.client.player;
       player.reset_position();
@@ -613,19 +612,27 @@ elation.require([
         });
 //}), Math.random() * 500);
         }
-        // set player position based on room info
-        this.playerstartposition = room.pos;
-        this.playerstartorientation = room.orientation;
-
+        // set player spawnpoint based on room info
         if (room.pos) {
           this.spawnpoint.position.fromArray(room.pos);
         }
         if (room.orientation) {
           this.spawnpoint.quaternion.copy(room.orientation);
-          this.spawnpoint.quaternion.multiply(new THREE.Quaternion().setFromEuler(new THREE.Euler(0,Math.PI,0)));
+          this.spawnpoint.quaternion.multiply(new THREE.Quaternion().setFromEuler(new THREE.Euler(0,Math.PI,0))); // Janus Native starts the player backwards
           this.spawnpoint.updateMatrixWorld();
         }

+        // If we have a referrer, check to see if a reciprocal link exists.  If it does, use this as our spawn point.
+        if (roomdata.link && this.referrer) {
+          roomdata.link.forEach(link => {
+            if (link.url == this.referrer) {
+              this.spawnpoint.quaternion.copy(link.orientation.inverse());
+              this.spawnpoint.position.fromArray(link.pos);
+              this.spawnpoint.position.add(this.spawnpoint.localToWorld(V(0,0,-player.fatness)));
+            }
+          });
+        }
+
         if (room.skybox_left_id) this.properties.skybox_left = room.skybox_left_id;
         if (room.skybox_right_id) this.properties.skybox_right = room.skybox_right_id;
         if (room.skybox_up_id) this.properties.skybox_up = room.skybox_up_id;
@@ -1439,6 +1446,7 @@ elation.require([
       if (!this._proxyobject) {
         var proxy = new elation.proxy(this, {
           url:           ['property', 'url', { readonly: true}],
+          referrer:      ['property', 'referrer'],
           objects:       ['property', 'jsobjects'],
           cookies:       ['property', 'cookies'],
           walk_speed:    ['property', 'walk_speed'],

-----END OF PAGE-----