Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2008-07-09 13:21:52 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-07-09 13:21:52 +0400
commit60d099648c05ac469e3499e9755477c5180b9721 (patch)
tree63d8abada83e13e760ca25fdde42200c7afc2b08 /source
parent16dccd3ffdb00bb81400c804b30b13de26d1dc10 (diff)
added a factor argument for aligning to vector, this isn't correct since it does linear interpolation of the vector and renormalizes.
(can be improved to rotate correctly but for our use ist ok for now, would also be useful to have an argument to clamp the maximum rotation angle to get a constant rotation speed), This will used to make franky upright when falling from an angle, to track to a surface when hanging onto a ledge and setting the glide pitch. Without this rotation is instant and jerky. currently this is done with Mathutils which isnt available in Blender Player. def do_rotate_up(own): own.alignAxisToVect([0,0,1], 2, 0.1) replaces... def do_rotate_up(own): up_nor = Vector(0,0,1) own_mat = Matrix(*own.getOrientation()).transpose() own_up = up_nor * own_mat ang = AngleBetweenVecs(own_up, up_nor) if ang > 0.005: # Set orientation cross = CrossVecs(own_up, up_nor) new_mat = own_mat * RotationMatrix(ang*0.1, 3, 'r', cross) own.setOrientation(new_mat.transpose()) M source/gameengine/Ketsji/KX_GameObject.cpp M source/gameengine/Ketsji/KX_GameObject.h
Diffstat (limited to 'source')
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp39
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.h3
2 files changed, 35 insertions, 7 deletions
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
index 88fbbb5fd1f..e29ca72500a 100644
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ b/source/gameengine/Ketsji/KX_GameObject.cpp
@@ -572,7 +572,7 @@ void KX_GameObject::SetObjectColor(const MT_Vector4& rgbavec)
m_objectColor = rgbavec;
}
-void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis)
+void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
{
MT_Matrix3x3 orimat;
MT_Vector3 vect,ori,z,x,y;
@@ -585,6 +585,11 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis)
cout << "alignAxisToVect() Error: Null vector!\n";
return;
}
+
+ if (fac<=0.0) {
+ return;
+ }
+
// normalize
vect /= len;
orimat = GetSGNode()->GetWorldOrientation();
@@ -594,7 +599,14 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis)
ori = MT_Vector3(orimat[0][2], orimat[1][2], orimat[2][2]); //pivot axis
if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON) //is the vector paralell to the pivot?
ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]); //change the pivot!
- x = vect;
+ if (fac == 1.0) {
+ x = vect;
+ } else {
+ x = (vect * fac) + ((orimat * MT_Vector3(1.0, 0.0, 0.0)) * (1-fac));
+ len = x.length();
+ if (MT_fuzzyZero(len)) x = vect;
+ else x /= len;
+ }
y = ori.cross(x);
z = x.cross(y);
break;
@@ -602,7 +614,14 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis)
ori = MT_Vector3(orimat[0][0], orimat[1][0], orimat[2][0]);
if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON)
ori = MT_Vector3(orimat[0][2], orimat[1][2], orimat[2][2]);
- y = vect;
+ if (fac == 1.0) {
+ y = vect;
+ } else {
+ y = (vect * fac) + ((orimat * MT_Vector3(0.0, 1.0, 0.0)) * (1-fac));
+ len = y.length();
+ if (MT_fuzzyZero(len)) y = vect;
+ else y /= len;
+ }
z = ori.cross(y);
x = y.cross(z);
break;
@@ -610,7 +629,14 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis)
ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]);
if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON)
ori = MT_Vector3(orimat[0][0], orimat[1][0], orimat[2][0]);
- z = vect;
+ if (fac == 1.0) {
+ z = vect;
+ } else {
+ z = (vect * fac) + ((orimat * MT_Vector3(0.0, 0.0, 1.0)) * (1-fac));
+ len = z.length();
+ if (MT_fuzzyZero(len)) z = vect;
+ else z /= len;
+ }
x = ori.cross(z);
y = z.cross(x);
break;
@@ -1386,13 +1412,14 @@ PyObject* KX_GameObject::PyAlignAxisToVect(PyObject* self,
{
PyObject* pyvect;
int axis = 2; //z axis is the default
+ float fac = 1.0;
- if (PyArg_ParseTuple(args,"O|i",&pyvect,&axis))
+ if (PyArg_ParseTuple(args,"O|if",&pyvect,&axis, &fac))
{
MT_Vector3 vect;
if (PyVecTo(pyvect, vect))
{
- AlignAxisToVect(vect,axis);
+ AlignAxisToVect(vect,axis,fac);
Py_RETURN_NONE;
}
}
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
index b4f50087742..ddbf863aa1a 100644
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ b/source/gameengine/Ketsji/KX_GameObject.h
@@ -278,7 +278,8 @@ public:
void
AlignAxisToVect(
const MT_Vector3& vect,
- int axis = 2
+ int axis = 2,
+ float fac = 1.0
);
/**