Author Topic: set the scaling on SerializedObject  (Read 2374 times)

Offline ashunkhs

  • byte
  • *
  • Posts: 24
    • View Profile
set the scaling on SerializedObject
« on: May 07, 2013, 11:12:13 am »
     
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?
« Last Edit: May 07, 2013, 01:35:10 pm by ashunkhs »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: set the scaling on SerializedObject
« Reply #1 on: May 07, 2013, 01:30:20 pm »
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?

Offline ashunkhs

  • byte
  • *
  • Posts: 24
    • View Profile
Re: set the scaling on SerializedObject
« Reply #2 on: May 07, 2013, 02:01:53 pm »
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.
« Last Edit: May 07, 2013, 02:27:46 pm by ashunkhs »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: set the scaling on SerializedObject
« Reply #3 on: May 07, 2013, 02:39:33 pm »
..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
Code: [Select]
obj.setScale(3f);
obj.rotateMesh();
obj.setScale(1f);
« Last Edit: May 08, 2013, 01:24:22 pm by EgonOlsen »

Offline ashunkhs

  • byte
  • *
  • Posts: 24
    • View Profile
Re: set the scaling on SerializedObject
« Reply #4 on: May 08, 2013, 11:57:18 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: set the scaling on SerializedObject
« Reply #5 on: May 08, 2013, 01:28:31 pm »
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.