Changing default Perspective after Rotation

Hi,

currently I am working on Rotation of Android ImageView and my goal is to be able to, beside setting the angle of rotation, set the perspective after transformation is set.

-First, thing that I've tried was overriding SetCameraDistance() method, but even if method is called as it should, no metter which value I use for distance no change happens after rendering (?)

-Second, I tried to use Android's Graphics.Camera object and it's SetLocation() method, but I am not sure how this works since values that this method receives are not pixels but some other values that I do not understand. The only thing is that default Z value is -8 (?) and if I set it to be under -3, Image is not render at all. I found something on StackOverflow stackoverflow.com/questions/27704670/android-view-3d-rotate-transformation-on-big-resolution-screens but still I was not able to set perspective properly.

On iOS everything seems more obvious since perspective thing is related with m34 value in Transformation Matrix of component:

var transform = CoreAnimation.CATransform3D.Identity;
transform.m34 = new nfloat(-1f) / (new nfloat(_component.Perspective) * scaleFactor);
transform = transform.Rotate(new nfloat(_component.Rotation.RotationX * Math.PI / 180f), 1, 0, 0); // X axis
transform = transform.Rotate(new nfloat(_component.Rotation.RotationY * Math.PI / 180f), 0, 1, 0); // Y axis
transform = transform.Rotate(new nfloat(_component.Rotation.RotationZ * Math.PI / 180f), 0, 0, 1); // Z axis

Suppose that there must be something similar for Android Platform.

I would really appreciate some help.

Thanks in advance

Posts

  • I'm experiencing the same issue. Using a subclass of ImageRenderer I used the SetCameraDistance method. It does not appear to work, because I immediately use Console.WriteLine to print the CameraDistance value and it does not match the value I provided.

    I have acceptable perspective on Nexus 4 (Lollipop API 22) but not on Nexus 5. Would really love an answer for this!

  • I finally got perspective working. There were a couple of things I noticed I was doing wrong which were not intuitive to me:

    1. On the renderer I had been calling "Control.SetCameraDistance" but needed to just call "SetCameraDistance" (without the Control part).

    2. It wasn't enough to call the method once at the beginning such as within "OnElementChanged". Something somewhere else was setting too. I fixed it by setting it continually as I updated the rotation value. It didn't seem to matter whether I set the Camera position before or after applying rotation but I did need to set it again.

Sign In or Register to comment.