本文整理汇总了Java中javax.vecmath.Quat4f类的典型用法代码示例。如果您正苦于以下问题:Java Quat4f类的具体用法?Java Quat4f怎么用?Java Quat4f使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Quat4f类属于javax.vecmath包,在下文中一共展示了Quat4f类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EntityCrazyCube
import javax.vecmath.Quat4f; //导入依赖的package包/类
public EntityCrazyCube(World world, Vec3f pos){
super(world, getModel0(), pos);
float s=Rand.f()+1;
scale.set(s, s, s);
// model.getMaterial(2).getDiffuse().set(177/256F, 0, 177/256F, 1);
// model.getMaterial(1).getDiffuse().set(0x00C7E7);
// model.getMaterial(1).getAmbient().set(0x00C7E7).a(1);
// model.getMaterial(0).getDiffuse().set(0x0000FF);
float massKg=0.5F*scale.x*scale.y*scale.z;
if(CAM==null) CAM=this;
getPhysicsObj().init(massKg, new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(pos.x, pos.y, pos.z), 0.5F)), new SphereShape(scale.x/2), Vec3f.single(0.9F));
// getPhysicsObj().init(massKg, new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(pos.x, pos.y, pos.z), 0.5F)), new BoxShape(new Vector3f(scale.x/2, scale.y/2, scale.z/2)), Vec3f.single(0.9F));
getPhysicsObj().body.setDamping(0.15F, 0.15F);
getPhysicsObj().hookPos(this.pos);
getPhysicsObj().hookRot(rot);
}
示例2: parseRotation
import javax.vecmath.Quat4f; //导入依赖的package包/类
public static Quat4f parseRotation(JsonElement e)
{
if (e.isJsonArray())
{
if (e.getAsJsonArray().get(0).isJsonObject())
{
Quat4f ret = new Quat4f(0, 0, 0, 1);
for (JsonElement a : e.getAsJsonArray())
{
ret.mul(parseAxisRotation(a));
}
return ret;
}
else
{
// quaternion
return new Quat4f(parseFloatArray(e, 4, "Rotation"));
}
}
else if (e.isJsonObject())
{
return parseAxisRotation(e);
}
else throw new JsonParseException("Rotation: expected array or object, got: " + e);
}
示例3: mul
import javax.vecmath.Quat4f; //导入依赖的package包/类
public static Matrix4f mul(Vector3f translation, Quat4f leftRot, Vector3f scale, Quat4f rightRot)
{
Matrix4f res = new Matrix4f(), t = new Matrix4f();
res.setIdentity();
if(leftRot != null)
{
t.set(leftRot);
res.mul(t);
}
if(scale != null)
{
t.setIdentity();
t.m00 = scale.x;
t.m11 = scale.y;
t.m22 = scale.z;
res.mul(t);
}
if(rightRot != null)
{
t.set(rightRot);
res.mul(t);
}
if(translation != null) res.setTranslation(translation);
return res;
}
示例4: applyInitTransform
import javax.vecmath.Quat4f; //导入依赖的package包/类
public void applyInitTransform(List<Vector3f> helperPoints) {
float shiftX = shift.getX() + initialShift.getX();
float shiftY = shift.getY() + initialShift.getY();
float shiftZ = shift.getZ() + initialShift.getZ();
Quat4f rotationQuat = new Quat4f(0,0,0,1) ;
rotationQuat.mul(rotQuat,initRotQuat);
for (int i = 0; i < helperPoints.size(); i++) {
Vector3f vert = new Vector3f();
vert.setX(helperPoints.get(i).getX());
vert.setY(helperPoints.get(i).getY());
vert.setZ(helperPoints.get(i).getZ());
vert = rotate(vert,rotationQuat);
helperPoints.get(i).setX(vert.getX() * scale.getX() + shiftX);
helperPoints.get(i).setY(vert.getY() * scale.getY() + shiftY);
helperPoints.get(i).setZ(vert.getZ() * scale.getZ() + shiftZ);
}
}
示例5: quaternionToEuler
import javax.vecmath.Quat4f; //导入依赖的package包/类
private Vector3f quaternionToEuler(Quat4f quat) {
Vector3f p = new Vector3f();
double sqw = quat.w * quat.w;
double sqx = quat.x * quat.x;
double sqy = quat.y * quat.y;
double sqz = quat.z * quat.z;
double unit = sqx + sqy + sqz + sqw;
double test = quat.x * quat.y + quat.z * quat.w;
if (test > 0.499 * unit) { // singularity at north pole
p.y = (float) (2 * Math.atan2(quat.x, quat.w));
p.z = (float) (Math.PI * 0.5);
p.x = 0;
} else if (test < -0.499 * unit) { // singularity at south pole
p.y = (float) (-2 * (Math.atan2(quat.x, quat.w)));
p.z = (float) (-Math.PI * 0.5);
p.x = 0;
} else {
p.y = (float) Math.toDegrees((Math.atan2(2 * quat.y * quat.w - 2 * quat.x * quat.z, sqx - sqy - sqz + sqw)));
p.z = (float) Math.toDegrees((Math.asin(2 * test / unit)));
p.x = (float) Math.toDegrees((Math.atan2(2 * quat.x * quat.w - 2 * quat.y * quat.z, -sqx + sqy - sqz + sqw)));
}
return p;
}
示例6: updateSelectedPart
import javax.vecmath.Quat4f; //导入依赖的package包/类
/**
* Updates position rotation and size of selected model.
*
* @param position new position of a model
* @param rotation new rotation of a model (in case of editing both models
* from pair(both eyes, ears...) new rotation of right model)
* @param rotation2 in case of editing both models from pair (both eyes,
* ears...) new rotation of left model
* @param size new size of a model
*/
public void updateSelectedPart(Vector3f position, Quat4f rotation, Quat4f rotation2, Vector3f size) {
if (currentPart != null && (getSelectedPart(1) != null)) {
if (currentPart.equals(FacePartType.EYES) || currentPart.equals(FacePartType.EYEBROWS) || currentPart.equals(FacePartType.EARS)) {
if (getSelectedPart(1).getEditMode() == BOTH) {
updatePositions(getSelectedPart(1), getSelectedPart(2), position, rotation, rotation2, size);
} else if (getSelectedPart(1).getEditMode() == RIGHT) {
updatePositions(getSelectedPart(1), null, position, rotation, rotation2, size);
} else {
updatePositions(getSelectedPart(2), null, position, rotation, rotation2, size);
}
} else {
updatePositions(getSelectedPart(1), null, position, rotation, rotation2, size);
}
}
}
示例7: getSignRotate
import javax.vecmath.Quat4f; //导入依赖的package包/类
public @Nonnull Quat4f getSignRotate(final @Nonnull TileEntitySign tile) {
// Vanilla Translate
final Block block = tile.getBlockType();
if (block==Blocks.standing_sign) {
final float f2 = tile.getBlockMetadata()*360f/16f;
return RotationMath.quatDeg(-f2, 0f, 1f, 0f);
} else {
final int j = tile.getBlockMetadata();
float f3;
switch (j) {
case 2:
f3 = 180f;
break;
case 4:
f3 = 90f;
break;
case 5:
f3 = -90f;
break;
default:
f3 = 0f;
break;
}
return RotationMath.quatDeg(-f3, 0f, 1f, 0f);
}
}
示例8: quatFromEuler
import javax.vecmath.Quat4f; //导入依赖的package包/类
/**
* Create a new Quat4f representing the yaw, pitch and roll given(applied in
* that order).
*
* @param pitch
* The pitch.
* @param yaw
* The yaw.
* @param roll
* The roll.
* @return The new Quat4f.
*/
public static Quat4f quatFromEuler(float pitch, float yaw, float roll) {
Quat4f quat = new Quat4f();
pitch = (float) Math.toRadians(pitch);
yaw = (float) Math.toRadians(yaw);
roll = (float) Math.toRadians(roll);
final Vector3f coss = new Vector3f();
coss.x = (float) Math.cos(pitch * 0.5F);
coss.y = (float) Math.cos(yaw * 0.5F);
coss.z = (float) Math.cos(roll * 0.5F);
final Vector3f sins = new Vector3f();
sins.x = (float) Math.sin(pitch * 0.5F);
sins.y = (float) Math.sin(yaw * 0.5F);
sins.z = (float) Math.sin(roll * 0.5F);
quat.w = coss.x * coss.y * coss.z + sins.x * sins.y * sins.z;
quat.x = sins.x * coss.y * coss.z + coss.x * sins.y * sins.z;
quat.y = coss.x * sins.y * coss.z - sins.x * coss.y * sins.z;
quat.z = coss.x * coss.y * sins.z - sins.x * sins.y * coss.z;
return quat;
}
示例9: shortestArcQuat
import javax.vecmath.Quat4f; //导入依赖的package包/类
public static Quat4f shortestArcQuat(Vector3f v0, Vector3f v1, Quat4f out) {
Vector3f c = Stack.alloc(Vector3f.class);
c.cross(v0, v1);
float d = v0.dot(v1);
if (d < -1.0 + BulletGlobals.FLT_EPSILON) {
// just pick any vector
out.set(0.0f, 1.0f, 0.0f, 0.0f);
return out;
}
float s = (float) Math.sqrt((1.0f + d) * 2.0f);
float rs = 1.0f / s;
out.set(c.x * rs, c.y * rs, c.z * rs, s * 0.5f);
return out;
}
示例10: setRotation
import javax.vecmath.Quat4f; //导入依赖的package包/类
public static void setRotation(Matrix3f dest, Quat4f q) {
float d = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
assert (d != 0f);
float s = 2f / d;
float xs = q.x * s, ys = q.y * s, zs = q.z * s;
float wx = q.w * xs, wy = q.w * ys, wz = q.w * zs;
float xx = q.x * xs, xy = q.x * ys, xz = q.x * zs;
float yy = q.y * ys, yz = q.y * zs, zz = q.z * zs;
dest.m00 = 1f - (yy + zz);
dest.m01 = xy - wz;
dest.m02 = xz + wy;
dest.m10 = xy + wz;
dest.m11 = 1f - (xx + zz);
dest.m12 = yz - wx;
dest.m20 = xz - wy;
dest.m21 = yz + wx;
dest.m22 = 1f - (xx + yy);
}
示例11: init
import javax.vecmath.Quat4f; //导入依赖的package包/类
@Override
public void init() {
Engine.scene.sun.direction = vec3(0.0f, -1.0f, 0.0f);
Engine.scene.sun.color = vec3(1.2f, 1.2f, 1.2f);
loadTexture("stone_tile.png", false, true);
loadTexture("stone_tile_normal.png");
loadTexture("stone_tile_specular.png");
loadTexture("planks.jpg", false, true);
loadTexture("planks_specular.jpg");
planeMesh = Mesh.raw(Primitives.plane(16.0f), true);
boxMesh = Mesh.raw(Primitives.cube(16.0f), true);
sphereMesh = ObjLoader.loadFile("sphere.obj");
Engine.scene.skybox = new Cubemap("sunset");
Engine.scene.irradiance = new Cubemap("sunset-irradiance");
Engine.scene.add(new PointLight(vec3(0.0f, 0.0f, 0.0f), vec3(1.0f, 1.0f, 1.0f), 0.42f, 0.2f));
Engine.scene.add(new MeshSphere(vec3(), new Quat4f(), new SphereShape(1.0f), 1f, sphereMesh, 1f, sphereMaterial));
Engine.scene.add(new MeshObject(vec3(0.0f, 5.0f, 0.0f), new Quat4f(), new BoxShape(new Vector3f(0.0f, 0.0f, 0.0f)), 0f, boxMesh, 1f, boxMaterial));
Engine.scene.add(new MeshObject(vec3(0.0f, -10f, 0.0f), new Quat4f(1.0f, 0.0f, 0.0f, 60.0f), new BoxShape(new Vector3f(50f, 0f, 50f)), 0f, planeMesh, 100f, groundMaterial));
}
示例12: update
import javax.vecmath.Quat4f; //导入依赖的package包/类
@Override
public void update() {
accum += Engine.deltaTime;
//spawns cubes and lights, test if accum is a certain length
if (Input.isButtonDown(1) && accum > 0.1f) {
Camera cam = Engine.camera;
MeshObject c = new MeshObject(cam.getPosition(), cam.front.multiply(30), new Quat4f(1.0f, 0.3f, 0.5f, 0f), new BoxShape(new Vector3f(0.5f, 0.5f, 0.5f)), 1f, cubeMesh, 1f, crateMaterial);
Engine.scene.add(c);
accum = 0;
}
if (Input.isButtonDown(2) && accum > 1f) {
PointLight p = new PointLight(Engine.camera.getPosition(), vec3(1.0f, 1.0f, 2.0f), 5f, 10f);
Engine.scene.add(p);
accum = 0;
}
}
示例13: render
import javax.vecmath.Quat4f; //导入依赖的package包/类
@Override
public void render(Scene scene, Camera cam) {
Shader s = getShader("pbr");
s.bind();
s.uniformMaterial(this.material);
Transform trans = new Transform();
Quat4f q = new Quat4f();
rb.getMotionState().getWorldTransform(trans);
trans.getRotation(q);
Matrix4f mat = new Matrix4f();
trans.getMatrix(mat);
s.uniformMat4("model", mat4(mat).scale(this.scale));
mesh.draw();
}
示例14: makeDomino
import javax.vecmath.Quat4f; //导入依赖的package包/类
public boolean makeDomino(float mass, Vector3f inertia, Vector3f loc,
float angle) {
if (cntCreated >= numDominoes)
return false;
int i = cntCreated++;
dominoOrigTransform[i] = new Transform(new Matrix4f(new Quat4f(0,
sin(angle) / (float) Math.sqrt(2), 0, 1), loc, 1.0f));
DefaultMotionState dominoMotion = new DefaultMotionState(
dominoOrigTransform[i]);
RigidBodyConstructionInfo dominoRigidBodyCI = new RigidBodyConstructionInfo(
mass, dominoMotion, dominoShape, inertia);
domino[i] = new RigidBody(dominoRigidBodyCI);
domino[i].setRestitution(0.5f);
world.addRigidBody(domino[i]);
return true;
}
示例15: yrp2q
import javax.vecmath.Quat4f; //导入依赖的package包/类
private Quat4f yrp2q(float roll, float pitch, float yaw) {
float halfYaw = yaw * 0.5f;
float halfPitch = pitch * 0.5f;
float halfRoll = roll * 0.5f;
float cosYaw = (float) cos(halfYaw);
float sinYaw = (float) sin(halfYaw);
float cosPitch = (float) cos(halfPitch);
float sinPitch = (float) sin(halfPitch);
float cosRoll = (float) cos(halfRoll);
float sinRoll = (float) sin(halfRoll);
return new Quat4f(sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw, //x
cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw, //y
cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw, //z
cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw); //formerly yzx
}