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

[Task] Optimize trigonometry out of MapblockMeshGenerator::drawLiquidTop #13217

Closed
numberZero opened this issue Feb 17, 2023 · 4 comments · Fixed by #13599
Closed

[Task] Optimize trigonometry out of MapblockMeshGenerator::drawLiquidTop #13217

numberZero opened this issue Feb 17, 2023 · 4 comments · Fixed by #13599

Comments

@numberZero
Copy link
Contributor

f32 tcoord_angle = atan2(dz, dx) * core::RADTODEG;
v2f tcoord_center(0.5, 0.5);
v2f tcoord_translate(blockpos_nodes.Z + p.Z, blockpos_nodes.X + p.X);
tcoord_translate.rotateBy(tcoord_angle);
tcoord_translate.X -= floor(tcoord_translate.X);
tcoord_translate.Y -= floor(tcoord_translate.Y);
for (video::S3DVertex &vertex : vertices) {
vertex.TCoords.rotateBy(tcoord_angle, tcoord_center);
vertex.TCoords += tcoord_translate;
}

Using atan2, sin, and cos (in rotateBy) is not necessary for rotation as $\frac{\sin(\mathrm{atan2}(y, x))}{\cos(\mathrm{atan2}(y, x))} = \frac{y}{x}$.

@arihant2math
Copy link

arihant2math commented Feb 19, 2023

@numberZero
Copy link
Contributor Author

Where does the division happen?

It doesn’t. It’s just an equation that holds.

@numberZero
Copy link
Contributor Author

numberZero commented Feb 19, 2023

Basically, treat atan2 arguments as a vector, normalize it, and you get sine and cosine of the angle atan2 would return. Watch out for signs though.

@numberZero
Copy link
Contributor Author

5276c16

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

Successfully merging a pull request may close this issue.

3 participants