MCPcopy Create free account
hub / github.com/blender/blender / Vector_slerp

Function Vector_slerp

source/blender/python/mathutils/mathutils_Vector.cc:1431–1501  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1429 " :return: The interpolated vector.\n"
1430 " :rtype: :class:`Vector`\n");
1431static PyObject *Vector_slerp(VectorObject *self, PyObject *args)
1432{
1433 const int vec_num = self->vec_num;
1434 PyObject *value = nullptr;
1435 float fac, cosom, w[2];
1436 float self_vec[3], other_vec[3], ret_vec[3];
1437 float self_len_sq, other_len_sq;
1438 int x;
1439 PyObject *fallback = nullptr;
1440
1441 if (!PyArg_ParseTuple(args, "Of|O:slerp", &value, &fac, &fallback)) {
1442 return nullptr;
1443 }
1444
1445 if (BaseMath_ReadCallback(self) == -1) {
1446 return nullptr;
1447 }
1448
1449 if (self->vec_num > 3) {
1450 PyErr_SetString(PyExc_ValueError, "Vector must be 2D or 3D");
1451 return nullptr;
1452 }
1453
1454 if (mathutils_array_parse(
1455 other_vec, vec_num, vec_num, value, "Vector.slerp(other), invalid 'other' arg") == -1)
1456 {
1457 return nullptr;
1458 }
1459
1460 self_len_sq = normalize_vn_vn(self_vec, self->vec, vec_num);
1461 other_len_sq = normalize_vn(other_vec, vec_num);
1462
1463 /* use fallbacks for zero length vectors */
1464 if (UNLIKELY((self_len_sq < FLT_EPSILON) || (other_len_sq < FLT_EPSILON))) {
1465 /* avoid exception */
1466 if (fallback) {
1467 Py_INCREF(fallback);
1468 return fallback;
1469 }
1470
1471 PyErr_SetString(PyExc_ValueError,
1472 "Vector.slerp(): "
1473 "zero length vectors unsupported");
1474 return nullptr;
1475 }
1476
1477 /* We have sane state, execute slerp */
1478 cosom = float(dot_vn_vn(self_vec, other_vec, vec_num));
1479
1480 /* direct opposite, can't slerp */
1481 if (UNLIKELY(cosom < (-1.0f + FLT_EPSILON))) {
1482 /* avoid exception */
1483 if (fallback) {
1484 Py_INCREF(fallback);
1485 return fallback;
1486 }
1487
1488 PyErr_SetString(PyExc_ValueError,

Callers

nothing calls this directly

Calls 6

mathutils_array_parseFunction · 0.85
normalize_vn_vnFunction · 0.85
dot_vn_vnFunction · 0.85
interp_dot_slerpFunction · 0.85
Vector_CreatePyObjectFunction · 0.85
normalize_vnFunction · 0.50

Tested by

no test coverage detected