Orthographiccamera in 3D doubt

Anything libgdx related goes here!

Orthographiccamera in 3D doubt

Postby vik182 » Tue May 14, 2019 9:14 pm

I am trying to render a cube, but I need to use Orthographiccamera, so that once you see it is a perfect square, for this reason I do not use perspectivecamera, but I have problems when rendering it and with size. I do not know if this can be done, thank you.

As the image on the right:

My class:
Code: Select all
public class MainGame extends ApplicationAdapter

   private PerspectiveCamera camera;
   private ModelBatch modelBatch;
   private Model model;
   private ModelInstance modelInstance;
   private Environment environment;
//   private AnimationController controller;
   public CameraInputController camController;

   private OrthographicCamera ocamera;
   private Viewport viewport;
   private Stage stage;

   public void create()

      // Create camera sized to screens width/height with Field of View of 75 degrees
//      camera = new PerspectiveCamera(
//            75,
//            Gdx.graphics.getWidth(),
//            Gdx.graphics.getHeight());
//      // Move the camera 5 units back along the z-axis and look at the origin
//      camera.position.set(0f,0f,7f);
//      camera.lookAt(0f,0f,0f);
//       //Near and Far (plane) represent the minimum and maximum ranges of the camera in, um, units
//      camera.near = 0.1f;
//      camera.far = 300.0f;

      // A ModelBatch is like a SpriteBatch, just for models.  Use it to batch up geometry for OpenGL
      modelBatch = new ModelBatch();

      // Model loader needs a binary json reader to decode
//      UBJsonReader jsonReader = new UBJsonReader();
      // Create a model loader passing in our json reader
      G3dModelLoader loader = new G3dModelLoader(new UBJsonReader());
      // Now load the model by name
//      ModelLoader loader = new ObjLoader();
      // Note, the model (g3db file ) and textures need to be added to the assets folder of the Android proj
      model = loader.loadModel(Gdx.files.internal("model_1.g3db"));
      // Now create an instance.  Instance holds the positioning data, etc of an instance of your model
      modelInstance = new ModelInstance(model);

      // Finally we want some light, or we wont see our color.  The environment gets passed in during
      // the rendering process.  Create one, then create an Ambient ( non-positioned, non-directional ) light.
      environment = new Environment();
      environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1.0f));

      ocamera = new OrthographicCamera(720,1280);

//      viewport = new ExtendViewport(10, 10);
//      stage = new Stage(viewport);

      camController = new CameraInputController(ocamera);
   public void render()
// You've seen all this before, just be sure to clear the GL_DEPTH_BUFFER_BIT when working in 3D
      Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
//      Gdx.gl.glClearColor(1, 1, 1, 1);


//      stage.act();
//      stage.draw();

//      camController.update();

      // For some flavor, lets spin our camera around the Y axis by 1 degree each time render is called
      //camera.rotateAround(Vector3.Zero, new Vector3(0,1,0),1f);
      // When you change the camera details, you need to call update();
      // Also note, you need to call update() at least once.
//      ocamera.update();

      // You need to call update on the animation controller so it will advance the animation.  Pass in frame delta
//      controller.update(Gdx.graphics.getDeltaTime());
      // Like spriteBatch, just with models!  pass in the box Instance and the environment
      modelBatch.render(modelInstance, environment);

   public void dispose()

   public void resize(int width, int height)
//;      stage.getViewport().setScreenSize(width, height);

   public void pause() {

   public void resume() {
Posts: 40
Joined: Wed Jul 04, 2018 9:44 pm

Re: Orthographiccamera in 3D doubt

Postby tomski » Tue May 14, 2019 10:15 pm

Your camera looks to be in "pixel" units. Chances are your model is using a sensible world unit rather than this made up unit.
You'll also need to make sure your near and far are appropriately sized for your model.
Posts: 870
Joined: Wed Jun 26, 2013 6:06 pm

Re: Orthographiccamera in 3D doubt

Postby Zappp » Wed May 15, 2019 4:53 am

Orthographic camera is what you want, but first set up correctly. Look this post it may be helpful

Posts: 75
Joined: Sat Mar 29, 2014 3:34 am

Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest