Misunderstanding transform (line type 1)


Misunderstanding transform (line type 1)
#1
I think I'm misunderstanding something about the transform matrix for line type 1. Long story short, I've written a program to convert LDRAW files into something that threejs (3D library for JavaScript) can use, but I'm getting surfaces with the wrong normals, and it's not obvious what's going on.

So take a look at this line in p/stud.dat:

Code:
1 16 0 0 0 6 0 0 0 -4 0 0 0 6 4-4cyli.dat

And now p/4-4cyli, just the first quad:

Code:
4 16 1 1 0 0.9239 1 0.3827 0.9239 0 0.3827 1 0 0

So the vertices are (1,1,0) (0.9239,1,0.3827) (0.9239,0,0.3827) and (1,0,0). Plotting these out and assuming CCW winding shows that the normal faces outwards, as expected.


Proof for those who care: the first two vectors formed by the first three vertices are (-0.0761,0,0.3827) and (0,-1,0). Crossing the first vector by the second yields (0.3827,0,0.0761), a vector pointing positive along x and z.


Now, the transformation matrix in stud.dat transforms the vertices in 4-4cyli by scaling the x-axis by 6, the y-axis by -4, and the z-axis by 6. Unfortunately, scaling the y-axis by -4 reverses the sense of the face, and now its normal points inward.


Again, proof for those who care: the transformation matrix is
Code:
6  0 0 0
0 -4 0 0
0  0 6 0
0  0 0 1

Applying this to the first vertex:
Code:
6  0 0 0    1    6
0 -4 0 0 x  1 = -4 = (6,-4,0)
0  0 6 0    0    0
0  0 0 1    1    1

So the first three vertices transformed are (6,-4,0) (5.5434,-4,2.2962) and (5.5434,0,2.2962).

The vectors formed by these vertices are (-0.4566,0,2.2962) and (0,4,0). Crossing the first by the second yields (-9.1848,0,-1.8264): a vector pointing along the negative x and z axes.


The order of the vertices has not changed, but since y was inverted, the orientation of the face has changed. This means that stud.dat has an inward-facing cylinder, but a disc pointing in the -y direction, which is weird. But is this correct? If so, I'm not sure how stud.dat is supposed to display anything properly...
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Misunderstanding transform (line type 1) - by Robert Baruch - 2013-08-07, 0:53

Forum Jump:


Users browsing this thread: 1 Guest(s)