Little problem regarding MergeAll

Started by Marc, March 05, 2012, 12:43:56 PM

Previous topic - Next topic

Marc

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.


                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

EgonOlsen

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.

Marc

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

EgonOlsen


Marc

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.

EgonOlsen

setOrientation() only works properly if the vectors are perpendicular to each other. Is this the case with the vectors from udp?

Marc

I was checking that with the dot product. It's always 0, so they are perpendicular.

EgonOlsen

...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...

Marc

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