import java.awt.*;
|
import java.util.Vector;
|
|
class BezierPatch extends Composite/*Object3D*/ implements BezierElement, java.io.Serializable
|
{
|
boolean IsStatic()
|
{
|
return false;
|
}
|
|
static final long serialVersionUID = 822133018822597309L;
|
|
float minu, maxu, minv, maxv;
|
|
BezierPatch(Composite ictrlPnts)
|
{
|
this(ictrlPnts, 0,1,0,1);
|
}
|
|
BezierPatch(Composite ictrlPnts, float minu, float maxu, float minv, float maxv)
|
{
|
this.minu = minu;
|
this.maxu = maxu;
|
this.minv = minv;
|
this.maxv = maxv;
|
name = "BezierPatch";
|
|
// ctrlPnts = ictrlPnts;
|
ctrlPnts = this;
|
|
for (Object3D o : ictrlPnts)
|
{
|
addChild(o);
|
}
|
|
recalculate();
|
}
|
|
Object3D deepCopy()
|
{
|
BezierPatch l = new BezierPatch(ctrlPnts);
|
deepCopySelf(l);
|
return l;
|
}
|
|
protected void deepCopyNode(Object3D other)
|
{
|
super.deepCopyNode(other);
|
BezierPatch bp = (BezierPatch)other;
|
bp.depth = depth;
|
int count = ctrlPnts.size();
|
bp.ctrlPnts = bp; //new Composite(); // Not good
|
for (int i=0; i < count; i++)
|
{
|
Sphere p = (Sphere)ctrlPnts.elementAt(i);
|
//cVector q = new cVector();
|
//LA.vecCopy(p, q);
|
bp.ctrlPnts.addElement(p); // new Sphere(p)); // q);
|
}
|
}
|
|
/**/
|
void draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
|
{
|
//recalculate();
|
//System.out.println();
|
//if (CameraPane.HANDLES)
|
super.draw(display, root, selected, blocked);
|
//else
|
// super.DrawNode(display, root, selected);
|
|
//if (IsSelected())
|
// ctrlPnts.draw(display, true);
|
}
|
/**/
|
|
void createEditWindow(GroupEditor callee, boolean newWindow)
|
{
|
//editWindow = new BezierEditor(this, deepCopy(), callee);
|
if(newWindow)
|
objectUI = new BezierEditor(this, deepCopy(), callee);
|
else
|
objectUI = new BezierEditor(this, callee);
|
|
editWindow = objectUI.GetEditor();
|
}
|
|
void getBounds(cVector minima, cVector maxima, boolean xform)
|
{
|
//spline.getBounds(minima, maxima, true);
|
maxima.z = maxima.x;
|
minima.z = minima.x = -maxima.x;
|
if (xform)
|
transformBounds(minima, maxima);
|
}
|
|
boolean inside(double x, double y, double z, boolean xform)
|
{
|
assert false;
|
|
return false;
|
}
|
|
void doEditDrag(ClickInfo info)
|
{
|
if (!hitSomething)
|
return;
|
|
Sphere ctrlPoint = (Sphere)ctrlPnts.get(hitIndex);
|
/**/
|
cVector delta = LA.newVector(info.x - startX, startY - info.y, 0);
|
LA.xformDir(delta, info.camera.fromScreen, delta);
|
delta.x /= 100 * info.camera.SCALE / info.camera.Distance();
|
delta.y /= 100 * info.camera.SCALE / info.camera.Distance();
|
delta.z /= 100 * info.camera.SCALE / info.camera.Distance();
|
|
cVector p = ctrlPoint.getCenter();
|
LA.vecCopy(startVec, p);
|
LA.vecAdd(p, delta, p);
|
ctrlPoint.refreshCenter(p);
|
System.out.println("point = " + p);
|
/**/
|
//ctrlPoint.doEditDrag(info);
|
|
((BezierSurface)parent).currentHandle = ctrlPoint;
|
|
((BezierSurface)parent).recalculate();
|
}
|
|
void draw(ClickInfo info, int level, boolean select)
|
{
|
cVector sample;
|
info.g.setColor(Color.black);
|
int nPoints = ctrlPnts.size();
|
|
for (int i=0; i < nPoints; i++)
|
{
|
sample = ((Sphere)ctrlPnts.get(i)).getCenter();
|
Point prev = new Point(0, 0);
|
Point curr = new Point(0, 0);
|
Rectangle dummy = new Rectangle();
|
calcHotSpot(sample, //info,
|
prev, dummy);
|
sample = ((Sphere)ctrlPnts.get(i)).getCenter();
|
calcHotSpot(sample, //info,
|
curr, dummy);
|
info.g.drawLine(prev.x, prev.y, curr.x, curr.y);
|
prev.x = curr.x;
|
prev.y = curr.y;
|
}
|
}
|
|
void drawEditHandles(//ClickInfo info,
|
int level)
|
{
|
clickInfo.g.setColor(Color.red);
|
int count = ctrlPnts.size();
|
for (int i=0; i < count; i++)
|
{
|
cVector p = ((Sphere)ctrlPnts.elementAt(i)).getCenter();
|
Rectangle spot = calcHotSpot(p); //, info);
|
clickInfo.g.fillRect(spot.x, spot.y, spot.width, spot.height);
|
}
|
|
}
|
|
boolean doEditClick(//ClickInfo info,
|
int level)
|
{
|
startX = clickInfo.x;
|
startY = clickInfo.y;
|
int nPoints = ctrlPnts.size();
|
hitSomething = false;
|
for (int i=0; i < nPoints; i++)
|
{
|
cVector p = ((Sphere)ctrlPnts.elementAt(i)).getCenter();
|
Rectangle r = calcHotSpot(p); //, clickInfo);
|
if (r.contains(clickInfo.x, clickInfo.y))
|
{
|
hitSomething = true;
|
hitIndex = i;
|
LA.vecCopy(p, startVec);
|
}
|
}
|
|
return hitSomething;
|
}
|
|
/*
|
void Touch()
|
{
|
super.Touch();
|
|
if (parent != null)
|
parent.recalculate();
|
}
|
/**/
|
|
public void recalculate()
|
{
|
float[] vertices = new float[4*4*3];
|
|
for( int i=0, i3=0; i<ctrlPnts.size(); i++, i3+=3 )
|
{
|
cVector v = ((Sphere)ctrlPnts.get(i)).getCenter();
|
//LA.xformPos(v, ctrlPnts.get(i).fromParent, v);
|
vertices[i3] = (float)v.x;
|
vertices[i3+1] = (float)v.y;
|
vertices[i3+2] = (float)v.z;
|
//System.out.println("vertices = " + vertices[i3] + " " + vertices[i3+1] + " " + vertices[i3+2]);
|
}
|
|
bRep = cBezier.GenPatch(vertices, depth, minu,maxu,minv,maxv);
|
|
if (!bRep.trimmed)
|
bRep.Trim(false, false, false); // strip is slow
|
//bRep.Trim(true, true);
|
|
//ctrlPnts.deepCopySelf(reference);
|
|
super.recalculate();
|
}
|
|
private static int startX;
|
private static int startY;
|
private static boolean hitSomething;
|
private static int hitIndex;
|
private static cVector startVec = new cVector();
|
|
Composite ctrlPnts;
|
|
int depth = 3;
|
|
public int GetDepth()
|
{
|
return depth;
|
}
|
|
public void SetDepth(int d)
|
{
|
depth = d;
|
}
|
}
|