簡體   English   中英

iOS中的OpenGl渲染

[英]OpenGl rendering in iOS

在我的項目中,我必須旋轉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;

}        
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM