B3DMatrix hack #2.
David A. Smith
davidasmith at bellsouth.net
Tue Oct 11 20:36:16 UTC 2005
Thanks. I have been modifying the Matrix4x4 code and have added * and
*=. This is a much cleaner implementation of *= than I had. I like to
write my matrix code as m1*m2, as I think this is cleaner and more
consistent with how it is typically described in texts such as RP Paul's
"Robotics" book.
The pattern m1*=m2 is particularly elegent and useful.
Regards,
David
Alan Grimes wrote:
>"composedWith:" (and the function it wraps, below) are commonly used in
>B3D code and Croquet code. They work well enough except in that they
>always create a new matrix, "result". This is undesirable in some
>instances where it is the user's intention to overwrite the source
>matrix anyway because it means an extra memory allocation and,
>eventually, more work for the GC...
>
>The primative that this method wraps can perform this operation without
>allocating a new object. (It does not, however, work for
>composeWithGlobal:)
>
>The attached code is a tweak to the below that is intended to replace
>the form:
>
>
>foo := foo composedWith: bar.
>
>With:
>
>foo multiplyAndDiscard: bar.
>
>There are a number of caviats though...
>Firstly, you can only use it in contexts equivalent to the example just
>mentioned. (there are plenty of them), such an equivalent example is:
>
>self localTransform: (self localTransform composedWith: bar).
>
>(with the caveat that the "self-changed" method needs to be called)
>
>Second, there are several other matrix types common in squeak, make sure
>you are editing a method that only works with B3DMatrix4x4's...
>
>
>########################
>composedWithLocal: aB3DMatrix4x4
> | result |
> result _ self class new.
> self
> privateTransformMatrix: self
> with: aB3DMatrix4x4
> into: result.
> ^ result
>#########################
>
>
>
>------------------------------------------------------------------------
>
>'From Jasmine-rc1 of 7 October 2004 [latest update: #280] on 11 October 2005 at 1:09:33 pm'!
>
>!B3DMatrix4x4 methodsFor: 'transforming' stamp: 'atg 10/11/2005 01:09'!
>multiplyAndDiscard: aB3DMatrix4x4
> "derived from 'composedWithLocal'"
> self
> privateTransformMatrix: self
> with: aB3DMatrix4x4
> into: self! !
>
>
>------------------------------------------------------------------------
>
>
>
>
More information about the Squeak-dev
mailing list
|