简体   繁体   English

坐标中的C ++旋转立方体(非绘制)

[英]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. 我的目标是设置光标位置,以使其形成旋转立方体的方式与OpenGL旋转立方体边框类似。

Since OpenGL has a rotate function built it, it's not really something I can adapt to. 由于OpenGL内置了旋转功能,因此我无法适应。 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. 如果您想知道此点是什么,则在每个创建的帧(多维数据集旋转点)上,它都具有擦除在MsPaint中绘制的所有内容的功能,然后开始绘制下一个位置,基本上是创建一个正在绘制的旋转多维数据集。

If you try to rotate cube in C without help of any specialized library you should use Matrix operations to transform coordinates. 如果您尝试在C语言中旋转多维数据集而没有任何专用库的帮助,则应使用Matrix操作转换坐标。

  1. You sohuld get roatation matrix (Let's call it M ) 您将获得旋转矩阵(我们称其为M
  2. You should multiply M to your coordinates vector - result is new coordinates. 您应该将M乘以座标向量-结果是新座标。

for 2D rotation, example (f - rotation angle, +- is rotation direction): 对于2D旋转,例如(f-旋转角度,+-是旋转方向):

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

for 3D rotation, you should use 3x3 marix. 对于3D旋转,应使用3x3像素。 Alsoo you should rotation axis, depending on it you should choose matrix M : 另外,您还应该旋转轴,并根据它选择矩阵M

Mx (rotate around x axis): Mx (绕x轴旋转):

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

My (rotate around y axis): 我的 (绕y轴旋转):

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

Mz (rotate around z axis): Mz (绕z轴旋转):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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