.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/feature_demo/look_at.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_feature_demo_look_at.py: Look At ======= This example shows how the look_at function can be used. .. GENERATED FROM PYTHON SOURCE LINES 7-71 .. image-sg:: /_gallery/feature_demo/images/sphx_glr_look_at_001.webp :alt: look at :srcset: /_gallery/feature_demo/images/sphx_glr_look_at_001.webp :class: sphx-glr-single-img .. code-block:: Python from time import perf_counter import numpy as np import pygfx as gfx import pylinalg as la scene = gfx.Scene() sphere = gfx.Mesh( gfx.sphere_geometry(100, 20, 20), gfx.MeshPhongMaterial(color="#336699"), ) sphere.receive_shadow = sphere.cast_shadow = True scene.add(sphere) plane = gfx.Mesh( gfx.plane_geometry(4000, 4000), gfx.MeshPhongMaterial(color="#336699"), ) plane.local.position = (0, -2500, 0) plane.local.rotation = la.quat_from_euler(-np.pi / 2, order="X") plane.receive_shadow = True scene.add(plane) sun = gfx.DirectionalLight() sun.local.position = (0, 3000, 0) sun.cast_shadow = True sun.shadow.camera.depth_range = (1, 6000) sun.shadow.camera.width = 4000 sun.shadow.camera.height = 4000 scene.add(gfx.AmbientLight()) scene.add(sun) geometry = gfx.cylinder_geometry(10, 0, 100, 12) material = gfx.MeshPhongMaterial(color="#336699") cones = gfx.Group() for _i in range(100): cone = gfx.Mesh(geometry, material) cone.local.position = np.random.rand(3) * 4000 - 2000 cone.local.scale = np.random.rand() * 4 + 2 cone.receive_shadow = cone.cast_shadow = True cones.add(cone) scene.add(cones) def animate(): t = perf_counter() / 0.5 sphere.local.position = ( np.sin(t * 0.7) * 2000, np.cos(t * 0.5) * 2000, np.cos(t * 0.3) * 2000, ) for c in cones.children: c.look_at(sphere.world.position) if __name__ == "__main__": disp = gfx.Display() disp.before_render = animate disp.show(scene) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 12.244 seconds) .. _sphx_glr_download__gallery_feature_demo_look_at.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: look_at.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: look_at.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: look_at.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html