简体   繁体   中英

OpenGl rendering in iOS

In my project i have to rotate an OBJ file. i have constant pivot point. i got the horizontal rotation exactly.now i have to rotate my OBJ file as vertically. i concluded that have to change angle itself. give ideas to rotate vertically in that constant Pivot point.

my Pivot point is 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;

}        
}

I found answer myself https://github.com/antonholmquist/rend-ios in this rend-ios project.

Actually the problem is while clicking the right and left button the rotation is working properly, like top and bottom rotation is also working properly. but when i click right to top / bottom, the object is rotating but it flickered.

The solution is:

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;

}        
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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