@@ -79,6 +79,13 @@ def __create_grid_objects(self):
79
79
round (self .__scene .center .y , 2 ), \
80
80
round (self .__scene .center .z , 2 )
81
81
self .__focal_point = [x_origin , y_origin , z_origin ]
82
+ # Convert focal point for 2D rendering. Puts focus point in centre of the view
83
+ if not self .__is_3d :
84
+ self .__focal_point = [val - int (self .__num_squares / 2 ) for val in self .__focal_point ]
85
+ x_origin = self .__focal_point [0 ]
86
+ y_origin = self .__focal_point [1 ]
87
+ z_origin = 0
88
+ self .__focal_point [2 ] = z_origin
82
89
else :
83
90
x_origin , y_origin , z_origin = self .__focal_point [0 ], \
84
91
self .__focal_point [1 ], \
@@ -117,6 +124,11 @@ def __create_grid_objects(self):
117
124
y_coords = arange (min_y_coord , max_y_coord + self .__scale , self .__scale )
118
125
z_coords = arange (min_z_coord , max_z_coord + self .__scale , self .__scale )
119
126
127
+ # Compound origins are in the middle of the bounding boxes. Thus new pos will be between max and min.
128
+ x_middle = (max_x_coord + min_x_coord ) / 2
129
+ y_middle = (max_y_coord + min_y_coord ) / 2
130
+ z_middle = (max_z_coord + min_z_coord ) / 2
131
+
120
132
# XZ plane
121
133
for x_point in x_coords :
122
134
# Draw a line across for each x coord, along the same y-axis, from min to max z coord
@@ -166,9 +178,23 @@ def __create_grid_objects(self):
166
178
))
167
179
168
180
# Compound the lines together into respective objects
169
- xz_plane = compound (xz_lines )
170
- xy_plane = compound (xy_lines )
171
- yz_plane = compound (yz_lines )
181
+ # XY Plane
182
+ if camera_axes .z < 0 :
183
+ xy_plane = compound (xy_lines , origin = vector (x_middle , y_middle , min_z_coord ))
184
+ else :
185
+ xy_plane = compound (xy_lines , origin = vector (x_middle , y_middle , max_z_coord ))
186
+
187
+ # XZ Plane
188
+ if camera_axes .y < 0 :
189
+ xz_plane = compound (xz_lines , origin = vector (x_middle , min_y_coord , z_middle ))
190
+ else :
191
+ xz_plane = compound (xz_lines , origin = vector (x_middle , max_y_coord , z_middle ))
192
+
193
+ # YZ Plane
194
+ if camera_axes .x < 0 :
195
+ yz_plane = compound (yz_lines , origin = vector (min_x_coord , y_middle , z_middle ))
196
+ else :
197
+ yz_plane = compound (yz_lines , origin = vector (max_x_coord , y_middle , z_middle ))
172
198
173
199
# Combine all into one list
174
200
grid = [None , None , None ]
@@ -235,12 +261,19 @@ def __move_grid_objects(self):
235
261
y_middle = (max_y_coord + min_y_coord ) / 2
236
262
z_middle = (max_z_coord + min_z_coord ) / 2
237
263
264
+ print ("x" , min_x_coord , x_middle , max_x_coord )
265
+ print ("y" , min_y_coord , y_middle , max_y_coord )
266
+ print ("z" , min_z_coord , z_middle , max_z_coord )
267
+ print ("pos" , self .grid_object [self .__planes_idx ][self .__xy_plane_idx ])
268
+
238
269
# XY Plane
239
270
if camera_axes .z < 0 :
240
271
self .grid_object [self .__planes_idx ][self .__xy_plane_idx ].pos = vector (x_middle , y_middle , min_z_coord )
241
272
else :
242
273
self .grid_object [self .__planes_idx ][self .__xy_plane_idx ].pos = vector (x_middle , y_middle , max_z_coord )
243
274
275
+ print ("pos" , self .grid_object [self .__planes_idx ][self .__xy_plane_idx ])
276
+
244
277
# XZ Plane
245
278
if camera_axes .y < 0 :
246
279
self .grid_object [self .__planes_idx ][self .__xz_plane_idx ].pos = vector (x_middle , min_y_coord , z_middle )
@@ -258,18 +291,23 @@ def update_grid(self):
258
291
Update the grid axes and numbers if the camera position/rotation has changed.
259
292
"""
260
293
# Obtain the new camera settings
261
- new_camera_pos = self .__scene .camera .pos
262
- new_camera_axes = self .__scene .camera .axis
294
+ new_camera_pos = vector (self .__scene .camera .pos )
295
+ new_camera_axes = vector (self .__scene .camera .axis )
296
+
297
+ old_camera_pos = vector (self .camera_pos )
298
+ old_camera_axes = vector (self .camera_axes )
299
+
300
+ # Update old positions
301
+ self .camera_pos = new_camera_pos
302
+ self .camera_axes = new_camera_axes
263
303
264
- old_camera_pos = self .camera_pos
265
- old_camera_axes = self .camera_axes
304
+ distance_from_center = mag (self .__scene .center - self .__scene .camera .pos )
305
+ new_scale = round (distance_from_center / 30.0 , 1 )
306
+ if not new_scale == self .__scale :
307
+ self .set_scale (new_scale )
266
308
267
309
# If camera is different to previous: update
268
310
if (not new_camera_axes .equals (old_camera_axes )) or (not new_camera_pos .equals (old_camera_pos )):
269
- # Update old positions
270
- self .camera_pos = new_camera_pos
271
- self .camera_axes = new_camera_axes
272
-
273
311
# Update grid
274
312
self .__move_grid_objects ()
275
313
update_grid_numbers (self .__focal_point ,
@@ -332,6 +370,22 @@ def set_relative(self, is_relative):
332
370
self .__relative_cam = is_relative
333
371
self .update_grid ()
334
372
373
+ def set_scale (self , value ):
374
+ """
375
+ :param value: The value to set the scale to
376
+ :type value: `float`
377
+ """
378
+ value = max (min (value , 100 ), 0.1 ) # Between 0.1 and 100
379
+ self .__scale = value
380
+ # Turn off grid then delete
381
+ for plane in self .grid_object [self .__planes_idx ]:
382
+ plane .visible = False
383
+ for text in self .grid_object [self .__labels_idx ]:
384
+ text .visible = False
385
+
386
+ self .grid_object = [[], []]
387
+ self .__init_grid ()
388
+
335
389
336
390
def create_line (pos1 , pos2 , scene , colour = None , thickness = 0.01 ):
337
391
"""
0 commit comments