Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Rotate instruction with x and y axis. #5825

Closed
khalakhelo opened this issue Jun 24, 2018 · 3 comments
Closed

Problem with Rotate instruction with x and y axis. #5825

khalakhelo opened this issue Jun 24, 2018 · 3 comments
Labels

Comments

@khalakhelo
Copy link

Versions

  • Python: 3.5.2 / 2.7.12
  • OS: Linux (Ubuntu based)
  • Kivy: 1.10.0
  • Kivy installation method: pip

Description

Rotate instruction (kivy.graphics.Rotate) doesn't rotate the coming vertex instructions correctly when the rotation axis given is x (1, 0, 0) or y (0, 1, 0). Instead the coming matrix is like cropped from its ends away from the point of origin (and respective to the other 2d perpendicular axis).
The right behaviour when rotated on one of the x any axis would look like if the matrix was scaled down around the origin in trigonometric pace ((end-origin)*sin(angle)) (respective to the other 2d perpendicular axis too of course).

For example A rotation of 60 degrees on x-axis should make the shape shorter by one half. And 60 degrees on y-axis should make the shape thinner by one half.
But only one degree distort it like that on x-axis:
-1 degree on x-axis
And y-axis:
1 degree on y-axis
z-axis works perfect like it should:
61 degrees on z-axis

This isn't an issue of conversion between radians and degrees. (You can adjust the sliders'ranges to be between -pi to pi, but that won't fix it). The cropping happening is non-related to rotation, and the body near origin remain with it's shape unaffected until the copping reach it.

I made a quick look at Rotate class but couldn't spot the glitch. Probably I have to re-study Matrix multiplication in it's compute method. But of course if the issue was approved there would be someone more able to fix it than me.

Code and Logs

I made this app just for demonstration of the issue:

from kivy.app import App
from kivy.lang import Builder
from kivy.properties import NumericProperty


from kivy.config import Config
Config.set('graphics', 'width', '400')
Config.set('graphics', 'height', '600')

kv = '''
#:set h 75
BoxLayout:
    orientation: 'vertical'
    Widget:
        size_hint_y: None
        height: self.width
        canvas:
            PushMatrix:
            Color:
                rgba: .4, .6, .8, 1
            Rotate:
                origin: self.center
                axis: 1,0,0
                angle: app.xangle
            Rotate:
                origin: self.center
                axis: 0,1,0
                angle: app.yangle
            Rotate:
                origin: self.center
                axis: 0,0,1
                angle: app.zangle
            Triangle:
                points: (self.center_x, self.center_y+h*2,\
                         self.center_x-h*3**.5,self.center_y-h,\
                         self.center_x+h*3**.5,self.center_y-h)
            PopMatrix:
            Color:
                rgba: .1, .9, .5, .1
            Rectangle:
                pos: self.x+10, self.y+10
                size: self.width-20, self.height-20
    BoxLayout:
        Label:
            text: 'x :'
            size_hint_x: None
            width: self.height
        Slider:
            id: xslider
            value: 0
            range: (-180, 180)
            on_value: app.xangle=self.value
        Label:
            text: str(int(xslider.value))
            size_hint_x: None
            width: self.height
    BoxLayout:
        Label:
            text: 'y :'
            size_hint_x: None
            width: self.height
        Slider:
            id: yslider
            value: 0
            range: (-180, 180)
            on_value: app.yangle=self.value
        Label:
            text: str(int(yslider.value))
            size_hint_x: None
            width: self.height
    BoxLayout:
        Label:
            text: 'z :'
            size_hint_x: None
            width: self.height
        Slider:
            id: zslider
            value: 0
            range: (-180, 180)
            on_value: app.zangle=self.value;
        Label:
            text: str(int(zslider.value))
            size_hint_x: None
            width: self.height
'''


class RotationApp(App):
    xangle = NumericProperty(0)
    yangle = NumericProperty(0)
    zangle = NumericProperty(0)
    def build(self):
        return Builder.load_string(kv)

if(__name__ == '__main__'):
    RotationApp().run()
@khalakhelo
Copy link
Author

A little edit I would like to make to the code above:

origin: (*self.center, 0)

So that I ensure the z of point of origin is set to 0, the screen surface. It makes no changes anyway.
I understand one end could be cropped for crossing the screen surface , but that doesn't justify the opposite end.
also translating the matrix away by z beyond 1 (+or-) make it disappear.

@tshirtman
Copy link
Member

I think you want to read up on the OpenGL Projection matrix (for example http://www.songho.ca/opengl/gl_projectionmatrix.html), kivy being essentially 2D oriented, doesn't need one with much depth,

projection_mat.view_clip(0.0, w, 0.0, h, -1.0, 1.0, 0)

On the other hand the 3DRendering example sets a different one to be able to do more.

proj = Matrix().view_clip(-asp, asp, -1, 1, 1, 100, 1)

I can see how this can be surprising, but i assure you that kivy is very much able to do 3D rotations, it's just not setup to show the result nicely by default.

Hope this helps.

Closing as it's rather a support request than a bug report, but i can reopen if you disagree.

@support
Copy link

support bot commented Jun 26, 2018

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.

If you're having trouble installing Kivy, make sure to check out the installation docs for Windows, Linux and macOS.

Let us know if this comment was made in error, and we'll be happy to reopen the issue.

@support support bot closed this as completed Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants