Improved PointTrack calculations
*Improved PointTrack rotation calculations to include curved tracks *Fixed PointTrack not having len property *Fixed swaped arguments in Vector3.atanY
This commit is contained in:
parent
930ff81f7c
commit
ccbc50054c
@ -11,14 +11,29 @@ export default class PointTrack extends Track
|
||||
};
|
||||
|
||||
constructor(id, start, end, r, nextid, previd, id_station, start_slope, end_slope, id_isolation, prefab_name, maxspeed, derailspeed) {
|
||||
const ry = AngleHelper.radToDeg(start.atanY(end));
|
||||
const rot = new Vector3(0, ry, 0);
|
||||
// TODO: fix rx and rz = 0
|
||||
// TODO: calculate length
|
||||
super(id, start, rot, null, r, nextid, previd, id_station, start_slope, end_slope, id_isolation, prefab_name, maxspeed, derailspeed);
|
||||
const [rot, len] = PointTrack._getRotLen(start, end, r);
|
||||
super(id, start, rot, len, r, nextid, previd, id_station, start_slope, end_slope, id_isolation, prefab_name, maxspeed, derailspeed);
|
||||
|
||||
Object.assign(this.points, {
|
||||
start, end
|
||||
});
|
||||
}
|
||||
|
||||
static _getRotLen(start, end, r) {
|
||||
// TODO: include track slope in calculations
|
||||
const pointsAngle = start.atanY(end);
|
||||
|
||||
if(r === 0) {
|
||||
const rot = new Vector3(0, AngleHelper.radToDeg(pointsAngle), 0);
|
||||
const len = start.distance(end);
|
||||
|
||||
return [rot, len];
|
||||
}
|
||||
|
||||
const len = Math.abs(2 * r * Math.asin(start.distance(end) / (2 * r)));
|
||||
const ry = pointsAngle + len / (r * 2);
|
||||
|
||||
const rot = new Vector3(0, AngleHelper.radToDeg(ry), 0);
|
||||
return [rot, len];
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ export default class Vector3 {
|
||||
atanY(other) {
|
||||
const dx = other.x - this.x;
|
||||
const dz = other.z - this.z;
|
||||
return Math.atan2(dz, dx);
|
||||
return Math.atan2(dx, dz);
|
||||
}
|
||||
|
||||
add(other) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user