简体   繁体   中英

C++ Rotating Cube in Coordinates (non-draw)

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.

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'|

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM