Mercurial > hg > jslab
diff src/samer/j3d/PatchesAlpha.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/j3d/PatchesAlpha.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,102 @@ +package samer.j3d; + +import samer.core.types.*; +import samer.maths.*; +import java.util.*; +import javax.media.j3d.*; +import javax.vecmath.*; + + +public class PatchesAlpha extends QuadArray implements Observer +{ + int N; // number of patches + Matrix P; // positions and sizes of patches + VVector A; // scalar activations + VDouble K; // scaling factor for activations + VDouble L; // scaling factor for sizes + + Color4f carray[]; // array for holding colours + + public PatchesAlpha(Matrix points, VVector activities) + { + super(4*points.getRowDimension(), COORDINATES | COLOR_4); + + N=points.getRowDimension(); + P=points; + A=activities; + K=new VDouble("scale",1); + L=new VDouble("patch.size",1); + + carray=new Color4f[4*N]; + for (int i=0; i<4*N; i+=4) + carray[i+3]= + carray[i+2]= + carray[i+1]= + carray[i]=new Color4f(1f,1f,1f,1f); + + // set capabilities for subsequent updates + setCapability(ALLOW_COORDINATE_WRITE); + setCapability(ALLOW_COLOR_WRITE); + + updatePoints(); + updateActivities(); + + A.addObserver(this); + L.addObserver(new Observer () { + public void update(Observable o, Object a) { + updatePoints(); + } + }); + } + + + public void update(Observable o, Object a) + { + updateActivities(); + } + + private double quad[] = new double[12]; + + public void updatePoints() + { + // load points into point array + double [][] PA=P.getArray(); + double [] row; + double l=L.value; + int j=0; + + for (int i=0; i<N; i++) { + row=PA[i]; + double x1=row[0]-l*row[1]; + double x2=row[0]+l*row[1]; + double y1=row[3]-l*row[4]; + double y2=row[3]+l*row[4]; + + quad[0] = x1; quad[1] = y1; quad[2] = 0; + quad[3] = x1; quad[4] = y2; quad[5] = 0; + quad[6] = x2; quad[7] = y2; quad[8] = 0; + quad[9] = x2; quad[10]= y1; quad[11]= 0; + + // set 4 vertices of quad + setCoordinates(j,quad,0,4); j+=4; + + // choose color according to energy? + // carray[i].set(Color.getHSBColor((float)(row[3]*0.3)+0.16f,1f,1f)); + } + } + + public void updateActivities() + { + // load colours + double [] a=A.array(); + double k=K.value; + int j=0; + + for (int i=0; i<N; i++) { + float ai=(float)(a[i]*k); + carray[j].w = ai; j+=4; + } + setColors(0,carray); + } +} +