Log In  
Log In  

Cart [#40228#] | Code | 2017-05-06 | License: CC4-BY-NC-SA | Embed
6

Just a simple little 2D-rotation example.

The function takes a 2D position (X,Y) and rotates it by ANGLE. CX,CY represents the center/pivot point.

The lines of code in the middle are the rotation matrix:

local rotx=cosa*x-sina*y
local roty=sina*x+cosa*y

This rotates a point around the origin. Before and after doing so, we offset our position by our center coordinate - this lets us rotate around any arbitrary pivot point.

For bonus points: When you're rotating lots of objects by the same angle (like a camera rotating, or a complex prop rotating), you can re-use your SINA and COSA values.

P#40230 2017-05-05 22:07 ( Edited 2017-05-06 02:12)


[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-05-22 10:49 | 0.013s | 2097k | Q:22