Author Topic: Scale X and Y axis  (Read 1146 times)

Offline itsmeveno

  • byte
  • *
  • Posts: 14
    • View Profile
Scale X and Y axis
« on: January 30, 2019, 05:08:18 pm »
Good day i would like to ask if it is possible to resize the object by y axis or x axis runtime.

Like for example i drag the left side of the cube then the x-axis will expand. something like that.

Any idea or source code.
btw i already use this code.

public void setSize(float scalex, float scaley)
    {
        demoControl = new ResizerMod(scalex, scaley,1);
        planeMesh.setVertexController(demoControl, IVertexController.PRESERVE_SOURCE_MESH);
        planeMesh.applyVertexController();
        planeMesh.removeVertexController();
    }
    private static class ResizerMod extends GenericVertexController {
        private static final long serialVersionUID = 1L;

        float XFactor =1;
        float YFactor =1;
        float ZFactor =1;

        public ResizerMod(float xFactor, float yFactor, float zFactor)
        {
            this.XFactor = xFactor;
            this.YFactor = yFactor;
            this.ZFactor = zFactor;
        }
        public void apply() {
            SimpleVector[] s = getSourceMesh();
            SimpleVector[] d = getDestinationMesh();
            Log.i("vertex", "XFactor="+s[1] + s[2] +" YFactor="+d);
            for (int i = 0; i < s.length; i++) {

                //d.z = s.z   - (10f * ((float) Math.sin(s.x / 50f) + (float) Math.cos(s.y / 50f)));

                Log.i("vertex", "old vertex="+i+" x="+ d.x);
                Log.i("vertex", "old vertex="+i+" y="+ d.y);
                Log.i("vertex", "old vertex="+i+" z="+ d.z);

                d.x = s.x*XFactor;
                d.y = s.y*YFactor;
                d.z = s.z*ZFactor;

                Log.i("vertex", "vertex="+i+" x="+ d.x);
                Log.i("vertex", "vertex="+i+" y="+ d.y);
                Log.i("vertex", "vertex="+i+" z="+ d.z);
            }
        }
    }

but the problem is i can only resize the object at once. please help.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Scale X and Y axis
« Reply #1 on: January 30, 2019, 06:02:15 pm »
I'm not sure why the solution you've posted doesn't work in your case. Or in other words: I think that I haven't understand your problem properly!?

Offline itsmeveno

  • byte
  • *
  • Posts: 14
    • View Profile
Re: Scale X and Y axis
« Reply #2 on: February 01, 2019, 01:49:33 am »
it give me this error. FATAL EXCEPTION: main.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Scale X and Y axis
« Reply #3 on: February 01, 2019, 08:17:52 am »
That's not a proper exception...there has to be something more than that in your log output!?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Scale X and Y axis
« Reply #4 on: February 01, 2019, 08:30:14 am »
Apart from that: We are talking about Android/jPCT-AE here? In that case, you can't do it this way unless some more setup work which might not be worth it. There's another way, though. You can tweak the rotation matrix directly. This has some drawbacks as well, in particular it might increase a light source's brightness on the scaled object when it shouldn't and it doesn't work well together with the build-in scale methods. Anyway, this is how it works:

Code: [Select]
Matrix scale=new Matrix();
scale.set(0, 0, 2); // 0,0 for x-axis scaling, 1,1 for y, 2,2 for z
obj.getRotationMatrix().matMul(scale);

If you otherwise don't change the rotation matrix, you only have to apply this once. If you set it to a new anyway in each frame (or even sometimes), you have to apply this afterwards. Also keep in mind that scaling is cumulative. That means that doing this by 2 and then by 3 will result in a scaling of 6.

Offline itsmeveno

  • byte
  • *
  • Posts: 14
    • View Profile
Re: Scale X and Y axis
« Reply #5 on: February 05, 2019, 04:25:57 am »
Thanks for this.

Offline MichaelJPCT

  • long
  • ***
  • Posts: 168
    • View Profile
Re: Scale X and Y axis
« Reply #6 on: July 19, 2019, 06:57:34 pm »
Apart from that: We are talking about Android/jPCT-AE here? In that case, you can't do it this way unless some more setup work which might not be worth it. There's another way, though. You can tweak the rotation matrix directly. This has some drawbacks as well, in particular it might increase a light source's brightness on the scaled object when it shouldn't and it doesn't work well together with the build-in scale methods. Anyway, this is how it works:

Code: [Select]
Matrix scale=new Matrix();
scale.set(0, 0, 2); // 0,0 for x-axis scaling, 1,1 for y, 2,2 for z
obj.getRotationMatrix().matMul(scale);

If you otherwise don't change the rotation matrix, you only have to apply this once. If you set it to a new anyway in each frame (or even sometimes), you have to apply this afterwards. Also keep in mind that scaling is cumulative. That means that doing this by 2 and then by 3 will result in a scaling of 6.

hi Egon, i read this thread and remember that i used to tried lengthening the normal vector to change lighting effect (over bright effect ? :) ) , i did that when meshes were created from vertex info, such as multiplying the normal by 5. but the lighting didnt change at all, seems like the normal vector is normalized when rendering.
can this behavior of normalizing the normal vector be canceled?
i was just exploring possibilities.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Scale X and Y axis
« Reply #7 on: July 21, 2019, 02:33:11 pm »
Which version of jPCT (desktop or Android) and which rendering mode are you using?

Offline MichaelJPCT

  • long
  • ***
  • Posts: 168
    • View Profile
Re: Scale X and Y axis
« Reply #8 on: July 21, 2019, 06:04:24 pm »
i tested it on jpct-ae only,  openglES 2.0

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12011
    • View Profile
    • http://www.jpct.net
Re: Scale X and Y axis
« Reply #9 on: July 23, 2019, 02:20:38 pm »
I think the default shaders are normalizing them again.