re: “when i try and execute this method it throws a null pointer exception at the ballPhy.setCcdSweptSphereRadius(.1f); method”
No, it definitely does not. It may throw an exception inside that method but that line is definitely not throwing an NPE or you haven’t pasted the code correctly.
In general, if you want help with an exception then you will need to post the full stack trace so that we don’t have to guess which parts you’ve left out.
this is the entire output:
Jul 22, 2014 12:55:06 AM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.0.10
Jul 22, 2014 12:55:06 AM com.jme3.system.Natives extractNativeLibs
INFO: Extraction Directory: C:\Users\Melaia\.jmonkeyplatform\assetpacks\FallingBricks
Jul 22, 2014 12:55:09 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Lwjgl 2.9.0 context running on thread LWJGL Renderer Thread
Jul 22, 2014 12:55:09 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Adapter: igdumdim64
Jul 22, 2014 12:55:09 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Driver Version: 9.18.10.3257
Jul 22, 2014 12:55:09 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Vendor: NVIDIA Corporation
Jul 22, 2014 12:55:09 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: OpenGL Version: 4.4.0
Jul 22, 2014 12:55:09 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: Renderer: GeForce GT 630M/PCIe/SSE2
Jul 22, 2014 12:55:09 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
INFO: GLSL Ver: 4.40 NVIDIA via Cg compiler
Jul 22, 2014 12:55:09 AM com.jme3.asset.AssetConfig loadText
WARNING: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
Jul 22, 2014 12:55:09 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Device: OpenAL Soft
Jul 22, 2014 12:55:09 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Vendor: OpenAL Community
Jul 22, 2014 12:55:09 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Renderer: OpenAL Soft
Jul 22, 2014 12:55:09 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio Version: 1.1 ALSOFT 1.15.1
Jul 22, 2014 12:55:09 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: AudioRenderer supports 64 channels
Jul 22, 2014 12:55:09 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio effect extension version: 1.0
Jul 22, 2014 12:55:09 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread
INFO: Audio max auxilary sends: 4
Jul 22, 2014 12:55:15 AM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at com.jme3.bullet.objects.PhysicsRigidBody.setCcdSweptSphereRadius(PhysicsRigidBody.java:280)
at mygame.Main.shootCannonBall(Main.java:176)
at mygame.Main$1.onAction(Main.java:46)
at com.jme3.input.InputManager.invokeActions(InputManager.java:169)
at com.jme3.input.InputManager.onMouseButtonEventQueued(InputManager.java:433)
at com.jme3.input.InputManager.processQueue(InputManager.java:833)
at com.jme3.input.InputManager.update(InputManager.java:883)
at com.jme3.app.Application.update(Application.java:604)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:231)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:744)
BUILD SUCCESSFUL (total time: 17 seconds)
This is the whole application:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.scene.shape.Sphere.TextureMode;
//Busy on page 177
public class Main extends SimpleApplication{
private BulletAppState bulletAppState;
//
private Material brickMat, stoneMat, woodMat;
//
private static final Sphere ballMesh;
private static final Box brickMesh;
private static final Box floorMesh;
//
private static Node wallNode;
//
private RigidBodyControl brickPhy, ballPhy, floorPhy;
//
private static final float BRICK_LENGTH = 0.4F, BRICK_WIDTH = 0.3F,
BRICK_HEIGHT = 0.25F, WALL_WIDTH = 12, WALL_HEIGHT = 6;
//
private static final String SHOOT = "shoot";
//
private ActionListener actionListener = new ActionListener(){
public void onAction(String name, boolean isPressed, float tpf){
if(name.equals(SHOOT) && !isPressed){
shootCannonBall();
}
}
};
static{
floorMesh = new Box(Vector3f.ZERO, 10F, 0.5F, 5F);
brickMesh = new Box(Vector3f.ZERO, BRICK_LENGTH, BRICK_HEIGHT, BRICK_WIDTH);
ballMesh = new Sphere(32, 32, 0.25f, true, false);
ballMesh.setTextureMode(TextureMode.Projected);
floorMesh.scaleTextureCoordinates(new Vector2f(4, 4));
}
public static void main(String[] args){
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp(){
inputManager.addMapping(SHOOT, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(actionListener, SHOOT);
flyCam.setMoveSpeed(10.5F);
cam.setLocation(new Vector3f(0, 5, 0));
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
brickMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
stoneMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
woodMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
brickMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Brick.png"));
stoneMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Pebbles.png"));
woodMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Bark.png"));
brickMat.getAdditionalRenderState().setAlphaTest(true);
brickMat.getAdditionalRenderState().setAlphaFallOff(5.5F);
stoneMat.getAdditionalRenderState().setAlphaTest(true);
stoneMat.getAdditionalRenderState().setAlphaFallOff(5.5F);
woodMat.getAdditionalRenderState().setAlphaTest(true);
woodMat.getAdditionalRenderState().setAlphaFallOff(5.5F);
Geometry floorGeo = new Geometry("Floor", floorMesh);
floorGeo.setMaterial(woodMat);
floorGeo.move(0f, -BRICK_HEIGHT * 2F, 0f);
rootNode.attachChild(floorGeo);
floorPhy = new RigidBodyControl(0.0f);
floorGeo.addControl(floorPhy);
bulletAppState.getPhysicsSpace().add(floorPhy);
wallNode = new Node("Wall");
float offsetH = BRICK_LENGTH / 3;
float offsetV = 0;
for(int j = 0; j < WALL_HEIGHT; j++){
for(int i = 0; i < WALL_WIDTH; i++){
Vector3f brickPos = new Vector3f(offsetH + BRICK_LENGTH * 2.1f * i - (BRICK_LENGTH * WALL_WIDTH), offsetV + BRICK_HEIGHT, 0f);
wallNode.attachChild(makeBrick(brickPos));
}
offsetH = -offsetH;
offsetV += 2 * BRICK_HEIGHT;
}
rootNode.attachChild(wallNode);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(1, 0, -2));
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
AmbientLight ambient = new AmbientLight();
rootNode.addLight(ambient);
}
//<editor-fold defaultstate="collapsed" desc="Update method">
@Override
public void simpleUpdate(float tpf){
}
//</editor-fold>
private Geometry makeBrick(Vector3f loc){
Geometry brickGeo = new Geometry("brick", brickMesh);
brickGeo.setMaterial(brickMat);
wallNode.attachChild(brickGeo);
brickGeo.move(loc);
brickPhy = new RigidBodyControl(5f);
brickGeo.addControl(brickPhy);
bulletAppState.getPhysicsSpace().add(brickPhy);
return brickGeo;
}
/*public void shootCannonBall(){
* /**
* Create a cannon ball geometry and attach to scene graph.
*/
/*Geometry ball_geo = new Geometry("cannon ball", ballMesh);
ball_geo.setMaterial(stoneMat);
rootNode.attachChild(ball_geo);
/**
* Position the cannon ball
*/
/*ball_geo.setLocalTranslation(cam.getLocation());
/**
* Make the ball physcial with a mass > 0.0f
*/
/*ballPhy = new RigidBodyControl(6f);
/**
* Add physical ball to physics space.
*/
/*ball_geo.addControl(ballPhy);
bulletAppState.getPhysicsSpace().add(ballPhy);
/**
* Accelerate the physcial ball to shoot it.
*/
/*ballPhy.setLinearVelocity(cam.getDirection().mult(50));
}*/
public void shootCannonBall() {
Geometry ballGeo = new Geometry("cannon ball", ballMesh);
ballGeo.setMaterial(stoneMat);
ballGeo.setLocalTranslation(cam.getLocation());
rootNode.attachChild(ballGeo);
ballPhy = new RigidBodyControl(5f);
ballPhy.setCcdSweptSphereRadius(.1f);
ballPhy.setCcdMotionThreshold(0.001f);
ballPhy.setLinearVelocity(cam.getDirection().mult(50));
ballGeo.addControl(ballPhy);
bulletAppState.getPhysicsSpace().add(ballPhy);
}
}
“Yo, I pirated your book, don’t know what I’m coding and want to change file endings inside the assets.jar to make my game more personal.” *shakes head*
I’m sorry but i don’t quite understand you.