PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_Main/Languages/IronPython/Samples/Direct3D/demo1.py

#
Python | 69 lines | 39 code | 16 blank | 14 comment | 3 complexity | e1eea7ad2af2e2a8cc79d8eaf3134d88 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. #####################################################################################
  2. #
  3. # Copyright (c) Microsoft Corporation. All rights reserved.
  4. #
  5. # This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. # copy of the license can be found in the License.html file at the root of this distribution. If
  7. # you cannot locate the Apache License, Version 2.0, please send an email to
  8. # ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. # by the terms of the Apache License, Version 2.0.
  10. #
  11. # You must not remove this notice, or any other, from this software.
  12. #
  13. #
  14. #####################################################################################
  15. import clr
  16. from framework import *
  17. class DirectionalMover(object):
  18. def __init__(self, obj, direction, speed, distance):
  19. self.Object = obj
  20. self.Speed = speed
  21. self.Distance = distance
  22. self.Direction = Vectorize(direction)
  23. self.Direction.Normalize()
  24. def OnFrame(self, elapsed):
  25. toTravel = self.Speed * elapsed
  26. if self.Distance < toTravel:
  27. self.Object.Translate(self.Direction * single(self.Distance))
  28. return True
  29. else:
  30. self.Distance -= toTravel
  31. self.Object.Translate(self.Direction * single(toTravel))
  32. class DemoSceneCreator(object):
  33. def OnSceneCreate(self, sm):
  34. cam = sm.CreateCamera("Player Cam")
  35. cam.Position = [0, 3, -5]
  36. box = sm.LoadBasicObject("box", "box 1", Drawing.Color.Red, 0.25, 0.25, 0.25)
  37. box.Position = [-1, 0, 0]
  38. box = sm.LoadBasicObject("box", "box 2", Drawing.Color.Green, 0.25, 0.25, 0.25)
  39. box.Position = [0, 0, 0]
  40. cam.LookAt(box.Position)
  41. box = sm.LoadBasicObject("box", "box 3", Drawing.Color.Blue, 0.25, 0.25, 0.25)
  42. box.Position = [1, 0, 0]
  43. return True
  44. def OnSceneBegin(self, sm):
  45. dm = DirectionalMover(sm.Objects["box 1"], [1, 0, 0], 0.3, 3)
  46. sm.AddListener(dm)
  47. dm = DirectionalMover(sm.Objects["box 2"], [0, 1, 0], 0.2, 2)
  48. sm.AddListener(dm)
  49. dm = DirectionalMover(sm.Objects["box 3"], [0, 0, 1], 1, 10)
  50. sm.AddListener(dm)
  51. return True
  52. if __name__ == '__main__':
  53. Root().Main([DemoSceneCreator])