Mercurial > hg > jslab
diff src/samer/j3d/MatrixPointArray.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/MatrixPointArray.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,78 @@ +package samer.j3d; + +import samer.core.types.*; +import samer.maths.*; +import java.util.*; +import javax.media.j3d.*; +import javax.vecmath.*; + + +public class MatrixPointArray extends PointArray implements Observer +{ + int N; // number of points + Matrix P; // 3d positions of points + VVector A; // scalar activations + VDouble K; // scaling factor for activations + + float carray[]; // array for holding colours +// Color3f carray[]; + + public MatrixPointArray(Matrix points, VVector activities) + { + super(points.getRowDimension(), COORDINATES | COLOR_3); + + N=points.getRowDimension(); + P=points; + A=activities; + K=new VDouble("scale",1); + + carray=new float[3*N]; + + // set capabilities for subsequent updates + setCapability(ALLOW_COORDINATE_WRITE); + setCapability(ALLOW_COLOR_WRITE); + + updatePoints(); + updateActivities(); + + A.addObserver(this); + P.addObserver(new Observer () { + public void update(Observable o, Object a) { + updatePoints(); + } + }); + } + + + public void update(Observable o, Object a) + { + updateActivities(); + } + + public void updatePoints() + { + // load points into point array + double [][] PA=P.getArray(); + double [] row; + for (int i=0; i<N; i++) { + row=PA[i]; + setCoordinate(i,row); + } + } + + public void updateActivities() + { + // load colours + double [] a=A.array(); + double k=K.value; + + for (int i=0, j=0; i<N; i++,j+=3) { + float ai=(float)(a[i]*k); + carray[j]=ai; + carray[j+1]=0.8f*ai; + carray[j+2]=0.4f*ai; + } + setColors(0,carray); + } +} +