在我的项目中,我必须旋转OBJ文件。我有恒定的枢轴点。我完全得到了水平旋转。现在我必须将我的OBJ文件旋转为垂直。我得出结论,必须自己改变角度。给出在恒定的枢轴点垂直旋转的想法。
我的枢轴点是teapotNode_.rotationAxis = CC3VectorMake(0.1,1,0.3);
-(void)rightButtonPressed {
float angle;
teapotNode_.rotationAxis = CC3VectorMake(0.1, 1, 0.3);
angle +=2.0;
director_.running = YES;//Redirector object
if (director_.frameInterval == 2)
{
director_.running = NO;
}
}
-(void)leftButtonPressed {
float angle;
teapotNode_.rotationAxis = CC3VectorMake(0.1, 1, 0.3);
angle -=2.0;
director_.running = YES;//Redirector object
if (director_.frameInterval == 2)
{
director_.running = NO;
}
}
-(void)topButtonPressed {
float angle;
teapotNode_.rotationAxis = CC3VectorMake(0.1, 0, 0); ***//changed the Pivot point.***
angle +=2.0; **//how to calculate the Top Down angle.**
director_.running = YES;//Redirector object
if (director_.frameInterval == 2)
{
director_.running = NO;
}
}
我在这个rend-ios项目中找到了自己https://github.com/antonholmquist/rend-ios的答案。
实际上,问题是单击向右和向左按钮时旋转正常,就像顶部和底部旋转也正常一样。但是,当我单击右上/下时,该对象正在旋转,但是闪烁。
解决方案是:
Globally declared:
float x=0.0;
float y=0.0;
float z=0.0;
float angle;
float xangle;
float yangle;
-(void)rightButtonPressed {
x=0; y=1; z=0; //ROTATE OBJECT IN Y-AXIS(Y=1 & X=0)
yAngle+=2.0; //GET ANGLE OF OBJECT ROTATION IN Y-AXIS (ANTI CLOCKWISE)
angle +=2.0;
teapotNode_.rotationAxis = CC3VectorMake(x,y,z);
teapotNode_.rotation = CC3VectorMake(0, yAngle, 0);
director_.running = YES;//Redirector object
if (director_.frameInterval == 2)
{
director_.running = NO;
}
}
-(void)leftButtonPressed {
x=0; y=1; z=0; //ROTATE OBJECT IN Y-AXIS(Y=1 & X=0)
yAngle-=2.0; //GET ANGLE OF OBJECT ROTATION IN Y-AXIS (CLOCKWISE)
angle -=2.0;
teapotNode_.rotationAxis = CC3VectorMake(x,y,z);
teapotNode_.rotation = CC3VectorMake(0, yAngle, 0);
director_.running = YES;//Redirector object
if (director_.frameInterval == 2)
{
director_.running = NO;
}
}
-(void)topButtonPressed {
//Existing
/*float angle;
teapotNode_.rotationAxis = CC3VectorMake(0.1, 0, 0); //Changed the Pivot point.
angle +=2.0; //how to calculate the Top Down angle.
*/
//Modified
x=1; y=0; z=0; //ROTATE OBJECT IN Y-AXIS(Y=0 & X=1)
xAngle+=2.0; //GET ANGLE OF OBJECT ROTATION IN Y-AXIS (Top Down)
angle +=2.0;
teapotNode_.rotationAxis = CC3VectorMake(x,y,z);
teapotNode_.rotation = CC3VectorMake(xangle, 0, 0);
director_.running = YES;//Redirector object
if (director_.frameInterval == 2)
{
director_.running = NO;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句