Search in sources :

Example 6 with Quat4f

use of javax.vecmath.Quat4f in project MorePlanets by SteveKunG.

the class ItemRendererTieredRocket method getTransformForPerspective.

@Override
protected Matrix4f getTransformForPerspective(TransformType type) {
    if (type == TransformType.GUI) {
        Vector3f trans = new Vector3f(-0.08F, 0.0F, -0.08F);
        Matrix4f ret = new Matrix4f();
        ret.setIdentity();
        Matrix4f mul = new Matrix4f();
        mul.setIdentity();
        mul.setScale(1.0F);
        ret.mul(mul);
        mul.setIdentity();
        mul.setTranslation(new Vector3f(0.225F, -0.1F, 0.0F));
        ret.mul(mul);
        mul.setIdentity();
        mul.rotY((float) (Math.PI / 2.5F));
        ret.mul(mul);
        mul.setIdentity();
        mul.rotX((float) (-Math.PI / 4.0F));
        ret.mul(mul);
        mul.setIdentity();
        mul.setTranslation(trans);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotY(ClientUtil.getMilliseconds() / 2000.0F);
        ret.mul(mul);
        mul.setIdentity();
        trans.scale(-1.0F);
        mul.setTranslation(trans);
        ret.mul(mul);
        mul.setIdentity();
        mul.setScale(0.145F);
        ret.mul(mul);
        return ret;
    }
    if (type == TransformType.FIRST_PERSON_RIGHT_HAND) {
        Vector3f trans = new Vector3f(0.5F, 3.2F, -3.6F);
        Matrix4f ret = new Matrix4f();
        ret.setIdentity();
        Matrix4f mul = new Matrix4f();
        mul.setIdentity();
        Quat4f rot = TRSRTransformation.quatFromXYZDegrees(new Vector3f(0, 45, 0));
        mul.setRotation(rot);
        ret.mul(mul);
        mul.setIdentity();
        mul.setScale(0.45F);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotX(Constants.halfPI);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotZ((float) (-0.65F + Math.PI));
        ret.mul(mul);
        mul.setIdentity();
        mul.setTranslation(trans);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotX((float) Math.PI);
        ret.mul(mul);
        return ret;
    }
    if (type == TransformType.FIRST_PERSON_LEFT_HAND) {
        Vector3f trans = new Vector3f(0.4F, 3.2F, -3.2F);
        Matrix4f ret = new Matrix4f();
        ret.setIdentity();
        Matrix4f mul = new Matrix4f();
        mul.setIdentity();
        Quat4f rot = TRSRTransformation.quatFromXYZDegrees(new Vector3f(0, 35, 0));
        mul.setRotation(rot);
        ret.mul(mul);
        mul.setIdentity();
        mul.setScale(0.45F);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotX(Constants.halfPI);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotZ((float) (-0.65F + Math.PI));
        ret.mul(mul);
        mul.setIdentity();
        mul.setTranslation(trans);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotX((float) Math.PI);
        ret.mul(mul);
        return ret;
    }
    if (type == TransformType.THIRD_PERSON_RIGHT_HAND) {
        Vector3f trans = new Vector3f(1.0F, -2.4F, 1.2F);
        Matrix4f ret = new Matrix4f();
        ret.setIdentity();
        Matrix4f mul = new Matrix4f();
        mul.setIdentity();
        Quat4f rot = TRSRTransformation.quatFromXYZDegrees(new Vector3f(75, 15, 0));
        mul.setRotation(rot);
        ret.mul(mul);
        mul.setIdentity();
        mul.setScale(0.6F);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotX((float) (Math.PI / 3.0F));
        ret.mul(mul);
        mul.setIdentity();
        mul.rotZ((float) (-Math.PI / 2.0F));
        ret.mul(mul);
        mul.setIdentity();
        mul.rotX(0.3F);
        ret.mul(mul);
        mul.setIdentity();
        mul.setTranslation(trans);
        ret.mul(mul);
        return ret;
    }
    if (type == TransformType.THIRD_PERSON_LEFT_HAND) {
        Vector3f trans = new Vector3f(0.1F, -2.4F, 1.2F);
        Matrix4f ret = new Matrix4f();
        ret.setIdentity();
        Matrix4f mul = new Matrix4f();
        mul.setIdentity();
        Quat4f rot = TRSRTransformation.quatFromXYZDegrees(new Vector3f(75, 15, 0));
        mul.setRotation(rot);
        ret.mul(mul);
        mul.setIdentity();
        mul.setScale(0.6F);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotX((float) (Math.PI / 3.0F));
        ret.mul(mul);
        mul.setIdentity();
        mul.rotZ((float) (-Math.PI / 2.0F));
        ret.mul(mul);
        mul.setIdentity();
        mul.rotX(0.3F);
        ret.mul(mul);
        mul.setIdentity();
        mul.setTranslation(trans);
        ret.mul(mul);
        return ret;
    }
    if (type == TransformType.GROUND) {
        Matrix4f ret = new Matrix4f();
        ret.setIdentity();
        Matrix4f mul = new Matrix4f();
        mul.setIdentity();
        mul.setScale(0.135F);
        ret.mul(mul);
        mul.setIdentity();
        mul.setTranslation(new Vector3f(0.5F, 1.5F, 0.5F));
        ret.mul(mul);
        return ret;
    }
    if (type == TransformType.FIXED) {
        Matrix4f ret = new Matrix4f();
        ret.setIdentity();
        Matrix4f mul = new Matrix4f();
        mul.setIdentity();
        mul.setScale(0.135F);
        ret.mul(mul);
        mul.setIdentity();
        mul.rotY(3.1F);
        ret.mul(mul);
        mul.setIdentity();
        mul.setTranslation(new Vector3f(0.5F, -1.5F, 0.5F));
        ret.mul(mul);
        return ret;
    }
    return null;
}
Also used : Matrix4f(javax.vecmath.Matrix4f) Vector3f(javax.vecmath.Vector3f) Quat4f(javax.vecmath.Quat4f)

