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.