Rookie rotation issue?

Ok this is probably a rookie mistake caused by my ignorance, but if anyone could spot the mistake I would be most grateful

This is what is happening in my app…

The user uses the LHM button to dynamically rotate/pan/zoom.
I use a class based on Ken Schomakers Arc ball. This basically returns a matrix ---- mNow

This works fine.

However I would like to put a few buttons in my app for standard views XY, YZ etc

I have done this like so — Press a button and do,
glRotatef 180, 0, 1, 0

Also fine…

Now the problem/issue.

  1. Imagine you have rotated the model with the mouse to some arbitrary position.
  2. You then press the XY view button and the model moves to the XY view.
  3. You now wish to rotate the model again via the mouse.

You (the user) would expect the model to rotate from an XY start position (position 2)

What happens is that as soon as you click the mouse in the graphics region the model ‘flicks’ back to its position at 1 above and does not start from the XY position. It just looks wrong.

Its driving me nuts…

I suspect its some sort of matrix stack thing but I don’t know really…

The code (editited to remove stuff not relevant??) is below

Can anyone spot the mistake?

Thanks guys


(edit - the code indentations have gone - sorry)

Public Sub Draw()
'This is where all the action takes place
'All the OGL rendering is done here

Dim mNow!(0 To 15), radius!

Ball.GetValue mNow

'This parameter sets the scale for the view based on the Ball Rad
'This is used as a zoom
radius = Ball.radius * sngZoomFactor
    glMultMatrixf mNow(0)
    glScalef radius, radius, radius
    Select Case gintView
    Case 0
    Case 1 '1=XY Top
    Case 2 '2=XY Bottom
        glRotatef 180, 0, 1, 0
    Case 3 '3=XZ Front
        glRotatef 90, 1, 0, 0
    Case 4 '4=XZ Back
        glRotatef -90, 1, 0, 0
    Case 5 '5=YZ Left
        glRotatef 90, 0, 1, 0
    Case 6 '6=YZ Right
        glRotatef -90, 0, 1, 0
    Case 7 '7=ISO
        glRotatef 45, 0, 1, 0
        glRotatef 10, 1, 0, 0
    Case Else
    End Select


End Sub

Thinking about it…

Is it a case that mNow is set at some arbitrary rotation/view and isn’t being set to the XY view matrix when I press the button?

Edit Hmmmm just tried this crude load of mNow

         mNow(0) = 1
         mNow(1) = 0
         mNow(2) = 0
         mNow(3) = 0
         mNow(4) = 0
         mNow(5) = 1
         mNow(6) = 0
         mNow(7) = 0
         mNow(8) = 0
         mNow(9) = 0
         mNow(10) = 1
         mNow(11) = 0
         mNow(12) = 0
         mNow(13) = 0
         mNow(14) = 0
         mNow(15) = 1

Same problem.

When I comment out the glLoadIdentity line the model doesn’t move back (the problem)… However, it doesn’t seem to do anything… It doesnt move at all!

I bet this is a really simple/daft one :slight_smile: