# Collision question for pong game

Winkman, thanks for the tip!

I tried that out, and Eclipse suggested:

n.updateRenderState();

which moved my node!

OK, no more questions from me until I go over the SimpleGame code a LOT more

Thanks again!

You know what Winkman,

You were right.  I just realized when I tried the updateGeomState,

I didn't have the (0.0f, true) in there.

I used that and it's working too with just that (not updateRenderState).

So either updateGeomState or updateRenderState get me my results.

I'm sure there is a difference in which one to use, but I will look into that.

Thanks again!

Umm, updateRenderState does not update any position, but only render states (lighting, material, alpha etc.)

It should not move anything  :?

Here is what I have so far.

At the bottom (commented out for now), if I uncomment the SetLocal and either updateGeom or updateRender,

the whole node moves tooβ¦

(And this isn't the latest version,  the newer one isn't so lame :), but this demontrates it just as well).

import com.jme.app.SimpleGame;

import com.jme.scene.Node;

import com.jme.scene.shape.Box;

import com.jme.scene.shape.Sphere;

import com.jme.math.Vector3f;

import com.jme.bounding.BoundingSphere;

import com.jme.bounding.BoundingBox;

import com.jme.renderer.ColorRGBA;

import com.jme.input.KeyBindingManager;

import com.jme.input.KeyInput;

/**

• Started Date: Jul 20, 2004<br><br>

*
• Simple Node object with a few Geometry manipulators.

*
• @author Jack Lindamood

/

public class test5 extends SimpleGame {

float ballx=0, bally=0, ballz=0;

int balldir=-1;

int ballang=1;

Box boxl, boxr, boxt, boxb;

Sphere s;

Node n=new Node("My Node");

public static void main(String[] args) {

test5 app = new test5();

app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);

app.start();

}

protected void simpleInitGame() {

Vector3f pos = new Vector3f(0.0f, 10.0f, 10.0f);

Vector3f left = new Vector3f( -1.0f, 0.0f, 0.0f);

Vector3f up = new Vector3f(0.0f, 0.7f, -0.7f);

Vector3f dir = new Vector3f(0.0f, -0.7f, -0.7f);

/**

Vector3f pos = new Vector3f(0.0f, 10.0f, 10.0f);

Vector3f left = new Vector3f( -1.0f, 0.0f, 0.0f);

Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);

Vector3f dir = new Vector3f(0.0f, 0.0f, -1.0f);

/

/
Move our camera to a correct place and orientation. /

cam.setFrame(pos, left, up, dir);

//cam.setLocation(new Vector3f(0.0f, 0.0f, 10.0f));

boxl=new Box("My Box",new Vector3f(0,0,0),new Vector3f(0.5f,0.5f,2));

// Give the box a bounds object to allow it to be culled

boxl.setModelBound(new BoundingBox());

// Calculate the best bounds for the object you gave it

boxl.updateModelBound();

// Move the box 2 in the y direction up

// Give the box a solid color of blue.

boxl.setSolidColor(ColorRGBA.blue);

boxr=new Box("My Box",new Vector3f(0,0,0),new Vector3f(0.5f,0.5f,10));

// Give the box a bounds object to allow it to be culled

boxr.setModelBound(new BoundingBox());

// Calculate the best bounds for the object you gave it

boxr.updateModelBound();

// Move the box 2 in the y direction up

boxr.setLocalTranslation(new Vector3f(5,0,-5));

// Give the box a solid color of blue.

boxr.setSolidColor(ColorRGBA.red);

//BALL

s=new Sphere("My sphere",10,10,0.5f);

// Do bounds for the sphere, but we'll use a BoundingBox this time

BoundingSphere.useExactBounds=true;

s.setModelBound(new BoundingSphere());

s.updateModelBound();

BoundingSphere.useExactBounds=false;

// Move the box 2 in the y direction up

s.setLocalTranslation(new Vector3f(ballx,0,ballz));

// Give the sphere random colors

s.setRandomColors();

// Make a node and give it children

//TOP WALL

boxt=new Box("My Box",new Vector3f(0,0,0),new Vector3f(10.0f,0.5f,0.5f));

// Give the box a bounds object to allow it to be culled

boxt.setModelBound(new BoundingBox());

// Calculate the best bounds for the object you gave it

boxt.updateModelBound();

// Move the box 2 in the y direction up

boxt.setLocalTranslation(new Vector3f(-5,0,-5));

// Give the box a solid color of blue.

boxt.setSolidColor(ColorRGBA.green);

//BOTTOM WALL

boxb=new Box("My Box",new Vector3f(0,0,0),new Vector3f(10.0f,0.5f,0.5f));

// Give the box a bounds object to allow it to be culled

boxb.setModelBound(new BoundingBox());

// Calculate the best bounds for the object you gave it

boxb.updateModelBound();

// Move the box 2 in the y direction up

boxb.setLocalTranslation(new Vector3f(-5,0,5));

// Give the box a solid color of blue.

boxb.setSolidColor(ColorRGBA.green);

n.attachChild(s);

n.attachChild(boxl);

n.attachChild(boxr);

n.attachChild(boxt);

n.attachChild(boxb);

// Make the node and all its children 5 times larger.

//n.setLocalScale(5);

// Remove lighting for rootNode so that it will use our

//basic colors.

lightState.detachAll();

rootNode.attachChild(n);

// Adds the "c" key to the command "getSpecs"

KeyBindingManager.getKeyBindingManager().set("getSpecs", KeyInput.KEY_V);

}

protected void simpleUpdate(){

//if the padlUp command was activated

}

//if the padlDown command was activated

}

//if the getSpecs command was activated

if (KeyBindingManager.getKeyBindingManager().isValidCommand("getSpecs",true)){

//Get Specs

System.out.println("Cam Loc:" + cam.getLocation());

System.out.println("Cam Left:" + cam.getLeft());

System.out.println("Cam Up:" + cam.getUp());

System.out.println("Cam Dir:" + cam.getDirection());

//System.out.println("Node at:" + b.getCenter());

}

///////////////////////

//COLLISION CHECKS

if (s.getWorldBound().intersects(boxl.getWorldBound())){

System.out.println("Collision");

balldir=(balldir
-1);

}

if (s.getWorldBound().intersects(boxr.getWorldBound())){

System.out.println("Collision");

balldir=(balldir
-1);

}

//BALL WITH TOP WALL

if (s.getWorldBound().intersects(boxt.getWorldBound())){

System.out.println("Collision");

ballang=(ballang*-1);

}

//BALL WITH BOTTOM WALL

if (s.getWorldBound().intersects(boxb.getWorldBound())){

System.out.println("Collision");

ballang=(ballang*-1);

}

//END COLLISION CHECKS

//////////////////////

ballx=ballx+(balldir*.01f);

ballz=ballz+(ballang*.01f);

s.setLocalTranslation(new Vector3f(ballx,0,ballz));

//n.setLocalTranslation(new Vector3f(ballx,0,ballz));

//n.updateGeometricState(0.0f, true);

//n.updateRenderState();

}

}