diff examples/java3d/MatrixPointArray.java @ 1:5df24c91468d

Oh my what a mess.
author samer
date Fri, 05 Apr 2019 16:26:00 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/java3d/MatrixPointArray.java	Fri Apr 05 16:26:00 2019 +0100
@@ -0,0 +1,73 @@
+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;  // slaing factor for activations
+	float		carray[];	// array for holding colours
+
+
+	public MatrixPointArray(Matrix points, VVector activities)
+	{
+		super(points.getRowDimension(), COORDINATES | COLOR_3);
+
+		N=points.getRowDimension();
+		P=points;
+		A=activities;
+		carray=new float[3*N];
+		K=new VDouble("scale",1);
+
+		// set capabilities for subsequent updates
+		setCapability(ALLOW_COORDINATE_WRITE);
+		setCapability(ALLOW_COLOR_WRITE);
+
+		{
+			double [] a=A.array();
+			for (int i=0; i<N; i++) a[i]=1;
+		}
+
+		updatePoints();
+		updateActivities();
+
+		A.addObserver(this);
+	}
+
+
+	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);
+	}
+}