Ejemplo n.º 1
0
def test_trackball__identity():
    origin_original = Point3(0., 1., 6.8)

    trackball = Trackball(origin_original, Point3(0., 1., 0.))

    origin_new = trackball.drag(Point2(0, 0))
    _assert_vectors_eq(origin_original, origin_new)
Ejemplo n.º 2
0
    def update(self):
        super().update()

        if self.tracking: return

        origin = Point3.from_vec3(self.model.getCameraOrigin())
        target = Point3.from_vec3(self.model.getCameraTarget())
        self.trackball.reset(origin, target)
Ejemplo n.º 3
0
def test_transform__identity():
    z_axis = Point3(0., 0., 6.8)
    up = Point3(0, 1, 0)

    transform = Transform.to_world(z_axis, up)

    z_axis_new = transform.transform_direction(Point3(0, 0, 1))

    _assert_vectors_eq(z_axis.normalized(), z_axis_new)
Ejemplo n.º 4
0
    def to_world(cls, z_axis, up):
        x_axis = Point3.cross(z_axis, up).normalized()
        y_axis = Point3.cross(z_axis, x_axis).normalized()
        z_axis = z_axis.normalized()

        return cls([
            [x_axis.x, y_axis.x, z_axis.x, 0.],
            [x_axis.y, y_axis.y, z_axis.y, 0.],
            [x_axis.z, y_axis.z, z_axis.z, 0.],
            [0., 0., 0., 1.],
        ])
Ejemplo n.º 5
0
    def __init__(self, pt, parent=None):
        super().__init__(parent)

        self.pt = pt
        self.model = self.pt.getSceneModel()

        self.setFixedSize(pt.getWidth(), pt.getHeight())

        origin = Point3.from_vec3(self.model.getCameraOrigin())
        target = Point3.from_vec3(self.model.getCameraTarget())
        self.trackball = Trackball(origin, target)
        self.tracking = False
        self.setMouseTracking(False)
Ejemplo n.º 6
0
def spherical_to_cartesian(phi, theta):
    y = math.cos(theta)

    x = math.sin(theta) * math.cos(phi)
    z = math.sin(theta) * math.sin(phi)

    return Point3(x, y, z)
Ejemplo n.º 7
0
    def drag(self, point):
        velocity = 0.1
        delta = (point - self.anchor) * velocity

        radians = delta / 180. * math.pi

        cartesian = coordinates.spherical_to_cartesian(math.pi / 2 - radians.x,
                                                       math.pi / 2 + radians.y)
        transform = Transform.to_world((self.origin - self.target),
                                       Point3(0, 1, 0))

        new_origin_direction = transform.transform_direction(cartesian)

        return self.target + new_origin_direction * self.radius
Ejemplo n.º 8
0
    def transform_direction(self, direction):
        x = np.array([direction.x, direction.y, direction.z, 0.])

        result = self.data.dot(x)
        return Point3(*self.data.dot(x)[:3])
Ejemplo n.º 9
0
def test_cartesian_zero():
    cartesian = coordinates.spherical_to_cartesian(math.pi / 2, math.pi / 2)
    _assert_vectors_eq(cartesian, Point3(0, 0, 1))