[Bf-committers] Re: GameObject Python Distance function
antont at kyperjokki.fi
Wed Jan 12 09:10:46 CET 2005
On Wed, 12 Jan 2005 bf-committers-request at projects.blender.org wrote:
> From: erwin at erwincoumans.com
> Wouldn't it be better to add a new Math/Utility module ?
even if yes, and the actual calculating code would be there, there still
could be this interface that just further calls that
> useful things. Also just passing simpel types makes it more general purpose
> , passing objects limits the usage: you can't get the distance between to
> points (for example the distance from a hitpoint and another point).
i did note that too ('allows giving other positions than those of
objects'), and that's why said *also* -- the method could well allow for
giving either a position or an object that has position.
a nice example of such flexibility is the so-called rectstyle argument in
Pygame, http://www.pygame.org/docs/ref/Rect.html . that lib has a lot of
places where rectangles are given as arguments, e.g. blitting
destinations, areas to which something is restricted by clamping etc.
where it expects a rectstyle argument, which can be many things: "an
actual Rect object, a sequence of [xpos, ypos, width, height], a pair of
sequences, representing the position and size [[xpos, ypos],
[width,height]], if a method takes a rectstyle argument as its only
argument, you can simply pass four arguments representing xpos, ypos,
width, height, and perhaps most importantly: A rectstyle argument can also
be _any_ python object with an attribute named 'rect'."
when working on high-level behaviour such as AI, i think it's nice to be
able to omit lower level details from the code -- such as the name of the
attribute that some method needs to dig up.
sure this is a minor point, but just wanted to bring it up when there
seemed to be a good example.
> Toni Alatalo writes:
> > allows giving other positions than those of objects. however, at least
> > i've found it nice when you can just give objects to such calls.
> > for example, in Soya3d you can do obj1.look_at(obj2) (that rotates obj1).
> > so would it be good to add support for obj1.getDistance(obj2) here too?
> > ~Toni
More information about the Bf-committers