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

Simpler rotations #2

Open
atesgoral opened this issue Dec 5, 2022 · 0 comments
Open

Simpler rotations #2

atesgoral opened this issue Dec 5, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@atesgoral
Copy link

atesgoral commented Dec 5, 2022

While reading through your work (THANK YOU! ❤️ ) to understand the scan pattern, I noticed that there could be some room for making things easier to maintain and bringing support for flipping.

Instead of mutating the position array, you could do a fast transformation matrix multiplication during rendering. Bonus: the same transformation matrix can also be used for horizontal/vertical flipping.

Here's how I use a transformation matrix in my FREKVENS hack:
https://github.com/atesgoral/node-omega-frekvens/blob/master/lib/frekvens/src/OmegaDriver.cpp#L51-L58

        char colT = (colCx2
          + colNx2 * m_transform[0]
          + rowNx2 * m_transform[1])
          >> 1;
        char rowT = (rowCx2
          + colNx2 * m_transform[2]
          + rowNx2 * m_transform[3])
          >> 1;

And here's how that transformation matrix is set up, based on rotation and flip:

https://github.com/atesgoral/node-omega-frekvens/blob/master/index.js#L181-L205

  let transform = Int8Array.from([
    1, 0,
    0, 1
  ]);

  if (process.env.ROTATE) {
    const turns = parseInt(process.env.ROTATE);
    const theta = Math.PI / 2 * turns;
    const sin = Math.round(Math.sin(theta));
    const cos = Math.round(Math.cos(theta));

    transform = Int8Array.from([
      cos, -sin,
      sin, cos
    ]);
  }

  switch (process.env.FLIP) {
    case 'H':
      transform[0] = -transform[0];
      break;
    case 'V':
      transform[3] = -transform[3];
      break;
  }
@ph1p ph1p added the enhancement New feature or request label Dec 23, 2022
semicuda pushed a commit to semicuda/ikea-led-obegraensad that referenced this issue Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants