简体   繁体   English

围绕中心旋转3D对象

[英]rotating 3D object around the center

I have object moving from A to B on x-axis and there is no translation of object apart from it. 我的对象在x轴上从A移动到B,并且没有平移的对象。 Now, while moving, i want to rotate it around y-axis and the motion should change accordingly, i mean if i rotate it right when moving from -x to +x axis, it should move towards near plane that is in z-direction. 现在,在移动时,我想绕y轴旋转它,并且运动应该相应地改变,这意味着如果我在从-x到+ x轴移动时向右旋转,它应该朝着z方向的近平面移动。 I am using perspective projection. 我正在使用透视投影。 I have variable in gltranslatef which is modified in the loop after that i have glscalef to scale whole object which is made of hierarchical structure. 我在gltranslatef中有一个变量,该变量在循环后被修改,而我有glscalef来缩放由分层结构组成的整个对象。 Now i tried following code to achieve the expected result but its not working properly. 现在,我尝试使用以下代码来达到预期的效果,但无法正常工作。

 glTranslatef(move, 0, 0);

// If I comment these 3 lines, it does not affect the output
     glTranslatef(-move, 0, 0);
glRotatef(rotate,0,1,0);
glTranslatef(move, 0, 0);

glScalef(0.2, 0.2, 1.0);

Your description is not accurate enough. 您的描述不够准确。 On one hand you mention to rotate it around the y-axis. 一方面,您提到要绕y轴旋转它。 On the other hand it should move towards the near plane. 另一方面,它应该向近平面移动。

The important question is: How have you setup your projection matrix? 重要的问题是:您如何设置投影矩阵? In general, what you try to achieve in your code doesn't look too bad. 通常,您尝试在代码中实现的效果看起来还不错。 However, you maybe have setup an orthogonal projection matrix. 但是,您可能已经设置了正交投影矩阵。

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

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