【问题标题】:OpenGl rendering in iOSiOS 中的 OpenGL 渲染
【发布时间】:2013-07-30 06:54:58
【问题描述】:

在我的项目中,我必须旋转一个 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;

}        
}

【问题讨论】:

  • 左右旋转工作正常。自上而下的旋转也可以工作,但是当我突然单击顶部按钮时,渲染图像会闪烁。 b'coz 我改变了枢轴点。我的问题是枢轴点是恒定的。我必须改变角度本身。所以我要求为垂直渲染提供角度计算。
  • 提及您在项目中使用的示例代码链接,以便我们回答您的问题
  • 我从github.com/antonholmquist/rend-ios下载了项目。

标签: iphone ios opengl-es rendering


【解决方案1】:

我在这个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;

}        
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 2013-01-06
    • 1970-01-01
    相关资源
    最近更新 更多