Skip to content

Cap gamepad axis range#21

Closed
KoltesDigital wants to merge 1 commit intofand:masterfrom
KoltesDigital:patch-1
Closed

Cap gamepad axis range#21
KoltesDigital wants to merge 1 commit intofand:masterfrom
KoltesDigital:patch-1

Conversation

@KoltesDigital
Copy link
Contributor

Otherwise it wraps to 0 when axis is 1.

Otherwise it wraps to 0 when axis is 1.
@fand
Copy link
Owner

fand commented Jul 6, 2018

thx for PR!
I didn't know that 256 is wrapped to 0 in Uint8Array😫

hmm, Math.min(axis * 128 + 128, 255); works well, but it's kind of hack.
It looks that UnsignedByteType is not suitable for representing axis data...
We should replace it with float texture because Gamepad API returns float values:
https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/axes

It's a breaking change but is reasonable, IMO

@KoltesDigital
Copy link
Contributor Author

Oh come on, your code tells you're an excellent coder!

I thought it was on purpose, because with floats it'll take four times the space in memory. 256 values is good enough for gamepad values.

@fand
Copy link
Owner

fand commented Jul 6, 2018

Currently the DataTexture takes 256 bytes (=256 * 1byte)
If we choodse float texture and use Float32Array, the array takes only 1KB (= 128 * 2 * 4bytes).
This difference is ignorable in modern PC.

@KoltesDigital
Copy link
Contributor Author

Superseded by #24 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants