Ginny
Ginny

Reputation: 63

Android: 3D-transform an object

In an Android app I have an object that is created through a custom view. It basically has a rectangular shape. I want to apply a 3D transformation that makes it look like this:

what i have vs. what i want

In the draw() function I have tried various things like this:

override fun draw(canvas: Canvas?) {

    super.draw(canvas)
    
    val matrix = Matrix()
    var pivX = myWidth / 2.0f
    var pivY = myHeight /1.0f
    matrix.setSkew(1f, 0f, pivX, pivY);

    canvas?.withMatrix(matrix) {
        drawPath(path(-150F), paint())
        drawPath(path(150F), paint())
    }

}

I couldn't make it work though. Where's my mistake? What am I missing?

Upvotes: 1

Views: 302

Answers (0)

Related Questions