Example 7 with Quat4f

use of javax.vecmath.Quat4f in project bdx by GoranM.

the class ConeTwistConstraint method buildJacobian.

@Override
public void buildJacobian() {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    Vector3f tmp1 = stack.allocVector3f();
    Vector3f tmp2 = stack.allocVector3f();
    Transform tmpTrans = stack.allocTransform();
    appliedImpulse = 0f;
    // set bias, sign, clear accumulator
    swingCorrection = 0f;
    twistLimitSign = 0f;
    solveTwistLimit = false;
    solveSwingLimit = false;
    accTwistLimitImpulse = 0f;
    accSwingLimitImpulse = 0f;
    if (!angularOnly) {
        Vector3f pivotAInW = stack.alloc(rbAFrame.origin);
        rbA.getCenterOfMassTransform(tmpTrans).transform(pivotAInW);
        Vector3f pivotBInW = stack.alloc(rbBFrame.origin);
        rbB.getCenterOfMassTransform(tmpTrans).transform(pivotBInW);
        Vector3f relPos = stack.allocVector3f();
        relPos.sub(pivotBInW, pivotAInW);
        // TODO: stack
        Vector3f[] normal = /*[3]*/
        new Vector3f[] { stack.allocVector3f(), stack.allocVector3f(), stack.allocVector3f() };
        if (relPos.lengthSquared() > BulletGlobals.FLT_EPSILON) {
            normal[0].normalize(relPos);
        } else {
            normal[0].set(1f, 0f, 0f);
        }
        TransformUtil.planeSpace1(normal[0], normal[1], normal[2]);
        for (int i = 0; i < 3; i++) {
            Matrix3f mat1 = rbA.getCenterOfMassTransform(stack.allocTransform()).basis;
            mat1.transpose();
            Matrix3f mat2 = rbB.getCenterOfMassTransform(stack.allocTransform()).basis;
            mat2.transpose();
            tmp1.sub(pivotAInW, rbA.getCenterOfMassPosition(tmp));
            tmp2.sub(pivotBInW, rbB.getCenterOfMassPosition(tmp));
            jac[i].init(mat1, mat2, tmp1, tmp2, normal[i], rbA.getInvInertiaDiagLocal(stack.allocVector3f()), rbA.getInvMass(), rbB.getInvInertiaDiagLocal(stack.allocVector3f()), rbB.getInvMass());
        }
    }
    Vector3f b1Axis1 = stack.allocVector3f(), b1Axis2 = stack.allocVector3f(), b1Axis3 = stack.allocVector3f();
    Vector3f b2Axis1 = stack.allocVector3f(), b2Axis2 = stack.allocVector3f();
    rbAFrame.basis.getColumn(0, b1Axis1);
    getRigidBodyA().getCenterOfMassTransform(tmpTrans).basis.transform(b1Axis1);
    rbBFrame.basis.getColumn(0, b2Axis1);
    getRigidBodyB().getCenterOfMassTransform(tmpTrans).basis.transform(b2Axis1);
    float swing1 = 0f, swing2 = 0f;
    float swx = 0f, swy = 0f;
    float thresh = 10f;
    float fact;
    // Get Frame into world space
    if (swingSpan1 >= 0.05f) {
        rbAFrame.basis.getColumn(1, b1Axis2);
        getRigidBodyA().getCenterOfMassTransform(tmpTrans).basis.transform(b1Axis2);
        //			swing1 = ScalarUtil.atan2Fast(b2Axis1.dot(b1Axis2), b2Axis1.dot(b1Axis1));
        swx = b2Axis1.dot(b1Axis1);
        swy = b2Axis1.dot(b1Axis2);
        swing1 = ScalarUtil.atan2Fast(swy, swx);
        fact = (swy * swy + swx * swx) * thresh * thresh;
        fact = fact / (fact + 1f);
        swing1 *= fact;
    }
    if (swingSpan2 >= 0.05f) {
        rbAFrame.basis.getColumn(2, b1Axis3);
        getRigidBodyA().getCenterOfMassTransform(tmpTrans).basis.transform(b1Axis3);
        //			swing2 = ScalarUtil.atan2Fast(b2Axis1.dot(b1Axis3), b2Axis1.dot(b1Axis1));
        swx = b2Axis1.dot(b1Axis1);
        swy = b2Axis1.dot(b1Axis3);
        swing2 = ScalarUtil.atan2Fast(swy, swx);
        fact = (swy * swy + swx * swx) * thresh * thresh;
        fact = fact / (fact + 1f);
        swing2 *= fact;
    }
    float RMaxAngle1Sq = 1.0f / (swingSpan1 * swingSpan1);
    float RMaxAngle2Sq = 1.0f / (swingSpan2 * swingSpan2);
    float EllipseAngle = Math.abs(swing1 * swing1) * RMaxAngle1Sq + Math.abs(swing2 * swing2) * RMaxAngle2Sq;
    if (EllipseAngle > 1.0f) {
        swingCorrection = EllipseAngle - 1.0f;
        solveSwingLimit = true;
        // Calculate necessary axis & factors
        tmp1.scale(b2Axis1.dot(b1Axis2), b1Axis2);
        tmp2.scale(b2Axis1.dot(b1Axis3), b1Axis3);
        tmp.add(tmp1, tmp2);
        swingAxis.cross(b2Axis1, tmp);
        swingAxis.normalize();
        float swingAxisSign = (b2Axis1.dot(b1Axis1) >= 0.0f) ? 1.0f : -1.0f;
        swingAxis.scale(swingAxisSign);
        kSwing = 1f / (getRigidBodyA().computeAngularImpulseDenominator(swingAxis) + getRigidBodyB().computeAngularImpulseDenominator(swingAxis));
    }
    // Twist limits
    if (twistSpan >= 0f) {
        //Vector3f b2Axis2 = stack.allocVector3f();
        rbBFrame.basis.getColumn(1, b2Axis2);
        getRigidBodyB().getCenterOfMassTransform(tmpTrans).basis.transform(b2Axis2);
        Quat4f rotationArc = QuaternionUtil.shortestArcQuat(b2Axis1, b1Axis1, stack.allocQuat4f());
        Vector3f TwistRef = QuaternionUtil.quatRotate(rotationArc, b2Axis2, stack.allocVector3f());
        float twist = ScalarUtil.atan2Fast(TwistRef.dot(b1Axis3), TwistRef.dot(b1Axis2));
        float lockedFreeFactor = (twistSpan > 0.05f) ? limitSoftness : 0f;
        if (twist <= -twistSpan * lockedFreeFactor) {
            twistCorrection = -(twist + twistSpan);
            solveTwistLimit = true;
            twistAxis.add(b2Axis1, b1Axis1);
            twistAxis.scale(0.5f);
            twistAxis.normalize();
            twistAxis.scale(-1.0f);
            kTwist = 1f / (getRigidBodyA().computeAngularImpulseDenominator(twistAxis) + getRigidBodyB().computeAngularImpulseDenominator(twistAxis));
        } else if (twist > twistSpan * lockedFreeFactor) {
            twistCorrection = (twist - twistSpan);
            solveTwistLimit = true;
            twistAxis.add(b2Axis1, b1Axis1);
            twistAxis.scale(0.5f);
            twistAxis.normalize();
            kTwist = 1f / (getRigidBodyA().computeAngularImpulseDenominator(twistAxis) + getRigidBodyB().computeAngularImpulseDenominator(twistAxis));
        }
    }
    stack.leave();
}
Also used : Matrix3f(javax.vecmath.Matrix3f) Vector3f(javax.vecmath.Vector3f) Transform(com.bulletphysics.linearmath.Transform) Quat4f(javax.vecmath.Quat4f) Stack(com.bulletphysics.util.Stack)

