Ok, trying to get the hang of how to use them.
I create a plane at size 1/1, then apply a scale mod in order to resize it to any value.
This seems to work....once. But if I try to resize it again, it doesn't work.
The vertex values appearing in the log seem very high - I think its multiplying it all based on what they were last time rather then starting afresh....however, I am using IVertexController.PRESERVE_SOURCE_MESH.
Heres my code:
public class Rectangle extends Object3D {
int quads = 0;
Object3D obj;
Mesh planeMesh;
public Rectangle (int quads, float scalex, float scaley) {
super(quads*quads*2+8);
this.quads = quads;
obj=this;
createRect(quads, 1,1);
obj.build();
planeMesh = obj.getMesh();
this.setSize(1, 1);
}
private void createRect(int quads, float scalex, float scaley) {
Log.i("text", "building for size: = "+scalex+","+scaley);
float startx=-scalex*(float) quads/2f;
float starty=startx;
float tx=0f;
float ty=0f;
float dtex=(1f/(float) quads);
for (int i=0; i<quads; i++) {
for (int p=0; p<quads; p++) {
float dtx=tx+dtex;
float dty=ty+dtex;
if (dtx>1f) {
dtx=1f;
}
if (dty>1f) {
dty=1f;
}
obj.addTriangle(new SimpleVector(startx, starty, 0), tx, ty, new SimpleVector(startx, starty+scaley, 0), tx, dty, new SimpleVector(startx+scalex, starty, 0),
dtx, ty);
obj.addTriangle(new SimpleVector(startx, starty+scaley, 0), tx, dty, new SimpleVector(startx+scalex, starty+scaley, 0), dtx, dty, new SimpleVector(startx+scalex,
starty, 0), dtx, ty);
startx+=scalex;
tx+=dtex;
}
starty+=scaley;
startx=-scalex*quads/2;
tx=0;
ty+=dtex;
}
}
/** uses a vertex controller to rescale **/
public void setSize(float scalex, float scaley)
{
IVertexController demoControl=new ResizerMod(scalex,scaley,1);
Log.i("text", "resizing to size: = "+scalex+","+scaley);
planeMesh.setVertexController(demoControl, IVertexController.PRESERVE_SOURCE_MESH);
planeMesh.applyVertexController();
planeMesh.removeVertexController();
}
private static class ResizerMod extends GenericVertexController {
private static final long serialVersionUID = 1L;
float XFactor =1;
float YFactor =1;
float ZFactor =1;
public ResizerMod(float xFactor, float yFactor, float zFactor) {
super();
this.XFactor = xFactor;
this.YFactor = yFactor;
this.ZFactor = zFactor;
Log.i("vertex", "XFactor="+XFactor+" YFactor="+YFactor);
}
public void apply() {
SimpleVector[] s = getSourceMesh();
SimpleVector[] d = getDestinationMesh();
Log.i("vertex", "XFactor="+XFactor+" YFactor="+YFactor);
for (int i = 0; i < s.length; i++) {
//d[i].z = s[i].z - (10f * ((float) Math.sin(s[i].x / 50f) + (float) Math.cos(s[i].y / 50f)));
Log.i("vertex", "old vertex="+i+" x="+ d[i].x);
Log.i("vertex", "old vertex="+i+" y="+ d[i].y);
Log.i("vertex", "old vertex="+i+" z="+ d[i].z);
d[i].x = s[i].x*XFactor;
d[i].y = s[i].y*YFactor;
d[i].z = s[i].z*ZFactor;
Log.i("vertex", "vertex="+i+" x="+ d[i].x);
Log.i("vertex", "vertex="+i+" y="+ d[i].y);
Log.i("vertex", "vertex="+i+" z="+ d[i].z);
}
}
}
}