Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GlobeControls: Scroll normalization #456

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions example/src/controls/PivotPointMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class PivotPointMesh extends Mesh {

const uniforms = this.material.uniforms;
renderer.getSize( uniforms.resolution.value );
uniforms.pixelRatio.value = renderer.getPixelRatio();
uniforms.thickness.value = 2.0 / renderer.getPixelRatio();

}

Expand Down Expand Up @@ -44,9 +44,8 @@ class PivotMaterial extends ShaderMaterial {
uniforms: {

resolution: { value: new Vector2() },
pixelRatio: { value: 1 },
size: { value: 7.5 },
thickness: { value: 1 },
size: { value: 15 },
thickness: { value: 2 },
opacity: { value: 1 },

},
Expand All @@ -68,7 +67,7 @@ class PivotMaterial extends ShaderMaterial {
offset.y *= aspect;

vec4 screenPoint = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
screenPoint.xy += offset * pixelRatio * ( size + thickness ) * screenPoint.w / resolution.x;
screenPoint.xy += offset * ( size + thickness ) * screenPoint.w / resolution.x;

gl_Position = screenPoint;

Expand All @@ -91,7 +90,7 @@ class PivotMaterial extends ShaderMaterial {

vec2 vec = vUv * 2.0 - vec2( 1.0 );
float dist = abs( length( vec ) - offset );
float fw = fwidth( dist );
float fw = fwidth( dist ) * 0.5;
float a = smoothstep( texelThickness - fw, texelThickness + fw, dist );

gl_FragColor = vec4( 1, 1, 1, opacity * ( 1.0 - a ) );
Expand Down
20 changes: 19 additions & 1 deletion example/src/controls/TileControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,26 @@ export class TileControls extends EventDispatcher {

const wheelCallback = e => {

let delta;
switch ( e.deltaMode ) {

case 2: // Pages
delta = e.deltaY * 100;
break;
case 1: // Lines
delta = e.deltaY * 16;
break;
case 0: // Pixels
delta = e.deltaY;
break;

}

// use LOG to scale the scroll delta and hopefully normalize them across platforms
const deltaSign = Math.sign( delta );
const normalizedDelta = Math.log( Math.abs( delta ) + 1 );
this.zoomDelta -= 3 * deltaSign * normalizedDelta;
this.needsUpdate = true;
this.zoomDelta -= e.deltaY;

};

Expand Down
Loading