Java 类javax.vecmath.Quat4f 实例源码
项目:OpenGL-Bullet-engine
文件:EntityCrazyCube.java
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);
}
项目:CustomWorldGen
文件:ForgeBlockStateV1.java
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);
}
项目:CustomWorldGen
文件:TRSRTransformation.java
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;
}
项目:Analyst
文件:CompositeModel.java
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);
}
}
项目:Analyst
文件:CompositeModel.java
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;
}
项目:Analyst
文件:Composite.java
/**
* 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);
}
}
}
项目:SignPicture
文件:CustomTileEntitySignRenderer.java
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);
}
}
项目:CraftStudioAPI
文件:MathHelper.java
/**
* 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;
}
项目:Null-Engine
文件:QuaternionUtil.java
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;
}
项目:Null-Engine
文件:MatrixUtil.java
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);
}
项目:Point-Engine
文件:KDemo.java
@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));
}
项目:Point-Engine
文件:GLDemo.java
@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;
}
}
项目:Point-Engine
文件:MeshObject.java
@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();
}
项目:JACWfA
文件:Domino.java
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;
}
项目:rct-java
文件:Cross_lib_provider.java
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
}
项目:form-follows-function
文件:MovingConcaveDemo.java
public void shootTrimesh(Vector3f destination) {
if (dynamicsWorld != null) {
float mass = 4f;
Transform startTransform = new Transform();
startTransform.setIdentity();
Vector3f camPos = getCameraPosition();
startTransform.origin.set(camPos);
RigidBody body = localCreateRigidBody(mass, startTransform, trimeshShape);
Vector3f linVel = new Vector3f(destination.x - camPos.x, destination.y - camPos.y, destination.z - camPos.z);
linVel.normalize();
linVel.scale(ShootBoxInitialSpeed * 0.25f);
Transform tr = new Transform();
tr.origin.set(camPos);
tr.setRotation(new Quat4f(0f, 0f, 0f, 1f));
body.setWorldTransform(tr);
body.setLinearVelocity(linVel);
body.setAngularVelocity(new Vector3f(0f, 0f, 0f));
}
}
项目:form-follows-function
文件:QuaternionUtil.java
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;
}
项目:form-follows-function
文件:MatrixUtil.java
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);
}
项目:form-follows-function
文件:MovingConcaveDemo.java
public void shootTrimesh(Vector3f destination) {
if (dynamicsWorld != null) {
float mass = 4f;
Transform startTransform = new Transform();
startTransform.setIdentity();
Vector3f camPos = getCameraPosition();
startTransform.origin.set(camPos);
RigidBody body = localCreateRigidBody(mass, startTransform, trimeshShape);
Vector3f linVel = new Vector3f(destination.x - camPos.x, destination.y - camPos.y, destination.z - camPos.z);
linVel.normalize();
linVel.scale(ShootBoxInitialSpeed * 0.25f);
Transform tr = new Transform();
tr.origin.set(camPos);
tr.setRotation(new Quat4f(0f, 0f, 0f, 1f));
body.setWorldTransform(tr);
body.setLinearVelocity(linVel);
body.setAngularVelocity(new Vector3f(0f, 0f, 0f));
}
}
项目:form-follows-function
文件:QuaternionUtil.java
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;
}
项目:form-follows-function
文件:MatrixUtil.java
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);
}
项目:Hard-Science
文件:QuadHelper.java
/**
* Builds the appropriate quaternion to rotate around the given orthogonalAxis.
*/
public static Quat4f rotationForAxis(EnumFacing.Axis axis, double degrees)
{
Quat4f retVal = new Quat4f();
switch (axis) {
case X:
retVal.set(new AxisAngle4d(1, 0, 0, Math.toRadians(degrees)));
break;
case Y:
retVal.set(new AxisAngle4d(0, 1, 0, Math.toRadians(degrees)));
break;
case Z:
retVal.set(new AxisAngle4d(0, 0, 1, Math.toRadians(degrees)));
break;
}
return retVal;
}
项目:MCAnm
文件:Utils.java
/**
* Takes a {@link Quaternion} and a {@link Vector3f} as input and returns a {@link Matrix4f} that represents the
* rotation-translation of the passed in arguments.<br>
* This handles null values as follows:<br>
* - if rotation is <code>null</code> the upper left 3x3 matrix will be the identity matrix - if translation is
* <code>null</code> the third column will be the identity vector
*
*/
public static Matrix4f fromRTS(Quat4f rotation, Vector3f offset, Vector3f scale, Matrix4f out) {
fromRTS(rotation, offset, 1.0f, out);
float sX = scale.x, sY = scale.y, sZ = scale.z;
out.m00 *= sX;
out.m01 *= sX;
out.m02 *= sX;
out.m10 *= sY;
out.m11 *= sY;
out.m12 *= sY;
out.m20 *= sZ;
out.m21 *= sZ;
out.m22 *= sZ;
return out;
}
项目:Wicken
文件:PhysicsSystem.java
public static Transform createTransform(Vector3f position, Quaternion rotation) {
if (position == null) {
position = new Vector3f(0);
}
if (rotation == null) {
rotation = new Quaternion(new Matrix4f().initIdentity());
}
Transform transform = new Transform();
transform.origin.set(position.getX(), position.getY(), position.getZ());
transform.basis.set(new Quat4f(rotation.getX(),rotation.getY(),rotation.getZ(),rotation.getW()));
return transform;
}
项目:swg-old
文件:TestClass.java
public static double staticMethod1(Quat4f q) {
double angle;
float dirW = q.w;
if (q.w * q.w + q.y * q.y > 0.0f) {
if (q.w > 0.f && q.y < 0.0f)
dirW *= -1.0f;
angle = 2.0f * Math.acos(dirW);
} else {
angle = 0.0f;
}
return angle / 6.283f * 100.f;
}
项目:breakout
文件:CameraPosition.java
public void move( float right , float up , float back )
{
q1.conjugate( orientation );
Quat4f qright = new Quat4f( 1 , 0 , 0 , 0 );
Quat4f qup = new Quat4f( 0 , 1 , 0 , 0 );
Quat4f qback = new Quat4f( 0 , 0 , 1 , 0 );
qright.mul( q1 );
qright.mul( orientation , qright );
qup.mul( q1 );
qup.mul( orientation , qup );
qback.mul( q1 );
qback.mul( orientation , qback );
position.x += qright.x * right + qup.x * up + qback.x * back;
position.y += qright.y * right + qup.y * up + qback.y * back;
position.z += qright.z * right + qup.z * up + qback.z * back;
}
项目:pre-cu
文件:TestClass.java
public static double staticMethod1(Quat4f q) {
double angle;
float dirW = q.w;
if (q.w * q.w + q.y * q.y > 0.0f) {
if (q.w > 0.f && q.y < 0.0f)
dirW *= -1.0f;
angle = 2.0f * Math.acos(dirW);
} else {
angle = 0.0f;
}
return angle / 6.283f * 100.f;
}
项目:jglrEngine
文件:PhysicsComponent.java
public void update(double delta)
{
Transform out = new Transform();
out = body.getWorldTransform(out);
Quat4f rot = new Quat4f(0, 0, 0, 1);
rot = out.getRotation(rot);
Quaternion newRot = PhysicsEngine.toJGE(rot);
Vector3 physicalPos = PhysicsEngine.toJGE(out.origin);
org.jge.maths.Transform parentTransform = getParent().getTransform().getParent();
if(parentTransform != null)
{
Vector3 parentPos = parentTransform.getTransformedPos();
physicalPos = physicalPos.sub(parentPos);
physicalPos = physicalPos.rotate(parentTransform.getTransformedRotation().conjugate());
newRot = newRot.mul(parentTransform.getTransformedRotation().conjugate());
}
this.getParent().getTransform().setPosition(physicalPos);
this.getParent().getTransform().setRotation(newRot);
}
项目:j3d-core
文件:RotPosScalePathInterpolator.java
/**
* Constructs a new RotPosScalePathInterpolator object that varies the
* rotation, translation, and scale of the target TransformGroup's
* transform.
* @param alpha the alpha object for this interpolator.
* @param target the TransformGroup node affected by this interpolator.
* @param axisOfTransform the transform that specifies the local
* coordinate system in which this interpolator operates.
* @param knots an array of knot values that specify interpolation points.
* @param quats an array of quaternion values at the knots.
* @param positions an array of position values at the knots.
* @param scales an array of scale component values at the knots.
* @exception IllegalArgumentException if the lengths of the
* knots, quats, positions, and scales arrays are not all the same.
*/
public RotPosScalePathInterpolator(Alpha alpha,
TransformGroup target,
Transform3D axisOfTransform,
float[] knots,
Quat4f[] quats,
Point3f[] positions,
float[] scales) {
super(alpha, target, axisOfTransform, knots);
if (knots.length != quats.length)
throw new IllegalArgumentException(J3dI18N.getString("RotPosScalePathInterpolator1"));
if (knots.length != positions.length)
throw new IllegalArgumentException(J3dI18N.getString("RotPosScalePathInterpolator0"));
if (knots.length != scales.length)
throw new IllegalArgumentException(J3dI18N.getString("RotPosScalePathInterpolator2"));
setPathArrays(quats, positions, scales);
}
项目:j3d-core
文件:RotPosScalePathInterpolator.java
/**
* Replaces the existing arrays of knot values, quaternion
* values, position values, and scale values with the specified arrays.
* The arrays of knots, quats, positions, and scales are copied
* into this interpolator object.
* @param knots a new array of knot values that specify
* interpolation points.
* @param quats a new array of quaternion values at the knots.
* @param positions a new array of position values at the knots.
* @param scales a new array of scale component values at the knots.
* @exception IllegalArgumentException if the lengths of the
* knots, quats, positions, and scales arrays are not all the same.
*
* @since Java 3D 1.2
*/
public void setPathArrays(float[] knots,
Quat4f[] quats,
Point3f[] positions,
float[] scales) {
if (knots.length != quats.length)
throw new IllegalArgumentException(J3dI18N.getString("RotPosScalePathInterpolator1"));
if (knots.length != positions.length)
throw new IllegalArgumentException(J3dI18N.getString("RotPosScalePathInterpolator0"));
if (knots.length != scales.length)
throw new IllegalArgumentException(J3dI18N.getString("RotPosScalePathInterpolator2"));
setKnots(knots);
setPathArrays(quats, positions, scales);
}
项目:j3d-core
文件:RotPosScalePathInterpolator.java
private void setPathArrays(Quat4f[] quats,
Point3f[] positions,
float[] scales) {
this.quats = new Quat4f[quats.length];
for(int i = 0; i < quats.length; i++) {
this.quats[i] = new Quat4f();
this.quats[i].set(quats[i]);
}
this.positions = new Point3f[positions.length];
for(int i = 0; i < positions.length; i++) {
this.positions[i] = new Point3f();
this.positions[i].set(positions[i]);
}
this.scales = new float[scales.length];
for(int i = 0; i < scales.length; i++) {
this.scales[i] = scales[i];
}
}
项目:j3d-core
文件:RotPosPathInterpolator.java
/**
* Constructs a new interpolator that varies the rotation and translation
* of the target TransformGroup's transform.
* @param alpha the alpha object for this interpolator
* @param target the TransformGroup node affected by this translator
* @param axisOfTransform the transform that defines the local coordinate
* system in which this interpolator operates
* @param knots an array of knot values that specify interpolation points.
* @param quats an array of quaternion values at the knots.
* @param positions an array of position values at the knots.
* @exception IllegalArgumentException if the lengths of the
* knots, quats, and positions arrays are not all the same.
*/
public RotPosPathInterpolator(Alpha alpha,
TransformGroup target,
Transform3D axisOfTransform,
float[] knots,
Quat4f[] quats,
Point3f[] positions) {
super(alpha, target, axisOfTransform, knots);
if (knots.length != positions.length)
throw new IllegalArgumentException(J3dI18N.getString("RotPosPathInterpolator0"));
if (knots.length != quats.length)
throw new IllegalArgumentException(J3dI18N.getString("RotPosPathInterpolator0"));
setPathArrays(quats, positions);
}
项目:j3d-core
文件:RotPosPathInterpolator.java
/**
* Copies all RotPosPathInterpolator information from
* <code>originalNode</code> into
* the current node. This method is called from the
* <code>cloneNode</code> method which is, in turn, called by the
* <code>cloneTree</code> method.<P>
*
* @param originalNode the original node to duplicate.
* @param forceDuplicate when set to <code>true</code>, causes the
* <code>duplicateOnCloneTree</code> flag to be ignored. When
* <code>false</code>, the value of each node's
* <code>duplicateOnCloneTree</code> variable determines whether
* NodeComponent data is duplicated or copied.
*
* @exception RestrictedAccessException if this object is part of a live
* or compiled scenegraph.
*
* @see Node#duplicateNode
* @see Node#cloneTree
* @see NodeComponent#setDuplicateOnCloneTree
*/
void duplicateAttributes(Node originalNode, boolean forceDuplicate) {
super.duplicateAttributes(originalNode, forceDuplicate);
RotPosPathInterpolator ri = (RotPosPathInterpolator) originalNode;
int len = ri.getArrayLengths();
// No API availble to set array size, so explicitly set it here
positions = new Point3f[len];
quats = new Quat4f[len];
Point3f point = new Point3f();
Quat4f quat = new Quat4f();
for (int i = 0; i < len; i++) {
positions[i] = new Point3f();
ri.getPosition(i, point);
setPosition(i, point);
quats[i] = new Quat4f();
ri.getQuat(i, quat);
setQuat(i, quat);
}
}
项目:Mineworld
文件:EntitySystemBuilder.java
private void registerTypeHandlers(ComponentLibrary library) {
library.registerTypeHandler(BlockFamily.class, new BlockFamilyTypeHandler());
library.registerTypeHandler(Color4f.class, new Color4fTypeHandler());
library.registerTypeHandler(Quat4f.class, new Quat4fTypeHandler());
library.registerTypeHandler(Mesh.class, new AssetTypeHandler(AssetType.MESH, Mesh.class));
library.registerTypeHandler(Sound.class, new AssetTypeHandler(AssetType.SOUND, Sound.class));
library.registerTypeHandler(Material.class, new AssetTypeHandler(AssetType.MATERIAL, Material.class));
library.registerTypeHandler(SkeletalMesh.class, new AssetTypeHandler(AssetType.SKELETON_MESH, SkeletalMesh.class));
library.registerTypeHandler(MeshAnimation.class, new AssetTypeHandler(AssetType.ANIMATION, MeshAnimation.class));
library.registerTypeHandler(Vector3f.class, new Vector3fTypeHandler());
library.registerTypeHandler(Vector2f.class, new Vector2fTypeHandler());
Vector3iTypeHandler vector3iHandler = new Vector3iTypeHandler();
library.registerTypeHandler(Vector3i.class, vector3iHandler);
library.registerTypeHandler(CollisionGroup.class, new CollisionGroupTypeHandler());
library.registerTypeHandler(Region3i.class, new Region3iTypeHandler(vector3iHandler));
}
项目:Mineworld
文件:SkeletonRenderer.java
private void updateSkeleton(SkeletalMeshComponent skeletalMeshComp, MeshAnimationFrame frameA, MeshAnimationFrame frameB, float interpolationVal) {
Vector3f newPos = new Vector3f();
Quat4f newRot = new Quat4f();
for (int i = 0; i < skeletalMeshComp.animation.getBoneCount(); ++i) {
EntityRef boneEntity = skeletalMeshComp.boneEntities.get(skeletalMeshComp.animation.getBoneName(i));
if (boneEntity == null) {
continue;
}
LocationComponent boneLoc = boneEntity.getComponent(LocationComponent.class);
if (boneLoc != null) {
newPos.interpolate(frameA.getPosition(i), frameB.getPosition(i), interpolationVal);
boneLoc.setLocalPosition(newPos);
newRot.interpolate(frameA.getRotation(i), frameB.getRotation(i), interpolationVal);
newRot.normalize();
boneLoc.setLocalRotation(newRot);
boneEntity.saveComponent(boneLoc);
}
}
}
项目:Mineworld
文件:SkeletonRenderer.java
private void renderBoneOrientation(EntityRef boneEntity) {
LocationComponent loc = boneEntity.getComponent(LocationComponent.class);
if (loc == null) {
return;
}
glPushMatrix();
Vector3f worldPosA = loc.getWorldPosition();
Quat4f worldRot = loc.getWorldRotation();
Vector3f offset = new Vector3f(0, 0, 0.1f);
QuaternionUtil.quatRotate(worldRot, offset, offset);
offset.add(worldPosA);
glBegin(GL11.GL_LINES);
glVertex3f(worldPosA.x, worldPosA.y, worldPosA.z);
glVertex3f(offset.x, offset.y, offset.z);
glEnd();
for (EntityRef child : loc.getChildren()) {
renderBoneOrientation(child);
}
glPopMatrix();
}
项目:Mineworld
文件:SkeletalMesh.java
public List<Vector3f> getVertexPositions(List<Vector3f> bonePositions, List<Quat4f> boneRotations) {
List<Vector3f> results = Lists.newArrayListWithCapacity(getVertexCount());
for (int i = 0; i < vertexStartWeights.size(); ++i) {
Vector3f vertexPos = new Vector3f();
for (int weightIndexOffset = 0; weightIndexOffset < vertexWeightCounts.get(i); ++weightIndexOffset) {
int weightIndex = vertexStartWeights.get(i) + weightIndexOffset;
BoneWeight weight = weights.get(weightIndex);
Vector3f current = QuaternionUtil.quatRotate(boneRotations.get(weight.getBoneIndex()), weight.getPosition(), new Vector3f());
current.add(bonePositions.get(weight.getBoneIndex()));
current.scale(weight.getBias());
vertexPos.add(current);
}
results.add(vertexPos);
}
return results;
}
项目:Mineworld
文件:SkeletalMesh.java
public List<Vector3f> getVertexNormals(List<Vector3f> bonePositions, List<Quat4f> boneRotations) {
List<Vector3f> results = Lists.newArrayListWithCapacity(getVertexCount());
for (int i = 0; i < vertexStartWeights.size(); ++i) {
Vector3f vertexNorm = new Vector3f();
for (int weightIndexOffset = 0; weightIndexOffset < vertexWeightCounts.get(i); ++weightIndexOffset) {
int weightIndex = vertexStartWeights.get(i) + weightIndexOffset;
BoneWeight weight = weights.get(weightIndex);
Vector3f current = QuaternionUtil.quatRotate(boneRotations.get(weight.getBoneIndex()), weight.getNormal(), new Vector3f());
current.scale(weight.getBias());
vertexNorm.add(current);
}
results.add(vertexNorm);
}
return results;
}
项目:Mineworld
文件:Commands.java
@Command(shortDescription = "Spawns an instance of a prefab in the world")
public void spawnPrefab(@CommandParam(name = "prefabId") String prefabName) {
Camera camera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
Vector3f spawnPos = camera.getPosition();
Vector3f offset = new Vector3f(camera.getViewingDirection());
offset.scale(2);
spawnPos.add(offset);
Vector3f dir = new Vector3f(camera.getViewingDirection());
dir.y = 0;
if (dir.lengthSquared() > 0.001f) {
dir.normalize();
} else {
dir.set(0, 0, 1);
}
Quat4f rotation = QuaternionUtil.shortestArcQuat(new Vector3f(0, 0, 1), dir, new Quat4f());
Prefab prefab = CoreRegistry.get(PrefabManager.class).getPrefab(prefabName);
if (prefab != null && prefab.getComponent(LocationComponent.class) != null) {
CoreRegistry.get(EntityManager.class).create(prefab, spawnPos, rotation);
}
}
项目:MikuMikuStudio
文件:VMDMotion.java
public final void readFromStream(DataInputStreamLittleEndian is) throws IOException {
boneName = is.readString(15);
boneIndex = -1;
// for(int i=0;i<vmdFile.boneNames.size();i++) {
// if (boneName.equals(vmdFile.boneNames.get(i))) {
// boneIndex = (short)i;
// break;
// }
// }
boneIndex = (short)vmdFile.boneNames.indexOf(boneName);
if (boneIndex < 0) {
vmdFile.boneNames.add(boneName);
// boneIndex = (short)(vmdFile.boneNames.size() - 1);
boneIndex = (short)vmdFile.boneNames.indexOf(boneName);
}
frameNo = is.readInt();
location = new Point3f();
location.x = is.readFloat();
location.y = is.readFloat();
location.z = -is.readFloat();
rotation = new Quat4f(is.readFloat(), is.readFloat(), -is.readFloat(), -is.readFloat());
int pos = 0;
while(pos < 64) {
pos += is.read(interpolation, pos, 64 - pos);
}
}