Skip to main content
Notice removed Authoritative reference needed by CommunityBot
Bounty Ended with no winning answer by CommunityBot
added 4 characters in body
Source Link
Itzik984
  • 205
  • 2
  • 11

Since i am rotating the model's axis, I get this problem (video)problem (video). the issue appears in the 23'd seconds, while i'm demonstrating how it works. As can been seen, when the z rotation causes a wrong x and y rotations.

Since i am rotating the model's axis, I get this problem (video). the issue appears in the 23'd seconds, while i'm demonstrating how it works. As can been seen, when the z rotation causes a wrong x and y rotations.

Since i am rotating the model's axis, I get this problem (video). the issue appears in the 23'd seconds, while i'm demonstrating how it works. As can been seen, when the z rotation causes a wrong x and y rotations.

edited body
Source Link
Itzik984
  • 205
  • 2
  • 11

Since i awam rotating the model's axis, I get this problem (video). the issue appears in the 23'd seconds, while i'm demonstrating how it works. As can been seen, when the z rotation causes a wrong x and y rotations.

Since i aw rotating the model's axis, I get this problem (video). the issue appears in the 23'd seconds, while i'm demonstrating how it works. As can been seen, when the z rotation causes a wrong x and y rotations.

Since i am rotating the model's axis, I get this problem (video). the issue appears in the 23'd seconds, while i'm demonstrating how it works. As can been seen, when the z rotation causes a wrong x and y rotations.

Notice added Authoritative reference needed by Itzik984
Bounty Started worth 50 reputation by Itzik984
added 570 characters in body
Source Link
Itzik984
  • 205
  • 2
  • 11

NowEDIT: Second attempt

As kindly explained by the user @Fault, fori understood the problems i was facing with. So i tried to solve those by just rotating the projection matrix around the z axis, which seemed to be working, but it doesn't.

Since i aw rotating the model's axis, I get this problem (video). the issue appears in the 23'd seconds, while i'm demonstrating how it works. As can been seen, when the z rotation causes a wrong x and y rotations.

I do understand that i must likely have to move these rotations to world view and not model view, the thing is i'm not really sure how to do that.

Here is the relevant code part:

The renderingRender function:

