0

I've been looking for this for quite a long time without any results, been trying to figure out the math for this myself for about a week+.

My goal is to set my cursor position(s) so in the way that it forms a rotating cube much in the way like an OpenGL rotating cube border box would.

Since OpenGL has a rotate function built it, it's not really something I can adapt to. I just wonder if anyone has any ideas how I'd go about this. If you're wondering what the point of this is, on each created frame(cube rotating point) it has a function to erase anything drawn in MsPaint and then the next positions begin drawing, basically to create a spinning cube being drawn.

Harino
  • 11
  • 1
  • I don't want to write an extended post right now, but see https://en.wikipedia.org/wiki/Rotation_matrix You might also want to look into the glm (OpenGL mathematics) library. – Adrian Roman Sep 11 '16 at 07:50
  • This isn't very clear. What's the connection between the cursor, the rotating cube, and MS Paint? And which cursor are you looking to set? – molbdnilo Sep 11 '16 at 08:09
  • You can start from here: https://en.wikipedia.org/wiki/Affine_transformation. – max_hassen Sep 11 '16 at 08:31

1 Answers1

0

If you try to rotate cube in C without help of any specialized library you should use Matrix operations to transform coordinates.

  1. You sohuld get roatation matrix (Let's call it M)
  2. You should multiply M to your coordinates vector - result is new coordinates.

for 2D rotation, example (f - rotation angle, +- is rotation direction):

|cos f +-sin f| |x|   |x'|
|             | | | = |  |
|+-sin f cos f| |y|   |y'|

for 3D rotation, you should use 3x3 marix. Alsoo you should rotation axis, depending on it you should choose matrix M:

Mx (rotate around x axis):

|1      0       0 ||x|   |x'|
|0   cos f  -sin f||y| = |y'|                       
|0   sin f   cos f||z|   |z'|

My (rotate around y axis):

|cos f      0      sin f ||x|   |x'|
| 0         1      0     ||y| = |y'|                       
|-sin f     0      cos f ||z|   |z'|

Mz (rotate around z axis):

| cos f   -sin f    0    ||x|   |x'|
| sin f   cos f     0    ||y| = |y'|                       
| 0        0        1    ||z|   |z'|
Maxim Kitsenko
  • 2,042
  • 1
  • 20
  • 43