I have a class Point3D that creates a vertical numpy matrix and can be edited:
import numpy as np
class Point3D:
def __init__(self, x, y, z):
self.vector = np.matrix([x, y, z])
self.vector = self.vector.reshape(3, 1)
def __str__(self):
n = self.__class__.__name__
return f'{n}({self.x}, {self.y}, {self.z})'
@property
def x(self): return self.vector.item((0, 0))
@property
def y(self): return self.vector.item((1, 0))
@property
def z(self): return self.vector.item((2, 0))
@x.setter
def x(self, x_val): self.vector.itemset((0, 0), x_val)
@y.setter
def y(self, y_val): self.vector.itemset((1, 0), y_val)
@z.setter
def z(self, z_val): self.vector.itemset((2, 0), z_val)
In another file, I have code that moves a camera (the camera is a Point3D), this is the final part of the code:
self.camera_pos.x += (self.player_VX / (self.fps.get_fps() + 0.1))
self.camera_pos.z += (self.player_VZ / (self.fps.get_fps() + 0.1))
For some reason, even though the expression on the right is nonzero, camera_pos
is not changing. Why?
New contributor
Math Magician is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4