[Edu-sig] Freedom: some Smalltalk history and Python implications
andreas.raab at gmx.de
Fri Aug 11 20:08:05 CEST 2006
kirby urner wrote:
> OK, but then I want them to draw in 3D. Does Squeak make that easy
> for me. In VPython, do define a vector is to get on on screen. That's
> sometimes too immediate for me. I build a scene in vector language,
> then render it in POV-Ray.
Not knowing what is easy for you that question seems a little hard to
answer (also I'm thinking we're getting somewhat off-topic here). There
are different ways in whic you can go about this problem:
a) Using an immediate mode interface where you truly "draw yourself".
For the (older) Squeak 3D engine we have an interface that is similar to
OpenGL (in such that it supports very similar operations like submitting
vertices, normals, colors etc.) and in Croquet everything is built
directly on top of OpenGL. For the immediate mode interface there is a
pretty nice tutorial included with Balloon3D.
b) Using a retained mode interface, e.g., constructing a polygon mesh
and simply visualizing that. In this case you would probably use
Wonderland as it provides some nice high-level animation facilities.
> How do I draw an Icosahedron using Squeaks built-in 3D vector graphics engine?
Not sure what you're looking for here. Do you want to see some actual
code? Or are looking for general advice?
>> Operators are just binary messages in Smalltalk, which reminds of
>> another issue that is often a stumbling stone early on: No operator
>> precedence. All binary operations are evaluated strictly left to right
> How about operator overloading. That's pretty easy right? Like what
> we do with __add__.
Well, yes, that's what I said. Operators are just messages, you treat
them like anything else. If you want to implement addition using "+" you
just implement a message with the name "+" that's all.
> But there *is* a way to have + trigger vector addition yes. I was a
> bit unclear when you went:
>> v1Plus42 := v1 + 42.
>> v1Plusv2 := v1 + v2.
> How did you get that + behavior in Squeak?
By implementing it in the Vector class. Here is a simplified variant of
how this may look:
ifTrue:[^self scalarAdd: aNumericObject]
ifFalse:[^self vectorAdd: aNumericObject].
x := x + aNumber.
y := y + aNumber.
z := z + aNumber.
x := x + aVector x.
y := y + aVector y.
z := z + aVector z.
The case analysis in Vector>>+ can be quite annoying so often there are
other techniques (like double-dispatching) used to implement the proper
coercion. The common technique currently used by Squeak coerces based on
generality, so to implement the "reverse" set of operations you'd do, e.g.,
Vector>>adaptToNumber: aNumber andSend: aSymbol
"If I am involved in arithmetic with a scalar, return a Vector of
the results of each element combined with the scalar in that
x: (x perform: aSymbol with: aNumber)
y: (y perform: aSymbol with: aNumber)
z: (z perform: aSymbol with: aNumber)
But now we're *really* getting off topic. If you are interested in these
issues I'd recommend asking questions here:
>> E, V, F? Don't know that lingo ;-)
> E = Edges, V = Vertices, F = Faces. Euler's V + F = E + 2 is his law
> for polyhedra (the +2 goes away if you do a donut, or is +1 on a flat
> surface). This is where topology enters our curriculum (with Euler).
Oops, how embarrassing. It's been so long for me that I didn't even
recognize it. Of course I do (or should I say I did ;-) know that lingo...
More information about the Edu-sig