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