set the scaling on SerializedObject

Started by ashunkhs, May 07, 2013, 11:12:13 AM

Previous topic - Next topic

ashunkhs

     
hi ,
   Actually i have to set scaling on serialized object in PhysicsTest sample  and i am doing this :
 
                                world = new World();
            sBox = Loader.loadSerializedObject(res.openRawResource(R.raw.boxmodel));
            sBox.build();
            sBox.setScale(3f);    // no effect on the model

                               //sBox.setScale(100f);// no effect on the model

            sBox.rotateZ(50);

   But there is no any changes happened.if we can do then how?

EgonOlsen

Scaling has nothing to do with whether you are using serialized objects or not. The way you are doing it is fine. Are you sure that you don't reset it afterwards and/or are resetting the rotation matrix?

ashunkhs

#2
Hi ,
actually i am rendering the PhysicsTest sample on QCAR(Vuforia) . all most my work is complete . its rendering fine on QCAR GL. but i am working half an hour to set the scaling of serialized object. as u told i check the full code . the scaling is not set after this.

           private Object3D sBox;
           sBox = Loader.loadSerializedObject(res.openRawResource(R.raw.boxmodel));
          sBox.build();

   public void addBox(int x, int y, int z) {
         BoxShape shape = new BoxShape(new Vector3f(2, 2, 2));
         float mass = 500;
         Vector3f localInertia = new Vector3f(0, 0, 0);
         shape.calculateLocalInertia(mass, localInertia);

         
         Object3D boxgfx = new Object3D(sBox);
         boxgfx.translate(x, y, z);
         boxgfx.setScale(3f);  .............................................................here...............!!
         boxgfx.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
         boxgfx.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
         boxgfx.build();
         world.addObject(boxgfx);

         JPCTBulletMotionState ms = new JPCTBulletMotionState(boxgfx);
         RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, ms, shape, localInertia);
         RigidBody body = new RigidBody(rbInfo);
         body.setRestitution(0.1f);
         body.setFriction(0.5f);
         body.setDamping(0, 0);

         body.setUserPointer(boxgfx);
         boxgfx.setUserObject(body);
         bodyList.add(body);

         dynamicWorld.addRigidBody(body);
      }

for integrating the QCAR i am doing set he modelView matrix on JPCT camera.

EgonOlsen

#3
..but if it's using a physics engine, it's very likely that the binding changes the rotation matrix when updating the entities. You can make the scaling permanent by doing something like

obj.setScale(3f);
obj.rotateMesh();
obj.setScale(1f);

ashunkhs

hi ,
i tried as u told but i did't get any change.
but when i load md2 model i can do the scaling . like this


    sBox = Loader.loadMD2(getResources().openRawResource(R.raw.kingtest), 6.0f);  ...........its scaling
            
   sBox = Loader.loadSerializedObject(res.openRawResource(R.raw.boxmodel));    ..............its not
        sBox.setScale(3f);
   sBox.build();
     
How to do same as SerializedObject.

EgonOlsen

The MD2-loader scales the mesh at load time. The deserializer doesn't support this, because it makes no sense in this context. If you want that, why don't you scale the mesh before serializing it?
Apart from that, the code that i posted (it had a little typo in it, i've fixed that in my above post) should do what you want. Just load the model, apply the code snippet and call build(). There's no reason why it shouldn't work that way.