@Anton我坚持这种翻转。
我从here下载了该项目。 我有四个按钮,每个按钮将标题设置为str变量的右,左,底,顶。
渲染初始旋转轴为teapotNode_.rotationAxis = CC3VectorMake(0.1,1,0.3);
- (void)update:(float)dt
{
if ([str isEqualToString:@"right"])
{
teapotNode_.rotationAxis = CC3VectorMake(0.1, 1, 0.3);
angle +=2.0;
}
else if ([str isEqualToString:@"left"])
{
teapotNode_.rotationAxis = CC3VectorMake(0.1, 1, 0.3);
angle -=2.0;
}
else if ([str isEqualToString:@"bottom"])
{
teapotNode_.rotationAxis = CC3VectorMake(1,0,0);
angle +=2.0;
}
else if ([str isEqualToString:@"top"])
{
teapotNode_.rotationAxis = CC3VectorMake(1,0,0);
angle -=2.0;
}
else{
angle +=2.0;
}
teapotNode_.rotationAngle = angle;
}
我触摸顶部(或)向下旋转按钮更改轴 teapotNode_.rotationAxis = CC3VectorMake(1,0,0);对象翻转。
我希望使用相同的轴位置将对象从上到下,从下到上旋转。
答案 0 :(得分:1)
解决方案是:
你自己说旋转轴值为(0.1,1,0.3)的初始值。所以不要改变这个价值。
该项目本身具有单独的轮换功能。那是teapotNode_.rotation
像这样使用。它对我来说很好。试试这个。
全球声明:
float x=0.0;
float y=0.0;
float z=0.0;
float angle;
float rangle=2.0;
float xangle;
float yangle;
- (void)update:(float)dt
{
if ([str isEqualToString:@"right"])
{
x=0; y=1; z=0; //ROTATE OBJECT IN Y-AXIS(Y=1 & X=0)
yAngle+=rAngle; //GET ANGLE OF OBJECT ROTATION IN Y-AXIS (ANTI CLOCKWISE)
angle +=rAngle; //INCREMENT ANGLE OF OBJECT ROTATION IN ANTICLOCLWISE
}
else if ([str isEqualToString:@"left"])
{
x=0; y=1; z=0; //ROTATE OBJECT IN Y-AXIS(Y=1 & X=0)
yAngle-=rAngle; //GET ANGLE OF OBJECT ROTATION IN Y-AXIS (CLOCLWISE)
angle -= rAngle; //INC ANGLE OF OBJECT ROTATION IN CLOCKWISE
}
else if ([str isEqualToString:@"bottom"])
{
x=1; y=0; z=0; //ROTATE OBJECT IN X-AXIS(X=1 & Y=0)
xAngle+=rAngle; //GET ANGLE OF OBJECT ROTATION IN X-AXIS (ANTI CLOCKWISE)
angle += rAngle; //INC ANGLE OF OBJECT ROTATION
}
else if ([str isEqualToString:@"top"])
{
x=1; y=0; z=0 ; //ROTATE OBJECT IN Y-AXIS(X=1 & Y=0)
xAngle-=rAngle; //GET ANGLE OF OBJECT ROTATION IN X-AXIS (CLOCLWISE)
angle -= rAngle; //INC ANGLE OF OBJECT ROTATION
}
else
{
angle +=rAngle;
}
// teapotNode_.rotationAxis = CC3VectorMake(x, y, z);
// teapotNode_.rotationAngle = angle;
teapotNode_.rotation = CC3VectorMake(xAngle, yAngle, 0);
}