Fixed issues with compilation.
[IRC.git] / Robust / src / Benchmarks / Scheduling / GC / NON_BAMBOO / RayTracer / Sphere.java
1 package RayTracer;
2
3 /**************************************************************************
4  *                                                                         *
5  *             Java Grande Forum Benchmark Suite - Version 2.0             *
6  *                                                                         *
7  *                            produced by                                  *
8  *                                                                         *
9  *                  Java Grande Benchmarking Project                       *
10  *                                                                         *
11  *                                at                                       *
12  *                                                                         *
13  *                Edinburgh Parallel Computing Centre                      *
14  *                                                                         *
15  *                email: epcc-javagrande@epcc.ed.ac.uk                     *
16  *                                                                         *
17  *                 Original version of this code by                        *
18  *            Florian Doyon (Florian.Doyon@sophia.inria.fr)                *
19  *              and  Wilfried Klauser (wklauser@acm.org)                   *
20  *                                                                         *
21  *      This version copyright (c) The University of Edinburgh, 1999.      *
22  *                         All rights reserved.                            *
23  *                                                                         *
24  **************************************************************************/
25
26
27
28 public class Sphere extends Primitive 
29 //implements java.io.Serializable 
30 {
31   Vec      c;
32   float   r, r2;
33   //Vec      v,b; // temporary vecs used to minimize the memory load
34
35
36   public Sphere(Vec center, float radius) {
37     super();
38     c = center;
39     r = radius;
40     r2 = r*r;
41     //  v=new Vec();
42     //  b=new Vec();
43   }
44
45   public float dot(float x1, float y1, float z1, float x2, float y2, float z2){
46
47     return x1*x2 + y1*y2 + z1*z2; 
48
49   }
50
51   public Isect intersect(Ray ry) {
52
53
54     float b, disc, t;
55     Isect ip;
56
57     float x=c.x-ry.P.x;
58     float y=c.y-ry.P.y;
59     float z=c.z-ry.P.z;
60
61     b=dot( x, y, z, ry.D.x, ry.D.y, ry.D.z);
62     disc = (float) (b*b -dot(x,y,z,x,y,z) + r2);
63     if (disc < 0.0) {
64       return null;
65     }
66     disc = (float) Math.sqrtf((float)disc);
67     t = (b - disc < 1e-6) ? b + disc : b - disc;
68     if (t < 1e-6) {
69       return null;
70     }
71     ip = new Isect();
72     ip.t = t;
73     ip.enter = dot(x,y,z,x,y,z) > r2 + 1e-6 ? 1 : 0;
74     //  ip.enter = Vec.dot(v, v) > r2 + 1e-6 ? 1 : 0;
75     ip.prim = this;
76     ip.surf = surf;
77     return ip;
78
79   }
80
81   public Vec normal(Vec p) {
82     Vec r;
83     r = Vec.sub(p, c);
84     r.normalize();
85     return r;
86   }
87
88   public String toString() {
89     return "Sphere {" + c.toString() + "," + r + "}";
90   }
91
92   public Vec getCenter() {
93     return c;
94   }
95   public void setCenter(Vec c) {
96     this.c = c;
97   }
98 }
99