Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with lighting in Java3D

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Well I've been trying to code one level of a simple game with a bouncing ball, paddle, and bricks. I've more or less been snipping bits of code from the 2001 "The Joy of Java3D" tutorial by Greg Hopkins. In particular, I used an adaptation of BouncingBall.java and a small section cut from Position.java. Below is the section of code that is problematic. The problem is that after compiling fine, for some reason the red lighting is not falling on the mass of bricks AT ALL while it does fall on the ball and the paddle. Can anyone see why and maybe offer an alternative way of coding that will output the desired effect? Thank you in advance.

---------------------------------------------------------------------------

public BranchGroup createSceneGraph ()
{
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
ballTrans = new TransformGroup();
ballTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
paddleTrans = new TransformGroup();
paddleTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(ballTrans);
objRoot.addChild(paddleTrans);

// Create a ball.
Sphere sphere = new Sphere(0.05f);
Transform3D pos1 = new Transform3D();
pos1.setTranslation(new Vector3f(ballX,0.0f,0.0f));

// Create a paddle.
Cylinder cylinder = new Cylinder(0.2f, 0.02f);
Transform3D pos2 = new Transform3D();
//ap.setMaterial(new Material(white, black, white, black, 0.0f));
pos2.setTranslation(new Vector3f(paddleX,-0.5f,0.0f));

// Create bricks.
for (float f=-0.75f; f<=0.85f; f+=0.1f)
{
for (float g=0.0f; g<=0.5f; g+=0.05f)
{
TransformGroup bricksTrans = new TransformGroup();
bricksTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D pos3 = new Transform3D();
Box box = new Box(0.05f, 0.04f, 0.1f, new Appearance());
pos3.setTranslation(new Vector3f(f, g, 0.0f));
bricksTrans.setTransform(pos3);
bricksTrans.addChild(box);
objRoot.addChild(bricksTrans);
}
}

// Attach both objects to transform groups.
ballTrans.setTransform(pos1);
ballTrans.addChild(sphere);
paddleTrans.setTransform(pos2);
paddleTrans.addChild(cylinder);
BoundingSphere bounds = new BoundingSphere();

Color3f light1Color = new Color3f(1.0f, 0.0f, 0.2f);
Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
objRoot.addChild(light1);

// Set up the ambient light
Color3f ambientColor = new Color3f(1.0f, 1.0f, 1.0f);
AmbientLight ambientLightNode = new AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(bounds);
objRoot.addChild(ambientLightNode);

return objRoot;
}
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic