[no subject]

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


"Allegro actually cheats in the way it implements the matrix structure.
Rotation and scaling of a 3d point can be done with a simple 3x3 matrix,
but in order to translate it and project it onto the screen, the matrix
must be extended to 4x4, and the point extended into 4d space by the
addition of an extra coordinate, w=1. This is a bad thing in terms of
efficiency.."

To multiply a 3D vector with a 4x4 matrix, one will need to pad the vector
with 1.0. Eg the vector (x, y, z) -> (x, y, z, 1.0). There's nothing
wrong with that, but Allegro makes it impossible to do a 3x3
multiplication. My suggestion is to add a new matrix multiplication
function that does a 3D vector X 3x3 matrix multiplication. Eg. w=0.

This resembles the dp3 instruction in vertex shaders. It's commonly used
in graphics apps to rotate normals, light directions, etc..

This could of course be done with a custom matrix, but it is really
ugly to have two matrices, with one being a copy of the other with
the translation part zeroed out. => 0 * N = 0 and N * 0 = 0.

I first wanted to call the added function apply_matrix3(..), but
I thought it would be nice to have a complement function, that
converts a 3D vector (x, y, z) -> (0, 0, 0, 1). That's why I called
them apply_matrix_rotation(..) and apply_matrix_translation(..). These
names make the complement behaviour evident.

	matrix4x4 m
	vec3 v, v2, v3, v4, v5;

	apply_matrix_rotation(m, v, v2);
	apply_matrix_translation(m, v, v3);

	v4 = v2 + v3;

	apply_matrix(m, v, v5)

	=> v4 == v5 will be true.

-- Marcel




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/