content/hifi-public/brad/musicplayer/createNewiPodOnClick.js
Dale Glass 0d14e5a379 Initial data.
Needs a lot of cleanup. Data has been de-duplicated, and where identical copies existed, one of them
has been replaced with a symlink.

Some files have been excluded, such as binaries, installers and debug dumps. Some of that may still
be present.
2022-02-13 18:59:11 +01:00

85 lines
3.2 KiB
JavaScript

(function(){
function getPositionToCreateEntity() {
var distance = 0.5;
var direction = Quat.getFront(Camera.orientation);
var offset = Vec3.multiply(distance, direction);
var placementPosition = Vec3.sum(Camera.position, offset);
var cameraPosition = Camera.position;
var HALF_TREE_SCALE = 16384;
var cameraOutOfBounds = Math.abs(cameraPosition.x) > HALF_TREE_SCALE || Math.abs(cameraPosition.y) > HALF_TREE_SCALE || Math.abs(cameraPosition.z) > HALF_TREE_SCALE;
var placementOutOfBounds = Math.abs(placementPosition.x) > HALF_TREE_SCALE || Math.abs(placementPosition.y) > HALF_TREE_SCALE || Math.abs(placementPosition.z) > HALF_TREE_SCALE;
if (cameraOutOfBounds && placementOutOfBounds) {
return null;
}
placementPosition.x = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.x));
placementPosition.y = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.y));
placementPosition.z = Math.min(HALF_TREE_SCALE, Math.max(-HALF_TREE_SCALE, placementPosition.z));
return placementPosition;
}
function createNewIPOD() {
var iPodPosition = { x: 0, y: .5, z: 0};
var iPodDimensions = { x: 0.15, y: 0.3, z: 0.03 };
var overlayDimensions = { x: 0.13, y: 0.13, z: 0.001 };
var boxOverlayDimensions = { x: 0.13, y: 0.13, z: 0.0001 };
var iPodID = Entities.addEntity({
type: "Box",
name: "music player",
position: iPodPosition,
dimensions: iPodDimensions,
color: { red: 150, green: 150, blue: 150},
script: "https://s3.amazonaws.com/hifi-public/brad/musicplayer/musicPlayer.js",
dynamic: true
});
print(iPodID);
var textID = Entities.addEntity({
type: "Text",
name: "now playing",
position: { x: 0, y: (0.5+0.07), z: 0.0222}, // + 0.007
dimensions: overlayDimensions,
color: { red: 150, green: 150, blue: 150},
parentID: iPodID,
lineHeight: 0.01,
text: "Pause"
});
var newAlbumArt = JSON.stringify(
{
"ProceduralEntity": {
"version":2,
"shaderUrl":"https://s3.amazonaws.com/hifi-public/brad/musicplayer/imageShader.fs",
"uniforms":{"iSpeed":0,"iShell":1},
"channels":["http://wallpicshd.com/wp-content/uploads/2013/07/Black-Wallpaper-HD-Dekstop-Photos.jpg"]
}
});
var albumArtID = Entities.addEntity({
type: "Box",
name: "album art",
position: { x: 0, y: (0.5-0.07), z: 0.01506},
dimensions: boxOverlayDimensions,
color: { red: 255, green: 255, blue: 255},
userData: newAlbumArt,
parentID: iPodID
});
Entities.editEntity(iPodID, { position: getPositionToCreateEntity() });
}
this.clickDownOnEntity = function(myID, mouseEvent) {
createNewIPOD();
};
})