[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

can robot.rb be written a ruby way?

anne001

1/31/2006 11:55:00 PM

This site gives the c code from robot.c in its
robot-framework-1.3.tar.gz file
http://yallara.cs.rmit.edu.au/~aholkner/Inte...

and this site gives a ruby code for the same program in robot.rb in its
folder sample in version 0.32g
http://www2.giganet.n...

The c program is structured as follows:
void init(void)
void display(void)
void reshape (int w, int h)
void keyboard (unsigned char key, int x, int y)
int main(int argc, char** argv)
{ ...
/* Tell GLUT to create and display the window, with the given title
*/
glutCreateWindow("Robot Arm Demo");

/* Call our own init function to set up the background color and
shading
* model. */
init ();

/* Tell GLUT where each of our functions are. We are passing in the
name
* of each function, which it will then call as required. */
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);

/* All initialisation is finished, tell GLUT to run the application
forever
* (or until we tell it to quit) */
glutMainLoop();
....}

and the ruby program is set up as
def init
display = Proc.new {
reshape = Proc.new {|w, h|
keyboard = Proc.new {|key, x, y|
...
GLUT.CreateWindow($0);
init();
GLUT.DisplayFunc(display);
GLUT.ReshapeFunc(reshape);
GLUT.KeyboardFunc(keyboard);
GLUT.MainLoop();
....
I was surprised to find that robot.rb is a litteral translation of
robot.c. No objects talking to each other here!

On the other hand, GLUT has a function ReshapeFunc which requires a
function, and so reshape is going to be a function, etc, so there may
not be a lot of room for ruby like programming.

Is it the case here, that because it is calling opengl and GLUT code,
the structure is going to have to be "C" like, and not "Object OOP"
like? Or is there a way of writing robot.rb a more ruby like way?

6 Answers

anne001

2/1/2006 12:49:00 PM

0

Actually, maybe it is display which I would like to see more ruby like

display = Proc.new {
GL.Clear(GL::COLOR_BUFFER_BIT);
GL.PushMatrix();
GL.Translate(-1.0, 0.0, 0.0);
GL.Rotate($shoulder, 0.0, 0.0, 1.0);
GL.Translate(1.0, 0.0, 0.0);
GL.PushMatrix();
GL.Scale(2.0, 0.4, 1.0);
GLUT.WireCube (1.0);
GL.PopMatrix();

GL.Translate(1.0, 0.0, 0.0);
GL.Rotate($elbow, 0.0, 0.0, 1.0);
GL.Translate(1.0, 0.0, 0.0);
GL.PushMatrix();
GL.Scale(2.0, 0.4, 1.0);
GLUT.WireCube(1.0);
GL.PopMatrix();

GL.PopMatrix();
GLUT.SwapBuffers();
}
In this simple example, the arms are represented by a scaled cube.
so the basic drawing takes two lines
GL.Scale(2.0, 0.4, 1.0);
GLUT.WireCube(1.0);

But the figures I have seen on the internet have a long list of parts,
for ex
http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_213...

Typically, data like info in ruby would be stored in an object? So I
should create an object for each body part, with in this case a method
made of those two lines?

The other problem with this program is that it draws the upper arm, and
then draws the fore arm at the end of the upper arm. So whatever
rotation the arm went through the forearm will stay attached to the
arm. But with a whole body, this way of drawing does not generalise. It
seems to me that ruby's object oriented hierarchies would be perfect
for this.

So in the object Arm, I should create a forearmobject, and in
forearmobject, I should create a hand object. The method draw arm
object would draw the arm, and proceed to call the draw forearm method,
which would draw the forearm, and call the draw hand method.

This program seems to redraw the whole figure from scratch, even if
only the forearm was changed. I wonder if the computation could be
saved so only the part changed is redrawn, but it does not sound like
it, because push and pop suggests a giant laundry list which it would
not be easy to access in organised pieces.

If this is the case, I just need to figure out who is at the top of the
hierarchy, probably the hip, and build the thing.

are those thoughts on the right track for a ruby way version of
robot.rb?

Ilmari Heikkinen

2/2/2006 12:23:00 PM

0

On 2/1/06, anne001 <anne@wjh.harvard.edu> wrote:> Typically, data like info in ruby would be stored in an object? So I> should create an object for each body part, with in this case a method> made of those two lines?>> The other problem with this program is that it draws the upper arm, and> then draws the fore arm at the end of the upper arm. So whatever> rotation the arm went through the forearm will stay attached to the> arm. But with a whole body, this way of drawing does not generalise. It> seems to me that ruby's object oriented hierarchies would be perfect> for this.The usual way is to have a scenegraph, which is a tree that describesthe scene you're drawing. You then attach models and transformationsand material information to the nodes in the graph. When you draw it, therenderer (for example) traverses the graph depth-first, calling the statesetting functions and drawing functions. Other way would be to collectthe scene objects into a list and collapse their transforms into worldcoordinates and then draw the list.This way you can e.g. create a room object for the scene root, attachsome box objects to it, and put some books in the boxes. Now whenyou move a box, all the books in it move too.Here's some pseudocode:room = Room.newboxes = (1..3).each{ box = Box.new(:position => random_position) box.attach StackOfBooks.new box}room.attach(*boxes)renderer.draw(room)# hmm, one box too manyroom.detach(boxes.last)renderer.draw(room)The renderer#draw could be something like:def draw(scene) clear_frame setup_default_state setup_camera setup_lights draw_object(scene) swap_buffersenddef draw_object stack_state{ transform(obj) set_material(obj) draw_geometry(obj) obj.children.each{|c| draw_object(c) } }end> This program seems to redraw the whole figure from scratch, even if> only the forearm was changed. I wonder if the computation could be> saved so only the part changed is redrawn, but it does not sound like> it, because push and pop suggests a giant laundry list which it would> not be easy to access in organised pieces.With OpenGL, it's going to be a lot slower to figure out what parts of theframe have changed and need updating, than just clearing the frame anddrawing everything again. There are some situations where this doesn'tapply (like if there's a huge background scene in the horizon; it can bejust drawn to a texture once and the texture then used as an impostor),but generally it's not something to worry about.HTH,Ilmari

Carrie

7/26/2008 9:27:00 PM

0


"Gene" <gene@chewbacca.org> wrote in message
news:Xns9AE790E2E179Dgenewardsmithsbcglob@207.115.33.102...
> "Carrie" <starchild1124@yahoo.com> rote in news:g6fg2f$9uv$1@aioe.org:
>
>> Why would it matter toYOU what I (or anyone else) believes, about God
>> or
>> anything?
>
> This is a discussion group. I'm discussing.
>
> Why does it matter to you what people think? If you could figure that out,
> it
> might help you answer your question.

This is a discussion group. I'm discussing.


>
> --
> Change but your mind on what you want to see,
> And all the world must change accordingly.
>


Gene Ward Smith

7/26/2008 9:42:00 PM

0

"Carrie" <starchild1124@yahoo.com> rote in news:g6g4qh$bdu$1@aioe.org:

> If we are all one, and one with God, and the idea of separate bodies
> in form is illusion, how can anyone BE real to anyone else?

God created your brother as eternally unified with you, and real. Because he
is real to God, he is real to you. This cannot be changed, nor does it have
anything to do with bodies.


--
Change but your mind on what you want to see,
And all the world must change accordingly.

Gene Ward Smith

7/26/2008 9:49:00 PM

0

"Carrie" <starchild1124@yahoo.com> rote in news:g6g54k$d8j$1@aioe.org:

> Why does it bother you to think I think "I am God"?

Because the Course says that is the root of all evil, and this is a Course
group. We should at least be able to dispose of this very fundamental error.

--
Change but your mind on what you want to see,
And all the world must change accordingly.

Carrie

7/26/2008 11:08:00 PM

0


"MikeRyder" <nono@nospam.com> wrote in message
news:bd5n84hg54tvjvgeldslhssnkqlvs29jaa@4ax.com...
> On Sat, 26 Jul 2008 09:22:34 -0400, "Carrie" <starchild1124@yahoo.com>
> wrote:
>
>>
>>"MikeRyder" <nono@nospam.com> wrote in message
>>news:un4l84thu5mfcq9beaj2ipaq897cs4mf1t@4ax.com...
>>> On Fri, 25 Jul 2008 22:24:33 -0400, "Carrie" <starchild1124@yahoo.com>
>>> wrote:
>>>
>>>>
>>>>"MikeRyder" <nono@nospam.com> wrote in message
>>>>news:cdmk84dqomruuda6837voutn31c386t927@4ax.com...
>>>>> On Fri, 25 Jul 2008 18:26:49 -0400, "Carrie" <starchild1124@yahoo.com>
>>>>> wrote:
>>>>>
>>>>>>
>>>>>>"MikeRyder" <nono@nospam.com> wrote in message
>>>>>>news:t9kk84pin109tc4qaaavh1iuir0hh9hf97@4ax.com...
>>>>>>> On Fri, 25 Jul 2008 15:22:17 -0400, "Carrie"
>>>>>>> <starchild1124@yahoo.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>>
>>>>>>>>"Gene" <gene@chewbacca.org> wrote in message
>>>>>>>>news:Xns9AE671DF66A3genewardsmithsbcglob@207.115.17.102...
>>>>>>>>> "Carrie" <starchild1124@yahoo.com> rote in
>>>>>>>>> news:g6ct1g$nbq$1@aioe.org:
>>>>>>>>>
>>>>>>>>>> And, it's all real (or not) going by our belief in it.
>>>>>>>>>> If you see me as the Anti Christ, then (to you) that's what I
>>>>>>>>>> will
>>>>>>>>>> be.
>>>>>>>>>
>>>>>>>>> So Heaven and God are only real if we believe in them, sort of
>>>>>>>>> like
>>>>>>>>> Tinkerbell?
>>>>>>>>
>>>>>>>> Of course
>>>>>>>> How can anything "be" anything if there's no mind believing it and
>>>>>>>> making
>>>>>>>>it real?
>>>>>>>> Seems like you'd see the logic in that.
>>>>>>>
>>>>>>> I seem to remember the course saying that for the course to work we
>>>>>>> dont have to believe in God the creator; nevertheless, he does
>>>>>>> exist.
>>>>>>> Further, he is not bothered by one's disbelief, because he has no
>>>>>>> ego
>>>>>>> with which he could be bothered.
>>>>>>
>>>>>> Which is true because you believe it.
>>>>>> Your beliefs don't supercede someone else's, who might believe
>>>>>> something
>>>>>>else is true.
>>>>>
>>>>> Just out of curiosity, what does God look like in your opinion?
>>>>
>>>> God doesn't have form
>>>> God just is...
>>>>
>>>>
>>>
>>> I'm not talking about "form." Does your god insist on being called
>>> "god"?
>>
>> How can something look like anything without form?
>
> Word mincing. I'll try again. What do YOU think God is all about?
>
>> You asked what does God look like?
>> God doesn't look like anything and doesn't insist on anything.
>> God just is.
>
>
>> If that's not the right answer (going by what you believe) what would
>>you consider a better one?
>>
>
> Paranoid? lol

I remember the course saying "We say 'God is' and then we cease to speak"
Why would anyone try (or need) to discribe God?
And who would know if the person was right, or even close to what God
is...?
Seems like a waste of time.