Mercurial > hg > jslab
view src/samer/j3d/MatrixPointArrayRef.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
package samer.j3d; import samer.core.types.*; import samer.maths.*; import java.util.*; import javax.media.j3d.*; import javax.vecmath.*; public class MatrixPointArrayRef 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 GeometryUpdater updater; float carray[]; // array for holding colours // Color3f carray[]; public MatrixPointArrayRef(Matrix points, VVector activities) { super(points.getRowDimension(), BY_REFERENCE | 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_REF_DATA_WRITE); { double [] a=A.array(); for (int i=0; i<N; i++) a[i]=1; } updater = new GeometryUpdater() { public void updateData(Geometry g) { // 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; } } }; updater.updateData(this); setColorRefFloat(carray); setCoordRefDouble(P.getRowPackedCopy()); A.addObserver(this); /* P.addObserver(new Observer () { public void update(Observable o, Object a) { updatePoints(); } }); */ } public void update(Observable o, Object a) { updateData(updater); } }