B3DMatrix hack #2.

Alan Grimes alangrimes at starpower.net
Tue Oct 11 18:21:50 UTC 2005


"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
#########################

-- 
Friends don't let friends use GCC 3.4.4
GCC 3.3.6 produces code that's twice as fast on x86!

http://users.rcn.com/alangrimes/
-------------- next part --------------
'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