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

18.) Cleanup trackball example #25

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 38 additions & 32 deletions examples/trackball/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
import os
import math
from kivy.app import App
from kivy.clock import Clock
from kivy3 import Scene, Renderer, PerspectiveCamera
from kivy3.loaders import OBJLoader
from kivy.uix.floatlayout import FloatLayout
from kivy3 import PerspectiveCamera
from kivy3 import Renderer
from kivy3 import Scene
from kivy3.loaders import OBJLoader
import math
import os

# Resources pathes
_this_path = os.path.dirname(os.path.realpath(__file__))
obj_file = os.path.join(_this_path, "./MQ-27.obj")


class TrackballExample(App):
"""This example shows how to use the Trackball-Navigation.
"""

def build(self):
renderer = self.renderer = Renderer()

loader = OBJLoader()
obj = loader.load(obj_file)

camera = PerspectiveCamera(15, 1, 100, 2500)

root = ObjectTrackball(camera, 1500)

scene = Scene()
scene.add(obj)

renderer.render(scene, camera)
renderer.main_light.intensity = 500
renderer.bind(size=self._adjust_aspect)

root.add_widget(renderer)

return root

def _adjust_aspect(self, inst, val):
rsize = self.renderer.size
aspect = rsize[0] / float(rsize[1])
self.renderer.camera.aspect = aspect


class ObjectTrackball(FloatLayout):
def __init__(self, camera, radius, *args, **kw):
super(ObjectTrackball, self).__init__(*args, **kw)
Expand Down Expand Up @@ -56,31 +88,5 @@ def do_rotate(self, touch):
self.camera.look_at((0, 0, 0))


class MainApp(App):
def build(self):
self.renderer = Renderer()
scene = Scene()
camera = PerspectiveCamera(15, 1, 100, 2500)
loader = OBJLoader()
obj = loader.load(obj_file)
self.obj3d = obj
self.camera = camera
root = ObjectTrackball(camera, 1500)

scene.add(obj)

self.renderer.render(scene, camera)
self.renderer.main_light.intensity = 500

root.add_widget(self.renderer)
self.renderer.bind(size=self._adjust_aspect)
return root

def _adjust_aspect(self, inst, val):
rsize = self.renderer.size
aspect = rsize[0] / float(rsize[1])
self.renderer.camera.aspect = aspect


if __name__ == "__main__":
MainApp().run()
TrackballExample().run()