?
Solved

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

Posted on 2008-06-13
13
Medium Priority
?
1,512 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
13 Comments
 
LVL 11

Expert Comment

by:jgordos
ID: 21795956
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
ID: 21796032
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
ID: 21796425
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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 

Author Comment

by:VanceRegent
ID: 21796822
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
ID: 21796927
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
 

Author Comment

by:VanceRegent
ID: 21797163
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
ID: 21797312
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
ID: 21797370
The same old blues, the app runs without error, except that rotatation doesn't work.
0
 

Accepted Solution

by:
VanceRegent earned 0 total points
ID: 21831989
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
ID: 21833048
cool! glad it works!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

777 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