当前位置: 首页>>代码示例>>Java>>正文


Java Quaternion.normalize方法代码示例

本文整理汇总了Java中org.rajawali3d.math.Quaternion.normalize方法的典型用法代码示例。如果您正苦于以下问题:Java Quaternion.normalize方法的具体用法?Java Quaternion.normalize怎么用?Java Quaternion.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.rajawali3d.math.Quaternion的用法示例。


在下文中一共展示了Quaternion.normalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:sujitkjha,项目名称:360-Video-Player-for-Android,代码行数:45,代码来源:Vector3.java

示例2: 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;
}
 
开发者ID:godstale,项目名称:VR-Defense-Game,代码行数:46,代码来源:Vector3.java


注:本文中的org.rajawali3d.math.Quaternion.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。