Hyperboloid.java
package com.gwief.jTrace;
/*
Hyperboloid.java by Damian Newport
Uses Quadric.java to implement a Hyperboloid
*/
public class Hyperboloid {
public static final double[] intersect(Ray a){
double[] box = Box.intersect(a);
// do we hit the box?
if (box.length == 0){
return new double[0];
}
// if we got here we hit the box - lets test the Hyperboloid
// move the hyp up so we don't get )( shape
Ray ray = new Ray(a);
ray.origin.y -= 0.5;
// A, B, C, J
double[] hyp = Quadric.intersect(ray, 4, -0.9, 4, -0.1);
// do we hit the the hyperboloid
if (hyp.length == 0){
return new double[0];
}
if (rayTrace.bugmode){
System.out.println("Hyperboloid.box[0] = " + box[0]);
System.out.println("Hyperboloid.box[1] = " + box[1]);
System.out.println("Hyperboloid.hyp[0] = " + hyp[0]);
System.out.println("Hyperboloid.hyp[1] = " + hyp[1]);
}
// if we get here we've scored
// now just have to work out where
double result[] = new double[4];
result[0] = result[1] = hyp[0];
result[2] = result[3] = hyp[1];
return result;
}
public static final Vector3D normal(Vector3D a){
/* if it intersects with the box bit */
if ((0.5-a.y) < rayTrace.TINY){
return new Vector3D(0,1,0);
}
if ((0.5+a.y) < rayTrace.TINY){
return new Vector3D(0,-1,0);
}
/* move the hyp 'down' */
Vector3D temp = new Vector3D(a);
temp.y -= 0.5;
/* else it intersects with the hyperboloid */
/* A, B, C, J */
return Quadric.normal(temp, 4, -0.9, 4, -0.1);
}
}