+ #self._set_side()
+ taskMgr.doMethodLater(.01, lambda task: self._set_side(), 'a')
+ # i get weird values in the first frame; i could restore this approach
+ # when the hook with the events of the window is up
+
+ def _set_side(self):
+ p_from, p_to = Point3(), Point3() # in camera coordinates
+ base.camLens.extrude((-1, 1), p_from, p_to)
+ p_from = render.get_relative_point(base.cam, p_from) # global coords
+ p_to = render.get_relative_point(base.cam, p_to) # global coords
+ for hit in self._world.ray_test_all(p_from, p_to).get_hits():
+ if hit.get_node() == self._plane_node:
+ pos = hit.get_hit_pos()
+ bounds = self._np.get_tight_bounds()
+ dpos = bounds[1][0], 0, -bounds[1][2]
+ self._np.set_pos(pos + dpos)
+ new_node = NodePath('temp')
+ new_node.set_pos(pos + dpos + (bounds[1][0], bounds[1][1], -bounds[1][2]))
+ coord3d = new_node.get_pos(base.cam)
+ coord2d = Point2()
+ base.camLens.project(coord3d, coord2d)
+ coord_r2d = Point3(coord2d[0], 0, coord2d[1])
+ coord_a2d = base.aspect2d.get_relative_point(render2d, coord_r2d)
+ font = base.loader.load_font('assets/fonts/Hanken-Book.ttf')
+ font.clear()
+ font.set_pixels_per_unit(60)
+ font.set_minfilter(Texture.FTLinearMipmapLinear)
+ font.set_outline((0, 0, 0, 1), .8, .2)
+ self._txt = OnscreenText(
+ str(self._count), pos=(coord_a2d[0], coord_a2d[2]),
+ font=font, scale=0.06, fg=(.9, .9, .9, 1))
+ new_node.remove_node()