use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.
the class ConstrainedTranslator3d method render.
public void render(Renderer renderer, int flags) {
if (!myVisibleP) {
return;
}
Shading savedShading = renderer.setShading(Shading.NONE);
renderer.setLineWidth(myLineWidth);
renderer.pushModelMatrix();
Vector3d t = myXDraggerToWorld.p;
renderer.translateModelMatrix(t.x, t.y, t.z);
renderer.scaleModelMatrix(mySize);
if (renderObject == null) {
renderObject = createRenderable();
}
int gidx = selected ? 1 : 0;
renderer.drawLines(renderObject, gidx);
renderer.popModelMatrix();
renderer.setShading(savedShading);
}
use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.
the class LineSegment method drawGrid.
private void drawGrid(Renderer renderer) {
if (myMinSize == 0) {
return;
}
double distPerPixel = computeFocalPoint(null, XGridToWorld, renderer);
if (distPerPixel == -1) {
// grid is invisible
return;
}
if (myAutoSizedP) {
// start by computing the minor spacing, and then compute the major
// spacing assume 10 cell divisions
GLGridResolution res = updateResolution(distPerPixel);
if (!myResolution.equals(res)) {
if (myUseWorldOrigin) {
// May need to change position to accomodate new resolution.
RigidTransform3d TGWnew = new RigidTransform3d(XGridToWorldTarget);
AlignConstrainer aligner = new AlignConstrainer();
aligner.updatePose(TGWnew, XGridToWorldTarget);
double dpp = computeFocalPoint(null, TGWnew, renderer);
GLGridResolution resx = updateResolution(dpp);
if (resx.equals(res)) {
myResolution.set(res);
setGridToWorld(TGWnew);
} else {
// System.out.println ("cycle detected");
}
// Old code without cycle detection
// myResolution.set (res);
// setGridToWorld (XGridToWorldTarget);
} else {
myResolution.set(res);
}
}
}
double majorSize = myResolution.getMajorCellSize();
int numDivisions = myResolution.getNumDivisions();
// minor cell size
double minorSize;
// number of minor cells on each side of the x and y axes
int halfCellCnt;
minorSize = majorSize / numDivisions;
halfCellCnt = (int) Math.ceil(myMinSize / (2 * minorSize));
if (halfCellCnt == 0) {
halfCellCnt = numDivisions;
} else if (halfCellCnt % numDivisions != 0) {
// increase effective size so grid boundary lies on a major divison
halfCellCnt = numDivisions * (halfCellCnt / numDivisions + 1);
}
// Limit total number of cells that are drawn, in case a sideways view
// produces many subdivisions.
int maxCells = 200;
if (halfCellCnt > maxCells) {
halfCellCnt = maxCells;
}
double halfSize = halfCellCnt * minorSize;
// number of x axis cell divisions
int xcnt = 2 * halfCellCnt + 1;
// maximum x value
double xmax = halfSize;
// minimum x value
double xmin = -xmax;
// number of y axis cell divisions
int ycnt = 2 * halfCellCnt + 1;
// maximum y value
double ymax = halfSize;
// minimum y value
double ymin = -ymax;
// y_axis_i and x_axis_j are the cell division indices associated with
// the grid's x and y axes
double xoff = 0;
double yoff = 0;
if (myUseWorldOrigin) {
Point3d center = new Point3d();
// compute offset so the axes correspond to the real world center
center.inverseTransform(XGridToWorld);
xoff = center.x;
yoff = center.y;
}
int y_axis_i = (int) Math.round((xmax + xoff) / minorSize);
int x_axis_j = (int) Math.round((ymax + yoff) / minorSize);
float[] minorRGB = new float[3];
if (myMinorRGB == null) {
// create a default minor RBG
float s = 0.4f;
for (int i = 0; i < 3; i++) {
minorRGB[i] = s * myMajorRGB[i];
}
if (myViewer != null) {
// blend with background color of viewer
float[] backgroundRGB = myViewer.getBackgroundColor().getRGBColorComponents(null);
for (int i = 0; i < 3; i++) {
minorRGB[i] += (1 - s) * backgroundRGB[i];
}
}
} else {
minorRGB = myMinorRGB;
}
float[] xColor = myXAxisRGB;
float[] yColor = myYAxisRGB;
if (myLockAxesToWorld) {
// x and y axis colors are determined from corresponding world axes
RotationMatrix3d R = XGridToWorld.R;
// world x axis extracted from first column of XGridToWorld.R
xColor = getWorldAxisColor(R.m00, R.m10, R.m20);
// world y axis extracted from second column of XGridToWorld.R
yColor = getWorldAxisColor(R.m01, R.m11, R.m21);
}
// *********************************************************
// Old code that adjusted the intensity of the minor axis lines depending
// on how close we were to changing the grid resolution. This gave a
// smooth transition between different resolutions when
// autosizing. Difficult to get right (and not as necessary) with the
// more complex autosizing algorithm.
//
// // minSpc is the minimum possible value for minorSize. Maximum possible
// // value is 10x this, and the difference is used to determine the minor
// // grid color
// double minSpc = myMinCellPixels * distPerPixel;
//
// if (myAutoSizingP) {
// float s = (float)(minorSize / (10 * minSpc));
// for (int i = 0; i < 3; i++) {
// myMinorRGB[i] = (0.2 + 0.8 * s)*myDivisionRGB[i]
// }
// }
// *********************************************************
// maybe update info
rcacheInfo.update(numDivisions, (float) minorSize, xcnt, ycnt, x_axis_j, y_axis_i, (float) xmin, (float) xmax, (float) ymin, (float) ymax, xColor, yColor, myMajorRGB, minorRGB);
Shading savedShading = renderer.setShading(Shading.NONE);
renderer.setLineWidth(myLineWidth);
renderer.pushModelMatrix();
renderer.mulModelMatrix(XGridToWorld);
renderer.drawLines(rcacheInfo.getRenderObject());
renderer.setDepthOffset(1);
if (myXAxisLabeling != AxisLabeling.OFF || myYAxisLabeling != AxisLabeling.OFF) {
drawAxisLabels(renderer, xcnt, ycnt, majorSize, numDivisions, distPerPixel);
}
renderer.popModelMatrix();
renderer.setLineWidth(1);
renderer.setShading(savedShading);
}
use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.
the class Rotator3d method render.
public void render(Renderer renderer, int flags) {
if (!myVisibleP) {
return;
}
renderer.pushModelMatrix();
renderer.mulModelMatrix(myXDraggerToWorld);
Shading savedShading = renderer.setShading(Shading.NONE);
renderer.setLineWidth(myLineWidth);
renderer.scaleModelMatrix(mySize);
if (renderObject == null || !renderObject.isValid()) {
renderObject = createRotatorRenderable();
}
// highlight appropriate axis
if (mySelectedComponent != 0) {
renderer.drawLines(renderObject, mySelectedComponent);
}
renderer.drawLines(renderObject, 0);
renderer.popModelMatrix();
if (myDragMode != DragMode.OFF) {
switch(mySelectedComponent) {
case X_AXIS:
case Y_AXIS:
case Z_AXIS:
{
final float[] coords0 = new float[] { 0, 0, 0 };
float[] coords = new float[3];
// Draw rotation lines using the orientation at the time the drag was
// started
RigidTransform3d X = new RigidTransform3d(myXDraggerToWorld0);
X.p.set(myXDraggerToWorld.p);
renderer.pushModelMatrix();
renderer.mulModelMatrix(X);
renderer.setColor(0.5f, 0.5f, 0.5f);
myPnt0.get(coords);
renderer.drawLine(coords0, coords);
renderer.setColor(1, 1, 0);
myRotPnt.get(coords);
renderer.drawLine(coords0, coords);
renderer.popModelMatrix();
break;
}
}
}
renderer.setLineWidth(1);
renderer.setShading(savedShading);
}
use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.
the class Scaler3d method render.
public void render(Renderer renderer, int flags) {
if (!myVisibleP) {
return;
}
Shading savedShading = renderer.setShading(Shading.NONE);
renderer.setLineWidth(myLineWidth);
renderer.pushModelMatrix();
renderer.mulModelMatrix(myXDraggerToWorld);
float[] coords = new float[3];
if (myDragMode != DragMode.OFF && mySelectedComponent != NONE) {
renderer.setColor(1.0f, 1.0f, 0f);
renderer.setPointSize(3);
myPnt0.get(coords);
renderer.drawPoint(coords);
renderer.setPointSize(1);
}
renderer.scaleModelMatrix(mySize);
if (renderObject == null) {
renderObject = createScalerRenderable();
}
// draw selected component first
if (mySelectedComponent != 0) {
renderer.drawLines(renderObject, mySelectedComponent);
}
renderer.drawLines(renderObject, 0);
renderer.popModelMatrix();
renderer.setLineWidth(1);
renderer.setShading(savedShading);
}
use of maspack.render.Renderer.Shading in project artisynth_core by artisynth.
the class Translator3d method render.
public void render(Renderer renderer, int flags) {
if (!myVisibleP) {
return;
}
Shading savedShading = renderer.setShading(Shading.NONE);
renderer.setLineWidth(myLineWidth);
renderer.pushModelMatrix();
renderer.mulModelMatrix(myXDraggerToWorld);
float[] coords = new float[3];
if (myDragMode != DragMode.OFF && mySelectedComponent != NONE) {
renderer.setColor(1.0f, 1.0f, 0f);
renderer.setPointSize(3);
myPnt0.get(coords);
renderer.drawPoint(coords);
renderer.setPointSize(1);
}
renderer.scaleModelMatrix(mySize);
if (renderObject == null) {
renderObject = createTranslatorRenderable();
}
// draw selected component first
if (mySelectedComponent != 0) {
renderer.drawLines(renderObject, mySelectedComponent);
}
renderer.drawLines(renderObject, 0);
renderer.popModelMatrix();
renderer.setLineWidth(1);
renderer.setShading(savedShading);
}
Aggregations