Scale X and Y axis

Started by itsmeveno, January 30, 2019, 05:08:18 PM

Previous topic - Next topic

itsmeveno

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.

EgonOlsen

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!?

itsmeveno

it give me this error. FATAL EXCEPTION: main.

EgonOlsen

That's not a proper exception...there has to be something more than that in your log output!?

EgonOlsen

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:


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.

itsmeveno


MichaelJPCT

Quote from: EgonOlsen 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:


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.

EgonOlsen

Which version of jPCT (desktop or Android) and which rendering mode are you using?

MichaelJPCT

i tested it on jpct-ae only,  openglES 2.0

EgonOlsen

I think the default shaders are normalizing them again.