Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #154 from CptWesley/api-rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
CptWesley authored Nov 7, 2021
2 parents 8ad7f67 + 9f02694 commit 8a184e0
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 28 deletions.
28 changes: 20 additions & 8 deletions overwolf/src/AppSettings/pages/WindowSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,29 @@ export default function WindowSettingsPage(props: IAppSettingsPageProps) {
{t('settings.window.resamplingRate')}
</label>
</div>
<div className={classes.setting} title={t('settings.window.showPlayerCoordinatesTooltip')}>
<label className={classes.checkbox}>
<input
type='checkbox'
checked={settings.showPlayerCoordinates}
onChange={e => updateSimpleSetting('showPlayerCoordinates', e.currentTarget.checked)}
/>
{t('settings.window.showPlayerCoordinates')}
<div className={classes.setting}>
<label className={classes.select} title={t('settings.window.rotationSourceTooltip')}>
<select
value={settings.rotationSource}
onChange={e => updateSimpleSetting('rotationSource', e.currentTarget.value as RotationSource)}
>
<option value='api'>{t('settings.window.rotationSourceApi')}</option>
<option value='computed'>{t('settings.window.rotationSourceComputed')}</option>
</select>
{t('settings.window.rotationSource')}
</label>
</div>
<AdvancedSettings>
<div className={classes.setting} title={t('settings.window.showPlayerCoordinatesTooltip')}>
<label className={classes.checkbox}>
<input
type='checkbox'
checked={settings.showPlayerCoordinates}
onChange={e => updateSimpleSetting('showPlayerCoordinates', e.currentTarget.checked)}
/>
{t('settings.window.showPlayerCoordinates')}
</label>
</div>
<div className={classes.setting} title={t('settings.window.showNavMeshTooltip')}>
<label className={classes.checkbox}>
<input
Expand Down
7 changes: 6 additions & 1 deletion overwolf/src/Global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ declare type IconSettings = {

declare type PlayerData = {
position: Vector3,
rotation: Vector3,
rotation: number,
compass: string,
map: string | undefined,
name: string | undefined,
Expand All @@ -66,6 +66,11 @@ type AnimationInterpolation =
| 'linear'
;

type RotationSource =
| 'api'
| 'computed'
;

declare type GraphNode = {
position: Vector2,
neighbors: number[],
Expand Down
6 changes: 3 additions & 3 deletions overwolf/src/Minimap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ export default function Minimap(props: IProps) {
zoomBy,
} = useMinimapRenderer(canvas, hoverLabelCanvas);

function setPosition(pos: Vector2) {
function setPosition(pos: Vector2, rotation: number) {
if (appContext.settings.shareLocation) {
const sharedLocation = updateFriendLocation(appContext.settings.channelsServerUrl, playerName.current, pos);
sharedLocation.then(setFriends);
}

store('lastKnownPosition', pos);
setPlayerPosition(pos);
setPlayerPosition(pos, rotation);
}

function setFriends(channels: undefined | FriendData[]) {
Expand Down Expand Up @@ -268,7 +268,7 @@ export default function Minimap(props: IProps) {
(window as any).setFriends = setFriends;

const callbackUnregister = registerEventCallback(info => {
setPosition(info.position);
setPosition(info.position, info.rotation);

if (info.name) {
playerName.current = info.name;
Expand Down
6 changes: 3 additions & 3 deletions overwolf/src/Minimap/useMinimapRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ export default function useMinimapRenderer(canvas: React.RefObject<HTMLCanvasEle
drawWithInterpolationRef.current(force);
}

function setPlayerPosition(pos: Vector2) {
function setPlayerPosition(pos: Vector2, rotation: number) {
if (pos.x === currentPlayerPosition.current.x && pos.y === currentPlayerPosition.current.y) {
return;
}

currentPlayerAngle.current = getAngle(lastPlayerPosition.current, currentPlayerPosition.current);
currentPlayerAngle.current = appContext.settings.rotationSource === 'computed' ? getAngle(lastPlayerPosition.current, currentPlayerPosition.current) : rotation;
lastPositionUpdate.current = performance.now();
lastPlayerPosition.current = currentPlayerPosition.current;
currentPlayerPosition.current = pos;
Expand All @@ -225,7 +225,7 @@ export default function useMinimapRenderer(canvas: React.RefObject<HTMLCanvasEle
const predictedPosition = predictVector(lastPlayerPosition.current, currentPlayerPosition.current);
updateInterpolatedPlayerPosition(predictedPosition, updateTime);
}
updateInterpolatedAngle(getAngle(lastPlayerPosition.current, currentPlayerPosition.current), updateTime);
updateInterpolatedAngle(currentPlayerAngle.current, updateTime);

redraw(true);
}
Expand Down
1 change: 1 addition & 0 deletions overwolf/src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function loadAppContextSettings(): AppContextSettings {
showNavMesh: load('showNavMesh'),
alwaysLaunchDesktop: load('alwaysLaunchDesktop'),
autoLaunchInGame: load('autoLaunchInGame'),
rotationSource: load('rotationSource'),
};
}

Expand Down
6 changes: 5 additions & 1 deletion overwolf/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@
"resamplingRate": "Upsampling factor",
"resamplingRateTooltip": "The number of samples taken when performing inter/extra-polation. A higher value will give a smoother experience, but has worse performance.",
"showNavMesh": "Show Nagivation Mesh",
"showNavMeshTooltip": "Shows the navigation mesh. Useful for debugging the navigation system. Causes a heavy performance hit. Don't enable unless necessary."
"showNavMeshTooltip": "Shows the navigation mesh. Useful for debugging the navigation system. Causes a heavy performance hit. Don't enable unless necessary.",
"rotationSource": "Rotation Data",
"rotationSourceTooltip": "Determines which source of rotation data is used when rendering player on the minimap.",
"rotationSourceApi": "Character Direction",
"rotationSourceComputed": "Movement Direction"
},
"overlay": {
"_": "In-game overlay",
Expand Down
6 changes: 1 addition & 5 deletions overwolf/src/logic/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ function transformData(info: any): PlayerData | undefined {
z: parseFloat(locationParts[5]),
};

const rotation = {
x: parseFloat(locationParts[7]),
y: parseFloat(locationParts[9]),
z: parseFloat(locationParts[11]),
};
const rotation = -(parseFloat(locationParts[11]) - 90) * Math.PI / 180;

const compass = locationParts[13].trim();

Expand Down
2 changes: 2 additions & 0 deletions overwolf/src/logic/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const simpleStorageDefaultSettings = {
showNavMesh: false,
alwaysLaunchDesktop: false,
autoLaunchInGame: true,
rotationSource: 'api' as RotationSource,
};

{
Expand Down Expand Up @@ -82,6 +83,7 @@ export const scopedSettings: (keyof SimpleStorageSetting)[] = [
'extrapolateLocation',
'resamplingRate',
'showNavMesh',
'rotationSource',
];

export const iconSettingStorageScope = 'icon';
Expand Down
8 changes: 1 addition & 7 deletions overwolf/src/logic/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getNumberInterpolator(animationInterpolation: AnimationInterpola

export function getAngleInterpolator(animationInterpolation: AnimationInterpolation): Interpolator<number> {
switch (animationInterpolation) {
case 'cosine': return interpolateAngleCosine;
case 'cosine': return interpolateAngleLinear;
case 'linear': return interpolateAngleLinear;
case 'none': return undefined;
}
Expand Down Expand Up @@ -79,12 +79,6 @@ export function interpolateVectorsCosine(start: Vector2, end: Vector2, percentag
};
}

export function interpolateAngleCosine(start: number, end: number, percentage: number) {
const mu = computeCosineInterpolationMu(percentage);
const bestEnd = correctEndAngle(start, end);
return start * (1 - mu) + bestEnd * mu;
}

function correctEndAngle(start: number, end: number) {
const alternativeEnd1 = end - Math.PI * 2;
const alternativeEnd2 = end + Math.PI * 2;
Expand Down

0 comments on commit 8a184e0

Please sign in to comment.