Amos, I'm not sure why you're having difficulties joining the list; it
should work without any trouble.
The problem you're having below is that the TransformGroup createModel
should not be owned or controlled by you -- it is meant to be owned by
the field portrayal will be used to move your object to the appropriate
location in the field. Since the localTG in your code is no longer
being used for that purpose, I suggest you transform the localTG rather
than the globalTG because the field portrayal is just going to
transform your globalTG anyway.
That being said, there's a much easier way to do things than you're
doing below. Instead of rotating your own CylinderPortrayal3D in code,
just take your CylinderPortrayal3D and stick it inside a
TransformedPortrayal3D, and then hand the TransformedPortrayal3D to the
field portrayal. The TransformedPortrayal3D lets you apply a transform
however you like to the underlying model (the CylinderPortrayal3D).
Additionally, rather than setting the material in code, I would just
pass an Appearance object to the CylinderPortrayal3D's constructor.
Sean
On Apr 26, 2005, at 11:33 AM, Folarin, Amos Akinola (Medsch
Hampstead/Oncology) wrote:
> I’ve recently tried to join your mailing list but for some unknown
> reason I’m unable to post onto the site. I should be very grateful if
> you could provide me with some assistance.
>
> I have a query regarding the CylinderPortrayal3D, I’m trying to apply
> two transforms to a Cylinder, the first is a rotation the second is a
> translation. However these effects don’t seem to manifest in the
> display, why is this? (the transforms are listed below).
>
>
>
>
>
> public TransformGroup createModel(Object obj)
>
> {
>
> TransformGroup globalTG = new TransformGroup();
>
>
>
>
>
> CylinderPortrayalHW3D s = new
> CylinderPortrayalHW3D(Color.MAGENTA, (float)vesselElementDiameter,
> (float)vesselElementLength);
>
> s.appearance.setColoringAttributes(new
> ColoringAttributes(endoColor, ColoringAttributes.SHADE_GOURAUD));
>
> Material m= new Material();
>
> m.setAmbientColor(endoColor);
>
> m.setEmissiveColor(0f,0f,0f);
>
> m.setDiffuseColor(endoColor);
>
> m.setSpecularColor(1f,1f,1f);
>
> m.setShininess(128f);
>
> s.appearance.setMaterial(m);
>
> s.setParentPortrayal(parentPortrayal);
>
> TransformGroup localTG = s.getModel(obj, null);
>
> localTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
>
> globalTG.addChild(localTG);
>
> globalTG.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
>
>
>
> return globalTG;
>
> }
>
>
>
> public TransformGroup getModel(Object obj, TransformGroup transf)
>
> {
>
>
>
> if(transf==null)
>
> {return createModel(obj);}
>
>
>
> //handle the positioning of the cylinder using rotation and
> translation
>
> Transform3D tmpT3d = new Transform3D();
>
> //get the unit vector in the direction of a
>
> Vector3D posR = (new Vector3D(x,y,z)).normalize();
>
> //construct a rotation matrix
>
> Matrix3d rotMatrix = new Matrix3d(0.0d, posR.x, 0.0d, 0.0d,
> posR.y, 0.0d, 0.0d, posR.z, 0.0d);
>
> System.out.println("unit vec vals "+posR.x+" "+posR.y +" "+
> posR.z);
>
> //set translation of the cylinder from 0,0,0 to 0,1,0
>
> //tmpT3d.setTranslation(new Vector3d(0.0d,1.0d,0.0d));
>
> tmpT3d.setTranslation(new
> Vector3d(0.0d,vesselElementLength/2,0.0d));
>
> //apply rotation to the cylinder
>
> tmpT3d.setRotation(rotMatrix);
>
> //apply transpose to the cylinder
>
> tmpT3d.setTranslation(new Vector3d(x/2, y/2, z/2));
>
> //set the Transform of the localTG
>
> ((TransformGroup)transf.getChild(0)).setTransform(tmpT3d);
>
>
>
>
>
>
>
> return transf;
>
> }
|