Nick McBride Wrote:

> I'm not sure I entirely understand what you're

> asking

>

> For example:

> Say the line reads 1 10 -40 -10 -20 1 0 0 0 1 0 0

> 1 1 x.dat

> x y z

> a b c d e f g h i file

>

> I'm running through x.dat and pulling all the

> vertexes from each line and using this calculation

> on them:

>

> u' = (a * u) + (b * v) + (c * w) + x;

> v' = (d * u) + (e * v) + (f * w) +y;

> w' = (g *u) + (h * v) + (i * w) + z;

> where u, v, and w = the x,y,z coords from each of

> the the vertexes in x.dat. The a,b,c,d,e,f,g,h,

> and i come from the line 1, and so does x,y,z

>

> the u',v',and w' would then replace the vertices

> that were coming from x.dat

I take it you haven't worked with matrices before?

The type 1 line tells you how to transform the vertices of the referenced part in order to place it in the calling document's model space. This is done by a rotation (incl optional scaling) and translation. The rotation/scaling is given by a..i and the translation by x, y and z. But LDraw files are highly recursive so any file within the called file has to ALSO apply the transformation of higher level references.

To do this the 'easy way' you must use the 12 rotation and translation numbers to construct a 4x4 matrix which can be multiplied with the higher level matrices and then applied in one step to the vertices.

The formula you using above is actually a simplified matrix transformation for a 1x4 with a 4x4 matrix, which in it's 'pure' form looks like:

But it's only the one type 1 line matrix so it will only work for one level deep files. You need to multiply all level matrices with each other in the 4x4 matrix and use a full transformation formula (this one ignores the bottom line, cause it always results in zero)

For example you have the following file structure

To render e.g. e.dat absolutely you need to apply:

So in short you need to do some research on (rotation) matrices and get your hands on a matrix math library for your programming language or write one your self (you actually only need a multiplication and a transformation routine).

Hope this helps you, or at least gets you started. I'm by no means an expert so maybe another forum user can explain it better.

Anyway, I know matrix math can be hard to grasp. When I started with LDraw it was all magic to me too (it still kinda is)

[edit] -> forgot to add the '=' part of the formulas.

> I'm not sure I entirely understand what you're

> asking

>

> For example:

> Say the line reads 1 10 -40 -10 -20 1 0 0 0 1 0 0

> 1 1 x.dat

> x y z

> a b c d e f g h i file

>

> I'm running through x.dat and pulling all the

> vertexes from each line and using this calculation

> on them:

>

> u' = (a * u) + (b * v) + (c * w) + x;

> v' = (d * u) + (e * v) + (f * w) +y;

> w' = (g *u) + (h * v) + (i * w) + z;

> where u, v, and w = the x,y,z coords from each of

> the the vertexes in x.dat. The a,b,c,d,e,f,g,h,

> and i come from the line 1, and so does x,y,z

>

> the u',v',and w' would then replace the vertices

> that were coming from x.dat

I take it you haven't worked with matrices before?

The type 1 line tells you how to transform the vertices of the referenced part in order to place it in the calling document's model space. This is done by a rotation (incl optional scaling) and translation. The rotation/scaling is given by a..i and the translation by x, y and z. But LDraw files are highly recursive so any file within the called file has to ALSO apply the transformation of higher level references.

To do this the 'easy way' you must use the 12 rotation and translation numbers to construct a 4x4 matrix which can be multiplied with the higher level matrices and then applied in one step to the vertices.

The formula you using above is actually a simplified matrix transformation for a 1x4 with a 4x4 matrix, which in it's 'pure' form looks like:

Code:

`abs ver. vertex ref matrix `

/ x'\ / x \ / a b c x \

| y'| | y | | d e f y |

| z'| = | z | * | g h i z |

\ 1 / \ 1 / \ 0 0 0 1 /

But it's only the one type 1 line matrix so it will only work for one level deep files. You need to multiply all level matrices with each other in the 4x4 matrix and use a full transformation formula (this one ignores the bottom line, cause it always results in zero)

For example you have the following file structure

Code:

`a.dat`

AB -> b.dat

AC -> c.dat

CD -> d.dat

CE -> e.dat

To render e.g. e.dat absolutely you need to apply:

Code:

`abs ver. vertex CE Matrix AC Matrix`

/ x'\ / x \ / a b c x \ / a b c x \

| y'| | y | | d e f y | | d e f y |

| z'| = | z | * | g h i z | * | g h i z |

\ 1 / \ 1 / \ 0 0 0 1 / \ 0 0 0 1 /

So in short you need to do some research on (rotation) matrices and get your hands on a matrix math library for your programming language or write one your self (you actually only need a multiplication and a transformation routine).

Hope this helps you, or at least gets you started. I'm by no means an expert so maybe another forum user can explain it better.

Anyway, I know matrix math can be hard to grasp. When I started with LDraw it was all magic to me too (it still kinda is)

[edit] -> forgot to add the '=' part of the formulas.