Skip to content

Commit

Permalink
Merge pull request #8 from Carifio24/fix-arrow
Browse files Browse the repository at this point in the history
Fix issue with arrow potentially not loading
  • Loading branch information
patudom authored Mar 1, 2024
2 parents 3e45812 + 3d0a218 commit 527ecb8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
44 changes: 20 additions & 24 deletions src/M101SN.vue
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ import { applyImageSetLayerSetting } from "@wwtelescope/engine-helpers";
import { GotoRADecZoomParams } from "@wwtelescope/engine-pinia";
import { drawSkyOverlays, initializeConstellationNames, makeAltAzGridText, drawSpreadSheetLayer, layerManagerDraw } from "./wwt-hacks";
import { drawSkyOverlays, getScreenPosForCoordinates, initializeConstellationNames, makeAltAzGridText, drawSpreadSheetLayer, layerManagerDraw } from "./wwt-hacks";
interface MoveOptions {
instant?: boolean;
Expand All @@ -614,6 +614,7 @@ import {
const D2R = Math.PI / 180;
const R2D = 180 / Math.PI;
const D2H = 1 / 15;
const SECONDS_PER_DAY = 60 * 60 * 24;
const MILLISECONDS_PER_DAY = 1000 * SECONDS_PER_DAY;
Expand Down Expand Up @@ -758,6 +759,7 @@ export default defineComponent({
m101RADeg: 3.681181581357794 * R2D + 0.2/60,
m101DecDeg: 0.9480289529731357 * R2D - 1/60,
arrowAngleDeg: -60,
arrowCreated: false,
showSpeadSheetLater: false,
Expand Down Expand Up @@ -939,26 +941,18 @@ export default defineComponent({
setTimeout(() => {
this.centerView();
this.positionSet = true;
}, 100);
this.gotoRADecZoom({
raRad: D2R * this.initialPosition.ra,
decRad: D2R * this.initialPosition.dec,
zoomDeg: 2,
instant: true
});
setTimeout(() => {
this.createArrow();
if (this.showArrow) {
this.displayArrow();
}
this.gotoRADecZoom({
raRad: this.wwtRARad,
decRad: this.wwtDecRad,
zoomDeg: this.initialPosition.zoom,
instant: true
});
const createArrowFunction = () => {
try {
this.createArrow();
if (this.showArrow) {
this.displayArrow();
}
} catch (err) {
setTimeout(createArrowFunction, 100);
}
};
setTimeout(createArrowFunction, 100);
}, 100);
});
Expand Down Expand Up @@ -1119,7 +1113,7 @@ export default defineComponent({
createArrow() {
const m101XY = this.findScreenPointForRADec({ra: this.m101RADeg, dec: this.m101DecDeg});
const m101XY = getScreenPosForCoordinates(this.wwtControl, this.m101RADeg * D2H, this.m101DecDeg);
const m101Point: Point = [m101XY.x, m101XY.y];
// Create the outer (purple) arrow
Expand Down Expand Up @@ -1148,7 +1142,7 @@ export default defineComponent({
outerArrowCoordinates.push([headBackRA, bottomDec]);
for (const coords of outerArrowCoordinates) {
const point = this.findScreenPointForRADec({ra: coords[0], dec: coords[1]});
const point = getScreenPosForCoordinates(this.wwtControl, coords[0] * D2H, coords[1]);
const rotatedPoint = this.rotatePoint([point.x, point.y], m101Point, this.arrowAngleDeg);
const rotatedCoords = this.findRADecForScreenPoint({x: rotatedPoint[0], y: rotatedPoint[1]});
this.outerArrow.addPoint(rotatedCoords.ra, rotatedCoords.dec);
Expand Down Expand Up @@ -1181,7 +1175,7 @@ export default defineComponent({
innerArrowCoordinates.push([innerHeadBackRA, innerBottomDec]);
for (const coords of innerArrowCoordinates) {
const point = this.findScreenPointForRADec({ra: coords[0], dec: coords[1]});
const point = getScreenPosForCoordinates(this.wwtControl, coords[0] * D2H, coords[1]);
const rotatedPoint = this.rotatePoint([point.x, point.y], m101Point, this.arrowAngleDeg);
const rotatedCoords = this.findRADecForScreenPoint({x: rotatedPoint[0], y: rotatedPoint[1]});
this.innerArrow.addPoint(rotatedCoords.ra, rotatedCoords.dec);
Expand All @@ -1191,10 +1185,12 @@ export default defineComponent({
this.innerArrow.set_lineColor(innerColor);
this.innerArrow.set_fillColor(innerColor);
this.innerArrow.set_fill(true);
this.arrowCreated = true;
},
displayArrow() {
if (this.outerArrow == null || this.innerArrow == null) {
if (!this.arrowCreated) {
this.createArrow();
}
if (this.outerArrow) {
Expand Down
22 changes: 20 additions & 2 deletions src/wwt-hacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import {
Color, Colors, Constellations, Coordinates, Grids,
LayerManager, LayerMap, PushPin, Settings, SpaceTimeController,
SpreadSheetLayer, Text3d, Text3dBatch, URLHelpers,
LayerManager, Matrix3d, PushPin, Settings, SpaceTimeController,
SpreadSheetLayer, Text3d, Text3dBatch, URLHelpers, Vector2d,
Vector3d, WWTControl
} from "@wwtelescope/engine";

Expand Down Expand Up @@ -192,3 +192,21 @@ export function layerManagerDraw(renderContext, opacity, astronomical, reference
renderContext.set_world(matOld);
renderContext.set_worldBaseNonRotating(matOldNonRotating);
};

function transformWorldPointToPickSpace(wwtControl, worldPoint, backBufferWidth, backBufferHeight) {
var m = Matrix3d.multiplyMatrix(wwtControl.renderContext.get_world(), wwtControl.renderContext.get_view());
var p = new Vector2d();
var vz = worldPoint.x * m.get_m13() + worldPoint.y * m.get_m23() + worldPoint.z * m.get_m33();
var vx = (worldPoint.x * m.get_m11() + worldPoint.y * m.get_m21() + worldPoint.z * m.get_m31()) / vz;
var vy = -(worldPoint.x * m.get_m12() + worldPoint.y * m.get_m22() + worldPoint.z * m.get_m32()) / vz;
p.x = (1 + wwtControl.renderContext.get_projection().get_m11() * vx) * (backBufferWidth / 2);
p.y = (1 + wwtControl.renderContext.get_projection().get_m22() * vy) * (backBufferHeight / 2);
return p;
}

export function getScreenPosForCoordinates(wwtControl, ra, dec) {
var pt = Vector2d.create(ra, dec);
var cartesian = Coordinates.sphericalSkyToCartesian(pt);
var result = transformWorldPointToPickSpace(wwtControl, cartesian, wwtControl.renderContext.width, wwtControl.renderContext.height);
return result;
}

0 comments on commit 527ecb8

Please sign in to comment.