Sphere spikes. ActionListener / input manager problem

I came back to an old project after almost a year, tinkered a bit with it and somehow messed up the firing of my cannon!

When firing the cannon (By pressing space and having the input manager react) the ball is obviously supposed to exit the cannon muzzle, but the cannonball (a regular jmonkey sphere) is offset by quite a lot. In addition, two faces of the sphere, one in the “front” and one in the “back”, are not offset and remain roughly where the ball is supposed to be. Theses faces, however, are shrunk down into single points, which makes it appear as if the sphere has two long spikes protruding in front of it.

I cross-referenced the old and new version through GitHub and nothing major changed that I think could have an effect.

Creating a cylinder instead of a sphere when firing works perfectly fine. But not a Box, however the box will not have spikes, only offset.

Creating a sphere in the init places it correctly, without any spikes or offsets. Same for boxes.

Thus this is obviously contained in the ActionListener somehow, althouth I have no idea why or how to solve it.

Shortened code:

private ActionListener actionListener = new ActionListener()
{
    public void onAction(String name, boolean keyPressed, float tpf)
    {
        if (keyPressed && time > 0)
        {
            if (name == "fire")
            {
                Geometry cBall = geos.createcannonball(player.getLocalRotation(), player.getChild("cannonballStartNode").getWorldTranslation());
                cannonballNode.attachChild(cBall);
                playerBallList.get(playerIndex).add(shotIndex, cBall); 
            }
        }
    }
}

in geos.createcannonball

public Geometry createcannonball(Quaternion rotation, Vector3f translation)
{
    Sphere c = new Sphere(Util.CANNONBALL_RESOLUTION,Util.CANNONBALL_RESOLUTION,Util.CANNONBALL_RADIUS);
    Geometry cBall = new Geometry("cannonball", c);
    Material cannonballMat = new Material (assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    cannonballMat.setColor("Color", ColorRGBA.Gray);
    cBall.setMaterial(cannonballMat);
    cBall.setLocalRotation(rotation);
    cBall.setLocalTranslation(translation);
    return cBall;
} 

I’ve tried using zero vector and quaternion for translation and rotation. Still same.

All the code can be found on GitHub
The code regarding all this is in ClientMain.java (and creaing balls in CreateGeos). The server aspect doesn’t matter.
(Don’t mind how weird the GitHub is set up. I set this before I knew how to use git)

Thankful for replies! :slight_smile:

It’s unclear whether your sphere is moving and the spikes are staying fixed to a location or not… but if not then my guess is that you’ve corrupted your Vector3f.ZERO vector by passing it to something that has modified it.

Find all of your Vector3f.ZERO usage and make sure you aren’t modifying it.

That did the trick! Thanks a lot!

Seems like I was passing it into a localToWorld() function.

Quick follow up question (I haven’t actually researched this thoroughly), but why do those kinds of function need a storing vector as an argument? The function returns the result regardless, and the regular scope of java prevents me from declaring a vector, calling the function with that vector (without handling the result), and then using the same vector declared to access the result. Seems more akin to C programming to me.

Regardless, thanks a lot! Saved me a lot of headache :slight_smile:

Most of them will create the vector for you if you pass a null.

A lot of times Java programs will try to avoid creating garbage. So if they already have their own Vector3f handy then they can just pass it in to avoid creating a new one. The code is not more than one line either way.

Lots of functions return redundant values because then they can be chained together.
Vector3f v = …
localToWorld(someLoc, v).addLocal(delta).subtractLocal(offset)
…and so on.