Example 8 with Quat4f

use of javax.vecmath.Quat4f in project bdx by GoranM.

the class Stack method allocQuat4f.

public Quat4f allocQuat4f() {
    types[sp++] = TYPE_QUAT4F;
    int pos = stackPositions[TYPE_QUAT4F]++;
    if (quat4fStack.size() <= pos) {
        quat4fStack.add(new Quat4f());
    }
    return quat4fStack.get(pos);
}
Also used : Quat4f(javax.vecmath.Quat4f)

Example 9 with Quat4f

use of javax.vecmath.Quat4f in project bdx by GoranM.

the class Stack method alloc.

public Quat4f alloc(Quat4f rotation) {
    Quat4f q = allocQuat4f();
    q.set(rotation);
    return q;
}
Also used : Quat4f(javax.vecmath.Quat4f)

Example 10 with Quat4f

use of javax.vecmath.Quat4f in project MinecraftForge by MinecraftForge.

the class ModelDynBucket method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap<TransformType, TRSRTransformation> transformMap = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
    // if the fluid is a gas wi manipulate the initial state to be rotated 180° to turn it upside down
    if (flipGas && fluid != null && fluid.isGaseous()) {
        state = new ModelStateComposition(state, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(null, new Quat4f(0, 0, 1, 0), null, null)));
    }
    TRSRTransformation transform = state.apply(Optional.<IModelPart>absent()).or(TRSRTransformation.identity());
    TextureAtlasSprite fluidSprite = null;
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    if (fluid != null) {
        fluidSprite = bakedTextureGetter.apply(fluid.getStill());
    }
    if (baseLocation != null) {
        // build base (insidest)
        IBakedModel model = (new ItemLayerModel(ImmutableList.of(baseLocation))).bake(state, format, bakedTextureGetter);
        builder.addAll(model.getQuads(null, null, 0));
    }
    if (liquidLocation != null && fluidSprite != null) {
        TextureAtlasSprite liquid = bakedTextureGetter.apply(liquidLocation);
        // build liquid layer (inside)
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, NORTH_Z_FLUID, EnumFacing.NORTH, fluid.getColor()));
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, SOUTH_Z_FLUID, EnumFacing.SOUTH, fluid.getColor()));
    }
    if (coverLocation != null) {
        // cover (the actual item around the other two)
        TextureAtlasSprite base = bakedTextureGetter.apply(coverLocation);
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, NORTH_Z_BASE, base, EnumFacing.NORTH, 0xffffffff));
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, SOUTH_Z_BASE, base, EnumFacing.SOUTH, 0xffffffff));
    }
    return new BakedDynBucket(this, builder.build(), fluidSprite, format, Maps.immutableEnumMap(transformMap), Maps.<String, IBakedModel>newHashMap());
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ImmutableList(com.google.common.collect.ImmutableList) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType) IModelPart(net.minecraftforge.common.model.IModelPart) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Quat4f(javax.vecmath.Quat4f) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Aggregations

Quat4f (javax.vecmath.Quat4f)15 Stack (com.bulletphysics.util.Stack)5 Matrix3f (javax.vecmath.Matrix3f)5 Vector3f (javax.vecmath.Vector3f)5 Transform (com.bulletphysics.linearmath.Transform)1 StaticAlloc (com.bulletphysics.util.StaticAlloc)1 ImmutableList (com.google.common.collect.ImmutableList)1 Matrix4f (javax.vecmath.Matrix4f)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)1 ItemOverride (net.minecraft.client.renderer.block.model.ItemOverride)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 IModelPart (net.minecraftforge.common.model.IModelPart)1 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)1