for my game I want the 3D viewport to take up only 80% of the screen. The GUI should take up 100% of the screen as usual.
My trivial approach was to simply do this:
cam.setViewPortBottom(0.2f);
This works, but the aspect ratio of the rendered scene is now wrong; everything is squeezed together.
I tried to resize the camera with no avail:
cam.resize(1024, 768 * 0.8f, true);
Updating the frustum didn’t work, either. What is the correct way to change the main camera’s/viewport’s size?
Additional question: Where would be the right place to put this code. Putting it into simpleInitApp() worked. Putting it into the initialize()-method of an AppState didn’t.
Not enough information provided… these two things are functionally identical so something else must be in play.
Regarding your other, you need to setup the frustum properly. See the setPerspective… related methods on camera. Look at the javadoc. You can specify your own aspect ratio there.
SimpleApplication.simpleInitApp() is not the same as SomeAppState.initialize(), really.
Judging from a little debugging it seems that the altered viewport information is overwritten by some jME fullscreen post effect before it could be actually applied to the viewport. (Disclaimer: I didn’t dive fully into the code, so this first result could be completely wrong/misleaded.)
there is no method “setPerspective()”. Did you mean “setFrustumPerspective()”?
Minimal testcase, derived from jME’s HelloLoop example:
public class HelloLoop2 extends SimpleApplication
{
public static void main(String[] args) {
new HelloLoop2().start();
}
@Override
public void simpleInitApp() {
Geometry cube = new Geometry("blue cube", new Box(1, 1, 1));
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
cube.setMaterial(mat);
rootNode.attachChild(cube);
// Trying to update the viewport:
cam.setViewPortBottom(0.5f);
cam.resize(640, 480/2, false);
cam.setFrustumPerspective(40, 640f/(480/2), 0.05f, 500f);
cam.update();
}
}
Here, I’m trying to set the viewport to half the window height. (Resolution is 640x480 in this example.) The result is a squeezed box.
What am I doing wrong?
I’m using the most recent trunk revision of jME 3.1.0.
public class HelloLoop2 extends SimpleApplication
{
public static void main(String[] args) {
new HelloLoop2().start();
}
@Override
public void simpleInitApp() {
Geometry cube = new Geometry("blue cube", new Box(1, 1, 1));
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
cube.setMaterial(mat);
rootNode.attachChild(cube);
// Trying to update the viewport:
cam.setViewPortBottom(0.5f);
cam.setFrustumPerspective(40, 640f/(480f/2f), 0.05f, 500f);
//cam.update();
}
}
Unfortunately on my machine and with the must current trunk version of jME 3.1.0 the cube is still squeezed together to half its original height even with your code.
What version of jME do you use?
Yeah, sure everything is smaller when the viewport is only half the size. But the aspect ratio should not be affected. There should be no stretching.
Just to make sure; this is what I’m seeing:
What I should be seeing is a (smaller) 1x1x1 cube, not a (seemingly) 2x1x1 cube.
OK, first review shows that this does indeed not work anymore as it did in 3.0
Not yet sure if its related to Camera.java but a first view showed only 4 commits since the release of 3.0
Unfortunately i have also not found a code change in those lines… If i find time i will look into it more deeply in the evening. In the meantime you can open an issue on github, and link to this thread…