So, I put this in cineCam.py but, what line though.
I’m terrible with programming but, I’m slowly learning.
1. import gryLib as gry
2. class CineamaticCamera(gry.BaseClass):
3. """
4. a cineamatic camera
5. """
6. from gryLib import child
7. child
8.
9. def __init__(cam, DNU, sheet=None):
10. """
11. cam.get('smove', 0): the amout of camera smothing
12. cam.child('Cam'): the camera object
13. cam.child('Focus'): the object the camera looks at
14. """
15. gry.BaseClass.__init__(cam, DNU, sheet)
16. cam.cam = cam.child('Cam')
17. cam.focus = cam.child('Focus')
18. #: the focus needs its own independant position, but its convenyent to stor it as a child
19. cam.focus.removeParent
20. cam.target = None
21. cam.offset = cam.get('offset', 0)
22.
23. #: tell everyone that your the current camera
24. gry.msgr.say('currentCamera', [cam], 'currentCamera')
25. #: this alows you to easly set or disable the game camera
26. #: theres an object that represents the camera on an inactive layer
27. #: this alows you to see what the camera is doing from out side of the camera
28. if cam.get('setAsMain', False):
29. cam.scene.active_camera = cam.cam
30.
31. #: set veryious defaults for the camera
32. cam.smove = cam.get('smove', 0)
33.
34. cam.pivotType = None
35. cam.pivot = None
36. cam.focusOffset = 1
37. cam.camOffset = 3 # this raises up the focus of the camera so your not looking at the chars feet
38. cam.dist = 20
39. cam.minDist = 10
40. #found a little spot here but, don't know what to do next and this might be wrong
41.
42.
43.
44. def message(self, subject, args, filter, to, fromm):
45. """
46. currentChar
47. :cameraPost
48. if args[0] is the cameras target then it sets itself with
49. self.pivot, self.pivotType, self.dist, self.offset, self.lens = args[1:]
50. """
51. #: the camera will point at the current char
52. if subject == 'currentChar': self.target = args[0]
53. #: set the cameras stats from a cameraPost event
54. if subject == 'cameraPost':
55. if self.target == args[0]:
56. self.pivot, self.pivotType, self.dist, self.offset, self.lens = args[1:]
57.
58.
59. def run(cam):
60. """
61. updates the position of the camera
62. """
63. if not cam.target: return
64. #; the focus is what the camera looks at
65. #: the center of objects are often place at the bottom of the object,
66. #: therefore it can be usefull to bring the focus up a little so your looking at the targets eyes rather then its feet
67. cam.focus.worldPosition = cam.target.worldPosition
68. cam.focus.worldPosition.z += cam.offset
69. #: follow the char from the angle of the pivot
70. if cam.pivotType == 'pan':
71. cam.worldPosition = cam.focus.worldPosition
72.
73. #: this gets the direction the pivot is pointing
74. #: single arrow emptys point to positive z,
75. #: so the angle has to be fudged
76. vec = cam.pivot.getAxisVect([0, 0, 1])
77. #: the magnatude of the vector is how long it is
78. vec.magnitude = cam.dist
79. #: you can imagine there being an arrow pointing from the focus to were we want the camera
80. #: we send the camera down that arrow
81. cam.worldPosition -= vec
82. #: this causes the camera to look either up or down on at the focus
83. cam.worldPosition.z += cam.camOffset
84. #: rotate around the pivot keeping the same distance
85. #: the focus is always betwene the camera and the pivot
86. elif cam.pivotType == 'orbit':
87. cam.worldPosition = cam.focus.worldPosition
88.
89. #: this is hard to explane. you may want to draw it
90. #: draw a line A from the pivot to the target
91. #: draw a line B from the target to were we want the camera
92. #: draw a line C from the pivot to the were we want the camera
93. #: A and B should have the same angle,
94. #; so we set B's angle to A's
95. #: A + B should have the same distance as C
96. #: so we set the distance of B to the distance of C - A
97. #: now B gives us the position of the camera relitive to the position of the target
98. #: this alows us to ensure that the camera is not too close to the target
99. #: its posible that there may be an easer way to do this
100.
101. #: get the position of the target
102. vec = cam.target.worldPosition.copy()
103. #: move the vector so its the same hight as the pivot,
104. #: but dont change the hight of the char
105. vec.z = cam.pivot.worldPosition.z
106. import mathutils # currently the rotation on an orbit has to be 0. hopfully this wont mess anything up
107. cam.pivot.worldOrientation = mathutils.Euler((0, 0, 0))
108. #: get the distance and local vector from the pivot to the target
109. dist, wVec, lVec = cam.pivot.getVectTo(vec)
110.
111. #: find the distance from the target to the camera
112. dist = cam.dist - dist
113. dist = gry.minmax(dist, cam.minDist, cam.dist)
114. lVec.magnitude = dist
115. #: the cameras position was set to the target,
116. #: so if we add the local vector it gooes to the were we want the camera
117. cam.worldPosition += lVec
118. cam.worldPosition.z += cam.camOffset
119.
120. elif cam.pivotType == 'static':
121. #: put the camera on the static pivot
122. cam.worldPosition = cam.pivot.worldPosition
123.
124.
125.
126.
127.
128. @property # lower is faster. 0.0 to disable.
129. def smove(cam): return cam.cam.timeOffset
130. @smove.setter
131. def smove(cam, value): cam.cam.timeOffset = value
132.
133. @property
134. def lens(cam): return cam.cam.lens
135. @lens.setter
136. def lens(cam, value): cam.cam.lens = value