Author Topic: Little problem regarding MergeAll  (Read 3020 times)

Offline Marc

  • byte
  • *
  • Posts: 5
    • View Profile
Little problem regarding MergeAll
« on: March 05, 2012, 12:43:56 pm »
Hi everyone,

I'm quite new to jpct and currently trying to do a little AR Application for Android to run on my Tablet.

Now I have a little problem where I just can't get my head around. I'm calling Object3D.mergeAll on a 3ds File. But when I add it to the world I have, it just is at a fixed place, where I can't move it. I just want it on (0,0,0) but cube.setCenter() doesn't work and even something direct like                 
cube.translate(new SimpleVector(-cube.getTransformedCenter().x, -cube.getTransformedCenter().y, -cube.getTransformedCenter().z));
doesn't.

before I was using a Simple Loop over the Object3D array the Loader gave me, added everything to the world and added everything as a child of the array[0]. That work in a way, but then I had other problems.

Here are the codesnippets which are relevant imho.

Code: [Select]
                try{
                     InputStream f =    getResources().openRawResource(R.raw.liberty);
                     cube = Object3D.mergeAll(Loader.load3DS(f, 1));
                } catch (Exception e){
                    cube = Primitives.getCube(10);
                    Logger.log(e);
                }
                cube.rotateX(-90);
//                cube.translate(new SimpleVector(-cube.getTransformedCenter().x,-cube.getTransformedCenter().y,-cube.getTransformedCenter().z));
                cube.setCenter(new SimpleVector(0,0,0));
                cube.scale(0.02f);
                cube.build();
                world.addObject(cube);

The Position where it lands in the world depends on the 3ds File.

Probably it's just a simple mistake by me.

Thanks in advance,
Marc

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Little problem regarding MergeAll
« Reply #1 on: March 05, 2012, 01:21:57 pm »
Try to move the translate method after the call to build(). Without calling build(), your center will be (0,0,0) anyway..and a translation by (-0,-0,-0) doesn't do anything.

Offline Marc

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Little problem regarding MergeAll
« Reply #2 on: March 05, 2012, 06:30:52 pm »
Thank you for your quick reply. Moving it after the build funktion crashed my program somehow, but now it's working with that implementation. But sadly it didn't solve my real problem.

I have an object standing on (0,0,0) and the camera moving freely. I track the position and the 3 directional Vectors of the pad and give it to the Activity to change the Camera in the world space. but now here's the problem. When the camera stands in front of the Object everythings fine. But when I move behind the object the object is linearly tilted till it reaches 45°. I have no clue, why. Some Numbers:

Object (0,0,0)
Camera Pos: (0,0,-2) Direction (0,0,1) Up (0,-1,0) // Everything is fine
Camera Pos: (0,0,2) Direction (0,0,-1) Up (0,-1,0) // The object is 45° tilted

When I stand at the side of the object it is slightly tilted.~22.5°

The Numbers I get from the tracker are all accurate. It seems like the worldspace is bent. Do you have any instant idea, what the matter is?  Here is the onDrawFrame method:
Code: [Select]
       
public void onDrawFrame(GL10 gl) {
            udp.needData=true;

            Camera cam= world.getCamera();

            SimpleVector[] sv=udp.getLast(); //Getting the camera tracking through a threaded udp Client

            cam.setOrientation(sv[1], sv[2]);
            cam.setPosition(sv[0]);
            sun.setPosition(sv[0]);
            fb.clear(back);
            world.renderScene(fb);
            world.draw(fb);
            fb.display();

            if (System.currentTimeMillis() - time >= 1000) {
                Logger.log(fps + "fps");
                fps = 0;
                time = System.currentTimeMillis();
            }
            fps++;
        }

I could make a workaround tilting the scene against the "natural" tilting. But I would like to know, why it is that way. If you need more code, just tell me. :-)

Thank you in advance,
Marc
 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Little problem regarding MergeAll
« Reply #3 on: March 05, 2012, 08:20:55 pm »
What is udp?

Offline Marc

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Little problem regarding MergeAll
« Reply #4 on: March 06, 2012, 12:27:51 pm »
udp is just a little UDP Client which I use to get the tracking data from a server. I just parses the 3 Vectors needed from a UDP Packet.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Little problem regarding MergeAll
« Reply #5 on: March 06, 2012, 12:33:21 pm »
setOrientation() only works properly if the vectors are perpendicular to each other. Is this the case with the vectors from udp?

Offline Marc

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Little problem regarding MergeAll
« Reply #6 on: March 06, 2012, 12:39:06 pm »
I was checking that with the dot product. It's always 0, so they are perpendicular.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Little problem regarding MergeAll
« Reply #7 on: March 06, 2012, 12:45:41 pm »
...the setOrientation()-method is based on the code from this post: http://www.jpct.net/forum2/index.php/topic,1224.msg8184.html#msg8184. It should be correct IMHO, so maybe your vectors don't have the values that they are supposed to have? Or maybe that method is flawed...

Offline Marc

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Little problem regarding MergeAll
« Reply #8 on: March 06, 2012, 03:48:37 pm »
Sorry for the inconvenience. It seems as I looked at the wrong thing. It was a very silly mistake like I thought. rotateX nfrom Object3D works with RAD angles, not with degree. I simply ignored the places, where I used it.

Thank you for your time.

Marc