本文整理汇总了Java中org.rajawali3d.math.Quaternion.fromAngleAxis方法的典型用法代码示例。如果您正苦于以下问题:Java Quaternion.fromAngleAxis方法的具体用法?Java Quaternion.fromAngleAxis怎么用?Java Quaternion.fromAngleAxis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.rajawali3d.math.Quaternion
的用法示例。
在下文中一共展示了Quaternion.fromAngleAxis方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRotationTo
import org.rajawali3d.math.Quaternion; //导入方法依赖的package包/类
/**
* Creates a {@link Quaternion} which represents the rotation from a this {@link Vector3}
* to the provided {@link Vector3}. Adapted from OGRE 3D engine.
*
* @param direction {@link Vector3} The direction to rotate to.
*
* @return {@link Quaternion} The {@link Quaternion} representing the rotation.
* @see http://ogre.sourcearchive.com/documentation/1.4.5/classOgre_1_1Vector3_eeef4472ad0c4d5f34a038a9f2faa819.html#eeef4472ad0c4d5f34a038a9f2faa819
*/
public Quaternion getRotationTo(Vector3 direction) {
// Based on Stan Melax's article in Game Programming Gems
Quaternion q = new Quaternion();
// Copy, since cannot modify local
Vector3 v0 = this;
Vector3 v1 = direction;
v0.normalize();
v1.normalize();
double d = Vector3.dot(v0, v1);
// If dot == 1, vectors are the same
if (d >= 1.0f) {
q.identity();
}
if (d < 0.000001 - 1.0) {
// Generate an axis
Vector3 axis = Vector3.crossAndCreate(Vector3.getAxisVector(Axis.X), this);
if (axis.length() == 0) // pick another if colinear
axis = Vector3.crossAndCreate(Vector3.getAxisVector(Axis.Y), this);
axis.normalize();
q.fromAngleAxis(axis, MathUtil.radiansToDegrees(MathUtil.PI));
} else {
double s = Math.sqrt((1 + d) * 2);
double invs = 1 / s;
Vector3 c = Vector3.crossAndCreate(v0, v1);
q.x = c.x * invs;
q.y = c.y * invs;
q.z = c.z * invs;
q.w = s * 0.5;
q.normalize();
}
return q;
}
示例2: quaternionFromVector
import org.rajawali3d.math.Quaternion; //导入方法依赖的package包/类
protected Quaternion quaternionFromVector(Vector3 vec) {
vec.normalize();
final double angle = MathUtil.radiansToDegrees(Math.acos(Vector3.dot(mForwardVec, vec)));
final Quaternion q = new Quaternion();
q.fromAngleAxis(mTmpQuatVector.crossAndSet(mForwardVec, vec), angle);
return q;
}
示例3: getRotationTo
import org.rajawali3d.math.Quaternion; //导入方法依赖的package包/类
/**
* Creates a {@link Quaternion} which represents the rotation from a this {@link Vector3}
* to the provided {@link Vector3}. Adapted from OGRE 3D engine.
*
* @param direction {@link Vector3} The direction to rotate to.
*
* @return {@link Quaternion} The {@link Quaternion} representing the rotation.
* @see <a href="http://ogre.sourcearchive.com/documentation/1.4
* .5/classOgre_1_1Vector3_eeef4472ad0c4d5f34a038a9f2faa819.html#eeef4472ad0c4d5f34a038a9f2faa819">Ogre3d</a>
*/
public Quaternion getRotationTo(Vector3 direction) {
// Based on Stan Melax's article in Game Programming Gems
Quaternion q = new Quaternion();
// Copy, since cannot modify local
Vector3 v0 = this;
Vector3 v1 = direction;
v0.normalize();
v1.normalize();
double d = Vector3.dot(v0, v1);
// If dot == 1, vectors are the same
if (d >= 1.0f) {
q.identity();
}
if (d < 0.000001 - 1.0) {
// Generate an axis
Vector3 axis = Vector3.crossAndCreate(Vector3.getAxisVector(Axis.X), this);
if (axis.length() == 0) // pick another if colinear
axis = Vector3.crossAndCreate(Vector3.getAxisVector(Axis.Y), this);
axis.normalize();
q.fromAngleAxis(axis, MathUtil.radiansToDegrees(MathUtil.PI));
} else {
double s = Math.sqrt((1 + d) * 2);
double invs = 1 / s;
Vector3 c = Vector3.crossAndCreate(v0, v1);
q.x = c.x * invs;
q.y = c.y * invs;
q.z = c.z * invs;
q.w = s * 0.5;
q.normalize();
}
return q;
}