Solved

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

Posted on 2008-06-13
13
1,490 Views
Last Modified: 2013-12-06
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.
.(void)awakefromNib

{

      rotateX = 30.0;

}
 

-(GLfloat)rotateX {return rotateX;}

 

-(void)setRotateX:(GLfloat)rx 

{

        rotateX = rx;

        [self setNeedsDisplay:YES];

}

 

- (void) drawRect:(NSRect)rect

{               

        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glPushMatrix();

        GLfloat rx = [self rotateX];

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

        glRotatef(rx, 1.0, 0.0, 0.0);

        glCallList(coordinates);

        glPopMatrix();

        

        glFlush ();

Open in new window

0
Comment
Question by:VanceRegent
  • 5
  • 5
13 Comments
 
LVL 11

Expert Comment

by:jgordos
Comment Utility
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.

-john
0
 

Author Comment

by:VanceRegent
Comment Utility
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.
0
 
LVL 11

Expert Comment

by:jgordos
Comment Utility
Yes, I see that now.  I guess I should look it up and not go from memory....

So...

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".

-john

0
 

Author Comment

by:VanceRegent
Comment Utility
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.
0
 
LVL 11

Expert Comment

by:jgordos
Comment Utility
So, is

rotateX

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?

-john
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:VanceRegent
Comment Utility
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
0
 
LVL 11

Expert Comment

by:jgordos
Comment Utility
doesn't work... means... what?

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

Same as before?

-j
0
 

Author Comment

by:VanceRegent
Comment Utility
The same old blues, the app runs without error, except that rotatation doesn't work.
0
 

Accepted Solution

by:
VanceRegent earned 0 total points
Comment Utility
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.
0
 
LVL 11

Expert Comment

by:jgordos
Comment Utility
cool! glad it works!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The /etc/authorization file in Mac OS X 10.x can be used to control access to the various panes of the System Preferences amongst other things. It’s used by some of us Mac Sys Admin’s to give Standard Users access to System Prefs panes that only adm…
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now