Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const facts = database[bodyName];
const celestialBody = this.celestialBodies[bodyName];
if (facts.year > 0) {
// years = seconds (not in agreement with axial animation)
const orbitTimeInSeconds = facts.year / this.timeFactor;
const timeStep = orbitTimeInSeconds / this.orbitalKeyframeCount;
const angleStep = 360 / this.orbitalKeyframeCount;
const keyframes: MRESDK.AnimationKeyframe[] = [];
const initial = celestialBody.position.transform.local.position.clone();
let value: Partial;
for (let i = 0; i < this.orbitalKeyframeCount; ++i) {
const rotDelta = MRESDK.Quaternion.RotationAxis(
MRESDK.Vector3.Up(), (-angleStep * i) * MRESDK.DegreesToRadians);
const position = initial.rotateByQuaternionToRef(rotDelta, new MRESDK.Vector3());
value = {
transform: {
local: { position }
}
};
keyframes.push({
time: timeStep * i,
value,
});
}
// Final frame
value = {
transform: {
local: { position: celestialBody.position.transform.local.position }
}
const i = this.vertices.push(vert) - 1,
longNbr = i - 1 + (i == ringStart ? longLines + 1 : 0),
latNbr = i <= longLines + 1 ? 0 : i - longLines - 1,
latLongNbr = longNbr - longLines - 1;
// fill in the tri/quad connecting this vert to the sphereA
this.triangles.push(i, longNbr, latNbr);
if (latLongNbr > 0)
this.triangles.push(longNbr, latLongNbr, latNbr);
}
}
// generate south pole
const south = new Vertex({
position: new Vector3(0, -radius, 0),
normal: new Vector3(0, -1, 0),
texCoord0: new Vector2(0.5, 0)
});
const southIdx = this.vertices.push(south) - 1;
// connect last long ring to the south pole
const ringStart = southIdx - longLines - 1;
for (let i = southIdx - longLines - 1; i < southIdx; i++) {
const longNbr = i - 1 + (i == ringStart ? longLines + 1 : 0);
this.triangles.push(longNbr, i, southIdx);
}
}
}
public constructor(radius: number, longLines = 12, latLines = 8, material: Material = null) {
super({material});
// generate north pole
const north = new Vertex({
position: new Vector3(0, radius, 0),
normal: new Vector3(0, 1, 0),
texCoord0: new Vector2(0.5, 1)
});
this.vertices.push(north);
const longAngle = 2 * Math.PI / longLines,
latAngle = Math.PI / latLines;
// generate verts in rings starting from the north pole
for (let lat = latAngle; lat < Math.PI - 0.001; lat += latAngle) {
const ringStart = this.vertices.length;
for (let long = 0; long < 2 * Math.PI + 0.001; long += longAngle) {
// generate a vertex
const normal = new Vector3(Math.sin(lat) * Math.cos(long), Math.cos(lat), Math.sin(lat) * Math.sin(long))
const vert = new Vertex({
position: normal.scale(radius),
private coordinate(coord: Coordinate): Vector3 {
// Given a file and rank, return the coordinates of the center of the corresponding square.
const fileIndices: { [id: string]: number } = { 'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7 };
const file = fileIndices[coord.file];
const rank = coord.rank - 1;
const x = file * -boardStep;
const z = rank * -boardStep;
return new Vector3(x, baseHeight, z);
}
const facts = database[bodyName];
const celestialBody = this.celestialBodies[bodyName];
if (facts.year > 0) {
// years = seconds (not in agreement with axial animation)
const orbitTimeInSeconds = facts.year / this.timeFactor;
const timeStep = orbitTimeInSeconds / this.orbitalKeyframeCount;
const angleStep = 360 / this.orbitalKeyframeCount;
const keyframes: MRESDK.AnimationKeyframe[] = [];
const initial = celestialBody.position.transform.position.clone();
let value: Partial;
for (let i = 0; i < this.orbitalKeyframeCount; ++i) {
const rotDelta = MRESDK.Quaternion.RotationAxis(
MRESDK.Vector3.Up(), (-angleStep * i) * MRESDK.DegreesToRadians);
const position = initial.rotateByQuaternionToRef(rotDelta, new MRESDK.Vector3());
value = {
transform: {
position
}
};
keyframes.push({
time: timeStep * i,
value,
});
}
// Final frame
value = {
transform: {
position: celestialBody.position.transform.position
}
private async animateMovement(actor: Actor, dst: Square) {
const moveSpeed = 3;
const position = new Vector3();
position.copy(this.coordinate(dst));
position.y = actor.transform.local.position.y;
const diff = position.subtract(actor.transform.local.position);
const length = diff.length();
const [side, type] = actor.name.split('-');
const sideConfig = modelConfigs[side];
const modelConfig = sideConfig[type];
actor.animateTo({
transform: {
local: {
position,
rotation: modelConfig.rotation
}
}
}, moveSpeed * length, AnimationEaseCurves.EaseInOutSine);
}
private createChessPieces() {
const loads: Array> = [];
const status = this.game.getStatus() as Status;
for (const square of status.board.squares) {
if (square.piece) {
const side = modelConfigs[square.piece.side.name];
const info = side[square.piece.type];
const name = `${square.piece.side.name}-${square.piece.type}`;
const position = new Vector3();
position.copy(this.coordinate(square));
const prefab = this.preloads[`${square.piece.side.name}-${square.piece.type}`][0].prefab;
const actor = Actor.CreateFromPrefab(this.context, {
prefabId: prefab.id,
actor: {
name,
parentId: this.boardOffset.id,
transform: { local: { position, rotation: info.rotation } },
subscriptions: ['transform']
}
});
square.piece.actor = actor;
loads.push(actor.created());
}
}
return loads;
const distance = (square: Square) => Vector3.Distance(
new Vector3(position.x, 0, position.z),
new Vector3(
square.actor.transform.app.position.x, 0,
square.actor.transform.app.position.z));