Billboarding particles

I’m trying to work with particles now, and I can’t get the particles to billboard, I am using an isometric view so the cameras up angle and left angles have been altered and from looking around that’s probably a problem. I tried adding the particles to a billboard node which had no visible effect (I think the billboardnode class docs said something about world up having to be 0,1,0). Is there a way to work around this, I can’t be the only one foolish enough to move the camera’s position for an overhead view type game. Is there a different way to move the camera that wouldn’t require altering the up and left vectors? From what I have seen it seems if you change the angle of the camera you have to alter these values or the frustum stuff goes wonky.

cam.setLeft(new Vector3f(-0.5f,0f,0f));
cam.setUp(new Vector3f(0f,0.5f,0f));

Should this have been asked in effects, I had intended to post it there, not sure what happened (I musta been tired), can a mod move it if effects is where it belongs?

Hmm, so you’re saying that by shifting the camera facing values, the billboarding fails? Are your vectors all at right angles from each other? Also, the vectors in your above example are not normalized which is probably a big part of the problem.

Normalizing them makes them the same as 1,0,0 (ignore that it’s a negative -1 in the previous quote) and 0,1,0 which is the default camera, which doesn’t work right for the overhead view since clipping happens in the wrong locations. Using the vectors like this is based on a post I think mojo had made to someone else who was doing an isometric view. I’m pretty weak in the 3d math department so I don’t usually fully understand why some of the stuff works.

Looking at the source for ParticleManager the camera variable is set and returned, but otherwise not touched. The up vector is explicitly declared too… I’m going to try altering that locally and see what happens (it sounds crazy but it might already be that the math is all done, and it’s just a matter of providing the right up and left vectors from the camera that’s already passed in but unused).

My experiment with altering the particle manager didn’t seem to affect anything that I could see, here’s a pic so it’s more clear what I’m talking about.

This is so people can see what I’m talking about, unfortunately the picture doesn’t make it all that clear, but the particles are facing towards the default cameras position (south east) instead of towards the cameras actual location.

Are you passing the altered camera into the manager when you create it? Maybe you could send me a simple example to buzz through?

Yeah, I’ll whip one up, basically just involves the change to the camera angle and adding a particle (or probably a billboard node would have the same effect).

If you comment out the texture state being added to the particle manager the particles will show up as squares which may be easier to see what’s going on.

the problem is that your left and up vectors are not perpendicular to your direction vector:

left: com.jme.math.Vector3f [X=0.5, Y=0.0, Z=0.0]
up: com.jme.math.Vector3f [X=0.0, Y=0.5, Z=0.0]
direction: com.jme.math.Vector3f [X=0.57735026, Y=-0.57735026, Z=-0.57735026]

if we do some cross products to determine actual camera up and left based on the direction and an approximate up of (0.0, 0.5, 0.0) we can get something much nicer. Here's the code to replace your updateCamera:

    private Vector3f dirVec = new Vector3f();
    private Vector3f upVec = new Vector3f();
    private Vector3f leftVec = new Vector3f();
    public void updateCam() {
        cam.getLocation().set(location.x - camVec.x, location.y
                + camVec.y, location.z + camVec.z);
        dirVec.set(camVec.x, -camVec.y, -camVec.z).normalizeLocal();
        upVec.set(0,.5f,0);  // Using .5f instead of 1 as normal
        upVec.cross(dirVec, leftVec);
        dirVec.cross(leftVec, upVec);
        cam.setAxes(leftVec, upVec, dirVec);

FYI: Notice my use of getXXX().set(float, float, float)... This will prevent tons of object creation in your code and gc issues. Also, try to use methods that have a store argument as they also avoid object creation.

One other note… I’d recommend not updating your camera unless something actually changes… In your case, the location or the camera offset (camVec). Everytime you update the camera (via update() or any of the setXXX methods on it), it makes JNI calls to OpenGL which can be expensive.

Finally, try to set properties on the camera in the least calls possible… EG. setAxes(left, up, dir) instead of setLeft(), setUp() and setDirection(). This means 1 call to GL instead of 3.

Thanks for the fix to my camera code.

I was aware of the extra object creation, I had planned to cure some of that when I was a little more confident in some of the stuff. The camera actually changes in a typical frame, location is the vector that is used for my players movement so whenever the player moves the camera must move, I should probably have a camera node attached to my player, but I’m still just experimenting with jme (at a slow pace cause my math skills are pretty weak). Not sure I had noticed normalizeLocal yet though so always good to have it pointed out. My mouse code is a lot more screwy but I’ll spare you that horror for now…

Is there any books I should be looking for that might make it easier for me to understand the math behind 3d stuff a bit better (or websites, I usually prefer websites since I hate flipping between a book and computer and websites tend to be cheaper). For the most part I’ve worked through the various formulas but I don’t really know how to apply them for stuff. Jme takes away my need to know how to do the formulas by providing methods for them (woo hoo) but unfortunately jme doesn’t help with my real handicap of knowing how to use the various formulas.

"DanK" wrote:
Is there any books I should be looking for that might make it easier for me to understand the math behind 3d stuff a bit better
hi dank!

my math skills aren't the best as well so i'm always looking for
good resources on 3d math, too...

this book looks very promising(download the sample chapter):

this can be helpful, too:


When it comes to a great book for 3d math in the context of games, my absolute favorite (and it’s so good I don’t need anything else really) is this one by Eric Lengyel:

A must for the library of any serious game programmer.