Calculating g_WorldViewProjectionMatrix

Here be what I know:



WORLD * VIEW * PROJECTION = what I am looking for (I believe)



In jme you can get:



viewPort.getCamera().getViewMatrix();

viewPort.getCamera().getProjectionMatrix();



Where is the World Martix?

And how do I access it?



Actually… the code for building the g_WorldViewProjectionMatrix would be fine too :wink:

i think you’d want to use geometry.getWorldMatrix() but im not sure

http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/shader/UniformBindingManager.java#58

@pspeed

when I try:



Matrix4f mat = (Matrix4f)material.getActiveTechnique().getShader().getUniform(“WorldViewProjectionMatrix”).getValue();



BTW, I’ve tried both:

WorldViewProjectionMatrix

g_WorldViewProjectionMatrix



I get a null pointer exception.



What be I missing?

@t0neg0d said:
Actually... the code for building the g_WorldViewProjectionMatrix would be fine too ;)


So, even more specifically: http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/shader/UniformBindingManager.java#87

@pspeed

Since I can’t seem to successfully access the Bindings of the shader, where is the World Matrix calulated/set/etc in jme? I can rebuild it at least if I have this.

Do you really need me to search for where UniformBindingManager.setWorldMatrix() is called for you?

@pspeed Actually… lol… yes. I have found a call that sets up the world matrix for Nifty… buuuuut.



It seems funny to me that something as important as the world matrix would not be easily accessible. I can get every other matrix used for rendering except this one?

@pspeed Any clue what is returned by Matrix4f.fromFrame()? There is no JavaDoc info or comments.

Maybe if I explain what I need this for, it may prompt someone to want to know how to get this as well.



I need the WorldViewProjectionMatrix from the prior frame to compare where an object was to where it is now. It’s set up in a Filter… so I have tried both of the following:



[java]

@Override

protected void postFrame(RenderManager renderManager, ViewPort viewPort, FrameBuffer prevFilterBuffer, FrameBuffer sceneBuffer) {

pm = viewPort.getCamera().getViewProjectionMatrix();

pm.multLocal((Matrix4f)material.getActiveTechnique().getShader().getUniform(“g_WorldMatrix”).getValue());

}

[/java]



and



[java]

@Override

protected void postFrame(RenderManager renderManager, ViewPort viewPort, FrameBuffer prevFilterBuffer, FrameBuffer sceneBuffer) {

pm = (Matrix4f)material.getActiveTechnique().getShader().getUniform(“g_WorldViewProjectionMatrix”).getValue());

}

[/java]



both calls to the activeTechnique return null pointer exceptions.

The world view projection matrix will be different for every object, I think. You may have to capture this at the object level and then you might as well just get the world transform of the object.



I suspect the world view projection matrix is a multiplication of that matrix and the camera’s view projection matrix.



What is this for? The only time I’ve wanted something like this was for a rain effect but in that case it’s easier just to embed direction in the mesh data.



And for example of where setWorldMatrix is called, I’m not sure why this gave you trouble as it took only a few seconds to find:

http://code.google.com/p/jmonkeyengine/source/search?q=setWorldMatrix&origq=setWorldMatrix&btnG=Search+Trunk



It’s the second hit and its in RenderManager. Just click on setWorldMatrix(g.getWorldMatrix()); and you can see the exact call… and I’ll save you the trouble in the “g” is a Geometry so this is called once per geometry as expected above.

Geometries stores dirty world matrix in cachedWorldMat. The getter is getWorldMatrix().