62
62
the defined model and will correct the position if the cam is to close
65
# Camera Movement Updates
66
camvec = self.cam_floater.getPos(render) - camera.getPos(render)
68
camdist = camvec.length()
66
71
# check if the camera should be centered
67
72
if self.parent.isDown(self.parent.key_center_camera):
86
91
if base.win.movePointer(0, self.parent.win_width_half, self.parent.win_height_half):
87
92
# Vertical positioning
88
93
mouse_y = mw.getMouseY()
89
z = mouse_y * self.parent.mouse_speed_y * dt
94
z = mouse_y * self.parent.mouse_speed_y * camdist * dt
90
95
if self.parent.mouse_invert_vertical:
91
96
camera.setZ(camera, z)
136
141
self.last_platform_position_cam = None
137
142
self.last_platform_rotation_cam = None
139
# Camera Movement Updates
140
camvec = self.cam_floater.getPos(render) - camera.getPos(render)
142
camdist = camvec.length()
145
# camera collision detection
146
# always set the cameras position to the first hitpoint on a collision solid
147
pos = self.parent.getFirstCollisionInLine(self.cam_floater.getPos(render), camera.getPos(render))
148
had_ray_collision = False
150
had_ray_collision = True
153
# If the camera is to far from player start following
154
if camdist > self.parent.max_cam_distance:
155
camera.setPos(camera.getPos()+camvec*(camdist-self.parent.max_cam_distance))
156
camdist = self.parent.max_cam_distance
158
# If player is to close move the camera backwards
159
if camdist < self.parent.min_cam_distance:
160
if not had_ray_collision:
161
# move the camera backwards
162
camera.setPos(camera.getPos()-camvec*(self.parent.min_cam_distance-camdist))
163
camdist = self.parent.min_cam_distance
165
# we can't move the camera back into the wall, so move it up
166
#TODO: Maybe change max_cam_height_distance with something like
167
# self.parent.min_cam_dist - camdist
168
camera.setZ(self.cam_floater.getZ() + self.parent.max_cam_height_distance)
170
144
# Get the cameras current offset to the player model on the z-axis
171
145
offsetZ = camera.getZ(render) - self.cam_floater.getZ(render)
172
146
# check if the camera is within the min and max z-axis offset
200
174
# # set the cam z position to exactly the desired offset
201
175
# camera.setZ(self.cam_floater.getZ(render) + self.parent.cam_height_avg_up)
177
# If the camera is to far from player start following
178
if camdist > self.parent.max_cam_distance:
179
camera.setPos(camera.getPos()+camvec*(camdist-self.parent.max_cam_distance))
180
camdist = self.parent.max_cam_distance
182
# camera collision detection
183
# always set the cameras position to the first hitpoint on a collision solid
184
had_ray_collision = False
185
entry = self.parent.getFirstCollisionEntryInLine(self.cam_floater.getPos(render), camera.getPos(render))
186
if entry is not None:
188
if entry.hasSurfacePoint():
189
pos = entry.getSurfacePoint(render)
191
if entry.hasSurfaceNormal():
192
wall_normal = entry.getSurfaceNormal(render)
193
pos.setX(pos.getX() + wall_normal.getX()/2.0)
194
pos.setY(pos.getY() + wall_normal.getY()/2.0)
195
#pos = self.parent.getFirstCollisionInLine(self.cam_floater.getPos(render), camera.getPos(render))
197
had_ray_collision = True
200
# If player is to close move the camera backwards
201
if camdist < self.parent.min_cam_distance:
202
if not had_ray_collision:
203
# move the camera backwards
204
camera.setPos(camera.getPos()-camvec*(self.parent.min_cam_distance-camdist))
205
camdist = self.parent.min_cam_distance
207
# we can't move the camera back into the wall, so move it up
208
#TODO: Maybe change max_cam_height_distance with something like
209
# self.parent.min_cam_dist - camdist
210
camera.setZ(self.cam_floater.getZ() + self.parent.max_cam_height_distance)
203
212
camera.lookAt(self.cam_floater)