Mercurial > hg > jslab
comparison examples/java3d/MatrixPointArray.java @ 1:5df24c91468d
Oh my what a mess.
author | samer |
---|---|
date | Fri, 05 Apr 2019 16:26:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:bf79fb79ee13 | 1:5df24c91468d |
---|---|
1 import samer.core.types.*; | |
2 import samer.maths.*; | |
3 import java.util.*; | |
4 import javax.media.j3d.*; | |
5 import javax.vecmath.*; | |
6 | |
7 | |
8 public class MatrixPointArray extends PointArray implements Observer | |
9 { | |
10 int N; // number of points | |
11 Matrix P; // 3d positions of points | |
12 VVector A; // scalar activations | |
13 VDouble K; // slaing factor for activations | |
14 float carray[]; // array for holding colours | |
15 | |
16 | |
17 public MatrixPointArray(Matrix points, VVector activities) | |
18 { | |
19 super(points.getRowDimension(), COORDINATES | COLOR_3); | |
20 | |
21 N=points.getRowDimension(); | |
22 P=points; | |
23 A=activities; | |
24 carray=new float[3*N]; | |
25 K=new VDouble("scale",1); | |
26 | |
27 // set capabilities for subsequent updates | |
28 setCapability(ALLOW_COORDINATE_WRITE); | |
29 setCapability(ALLOW_COLOR_WRITE); | |
30 | |
31 { | |
32 double [] a=A.array(); | |
33 for (int i=0; i<N; i++) a[i]=1; | |
34 } | |
35 | |
36 updatePoints(); | |
37 updateActivities(); | |
38 | |
39 A.addObserver(this); | |
40 } | |
41 | |
42 | |
43 public void update(Observable o, Object a) | |
44 { | |
45 updateActivities(); | |
46 } | |
47 | |
48 public void updatePoints() | |
49 { | |
50 // load points into point array | |
51 double [][] PA=P.getArray(); | |
52 double [] row; | |
53 for (int i=0; i<N; i++) { | |
54 row=PA[i]; | |
55 setCoordinate(i,row); | |
56 } | |
57 } | |
58 | |
59 public void updateActivities() | |
60 { | |
61 // load colours | |
62 double [] a=A.array(); | |
63 double k=K.value; | |
64 | |
65 for (int i=0, j=0; i<N; i++,j+=3) { | |
66 float ai=(float)(a[i]*k); | |
67 carray[j]=ai; | |
68 carray[j+1]=0.8f*ai; | |
69 carray[j+2]=0.4f*ai; | |
70 } | |
71 setColors(0,carray); | |
72 } | |
73 } |