Cocoa, Xcode 3.0 OpenGL, glRotatef() bug like behaviour

Please have a look at the code.
When apllication launches, you can see a rotation with the preset angle, but changing the angle via UI has no
result. The debugger stops at the break point in drawRect, the new angle is displayed in the variable view,
but it seems, that openGL ignores the update.
If I replace [self rotateX] in drawRect with a constant, rotation takes place.
I cannot make senese of this behaviour.
      rotateX = 30.0;
-(GLfloat)rotateX {return rotateX;}
        rotateX = rx;
        [self setNeedsDisplay:YES];
- (void) drawRect:(NSRect)rect
        GLfloat rx = [self rotateX];
        NSLog(@"rx = %.2f \n", rx);     // console:  rx = 32.56
        glRotatef(rx, 1.0, 0.0, 0.0);
        glFlush ();

Open in new window

Who is Participating?
VanceRegentAuthor Commented:
I found a solution :
Don't know why, but the variable should be defined outside the implementation body as
static GLfloat rotateX.

Now I can call myself an expert.
I think you're not supplying radians, but you're supplying normal angles.

Make sure you are using RADIANs and not normal 360 degree angles of rotation.

VanceRegentAuthor Commented:
I am familiar with radians, but in this case I have to use degrees (see OpenGL Reference Manual,
page 443) .
The first call of drawRect uses the rotation value which was initialized in the awakeFromNib method
and rotation accured.
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Yes, I see that now.  I guess I should look it up and not go from memory....


Something is odd....

You have
rotateX = 30.0;

Your getter...

GLfloat)rotateX {return rotateX;}

but the console prints  "32.56" on this line, yes?

NSLog(@"rx = %.2f \n", rx);     // console:  rx = 32.56

I'd look for a problem with my stack.

This makes no sense to me at all.  I'd expect it to be exactly the same as the value I just set.. ie, 30.0.

But i'd not name my member variable "rotateX" and my getter "rotateX".


VanceRegentAuthor Commented:
Meanwhile I learned, that  setNeedsDisplay:Yes is dispenable. If I just clck on the slider, the debugger stops in drawRect, I assume because the meber rotateX appears in there. But this is not something that brings me further. Wether it is a bug or I do something illegal.
So, is


a member? or a method? is it a getter?  

This looks a lot like objective C to me, but I'm unsure exactly what's going on here.

Should this be something like

@property GLfloat rotateX;

Sorry about these newbie questions, but I'm not an objective C expert, and I don't code on the mac.

Can we try renaming the method
-(GLfloat)rotateX {return rotateX;}

to something like

(GLfloat)getRotateX { return rotateX; }

to see what breaks?

VanceRegentAuthor Commented:
Now I learned another thing, I thought the @property directive is only for objects, not for primitives.
I implemented now  @property GLfloat rotateX  and @synthesize rotateX;
The system creates the getter -(GLfloat)rotateX , getRotateX is against the convention.
However, it doesn't work
doesn't work... means... what?

Do you get errors? Does it compile?
Does it bomb at runtime?

Same as before?

VanceRegentAuthor Commented:
The same old blues, the app runs without error, except that rotatation doesn't work.
cool! glad it works!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.