~seh999/jcog/proto3

« back to all changes in this revision

Viewing changes to spacetime/src.ui/opencog/spacetime/swing/vr/BigMesh.java

  • Committer: SeH
  • Date: 2009-09-19 22:59:48 UTC
  • Revision ID: seh999@gmail.com-20090919225948-q3ab80xa57i74mm6
start of major jReality refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package opencog.spacetime.swing.vr;
 
2
 
 
3
import java.util.Arrays;
 
4
 
 
5
import opencog.spacetime.geometry.QuadMeshFactory;
 
6
import opencog.spacetime.space.IndexedFaceSet;
 
7
 
 
8
 
 
9
public class BigMesh {
 
10
        
 
11
        public static IndexedFaceSet bigMesh(int discretization, double cameraHeight, double size) {
 
12
                int n = discretization;
 
13
                QuadMeshFactory factory = new QuadMeshFactory();
 
14
                factory.setULineCount(n);
 
15
                factory.setVLineCount(n);
 
16
                factory.setGenerateEdgesFromFaces(true);
 
17
                factory.setGenerateTextureCoordinates(false);
 
18
                double totalAngle = Math.atan(size/cameraHeight);
 
19
                double dt = 2 * totalAngle/(n-1);
 
20
                double[] normal = new double[]{0,0,-1};
 
21
                double[][] normals = new double[n*n][];
 
22
                Arrays.fill(normals, normal);
 
23
                
 
24
                double[][][] coords = new double[n][n][3];
 
25
 
 
26
                for (int i=0; i<n; i++) {
 
27
                        double y = cameraHeight * Math.tan(-totalAngle + i * dt);
 
28
                        for (int j=0; j<n; j++) {
 
29
                                coords[i][j][0] = cameraHeight * Math.tan(-totalAngle + j * dt);
 
30
                                coords[i][j][1] = y;
 
31
                        }
 
32
                }
 
33
                
 
34
                double[][][] texCoords = new double[n][n][2];
 
35
                for (int i=0; i<n; i++) {
 
36
                        for (int j=0; j<n; j++) {
 
37
                                texCoords[i][j][0] = coords[i][j][0];
 
38
                                texCoords[i][j][1] = coords[i][j][1];
 
39
                        }
 
40
                }
 
41
                
 
42
                factory.setVertexCoordinates(coords);
 
43
                factory.setVertexNormals(normals);
 
44
                factory.setVertexTextureCoordinates(texCoords);
 
45
                factory.update();
 
46
                
 
47
                return factory.getIndexedFaceSet();
 
48
        }
 
49
}
 
 
b'\\ No newline at end of file'