hello, i'm still trying to understand the code you posted Florin... i tried to make some modifications,but i have a problem and i couldn't solve it..in the code which is attached to this email i played a bit with your code Florin...i tried to make a triangle only using your inner-face..but now i can see only inner side of triangle,but i want to see all of triangle..i'm trying to play with light to make outer face of triangle also..but until now i couldn't do it.. if you Florin or anyone can help me for this i'll be glad to him/her...
best wishes ps:enclosed code --- Florin Herinean <[EMAIL PROTECTED]> wrote: > :) I coudn't stop myself, so here is a slightly > modified scene which has a > waving water flowing through the pipe. > > Of course, the model is very simplistic, no bouncing > on the walls (infinite > pipe model, laminar flow), water waves follows a > strictly sinusoidal curve, > no textures (pure geometry). > > Starting with that model, I hope I'll see posted by > you a nice simulation of > a fluid flowing through a non liniar pipe: turbulent > / laminar flow > depending on the Reynolds/Prandtl numbers, etc. > > Consider shape of the pipe, roughness of the pipe > material, characteristics > of the flowing fluid (water, milk), debit of the > fluid, etc. > > Cheers, > > Florin > > -----Original Message----- > From: Discussion list for Java 3D API > [mailto:[EMAIL PROTECTED] Behalf Of > demir sencer > Sent: Donnerstag, 1. April 2004 17:18 > To: [EMAIL PROTECTED] > Subject: Re: [JAVA3D] how to draw a 3D > hollow-semi-cylinder HELP > > > wow!!! > thnx florin,it really looks interesting.. > i'll work on this all the nite i think.. > > thnk u.. > > --- Florin Herinean <[EMAIL PROTECTED]> wrote: > > Hi Demir, > > > > I've played a little and I've created for you a > > class to generate a half > > cylinder parametrized by height, inner/outer > radius > > and number of slices for > > the curvature. > > > > The class has a static method generate(...) which > > will create for you a > > Geometry object. > > > > Also the class is runnable, so you can test your > > cylinder. > > > > I've intentionally left out the texture > coordinates > > as an exercise for you. > > > > You should really try to experiment by creating > > geometries by hand from time > > to time, to get a feeling of what can be done and > > how. And don't forget to > > read the manuals. > > > > Cheers, > > > > Florin > > > > -----Original Message----- > > From: Discussion list for Java 3D API > > [mailto:[EMAIL PROTECTED] Behalf Of > > demir sencer > > Sent: Donnerstag, 1. April 2004 15:33 > > To: [EMAIL PROTECTED] > > Subject: Re: [JAVA3D] how to draw a 3D > > hollow-semi-cylinder HELP > > > > > > first of all i'm so so so sorry,Florin and Gilson, > > i made mistake,i wanted to send to whole group my > > messages but i sent emails by mistake to 2 u who > > helped me with their ideas/code..sorry to disturb > u > > :(:( > > > > its what i did up to now,its code of my 3DWorld > > class..i created everything here..if anyone wants > i > > can send all my package to have a look how it > > works,how it looks like.. > > ... > > > > > =========================================================================== > > To unsubscribe, send email to > [EMAIL PROTECTED] > > and include in the body > > of the message "signoff JAVA3D-INTEREST". For > > general help, send email to > > [EMAIL PROTECTED] and include in the body of > the > > message "help". > > > > > ATTACHMENT part 2 java/* name=HollowCilinder.java > > > > __________________________________ > Do you Yahoo!? > Yahoo! Small Business $15K Web Design Giveaway > http://promotions.yahoo.com/design_giveaway/ > > =========================================================================== > To unsubscribe, send email to [EMAIL PROTECTED] > and include in the body > of the message "signoff JAVA3D-INTEREST". For > general help, send email to > [EMAIL PROTECTED] and include in the body of the > message "help". > > =========================================================================== > To unsubscribe, send email to [EMAIL PROTECTED] > and include in the body > of the message "signoff JAVA3D-INTEREST". For > general help, send email to > [EMAIL PROTECTED] and include in the body of the > message "help". > > ATTACHMENT part 2 java/* name=HollowCilinder.java __________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/ =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
import java.awt.BorderLayout; import java.util.Enumeration; import javax.media.j3d.*; import javax.swing.JFrame; import javax.vecmath.Color3f; import javax.vecmath.Point3d; import javax.vecmath.Vector3f; import javax.vecmath.Vector3d; import com.sun.j3d.utils.behaviors.vp.OrbitBehavior; import com.sun.j3d.utils.universe.PlatformGeometry; import com.sun.j3d.utils.universe.SimpleUniverse; import com.sun.j3d.utils.universe.ViewingPlatform; public class HollowCylinder2 { private static int steps = 16; private static double length = 2; private static double inner = 0.4; private static double height = 0.3; private static double outer = 0.6; public static Geometry generatePipe() { int p_steps = 2 * steps; double[] coords = new double[(2 * p_steps + 1) * 24]; float[] normals = new float[(2 * p_steps + 1) * 24]; double[] xi = new double[p_steps + 1]; double[] xo = new double[p_steps + 1]; double[] zi = new double[p_steps + 1]; double[] zo = new double[p_steps + 1]; xi[0] = inner; xo[0] = outer; xi[p_steps] = -inner; xo[p_steps] = -outer; double a = Math.PI / p_steps; double h = length / 2; for (int i = 1; i < p_steps; i++) { double x = Math.cos(a * i); double z = Math.sin(a * i); xi[i] = x * inner; xo[i] = x * outer; zi[i] = z * inner; zo[i] = z * outer; } int c = 0; int n = 0; /* // upper cap for (int i = 0; i < p_steps; i++) { coords[c++] = xo[i]; coords[c++] = h; coords[c++] = zo[i]; coords[c++] = xi[i]; coords[c++] = h; coords[c++] = zi[i]; coords[c++] = xi[i + 1]; coords[c++] = h; coords[c++] = zi[i + 1]; coords[c++] = xo[i + 1]; coords[c++] = h; coords[c++] = zo[i + 1]; for (int j = 0; j < 4; j++) { normals[n++] = 0; normals[n++] = 1; normals[n++] = 0; } } // lower cap for (int i = 0; i < p_steps; i++) { coords[c++] = xi[i]; coords[c++] = -h; coords[c++] = zi[i]; coords[c++] = xo[i]; coords[c++] = -h; coords[c++] = zo[i]; coords[c++] = xo[i + 1]; coords[c++] = -h; coords[c++] = zo[i + 1]; coords[c++] = xi[i + 1]; coords[c++] = -h; coords[c++] = zi[i + 1]; for (int j = 0; j < 4; j++) { normals[n++] = 0; normals[n++] = -1; normals[n++] = 0; } } // outer face for (int i = 0; i < p_steps; i++) { coords[c++] = xo[i]; coords[c++] = -h; coords[c++] = zo[i]; coords[c++] = xo[i]; coords[c++] = h; coords[c++] = zo[i]; coords[c++] = xo[i + 1]; coords[c++] = h; coords[c++] = zo[i + 1]; coords[c++] = xo[i + 1]; coords[c++] = -h; coords[c++] = zo[i + 1]; for (int k = 0; k < 2; k++) { double nx = Math.cos((i + k) * a); double nz = Math.sin((i + k) * a); for (int j = 0; j < 2; j++) { normals[n++] = (float) nx; normals[n++] = 0; normals[n++] = (float) nz; } } } // first transition coords[c++] = xo[p_steps]; coords[c++] = -h; coords[c++] = zo[p_steps]; coords[c++] = xo[p_steps]; coords[c++] = h; coords[c++] = zo[p_steps]; coords[c++] = xi[p_steps]; coords[c++] = h; coords[c++] = zi[p_steps]; coords[c++] = xi[p_steps]; coords[c++] = -h; coords[c++] = zi[p_steps]; for (int k = 0; k < 4; k++) { normals[n++] = 0; normals[n++] = 0; normals[n++] = -1; } */ // inner face xi = new double[3]; zi = new double[3]; xi[0] = -0.1; xi[1] = 0; xi[2] = 0.1; zi[0] = 0.1; zi[1] = 0; zi[2] = 0.1; for (int i =2 /*p_steps*/; i > 0; i--) { coords[c++] = xi[i]; coords[c++] = -h; coords[c++] = zi[i]; coords[c++] = xi[i]; coords[c++] = h; coords[c++] = zi[i]; coords[c++] = xi[i - 1]; coords[c++] = h; coords[c++] = zi[i - 1]; coords[c++] = xi[i - 1]; coords[c++] = -h; coords[c++] = zi[i - 1]; /* for (int k = 0; k < 2; k++) { double nx = -Math.cos((i - k) * a); double nz = -Math.sin((i - k) * a); for (int j = 0; j < 2; j++) { normals[n++] = (float) nx; normals[n++] = 0; normals[n++] = (float) nz; } } */ } /* // last transition coords[c++] = xi[0]; coords[c++] = -h; coords[c++] = zi[0]; coords[c++] = xi[0]; coords[c++] = h; coords[c++] = zi[0]; coords[c++] = xo[0]; coords[c++] = h; coords[c++] = zo[0]; coords[c++] = xo[0]; coords[c++] = -h; coords[c++] = zo[0]; */ for (int k = 0; k < 4; k++) { normals[n++] = 0; normals[n++] = 0; normals[n++] = -1; } GeometryArray result = new QuadArray(coords.length / 3, GeometryArray.COORDINATES | GeometryArray.NORMALS); result.setCoordinates(0, coords); result.setNormals(0, normals); return result; } public static void main(String[] args) { // super("Memory Usage Test"); JFrame frame = new JFrame("my 2nd Hollow Half Cylinder :):)"); // create canvas & universe Canvas3D c3d = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); SimpleUniverse universe = new SimpleUniverse(c3d); ViewingPlatform platform = universe.getViewingPlatform(); Transform3D t3d = new Transform3D(); Point3d center = new Point3d(0, 0, 0.3); Point3d eye = new Point3d(3.6, 2, -0.7); Vector3d up = new Vector3d(0, 0, -1); t3d.lookAt(eye, center, up); t3d.invert(); platform.getViewPlatformTransform().setTransform(t3d); // create orbiter Bounds bounds = new BoundingSphere(new Point3d(), 10.0); OrbitBehavior orbit = new OrbitBehavior(c3d, OrbitBehavior.REVERSE_ALL /* | OrbitBehavior.DISABLE_TRANSLATE | OrbitBehavior.DISABLE_ZOOM */ ); orbit.setSchedulingBounds(bounds); platform.setViewPlatformBehavior(orbit); // setup the lights Color3f ambientLightColor = new Color3f(0.30f, 0.30f, 0.30f); Color3f diffuseLightColor = new Color3f(0.75f, 0.75f, 0.75f); Vector3f diffuseLightDirection = new Vector3f(-1, -1, -1); PlatformGeometry pg = new PlatformGeometry(); Light ambient = new AmbientLight(true, ambientLightColor); ambient.setInfluencingBounds(bounds); pg.addChild(ambient); Light directional = new DirectionalLight(true, diffuseLightColor, diffuseLightDirection); directional.setInfluencingBounds(bounds); pg.addChild(directional); platform.setPlatformGeometry(pg); BranchGroup root = new BranchGroup(); Appearance appearance1 = new Appearance(); Material material1 = new Material(); appearance1.setMaterial(material1); Shape3D shape1 = new Shape3D(generatePipe(), appearance1); root.addChild(shape1); Appearance appearance = new Appearance(); Material material = new Material(); material.setDiffuseColor(0.5f, 0.5f, 1); material.setShininess(100); appearance.setMaterial(material); appearance.setPolygonAttributes(new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, true)); appearance.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.NICEST, 0.7f)); GeometryArray water = generateWater(); Shape3D shape = new Shape3D(water, appearance); root.addChild(shape); Behavior wb = new WaterBehavior(water); wb.setSchedulingBounds(bounds); root.addChild(wb); root.compile(); universe.getLocale().addBranchGraph(root); // show the window frame.getContentPane().add(c3d, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); frame.setLocation(300, 300); frame.setVisible(true); } private static GeometryArray generateWater() { int w_steps = steps * 8; double[] coords = new double[w_steps * 4 * 3]; float[] normals = new float[w_steps * 4 * 3]; double l = length / w_steps; double y = length / 2; double z = inner - height; double x = Math.sqrt(inner * inner - z * z); int c = 0; int n = 0; for (int i = 0; i < w_steps; i++) { coords[c++] = -x; coords[c++] = y; coords[c++] = z; coords[c++] = x; coords[c++] = y; coords[c++] = z; y -= l; coords[c++] = x; coords[c++] = y; coords[c++] = z; coords[c++] = -x; coords[c++] = y; coords[c++] = z; } for (int i = 0; i < w_steps * 4; i++) { normals[n++] = 0; normals[n++] = 0; normals[n++] = -1; } GeometryArray result = new QuadArray(coords.length / 3, GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.BY_REFERENCE); result.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE); result.setCapability(GeometryArray.ALLOW_REF_DATA_READ); result.setCoordRefDouble(coords); result.setNormalRefFloat(normals); return result; } private static class WaterBehavior extends Behavior implements GeometryUpdater { private WakeupCondition wakeup = new WakeupOnElapsedTime(20); private GeometryArray geometry; private Alpha alpha = new Alpha(); public WaterBehavior(GeometryArray geometry) { this.geometry = geometry; } public void initialize() { wakeupOn(wakeup); } public void processStimulus(Enumeration enumeration) { geometry.updateData(this); wakeupOn(wakeup); } public void updateData(Geometry geometry) { double[] coords = ((GeometryArray) geometry).getCoordRefDouble(); float[] normals = ((GeometryArray) geometry).getNormalRefFloat(); int stripes = coords.length / 12; double delta = length / stripes; double u = 2 * Math.PI * alpha.value(); for (int i = 0; i < stripes; i++) { double a = u + i * delta * 20; double h = inner - height + Math.sin(a) * 0.025; int offset = 12 * i; coords[offset + 2] = h; coords[offset + 5] = h; a = u + (i + 1) * delta * 20; h = inner - height + Math.sin(a) * 0.025; coords[offset + 8] = h; coords[offset + 11] = h; double dz = coords[offset + 8] - coords[offset + 2]; double dy = coords[offset + 7] - coords[offset + 1]; double len = Math.sqrt(dz * dz + dy * dy); dz /= len; dy /= len; for (int k = 0; k < 4; k++) { normals[offset + 1] = (float) -dz; normals[offset + 2] = (float) dy; offset += 3; } } for (int i = 1; i < stripes; i++) { int offset = 12 * i; float dy = (normals[offset - 2] + normals[offset + 1]) / 2; float dz = (normals[offset - 1] + normals[offset + 2]) / 2; offset -= 5; for (int k = 0; k < 4; k++) { normals[offset] = dy; normals[offset + 1] = dz; offset += 3; } } } } } =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".