def toWorldCoordinate(self, scrx, scry, worldz, cam): invproj = vmath.inverse(cam.projectionMatrix) invview = cam.viewInverseMatrix w, h = pyxie.viewSize() x = scrx / w * 2 y = scry / h * 2 pos = vmath.vec4(x, y, 0.0, 1.0) npos = invproj * pos npos = invview * npos npos.z /= npos.w npos.x /= npos.w npos.y /= npos.w npos.w = 1.0 pos = vmath.vec4(x, y, 1.0, 1.0) fpos = invproj * pos fpos = invview * fpos fpos.z /= fpos.w fpos.x /= fpos.w fpos.y /= fpos.w fpos.w = 1.0 dir = vmath.normalize(fpos - npos) print(npos + (dir * (npos.z - worldz))) return npos + (dir * (npos.z - worldz))
def calculated_quarternion(self) -> pm.vec4: rot = pm.normalize( pm.quat_rotation(0) * pm.quat_rotationZ(math.radians(self.rotation.z)) * pm.quat_rotationY(math.radians(self.rotation.y)) * pm.quat_rotationX(math.radians(self.rotation.x))) return rot
def ConvertScreenToWorld(self, scrx, scry, worldz, cam, w=None, h=None): invproj = vmath.inverse(cam.projectionMatrix) invview = cam.viewInverseMatrix if not w or not h: w, h = pyxie.viewSize() x = scrx / w * 2 y = scry / h * 2 pos = vmath.vec4(x, y, 0.0, 1.0) npos = invproj * pos npos = invview * npos npos.z /= npos.w npos.x /= npos.w npos.y /= npos.w npos.w = 1.0 pos = vmath.vec4(x, y, 1.0, 1.0) fpos = invproj * pos fpos = invview * fpos fpos.z /= fpos.w fpos.x /= fpos.w fpos.y /= fpos.w fpos.w = 1.0 dir = vmath.normalize(fpos - npos) return npos + (dir * (npos.z - worldz))
def CalculateVelocity(self, pos): direction = [ self.currentTargetPos[0] - pos[0], self.currentTargetPos[1] - pos[1], self.currentTargetPos[2] - pos[2] ] normalizeDirection = vmath.normalize(vmath.vec3(direction)) newVelocity = [ normalizeDirection.x * self.move_speed, normalizeDirection.y * self.move_speed, normalizeDirection.z * self.move_speed ] return newVelocity