Author Topic: rendered image is mirrored  (Read 82 times)

Offline chocoman

  • byte
  • *
  • Posts: 2
    • View Profile
rendered image is mirrored
« on: December 08, 2017, 08:21:03 pm »
Hello,

it seems that when a scene is rendered, the resulting image is flipped left to right. I need to render the scene without this flipping.

see the modified code of the HelloWorld example below, which demonstrates this. The rendered screen is attached The expected rendered image would have a small box to the right from the big box, but in the rendered image the small box is to the left.

I tried to achieve this by modifying the camera matrix: I multiplied the first row by -1. This flipped the scene correctly, but the textures were "inside-out", The textures facing the camera were not visible, but the textures on the other side of the object were visible.

Is there any solution to this problem?

Thank you,
Martin


import com.threed.jpct.*;
import javax.swing.*;
import java.awt.*;

/**
 * A simple HelloWorld using the AWTGL-Renderer and rendering into a frame.
 * @author EgonOlsen
 *
 */
public class HelloWorldAWTGL {

   private World world;
   private FrameBuffer buffer;
   private Object3D box;
   private JFrame frame;

   public static void main(String[] args) throws Exception {
      new HelloWorldAWTGL().loop();
   }

   public HelloWorldAWTGL() throws Exception {
      
      frame=new JFrame("Hello world");
      frame.setSize(800, 600);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
      
      world = new World();
      world.setAmbientLight(0, 255, 0);

      TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));

      box = Primitives.getBox(13f, 2f);
      box.setTexture("box");
      box.setEnvmapped(Object3D.ENVMAP_ENABLED);
      box.build();
      world.addObject(box);
      
      Object3D smallbox = Primitives.getBox(5f, 2f);
      smallbox.translate(new SimpleVector(30,0,0));  // moving the small box to the right
      smallbox.setTexture("box");
      smallbox.setEnvmapped(Object3D.ENVMAP_ENABLED);
      smallbox.build();
      
      world.addObject(smallbox);

      world.getCamera().setPosition(0, 0, 200); // camera in front of both boxes
      world.getCamera().lookAt(box.getTransformedCenter());
   }

   private void loop() throws Exception {
      buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
      Canvas canvas=buffer.enableGLCanvasRenderer();
      buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
      frame.add(canvas);

      while (frame.isShowing()) {
         box.rotateY(0.01f);
         buffer.clear(java.awt.Color.BLUE);
         world.renderScene(buffer);
         world.draw(buffer);
         buffer.update();
         buffer.displayGLOnly();
         canvas.repaint();
         Thread.sleep(10);
      }
      buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
      buffer.dispose();
      frame.dispose();
      System.exit(0);
   }
}

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: rendered image is mirrored
« Reply #1 on: December 08, 2017, 08:38:15 pm »
Please don't fiddle around with the camera's matrix, there's no need for this. You are simply looking on the scene from behind. Positive Z goes into the screen in jPCT's coordinate system. So your code moves the camera behind the objects and then makes a 180 turn around y caused by the lookAt call. Just move the camera -200 units into z-direction instead and you should be fine.

Offline chocoman

  • byte
  • *
  • Posts: 2
    • View Profile
Re: rendered image is mirrored
« Reply #2 on: December 09, 2017, 01:56:47 am »
Thank you, I misinterpreted the image describing the coordinate system on the wiki at http://www.jpct.net/wiki/index.php?title=Coordinate_system
Maybe the attached image would be less ambiguous.
« Last Edit: December 09, 2017, 02:01:27 am by chocoman »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: rendered image is mirrored
« Reply #3 on: December 11, 2017, 03:35:42 pm »
That's true, I guess. I've replaced the image in the wiki with your image.