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:
Image

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;

   @Override
   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);
      ocamera.setToOrtho(false);
      ocamera.position.set(0,0,2);
      ocamera.lookAt(0,0,0);
      ocamera.update();

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

      camController = new CameraInputController(ocamera);
      Gdx.input.setInputProcessor(camController);
   }
   @Override
   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);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

      ocamera.update();

//      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.begin(ocamera);
      modelBatch.render(modelInstance, environment);
      modelBatch.end();
   }

   @Override
   public void dispose()
   {
      modelBatch.dispose();
      model.dispose();
   }

   @Override
   public void resize(int width, int height)
   {
//;      stage.getViewport().setScreenSize(width, height);
   }

   @Override
   public void pause() {
   }

   @Override
   public void resume() {
   }
vik182
 
Posts: 44
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.
tomski
 
Posts: 907
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

https://www.badlogicgames.com/wordpress/?p=2032
Zappp
 
Posts: 81
Joined: Sat Mar 29, 2014 3:34 am


Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest