From: <ega...@us...> - 2003-05-27 02:50:36
|
Update of /cvsroot/jrman/drafts/src/org/jrman/primitive In directory sc8-pr-cvs1:/tmp/cvs-serv27732/src/org/jrman/primitive Added Files: Hyperboloid.java Log Message: Added Hyperboloid implementation, it is incorrect, but Parser will not complie if it's missing. --- NEW FILE: Hyperboloid.java --- /* Sphere.java Copyright (C) 2003 Gerardo Horvilleur Martinez This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.jrman.primitive; import java.util.Map; import javax.vecmath.Point3f; import javax.vecmath.Vector3f; import org.jrman.attributes.Attributes; import org.jrman.geom.BoundingVolume; import org.jrman.geom.Bounds3f; import org.jrman.grid.Grid; import org.jrman.grid.Point3fGrid; import org.jrman.grid.Vector3fGrid; import org.jrman.render.ShaderVariables; public class Hyperboloid extends Quadric { private static Point3f tmp = new Point3f(); private static Vector3f vtmp = new Vector3f(); private float x1; private float y1; private float z1; private float x2; private float y2; private float z2; private float zMin; private float zMax; private float thetaMin; private float thetaMax; public Hyperboloid( float x1, float y1, float z1, float x2, float y2, float z2, float thetaMin, float thetaMax, Map parameters, Attributes attributes) { super(parameters, attributes); this.x1 = x1; this.y1 = y1; this.z1 = z1; this.x2 = x2; this.y2 = y2; this.z2 = z2; this.thetaMin = thetaMin; this.thetaMax = thetaMax; this.zMin = Math.min(z1,z2); this.zMax = Math.max(z1,z2); } public BoundingVolume getBoundingVolume() { float xMax = Math.max(x1,x2); float xMin = Math.min(x1,x2); float yMax = Math.max(y1,y2); float yMin = Math.min(y1,y2); Bounds3f result = new Bounds3f( xMin, xMax, yMin, yMax, zMin, zMax); return result; } public Primitive[] split() { Primitive[] result = new Primitive[2]; if ((thetaMax - thetaMin) > (float) Math.abs(z2 - z1)) { result[0] = new Hyperboloid( x1, y1, z1, x2, y2, z2, thetaMin, (thetaMin + thetaMax) / 2f, linearInterpolateParameters(0f, .5f, 0f, 1f), attributes); result[1] = new Hyperboloid( x1, y1, z1, x2, y2, z2, (thetaMin + thetaMax) / 2f, thetaMax, linearInterpolateParameters(.5f, 1f, 0f, 1f), attributes); } else { result[0] = new Hyperboloid( x1, y1, (z1 + z2) / 2f, x2, y2, z2, thetaMin, thetaMax, linearInterpolateParameters(0f, 1f, 0f, .5f), attributes); result[1] = new Hyperboloid( x1, y1, z1, x2, y2, (z1 + z2) / 2f, thetaMin, thetaMax, linearInterpolateParameters(0f, 1f, .5f, 1f), attributes); } return result; } protected void dice_P(ShaderVariables shaderVariables) { int uSize = Grid.getUSize(); int vSize = Grid.getVSize(); float thetaDelta = (thetaMax - thetaMin) / (uSize - 1); float zDelta = (float) Math.abs(z1 - z2) / (vSize - 1); Point3fGrid P = shaderVariables.P; float theta = thetaMin; for (int u = 0; u < uSize; u++) { float cosTheta = (float) Math.cos(theta); float sinTheta = (float) Math.sin(theta); float z = Math.min(z1,z2); for (int v = 0; v < vSize; v++) { float xr = ((1 -z) * x1 + z * x2 ); float yr = ((1 -z) * y1 + z * y2 ); float zr = ((1 -z) * z1 + z * z2 ); tmp.x = xr * cosTheta - yr * sinTheta; tmp.y = xr * sinTheta + yr * cosTheta; tmp.z = zr; P.set(u, v, tmp); z += zDelta; } theta += thetaDelta; } } protected void dice_Ng(ShaderVariables shaderVariables) { int uSize = Grid.getUSize(); int vSize = Grid.getVSize(); float thetaDelta = (thetaMax - thetaMin) / (uSize - 1); float zDelta = Math.abs(z1-z2) / (vSize - 1); Vector3fGrid Ng = shaderVariables.Ng; float theta = thetaMin; for (int u = 0; u < uSize; u++) { float z = Math.min(z1,z2); for (int v = 0; v < vSize; v++) { float ang = (float) Math.atan(90f); float cosAng = (float) Math.cos(ang); float sinAng = (float) Math.sin(ang); float cosThetaCosAng = (float) Math.cos(theta) * cosAng; float sinThetaCosAng = (float) Math.sin(theta) * cosAng; vtmp.x = cosThetaCosAng; vtmp.y = sinThetaCosAng; vtmp.z = sinAng; Ng.set(u, v, vtmp); z += zDelta; } theta += thetaDelta; } } } |