require File.expand_path('../boot', __FILE__) class Window < Gosu::Window if(!(defined? PIOVER180)) PIOVER180 = 0.0174532925 end attr_accessor :yrot, :walkbias, :walkbiasangle, :lookupdown, :zworld, :xpos, :zpos def initialize super(800,600,false) @yrot = 0.0 @walkbias = 0.0 @walkbiasangle = 0.0 @lookupdown = 0.0 @zworld = 0.0 @sector = TagSECTOR.new @xpos = 0.0 @zpos = 0.0 setupworld end def setupworld @file = File.new('C:\MI\myt.txt', 'r') numtriangles = 0 readstr = readstri self.caption = readstr if(readstr) readstr.match(/([0-9])/) numtriangles = $1 @sector.numtriangles = numtriangles.to_i (0...(numtriangles.to_i)).each{|a| @sector.triangles << TagTRIANGLE.new (0...3).each{|b| vertarr = readstri.to_a.collect!{|arnum| arnum.to_f} @sector.triangles[a].vertex[b].x = vertarr[0] @sector.triangles[a].vertex[b].y = vertarr[1] @sector.triangles[a].vertex[b].z = vertarr[2] } } end @file.close end def readstri @file.gets.chomp end def update if button_down? Gosu::Button::KbRight then @yrot -= 1.5 end if button_down? Gosu::Button::KbLeft then @yrot += 1.5 end if button_down? Gosu::Button::KbUp @xpos += Math.sin(@yrot * (Math::PI/180.0)) * 0.05 @zpos += Math.cos(@yrot * (Math::PI/180.0)) * 0.05 end if button_down? Gosu::Button::KbDown @xpos -= Math.sin(@yrot * (Math::PI/180.0)) * 0.05 @zpos -= Math.cos(@yrot * (Math::PI/180.0)) * 0.05 end if button_down? Gosu::Button::KbLeftControl @lookupdown -= 1.0 end if button_down? Gosu::Button::KbLeftAlt @lookupdown += 1.0 end if @walkbiasangle < 1.0 @walkbiasangle = 359.0 else @walkbiasangle -= 1.0 end @walkbias = Math.sin(walkbiasangle * (Math::PI/180.0)).to_f end def draw x_m, y_m, z_m, xtrans,ztrans,ytrans,sceneroty = 0.0 gl do glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) # see lesson01 glLoadIdentity # see lesson01 gluPerspective(45.0, width / height, 0.1, 100.0) # see lesson01 glMatrixMode(GL_MODELVIEW) # see lesson01 glLoadIdentity # see lesson01 sceneroty = 360 - @yrot glRotatef(@lookupdown, 1,0,0) glRotatef(sceneroty, 0,1,0) glTranslatef(0, 0, -10) # see lesson01 glTranslatef(@xpos,0,@zpos) glTranslatef(0,@walkbias / 20.0,0) self.caption = @xpos (0...@sector.numtriangles).each {|num| glBegin(GL_TRIANGLES) x_m = @sector.triangles[num].vertex[0].x y_m = @sector.triangles[num].vertex[0].y z_m = @sector.triangles[num].vertex[0].z glColor3f(1,0,0) glVertex3f(2.0, 0.0, 0.0) x_m = @sector.triangles[num].vertex[1].x y_m = @sector.triangles[num].vertex[1].y z_m = @sector.triangles[num].vertex[1].z glColor3f(0,1,0) glVertex3f(4.0, 4.0, 0.0) x_m = @sector.triangles[num].vertex[2].x y_m = @sector.triangles[num].vertex[2].y z_m = @sector.triangles[num].vertex[2].z glColor3f(0,0,1) glVertex3f(6.0,0.0,0.0) glEnd } end end def button_down(id) if id == Gosu::KbEscape close end end end class TagSECTOR attr_accessor :numtriangles, :triangles def initialize @numtriangles = 0 @triangles ||= [] end end class TagTRIANGLE attr_accessor :vertex def initialize @vertex = [] (0...3).each {|x| @vertex << Vertex.new } end end class Vertex attr_accessor :x,:y,:z def initialize @x = 0.0 @y = 0.0 @z = 0.0 end end

If I switch the order of rotation like so (so the rotation of the x-axis goes after the y-axis):

glRotatef(sceneroty, 0,1,0) glRotatef(@lookupdown, 1,0,0)

then it's no longer looks too great. Instead, if I go rotate around the x-axis, the triangle drawn looks like it's being pulled to one direction or the other, it's almost as if it's on a path of a slanted ring. When I visualize this, they do the exact same thing and are in the exact same positions.

Does the order matter here for some reason or is the fact that my sceneroty's default value being 360.0 degrees messing things up?