From: <ma...@us...> - 2003-05-22 07:36:29
|
Update of /cvsroot/jrman/drafts/src/org/jrman/primitive In directory sc8-pr-cvs1:/tmp/cvs-serv23650/src/org/jrman/primitive Modified Files: Primitive.java Added Files: BicubicPatch.java Log Message: Started work on bicubic patches. --- NEW FILE: BicubicPatch.java --- /* BilinearPatch.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.ConvexHull3f; import org.jrman.grid.Grid; import org.jrman.parser.Declaration; import org.jrman.parser.Parameter; import org.jrman.render.ShaderVariables; import org.jrman.util.Calc; public class BicubicPatch extends Primitive { private static Point3f P00; private static Point3f P10; private static Point3f P20; private static Point3f P30; private static Point3f P01; private static Point3f P11; private static Point3f P21; private static Point3f P31; private static Point3f P02; private static Point3f P12; private static Point3f P22; private static Point3f P32; private static Point3f P03; private static Point3f P13; private static Point3f P23; private static Point3f P33; private static Vector3f vtmp = new Vector3f(); public BicubicPatch(Map parameters, Attributes attributes) { super(parameters, attributes); } private void extractPoints() { Parameter param = (Parameter) parameters.get("P"); Point3f[][] P = (Point3f[][]) param.getData(); P00 = P[0][0]; P10 = P[1][0]; P20 = P[2][0]; P30 = P[3][0]; P01 = P[4][0]; P11 = P[5][0]; P21 = P[6][0]; P31 = P[7][0]; P02 = P[8][0]; P12 = P[9][0]; P22 = P[10][0]; P32 = P[11][0]; P03 = P[12][0]; P13 = P[13][0]; P23 = P[14][0]; P33 = P[15][0]; } public BoundingVolume getBoundingVolume() { ConvexHull3f ch = new ConvexHull3f(); extractPoints(); ch.addPoint(P00); ch.addPoint(P10); ch.addPoint(P20); ch.addPoint(P30); ch.addPoint(P01); ch.addPoint(P11); ch.addPoint(P21); ch.addPoint(P31); ch.addPoint(P02); ch.addPoint(P12); ch.addPoint(P22); ch.addPoint(P32); ch.addPoint(P03); ch.addPoint(P13); ch.addPoint(P23); ch.addPoint(P33); return ch; } public Primitive[] split() { Primitive[] result = new Primitive[2]; extractPoints(); vtmp.sub(P30, P00); float l1 = vtmp.length(); vtmp.sub(P33, P03); float l2 = vtmp.length(); float ul = (l1 + l2) / 2f; vtmp.sub(P03, P00); l1 = vtmp.length(); vtmp.sub(P33, P30); l2 = vtmp.length(); float vl = (l1 + l2) / 2f; if (ul > vl) { result[0] = new BicubicPatch(bezierInterpolateParameters(0f, .5f, 0f, 1f), attributes); result[1] = new BicubicPatch(bezierInterpolateParameters(.5f, 1f, 0f, 1f), attributes); } else { result[0] = new BicubicPatch(bezierInterpolateParameters(0f, 1f, 0f, .5f), attributes); result[1] = new BicubicPatch(bezierInterpolateParameters(0f, 1f, .5f, 1f), attributes); } return result; } protected Map bezierInterpolateParameters( float uv00, float uv10, float uv01, float uv11) { Map result = linearInterpolateParameters(uv00, uv10, uv01, uv11); extractPoints(); Point3f[][] p = new Point3f[16][]; for (int i = 0; i < 16; i++) { p[i] = new Point3f[1]; p[i][0] = new Point3f(); } Point3f PS00 = p[0][0]; Point3f PS10 = p[1][0]; Point3f PS20 = p[2][0]; Point3f PS30 = p[3][0]; Point3f PS01 = p[4][0]; Point3f PS11 = p[5][0]; Point3f PS21 = p[6][0]; Point3f PS31 = p[7][0]; Point3f PS02 = p[8][0]; Point3f PS12 = p[9][0]; Point3f PS22 = p[10][0]; Point3f PS32 = p[11][0]; Point3f PS03 = p[12][0]; Point3f PS13 = p[13][0]; Point3f PS23 = p[14][0]; Point3f PS33 = p[15][0]; if (uv00 == .5f) { splitUpper(P00, P10, P20, P30, PS00, PS10, PS20, PS30); splitUpper(P01, P11, P21, P31, PS01, PS11, PS21, PS31); splitUpper(P02, P12, P22, P32, PS02, PS12, PS22, PS32); splitUpper(P03, P13, P23, P33, PS03, PS13, PS23, PS33); } else if (uv10 == .5f) { splitLower(P00, P10, P20, P30, PS00, PS10, PS20, PS30); splitLower(P01, P11, P21, P31, PS01, PS11, PS21, PS31); splitLower(P02, P12, P22, P32, PS02, PS12, PS22, PS32); splitLower(P03, P13, P23, P33, PS03, PS13, PS23, PS33); } else if (uv01 == .5f) { splitUpper(P00, P01, P02, P03, PS00, PS01, PS02, PS03); splitUpper(P10, P11, P12, P13, PS10, PS11, PS12, PS13); splitUpper(P20, P21, P22, P23, PS20, PS21, PS22, PS23); splitUpper(P30, P31, P32, P33, PS30, PS31, PS32, PS33); } else { splitLower(P00, P01, P02, P03, PS00, PS01, PS02, PS03); splitLower(P10, P11, P12, P13, PS10, PS11, PS12, PS13); splitLower(P20, P21, P22, P23, PS20, PS21, PS22, PS23); splitLower(P30, P31, P32, P33, PS30, PS31, PS32, PS33); } result.put("P", new Parameter(new Declaration("P", "vertex point"), p)); return result; } protected void splitLower( Point3f in0, Point3f in1, Point3f in2, Point3f in3, Point3f out0, Point3f out1, Point3f out2, Point3f out3) { out0.set(in0); out1.add(in0, in1); out1.scale(.5f); out2.set(in1); out2.scale(2f); out2.add(in0); out2.add(in2); out2.scale(.25f); out3.add(in1, in2); out3.scale(3f); out3.add(in0); out3.add(in3); out3.scale(.125f); } protected void splitUpper( Point3f in0, Point3f in1, Point3f in2, Point3f in3, Point3f out0, Point3f out1, Point3f out2, Point3f out3) { out3.set(in3); out2.add(in3, in2); out2.scale(.5f); out1.set(in2); out1.scale(2f); out1.add(in3); out1.add(in1); out1.scale(.25f); out0.add(in2, in1); out0.scale(3f); out0.add(in3); out0.add(in0); out0.scale(.125f); } protected void dice_P(ShaderVariables sv) { extractPoints(); Point3f[] pdata = (Point3f[]) sv.P.data; float[] udata = sv.u.data; float[] vdata = sv.v.data; for (int i = 0; i < Grid.getSize(); i++) pdata[i].set( Calc.bezierInterpolate( P00, P10, P20, P30, P01, P11, P21, P31, P02, P12, P22, P32, P03, P13, P23, P33, udata[i], vdata[i])); } protected void dice_Ng(ShaderVariables sv) { sv.Ng.cross(sv.dPdu, sv.dPdv); } } Index: Primitive.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/primitive/Primitive.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Primitive.java 22 May 2003 04:50:14 -0000 1.14 --- Primitive.java 22 May 2003 07:36:26 -0000 1.15 *************** *** 106,112 **** shaderVariables.attributes = attributes; shaderVariables.parameters = parameters; - dice_P(shaderVariables); dice_u(shaderVariables); dice_v(shaderVariables); dice_du(shaderVariables); dice_dv(shaderVariables); --- 106,112 ---- shaderVariables.attributes = attributes; shaderVariables.parameters = parameters; dice_u(shaderVariables); dice_v(shaderVariables); + dice_P(shaderVariables); dice_du(shaderVariables); dice_dv(shaderVariables); |