content/hifi-public/anshuman/miniWikiplanet.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

101 lines
No EOL
3.9 KiB
JavaScript

// constantly re-orient the avatar's orientation such that UP points out from some center
var GRAVITATIONAL_CENTER = { x: 20.0, y: 20.0, z: 20.0 };
function updateAvatarGravity(dt) {
var upOffset = Vec3.subtract(MyAvatar.position, GRAVITATIONAL_CENTER);
var orientation = MyAvatar.orientation;
var oldUp = Quat.getUp(orientation);
var deltaRotation = Quat.rotationBetween(oldUp, upOffset);
MyAvatar.orientation = Quat.multiply(deltaRotation, MyAvatar.orientation);
}
Script.update.connect(updateAvatarGravity);
// Create a spherical planet
var PLANET_RADIUS = 20.0;
var SKY_RADIUS = 25.0;
var MOON_RADIUS = 4.0;
var fortyTwoDirections = [
{ x: 0.000000, y: -0.000000, z: -1.000000 },
{ x: 0.723608, y: -0.525725, z: -0.447219 },
{ x: -0.276388, y: -0.850649, z: -0.447219 },
{ x: -0.894426, y: -0.000000, z: -0.447216 },
{ x: -0.276388, y: 0.850649, z: -0.447220 },
{ x: 0.723608, y: 0.525725, z: -0.447219 },
{ x: 0.276388, y: -0.850649, z: 0.447220 },
{ x: -0.723608, y: -0.525725, z: 0.447219 },
{ x: -0.723608, y: 0.525725, z: 0.447219 },
{ x: 0.276388, y: 0.850649, z: 0.447219 },
{ x: 0.894426, y: 0.000000, z: 0.447216 },
{ x: -0.000000, y: 0.000000, z: 1.000000 },
{ x: 0.425323, y: -0.309011, z: -0.850654 },
{ x: -0.162456, y: -0.499995, z: -0.850654 },
{ x: 0.262869, y: -0.809012, z: -0.525738 },
{ x: 0.425323, y: 0.309011, z: -0.850654 },
{ x: 0.850648, y: -0.000000, z: -0.525736 },
{ x: -0.525730, y: -0.000000, z: -0.850652 },
{ x: -0.688190, y: -0.499997, z: -0.525736 },
{ x: -0.162456, y: 0.499995, z: -0.850654 },
{ x: -0.688190, y: 0.499997, z: -0.525736 },
{ x: 0.262869, y: 0.809012, z: -0.525738 },
{ x: 0.951058, y: 0.309013, z: 0.000000 },
{ x: 0.951058, y: -0.309013, z: 0.000000 },
{ x: 0.587786, y: -0.809017, z: 0.000000 },
{ x: 0.000000, y: -1.000000, z: 0.000000 },
{ x: -0.587786, y: -0.809017, z: 0.000000 },
{ x: -0.951058, y: -0.309013, z: -0.000000 },
{ x: -0.951058, y: 0.309013, z: -0.000000 },
{ x: -0.587786, y: 0.809017, z: -0.000000 },
{ x: -0.000000, y: 1.000000, z: -0.000000 },
{ x: 0.587786, y: 0.809017, z: -0.000000 },
{ x: 0.688190, y: -0.499997, z: 0.525736 },
{ x: -0.262869, y: -0.809012, z: 0.525738 },
{ x: -0.850648, y: 0.000000, z: 0.525736 },
{ x: -0.262869, y: 0.809012, z: 0.525738 },
{ x: 0.688190, y: 0.499997, z: 0.525736 },
{ x: 0.525730, y: 0.000000, z: 0.850652 },
{ x: 0.162456, y: -0.499995, z: 0.850654 },
{ x: -0.425323, y: -0.309011, z: 0.850654 },
{ x: -0.425323, y: 0.309011, z: 0.850654 },
{ x: 0.162456, y: 0.499995, z: 0.85065 }
];
var MOON_ORBIT_RADIUS = SKY_RADIUS + MOON_RADIUS;
var LIFETIME = 600;
var planetProperties = {
name: "planet",
type : "Sphere",
dimensions : { x: 2 * PLANET_RADIUS, y: 2 * PLANET_RADIUS, z: 2 * PLANET_RADIUS },
position : GRAVITATIONAL_CENTER,
lifetime : LIFETIME,
color : { red: 180, green: 180, blue: 180 }
};
Entities.addEntity(planetProperties);
var numMoons = fortyTwoDirections.length;
for (var i = 0; i < numMoons; ++i) {
var direction = fortyTwoDirections[i];
print("adebug dir = < " + direction.x + ", " + direction.y + ", " + direction.z + " >");
var moonPosition = {
x: GRAVITATIONAL_CENTER.x + MOON_ORBIT_RADIUS * direction.x,
y: GRAVITATIONAL_CENTER.y + MOON_ORBIT_RADIUS * direction.y,
z: GRAVITATIONAL_CENTER.z + MOON_ORBIT_RADIUS * direction.z
};
var moonColor = {
red: 255 * (direction.x + 1) / 2,
green: 255 * (direction.y + 1) / 2,
blue: 255 * (direction.z + 1) / 2
};
var moonProperties = {
name: "moon",
type: "Sphere",
dimensions: { x: 2 * MOON_RADIUS, y: 2 * MOON_RADIUS, z: 2 * MOON_RADIUS },
position: moonPosition,
lifetime: LIFETIME,
color : moonColor
};
Entities.addEntity(moonProperties);
}