Hi
I'm creating a maze type game and two of the functions within my program are "CreateViewer" which creates a viewer and attachs it to a canvas. the second function "CreateViewerAvatar" creates and positions a simple cone to represent the viewer.It also takes in a number passed in the "CreateViewer" function which determines which way the cone will be faced. The problem i'm having is that i've implemented two buttons "Turn left" and "Turn right" which should should turn the cone to the left and right respectively, B UT also turn the viewer in that direction too. I'm able to create a cone turned in a certain direction but i'm not able to do it by pressing a button and i'm not able to set the viewer to position that way too.Does anyone have any ideas in how to implement this.I'm new to Java3D so please bear with me. the two functions are below.
Thanks. Sharon

ViewingPlatform createViewer( Canvas3D c, Color3f objColor, double x, double z ){

// create a Viewer and attach to its canvas

// a Canvas3D can only be attached to a single Viewer

Viewer viewer2 = new Viewer( c );

// create a ViewingPlatform with 1 TransformGroups above the ViewPlatform

ViewingPlatform vp2 = new ViewingPlatform( 1 );

// create and assign the PlatformGeometry to the Viewer

// create and assign the ViewerAvatar to the Viewer

viewer2.setAvatar( createViewerAvatar( 1.0f ) );

// set the initial position for the Viewer

Transform3D t3d = new Transform3D( );

t3d.setTranslation( new Vector3d( x, 0, z ) );

vp2.getViewPlatformTransform( ).setTransform( t3d );

// set capabilities on the TransformGroup so that the KeyNavigatorBehavior

// can modify the Viewer's position

vp2.getViewPlatformTransform( ).setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );

vp2.getViewPlatformTransform( ).setCapability( TransformGroup.ALLOW_TRANSFORM_READ );

// attach a navigation behavior to the position of the viewer

KeyNavigatorBehavior key = new KeyNavigatorBehavior( vp2.getViewPlatformTransform( ) );

key.setSchedulingBounds( m_Bounds );

key.setEnable( true );

// add the KeyNavigatorBehavior to the ViewingPlatform

vp2.addChild( key );

// set the ViewingPlatform for the Viewer

viewer2.setViewingPlatform( vp2 );

// associate the name of the Viewer with its KeyNavigatorBehavior

return vp2;

}

*************************************************************

// creates and positions a simple Cone to represent the Viewer.

ViewerAvatar createViewerAvatar( float direction )

{

ViewerAvatar viewerAvatar = new ViewerAvatar( );

Color3f objColor = new Color3f( 0.1f, 1.0f, 1.0f );

// rotate the Cone so that it is lying down and

// points sharp-end towards the Viewer's field of view.

TransformGroup tg = new TransformGroup( );

tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

Transform3D t3d = new Transform3D( );

if ( direction == 1.0f )

{

//points the cone straight ahead

t3d.setEuler( new Vector3d( Math.PI / 2, Math.PI, 0 ) );

}

else if ( direction == 2.0f ){

//turns the cone to the right

t3d.setEuler( new Vector3d( Math.PI / 2, Math.PI/2.0f, 0 ) );

}

else if (direction == 3.0f ){

//turns the cone to the left

t3d.setEuler( new Vector3d( Math.PI / 2, Math.PI*1.5f, 0 ) );

}

tg.setTransform( t3d );

// create appearance and material for the Cone

Appearance app = new Appearance( );

Color3f black = new Color3f( 2.4f, 0.2f, 0.1f );

app.setMaterial( new Material( objColor, black, objColor, black, 90.0f ) );

// create the Primitive and add to the parent BranchGroup

Vector3f vector = new Vector3f(5, 0, -6 );

Cone cone = new Cone(1f,2f, Primitive.GENERATE_NORMALS, app);

tg.addChild( cone );

viewerAvatar.addChild( tg );

return viewerAvatar;

}


the new MSN 8 and get 2 months FREE*


MSN 8 helps ELIMINATE E-MAIL VIRUSES. Get 2 months FREE*. =========================================================================== 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".

Reply via email to