use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class GLViewer method scaleModelMatrix.
public void scaleModelMatrix(double sx, double sy, double sz) {
synchronized (modelMatrix) {
AffineTransform3d am = new AffineTransform3d(modelMatrix);
am.applyScaling(sx, sy, sz);
modelMatrix = am;
if (sx == 0) {
sx = Double.MAX_VALUE;
} else {
sx = 1.0 / sx;
}
if (sy == 0) {
sy = Double.MAX_VALUE;
} else {
sy = 1.0 / sy;
}
if (sz == 0) {
sz = Double.MAX_VALUE;
} else {
sz = 1.0 / sz;
}
modelNormalMatrix.scaleColumn(0, sx);
modelNormalMatrix.scaleColumn(1, sy);
modelNormalMatrix.scaleColumn(2, sz);
}
invalidateModelMatrix();
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class RotatableScaler3d method updatePosition.
private void updatePosition(Point3d p1, boolean constrained, boolean repositioning) {
if (repositioning) {
Vector3d del = new Vector3d();
del.sub(p1, myPnt0);
if (constrained) {
double s = getConstrainedStepSize();
del.x = s * Math.round(del.x / s);
del.y = s * Math.round(del.y / s);
del.z = s * Math.round(del.z / s);
}
myXDraggerToWorld.mulXyz(del.x, del.y, del.z);
} else {
AffineTransform3d Tinc = (AffineTransform3d) myIncrementalTransform;
AffineTransform3d T = (AffineTransform3d) myTransform;
Vector3d d = new Vector3d(), o = new Vector3d();
o.sub(myPnt0, T.p);
if (constrained) {
d.sub(p1, myPnt0);
double s = getConstrainedStepSize();
d.x = s * Math.round(d.x / s);
d.y = s * Math.round(d.y / s);
d.z = s * Math.round(d.z / s);
d.add(o);
} else {
d.sub(p1, T.p);
}
double x, y, z;
x = d.x == 0 ? 1 : (o.x == 0 ? 1e-10 : Math.abs(d.x / o.x));
y = d.y == 0 ? 1 : (o.y == 0 ? 1e-10 : Math.abs(d.y / o.y));
z = d.z == 0 ? 1 : (o.z == 0 ? 1e-10 : Math.abs(d.z / o.z));
// x = d.x == 0 ? 1 : (o.x == 0 ? 1e-10 : d.x / o.x);
// y = d.y == 0 ? 1 : (o.y == 0 ? 1e-10 : d.y / o.y);
// z = d.z == 0 ? 1 : (o.z == 0 ? 1e-10 : d.z / o.z);
Tinc.set(T);
T.setIdentity();
T.applyScaling(x, y, z);
Tinc.mulInverseLeft(Tinc, T);
}
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class StlRenderer method setModelMatrix2d.
@Override
public void setModelMatrix2d(double left, double right, double bottom, double top) {
AffineTransform3d XMW = new AffineTransform3d();
double w = right - left;
double h = top - bottom;
XMW.A.m00 = 2 / w;
XMW.A.m11 = 2 / h;
XMW.p.set(-(left + right) / w, -(top + bottom) / h, 0);
setModelMatrix(XMW);
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class StlRenderer method scaleModelMatrix.
@Override
public void scaleModelMatrix(double s) {
synchronized (modelMatrix) {
AffineTransform3d am = new AffineTransform3d(modelMatrix);
am.applyScaling(s, s, s);
// normal matrix is unchanged
modelMatrix = am;
}
}
use of maspack.matrix.AffineTransform3d in project artisynth_core by artisynth.
the class MultiViewerTesterBase method addCube.
protected static void addCube(MultiViewer tester) {
RenderObject cube = new RenderObject();
// positions // normals
int[] pIdxs = new int[8];
int[] nIdxs = new int[6];
pIdxs[0] = cube.addPosition(-1f, -1f, -1f);
nIdxs[0] = cube.addNormal(0f, 0f, -1f);
pIdxs[1] = cube.addPosition(1f, -1f, -1f);
nIdxs[1] = cube.addNormal(0f, 0f, 1f);
pIdxs[2] = cube.addPosition(1f, 1f, -1f);
nIdxs[2] = cube.addNormal(0f, -1f, 0f);
pIdxs[3] = cube.addPosition(-1f, 1f, -1f);
nIdxs[3] = cube.addNormal(0f, 1f, 0f);
pIdxs[4] = cube.addPosition(-1f, -1f, 1f);
nIdxs[4] = cube.addNormal(-1f, 0f, 0f);
pIdxs[5] = cube.addPosition(1f, -1f, 1f);
nIdxs[5] = cube.addNormal(1f, 0f, 0f);
pIdxs[6] = cube.addPosition(1f, 1f, 1f);
pIdxs[7] = cube.addPosition(-1f, 1f, 1f);
// vertices
int[] vIdxs = new int[24];
// bottom indices:(position, normal, color, texture)
vIdxs[0] = cube.addVertex(0, 0, -1, -1);
vIdxs[1] = cube.addVertex(1, 0, -1, -1);
vIdxs[2] = cube.addVertex(2, 0, -1, -1);
vIdxs[3] = cube.addVertex(3, 0, -1, -1);
// top
vIdxs[4] = cube.addVertex(4, 1, -1, -1);
vIdxs[5] = cube.addVertex(5, 1, -1, -1);
vIdxs[6] = cube.addVertex(6, 1, -1, -1);
vIdxs[7] = cube.addVertex(7, 1, -1, -1);
// left
vIdxs[8] = cube.addVertex(0, 2, -1, -1);
vIdxs[9] = cube.addVertex(1, 2, -1, -1);
vIdxs[10] = cube.addVertex(4, 2, -1, -1);
vIdxs[11] = cube.addVertex(5, 2, -1, -1);
// right
vIdxs[12] = cube.addVertex(2, 3, -1, -1);
vIdxs[13] = cube.addVertex(3, 3, -1, -1);
vIdxs[14] = cube.addVertex(6, 3, -1, -1);
vIdxs[15] = cube.addVertex(7, 3, -1, -1);
// front
vIdxs[16] = cube.addVertex(3, 4, -1, -1);
vIdxs[17] = cube.addVertex(0, 4, -1, -1);
vIdxs[18] = cube.addVertex(7, 4, -1, -1);
vIdxs[19] = cube.addVertex(4, 4, -1, -1);
// back
vIdxs[20] = cube.addVertex(1, 5, -1, -1);
vIdxs[21] = cube.addVertex(2, 5, -1, -1);
vIdxs[22] = cube.addVertex(5, 5, -1, -1);
vIdxs[23] = cube.addVertex(6, 5, -1, -1);
// triangular faces
// bottom
cube.addTriangle(2, 1, 0);
// bottom
cube.addTriangle(3, 2, 0);
// top
cube.addTriangle(4, 5, 6);
// top
cube.addTriangle(7, 4, 6);
// left
cube.addTriangle(8, 9, 10);
// left
cube.addTriangle(9, 11, 10);
// right
cube.addTriangle(12, 13, 14);
// right
cube.addTriangle(13, 15, 14);
// front
cube.addTriangle(16, 17, 18);
// front
cube.addTriangle(17, 19, 18);
// back
cube.addTriangle(20, 21, 22);
// back
cube.addTriangle(21, 23, 22);
// add to renderer
RenderObjectWrapper cuber = new RenderObjectWrapper(cube);
AffineTransform3d trans = new AffineTransform3d();
trans.setTranslation(0.5, 0.5, 0.5);
trans.applyScaling(0.2, 0.2, 0.2);
cuber.setTransform(trans);
RenderProps props = cuber.getRenderProps();
props.setFaceColor(Color.ORANGE.darker());
tester.addRenderable(cuber);
}
Aggregations