I am modifying robot.rb in opengl’s sample directory,
the original robot turns, mine does not! snif…
The original example goes something like this
A display proc
display = Proc.new {
…
GL.Rotate($shoulder, 0.0, 0.0, 1.0);
…
}
a keyboard proc
keyboard = Proc.new {|key, x, y|
case (key)
when ‘s’[0]
$shoulder = ($shoulder + 5) % 360;
GLUT.PostRedisplay();
Then you tell glut the name of those procs
GLUT.DisplayFunc(display);
Glut.KeyboardFunc(keyboard);
The new program goes like this
def displaytree
…
traversetree
…
end
def traversetree
applytransform
…
end
def applytransform
…
GL.Rotate(*@rotation);
end
…
and in the initialization definition
@rotation = [$shoulder, 0.0, 0.0, 1.0]
GLUT.DisplayFunc(lambda{trunk.displaytree});
GLUT.KeyboardFunc(keyboard);
The first program rotates, the second one does not.
I am wondering if it has something to do with the 2nd method
estimating $shoulder in a different way from the first method?
@rotation is probably evaluated before creating the new object,
and after that this line is never accessed? So my display does not have
a $shoulder parameter to update?
scale=[2.0, 0.4, 1.0]
jointP=[-1, 0, 0]
translation=[$shoulderposx, $shoulderposy, 0.0]
rotation = [$shoulder, 0.0, 0.0, 1.0]
draw = Proc.new { GLUT.WireCube(1.0)}
upperarm = Node.new(scale, translation, jointP, rotation,&draw)
How can I keep the $shoulder parameter physically with all the other
parameters defining the shoulder definitions, and still have $shoulder
update with keyboard presses?