self._prev_rot_info = None
self._instantiated = False
taskMgr.add(self.on_frame, 'on_frame')
- #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
+ self._repos()
- def _set_side(self):
+ def _repos(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
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]
+ bounds = bounds[0] - self._np.get_pos(), bounds[1] - self._np.get_pos()
+ margin = .3, .2
+ dpos = bounds[1][0] + margin[0], 0, -bounds[1][2] - margin[1]
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]))
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))
+ if not hasattr(self, '_txt'):
+ 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), font=font, scale=0.06, fg=(.9, .9, .9, 1))
+ self._txt['pos'] = coord_a2d[0], coord_a2d[2]
new_node.remove_node()
def _set_outline_model(self):
d_angle = curr_vec.signed_angle_deg(start_vec, (0, -1, 0))
self._np.set_r(self._prev_rot_info[2] + d_angle)
self._prev_rot_info = pos, self._np.get_pos(), self._np.get_r()
+
+ def on_aspect_ratio_changed(self):
+ if not self._instantiated:
+ self._repos()