- (void)render:(CADisplayLink*)displayLink {
    ...
    
    CC3GLMatrix *projection = [CC3GLMatrix matrix];
    float h = 4.0f * self.frame.size.height / self.frame.size.width;
    [projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:4 andFar:100];
    [projection rotateByZ:zRotationEnd];
    glUniformMatrix4fv(_projectionUniform, 1, 0, projection.glMatrix);
    
    [modelView populateFromTranslation:_currentPan];
    [modelView rotateBy:_currentRotation];
    [modelView rotateByZ:zRotationEnd];

    glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix);
    ...        
}
- (void) rotateAroundX:(float) x andY:(float) y newRotate:(BOOL) isNewRotate
{
    if (isNewRotate) {
        rotationStart = CC3VectorMake(0.0, 0.0, 0.0);
    }
    rotationEnd.x 
 = rotationEnd.x + int rotationDirection = ceil(x-rotationStart.xzRotationEnd/90);
    rotationEnd.yif =(rotationDirection rotationEnd.y% +4 (y-rotationStart.y);

== 2 || rotationDirection rotationStart.x% =4 x;
== 3) {
  rotationStart.y = y;
    _currentRotationrotationEnd.x = CC3VectorMake(rotationEnd.y,x rotationEnd- (x-rotationStart.x, 0);
}

And the relevant calling part:

if(sender.numberOfTouches == 1)
    {
  rotationEnd.y = rotationEnd.y - (y-rotationStart.y);
  BOOL started =} false;
else {
       CGPoint rotationrotationEnd.x = [sender translationInView:senderrotationEnd.view];
        float x =+ rotation(x-rotationStart.x;x);
        float rotationEnd.y = rotationrotationEnd.y;
       y if+ (sendery-rotationStart.state == UIGestureRecognizerStateBegany);
    }
    {
    

    rotationStart.x = x;
    startedrotationStart.y = true;y;
    _currentRotation = CC3VectorMake(rotationEnd.y, rotationEnd.x, }0);
        [self.glViewNSLog(@"Current rotateAroundX:x andYis: %f y newRotateis:started];
 %f z is: %f",_currentRotation.x,_currentRotation.y,zRotationEnd);

}

The Z rotation functionrotations:

And the relevant calling partvertex shader:

- (IBAction)rotation:(UIRotationGestureRecognizerattribute *)sendervec4 {Position;
    BOOL startedattribute =vec4 false;SourceColor;
  
varying vec4 floatDestinationColor;

uniform rotationmat4 =Projection;
uniform RadiansToDegrees([sendermat4 rotation]);Modelview;

attribute vec2 TexCoordIn;
varying vec2 ifTexCoordOut;

void main(sender.state == UIGestureRecognizerStateBeganvoid)
    {
        startedDestinationColor = true;SourceColor;
    }
gl_Position = Projection * [self.glViewModelview rotateAroundZ:rotation* newRotate:started];Position;
    NSLog(@"RotationTexCoordOut %f",= rotation);TexCoordIn;
}

I really can't point my finger on what i'm doing wrong over here. Wouldwould really appreciatelike to get this right, so any help will be appreciated.

Now, for the code part:

The rendering function:

- (void)render:(CADisplayLink*)displayLink {
    ...
    
    CC3GLMatrix *projection = [CC3GLMatrix matrix];
    float h = 4.0f * self.frame.size.height / self.frame.size.width;
    [projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:4 andFar:100];
    glUniformMatrix4fv(_projectionUniform, 1, 0, projection.glMatrix);
    
    [modelView populateFromTranslation:_currentPan];
    [modelView rotateBy:_currentRotation];
    [modelView rotateByZ:zRotationEnd];

    glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix);
    ...        
}
- (void) rotateAroundX:(float) x andY:(float) y newRotate:(BOOL) isNewRotate
{
    if (isNewRotate) {
        rotationStart = CC3VectorMake(0.0, 0.0, 0.0);
    }
    rotationEnd.x = rotationEnd.x + (x-rotationStart.x);
    rotationEnd.y = rotationEnd.y + (y-rotationStart.y);

    rotationStart.x = x;
    rotationStart.y = y;
    _currentRotation = CC3VectorMake(rotationEnd.y, rotationEnd.x, 0);
}

And the relevant calling part:

if(sender.numberOfTouches == 1)
    {
        BOOL started = false;
        CGPoint rotation = [sender translationInView:sender.view];
        float x = rotation.x;
        float y = rotation.y;
        if (sender.state == UIGestureRecognizerStateBegan)
        {
            started = true;
        }
        [self.glView rotateAroundX:x andY:y newRotate:started];
    }

The Z rotation function:

And the relevant calling part:

- (IBAction)rotation:(UIRotationGestureRecognizer *)sender {
    BOOL started = false;
    float rotation = RadiansToDegrees([sender rotation]);
    if (sender.state == UIGestureRecognizerStateBegan)
    {
        started = true;
    }
    [self.glView rotateAroundZ:rotation newRotate:started];
    NSLog(@"Rotation %f", rotation);
}

I really can't point my finger on what i'm doing wrong over here. Would really appreciate any help.

EDIT: Second attempt

As kindly explained by the user @Fault, i understood the problems i was facing with. So i tried to solve those by just rotating the projection matrix around the z axis, which seemed to be working, but it doesn't.

Since i aw rotating the model's axis, I get this problem (video). the issue appears in the 23'd seconds, while i'm demonstrating how it works. As can been seen, when the z rotation causes a wrong x and y rotations.

I do understand that i must likely have to move these rotations to world view and not model view, the thing is i'm not really sure how to do that.

Here is the relevant code:

Render function:

{
...
 
    CC3GLMatrix *projection = [CC3GLMatrix matrix];
    float h = 4.0f * self.frame.size.height / self.frame.size.width;
    [projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:4 andFar:100];
    [projection rotateByZ:zRotationEnd];
    glUniformMatrix4fv(_projectionUniform, 1, 0, projection.glMatrix);
    
    [modelView populateFromTranslation:_currentPan];
    [modelView rotateBy:_currentRotation];
    

    glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix);
...
}
- (void) rotateAroundX:(float) x andY:(float) y newRotate:(BOOL) isNewRotate
{
    if (isNewRotate) {
        rotationStart = CC3VectorMake(0.0, 0.0, 0.0);
    }
     
    int rotationDirection = ceil(zRotationEnd/90);
    if (rotationDirection % 4 == 2 || rotationDirection % 4 == 3) {
        rotationEnd.x = rotationEnd.x - (x-rotationStart.x);
        rotationEnd.y = rotationEnd.y - (y-rotationStart.y);
    } else {
        rotationEnd.x = rotationEnd.x + (x-rotationStart.x);
        rotationEnd.y = rotationEnd.y + (y-rotationStart.y);
    }
    
    

    rotationStart.x = x;
    rotationStart.y = y;
    _currentRotation = CC3VectorMake(rotationEnd.y, rotationEnd.x, 0);
    NSLog(@"Current x is: %f y is: %f z is: %f",_currentRotation.x,_currentRotation.y,zRotationEnd);

}

Z rotations:

And the vertex shader:

attribute vec4 Position;
attribute vec4 SourceColor;

varying vec4 DestinationColor;

uniform mat4 Projection;
uniform mat4 Modelview;

attribute vec2 TexCoordIn;
varying vec2 TexCoordOut;

void main(void) {
    DestinationColor = SourceColor;
    gl_Position = Projection * Modelview * Position;
    TexCoordOut = TexCoordIn;
}

I would really like to get this right, so any help will be appreciated.

Tweeted twitter.com/#!/StackGameDev/status/441069124421423104
added 4 characters in body
Source Link
Itzik984
  • 205
  • 2
  • 11
Loading
Source Link
Itzik984
  • 205
  • 2
  • 11
Loading