From: Phlip Date: 2001-12-02T16:19:36+09:00 Subject: [ruby-talk:27255] Is there a geometer in the house? (OpenGL Translate vs POVray Translate) Newsgroupies: Below my sig is a snip of RubyFX code attempting to drive OpenGL to make a Y shape. The symptom is the numbers in POVray code make a Y, but the same numbers pushed onto OpenGL's stack of quads creates a VI symbol. It broke. The POVray script looks like this: union { cylinder {<0,0,0>,<0,59.0625,0>, 3.32227 pigment{col_2} finish {ambient 0.3 diffuse 0.7 phong 1} rotate < 0, 0, -32.8296> rotate < 0, -99.4838, 0> translate < 0, 175, 0>} cylinder {<0,0,0>,<0,44.2969,0>, 1.86877 pigment{col_2} finish {ambient 0.3 diffuse 0.7 phong 1} rotate < 0, 0, -65.6593> rotate < 0, -99.4838, 0> translate < -5.31988, 222.175, 30.1705>} cylinder {<0,0,0>,<0,44.2969,0>, 1.86877 pigment{col_2} finish {ambient 0.3 diffuse 0.7 phong 1} rotate < 0, 0, -32.8296> rotate < 0, -99.4838, 0> translate < -5.31988, 222.175, 30.1705>} } Those brave enough to execute the Ruby snip below my sig (using FXRuby-0.99.181 -> fox-0.99.181 -> 2001/04/30 rbgl -> opengl) will see the three broken cylinders not joined at their branching point. The variable xyzEnd is (in this context) not used. But notice it equals the xyzTranslate value of the V cylinders. The POVray output transposes X and Y because POVray uses Z for "away from the viewer" while the input numbers (in the real app) use Z for "up". In the OpenGL system I did not deal with this, and left Z pointing towards the user. I have tried various permutations of the orders of the Rotate and Translate calls, and of the order of X, Y and Z within them. No luck. Any tips? -- Phlip #!/usr/bin/env ruby require 'fox' require 'opengl' require 'fox/glshapes' include Fox class GLViewWindow < FXMainWindow ID_GLVIEWER = enum(FXMainWindow::ID_LAST, 1)[0] def initialize(app) super(app, "Bad Thing Test", nil, nil, DECOR_ALL, 0, 0, 800, 600) @mdiclient = FXMDIClient.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y) mdichild = FXMDIChild.new(@mdiclient, "FOX GL Viewer", @mdiicon, nil, MDI_MAXIMIZED, 30, 30, 300, 200) @glvisual = FXGLVisual.new(getApp(), VISUAL_DOUBLEBUFFER) @mdiclient.setActiveChild(mdichild) viewer = FXGLViewer.new(mdichild, @glvisual, self, ID_GLVIEWER, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_LEFT) @scene = FXGLGroup.new gp2 = FXGLGroup.new @scene.append(gp2) addCylinder gp2, 59.0625, 3.322265625, 2, -32.82964323, -99.48376736, [0.0, 0.0, 175.0], [-5.319876145, 30.17051687, 222.1752194] addCylinder gp2, 44.296875, 1.868774414, 2, -65.65928646, -99.48376736, [-5.319876145, 30.17051687, 222.1752194], [-12.01231147, 68.12520364, 239.3344216] addCylinder gp2, 44.296875, 1.868774414, 2, -32.82964323, -99.48376736, [-5.319876145, 30.17051687, 222.1752194], [-9.309783254, 52.79840451, 257.556634] viewer.setScene(@scene) end def addCylinder gp, length,thickness,pigment,zeeRotation,whyRotation, xyzTranslation, xyzEnd exxTranslation, whyTranslation, zeeTranslation = xyzTranslation cyl = Cylinder.new ( exxTranslation, whyTranslation, zeeTranslation, length, thickness ) cyl.zeeRotation = zeeRotation cyl.whyRotation = whyRotation gp.append(cyl) end def create super show(PLACEMENT_SCREEN) end end def run application = FXApp.new("GLViewer", "FoxTest") application.disableThreads application.init(ARGV) GLViewWindow.new(application) application.create application.run end class Cylinder < FXGLCylinder def initialize(exxTranslation, whyTranslation, zeeTranslation, length , thickness ) super(0, 0, 0, length, thickness) @zeeRotation = 0 @whyRotation = 0 @exxTranslation, @whyTranslation, @zeeTranslation = exxTranslation, whyTranslation, zeeTranslation end attr_writer :zeeRotation, :whyRotation def drawshape(viewer) quad = GLU::NewQuadric() GLU::QuadricDrawStyle(quad, GLU::FILL) GL::PushMatrix() GL::Rotate(@whyRotation, 0, 0, 1) GL::Rotate(@zeeRotation, 0, 1, 0) GL::Translate ( @exxTranslation, @whyTranslation, 0 # @zeeTranslation, ) # p [@exxTranslation, @whyTranslation, @zeeTranslation] GLU::Cylinder(quad, @radius, @radius, @height, SLICES_NUMBER, STACKS_NUMBER) # XXX why all this was in the original? GLU::QuadricOrientation(quad, GLU::INSIDE) GLU::Disk(quad, 0, @radius, SLICES_NUMBER, LOOPS) GL::Translate(0, 0, @height) GLU::QuadricOrientation(quad, GLU::OUTSIDE) GLU::Disk(quad, 0, @radius, SLICES_NUMBER, LOOPS) GL::PopMatrix() GLU::DeleteQuadric(quad) end end run