Refine search
for(int i=0;i<24;i++)normals[i]=new Vector3f(); Point3f [] pts=new Point3f[24]; for(int i=0;i<24;i++)pts[i]=new Point3f(); Color3f [] clrs=new Color3f[24]; for(int i=0;i<24;i++)clrs[i]=new Color3f(0.5f,0.5f,0.5f); pa.setCullFace(PolygonAttributes.CULL_NONE); Material mat=new Material(); mat.setEmissiveColor(new Color3f(0.5f,0.5f,0.5f)); mat.setAmbientColor(new Color3f(0.1f,0.1f,0.1f)); mat.setDiffuseColor(new Color3f(0.2f,0.3f,0.4f)); mat.setSpecularColor(new Color3f(0.6f,0.3f,0.2f)); light1.setInfluencingBounds(new BoundingSphere(new Point3d(-5.0,0,0),10.0)); light1.setColor(new Color3f(1f,1f,1f)); light1.setDirection(new Vector3f(0,1,0)); objRotate.addChild(light1); DirectionalLight light2=new DirectionalLight(); light2.setInfluencingBounds(new BoundingSphere(new Point3d(5.0,0,0),10.0)); light2.setColor(new Color3f(0.5f,1f,0.5f)); light2.setDirection(new Vector3f(0,-1,0)); objRotate.addChild(light2); MouseRotate f1=new MouseRotate();
public Vector3f[] getNormals() { final Vector3f[] normals = new Vector3f[nVertices]; for (int i = 0; i < nVertices; i++) normals[i] = new Vector3f(); final Vector3f v1 = new Vector3f(), v2 = new Vector3f(); for (int i = 0; i < nFaces; i += 3) { final int f1 = faces[i]; final int f2 = faces[i + 1]; final int f3 = faces[i + 2]; v1.sub(vertices[f2], vertices[f1]); v2.sub(vertices[f3], vertices[f1]); v1.cross(v1, v2); normals[f1].add(v1); normals[f2].add(v1); normals[f3].add(v1); } for (int i = 0; i < nVertices; i++) normals[i].normalize(); return normals; }
Vector3f seperationVector=box2.getWorldTranslation().subtract(box1.getWorldTranslation()); Vector3f perpendicularFromTheAction= seperationVector.cross(Vector3f.UNIT_Y); perpendicularFromTheAction.normalizeLocal();
static boolean getNormal(Point3f p1, Point3f p2, Point3f p3, Vector3f normal) { Vector3f v1 = new Vector3f(); Vector3f v2 = new Vector3f(); // Must compute normal v1.sub(p2, p1); v2.sub(p2, p3); normal.cross(v1, v2); normal.negate(); float length = normal.length(); if (length > 0) { length = 1 / length; normal.x *= length; normal.y *= length; normal.z *= length; return true; } return false; }
Vector3f axis = new Vector3f((float)hotspot.x, (float)hotspot.y, (float)hotspot.z) ; Vector3f axis1 = new Vector3f() ; axis1.normalize(axis) ; Vector3f normal = new Vector3f(0.0f, 1.0f, 0.0f) ; normal.cross(axis1, normal) ; if (normal.lengthSquared() < 0.5f) { normal.set(0.0f, 0.0f, 1.0f) ; normal.cross(axis1, normal) ; normal.normalize() ; Point3f[] cap1 = new Point3f[divisions] ; Vector3f[] capNormals = new Vector3f[divisions] ; Vector3f cap0Normal = new Vector3f(axis1) ; Vector3f cap1Normal = new Vector3f(axis1) ; cap0Normal.negate() ; capNormals[i] = new Vector3f(normal) ; cap0[i] = new Point3f(normal) ; cap0[i].scale(halfWidth) ; cap1[i] = new Point3f(cap0[i]) ; cap1[i].add(axis) ; t3d.transform(normal) ;
double angle = 0; for (int i=0; i<parallels; i++) { plane.add(new Point3f((float)Math.cos(angle), (float)Math.sin(angle), 0)); angle += inc_rads; final Vector3f vplane = new Vector3f(0, 0, 1); final Transform3D t = new Transform3D(); final AxisAngle4f aa = new AxisAngle4f(); final Color3f cf = new Color3f(this.color); final HashMap<Color,Color3f> cached_colors = new HashMap<Color,Color3f>(); cached_colors.put(this.color, cf); final Vector3f vpc = new Vector3f(x - parx, y - pary, z - parz); final Vector3f cross = new Vector3f(); cross.cross(vpc, vplane); cross.normalize(); // not needed? aa.set(cross.x, cross.y, cross.z, -vplane.angle(vpc)); t.set(aa); c = cached_colors.get(nd.color); if (null == c) { c = new Color3f(nd.color); cached_colors.put(nd.color, c);
private void addText(final String s, final Point3f pos, final float fontsize, final Color3f c) { final Transform3D translation = new Transform3D(); translation.rotX(Math.PI); translation.setTranslation(new Vector3f(pos)); final TransformGroup tg = new TransformGroup(translation); final OrientedShape3D textShape = new OrientedShape3D(); textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT); textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f); textShape.setRotationPoint(new Point3f(0, 0, 0)); textShape.setConstantScaleEnable(true); final Text2D t2d = new Text2D(s, c, "Helvetica", 24, Font.PLAIN); t2d.setRectangleScaleFactor(0.03f); textShape.setGeometry(t2d.getGeometry()); textShape.setAppearance(t2d.getAppearance()); tg.addChild(textShape); addChild(tg); }
public void applyTranslation(final float dx, final float dy, final float dz) { final Transform3D t = new Transform3D(); t.setTranslation(new Vector3f(dx, dy, dz)); applyTransform(t); }
private final Vector3f yAxis = new Vector3f(0f, 1f, 0f); private Vector3f direction; Vector3f axis = new Vector3f(); axis.cross(yAxis, direction); axis.normalize(); final float angleX = yAxis.angle(direction); final float a = axis.x * (float) Math.sin(angleX / 2f); final float b = axis.y * (float) Math.sin(angleX / 2f); final float d = (float) Math.cos(angleX / 2f); Transform3D t3d = new Transform3D(); Quat4f quat = new Quat4f(a, b, c, d); t3d.set(quat); arrowheadRotationGroup.setTransform(t3d); Transform3D translateToTarget = new Transform3D(); translateToTarget.setTranslation(this.direction); arrowheadPositionGroup.setTransform(translateToTarget);
float allGains = this.gain; // product of gain scale factors Point3f workingPosition = new Point3f(); Point3f workingCenterEar = new Point3f(); Vector3f mixScale = new Vector3f(); // for mix*Samples code workingPosition.set(positions[currentIndex]); workingCenterEar.set(centerEars[currentIndex]); if (debugFlag) { xformHeadZAxis.z ); debugPrint("panSample:length of sourceToCenterEar " + sourceToCenterEar.length()); debugPrint("panSample:length of xformHeadZAxis " + xformHeadZAxis.length()); (sourceToCenterEar.dot(xformHeadZAxis))/ (sourceToCenterEar.length() * xformHeadZAxis.length())); if (debugFlag) debugPrint( " dot product = " + dotProduct );
void outVertex(Point3f[] dpts, Vector3f[] dnormals, TexCoord2f[] dtcoords, int dloc, Point3f[] spts, Vector3f[] snormals, TexCoord2f[] stcoords, int sloc) { if (debug >= 1) System.out.println("v " + spts[sloc].x + " " + spts[sloc].y + " " + spts[sloc].z); // PSP: Do we really need new points here? dpts[dloc] = new Point3f(spts[sloc]); if ((flags & Primitive.GENERATE_NORMALS) != 0){ dnormals[dloc] = new Vector3f(snormals[sloc]); } if ((flags & Primitive.GENERATE_TEXTURE_COORDS) != 0){ if (debug >= 2) System.out.println("final out tcoord"); dtcoords[dloc] = new TexCoord2f(stcoords[sloc]); } } }
final double c = r * Math.cos(a); final double s = r * Math.sin(a); p[i] = new Point3f((float) c, (float) s, 0); float ax = -(float) Math.asin((p1.y - p0.y) / p1.distance(p0)); rx.rotX(ax); final Point3f pi = p[i]; rx.transform(pi); pi.add(p0); p2 = points.get(pi + 1); final Vector3f p0p1 = new Vector3f(); p0p1.sub(p1, p0); final Vector3f p1p2 = new Vector3f(); p1p2.sub(p2, p1); p0p1.normalize(); p1p2.normalize(); final Vector3f plane = new Vector3f(); plane.add(p0p1); plane.add(p1p2); plane.normalize(); final Vector3f transl = new Vector3f(); transl.sub(p1, p0);
float length = (float)axisLength ; axes[FRONT] = new Point3f(0f, 0f, length) ; axes[BACK] = new Point3f(0f, 0f, -length) ; axes[LEFT] = new Point3f(-length, 0f, 0f) ; axes[RIGHT] = new Point3f( length, 0f, 0f) ; axes[TOP] = new Point3f(0f, length, 0f) ; transform.transform(axes[i]) ; for (int i = FRONT ; i <= BACK ; i++) for (int j = 0 ; j < 4 ; j++) transform.transform(cube[i][j]) ; Vector3f v0 = new Vector3f() ; Vector3f v1 = new Vector3f() ; Vector3f[] normals = new Vector3f[72] ; v0.sub(vertices[i+1], vertices[i]) ; v1.sub(vertices[i+2], vertices[i]) ; Vector3f n = new Vector3f() ; n.cross(v0, v1) ; n.normalize() ;
final float tickSize, final boolean noTicks) final float lineLength = start.distance(end); final int nTicks = (int) Math.floor((lineLength - first) / tickDistance) + 1; coords[i++] = end; if (!noTicks) { final Point3f p = new Point3f(); final Vector3f dir = new Vector3f(); dir.sub(end, start); dir.normalize(); final float fx = first * dir.x; final float fy = first * dir.y; final float fz = first * dir.z; dir.scale(tickDistance); for (int t = 0; t < nTicks; t++) { p.x = start.x + fx + t * dir.x; p.z = start.z + fz + t * dir.z; coords[i++] = new Point3f(p.x - tickSize, p.y, p.z); coords[i++] = new Point3f(p.x + tickSize, p.y, p.z); coords[i++] = new Point3f(p.x, p.y - tickSize, p.z);
Vector3f n1 = new Vector3f(), n2 = new Vector3f(); numPoints = 0; for (i = 0; i < islandCounts.length; i++) { Vector3f goodNormal = new Vector3f(); Vector3f n3 = new Vector3f(), n4 = new Vector3f(); Vector3f p1Normal = new Vector3f(); Vector3f p2Normal = new Vector3f(); Vector3f p3Normal = new Vector3f(); Vector3f q1Normal = new Vector3f(); Vector3f q2Normal = new Vector3f(); Vector3f q3Normal = new Vector3f(); n1.negate(); goodNormal.set(n1); break; n1.set(goodNormal); } else { if (!flip_side_orient) { n1.negate(); goodNormal.set(n1); n2.set(goodNormal); } else {
private static Point3f intersect(final Point3f p1, final Point3f p2, final Vector3f n, final Point3f p3) { // http://paulbourke.net/geometry/planeline/ final Vector3f v1 = new Vector3f(); v1.sub(p3, p1); final Vector3f v2 = new Vector3f(); v2.sub(p2, p1); final float u = (n.dot(v1)) / (n.dot(v2)); final Point3f res = new Point3f(); res.scaleAdd(u, v2, p1); return res; } }
Vector3f toScreenVector = new Vector3f(0, 0, 1); Transform3D t3d = new Transform3D(); canvas.getImagePlateToVworld(t3d); t3d.transform(toScreenVector); tg.getTransform(t3d); //tg is Transform Group of all objects in a scene t3d.transform(toScreenVector);