Example usage for com.badlogic.gdx.math Vector3 Zero

List of usage examples for com.badlogic.gdx.math Vector3 Zero

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector3 Zero.

Prototype

Vector3 Zero

To view the source code for com.badlogic.gdx.math Vector3 Zero.

Click Source Link

Usage

From source file:com.badlogic.gdx.ai.tests.utils.bullet.BulletConstructor.java

License:Apache License

private void create(final Model model, final float mass, final btCollisionShape shape) {
    this.model = model;
    this.shape = shape;

    if (shape != null && mass >= 0) {
        // Calculate the local inertia, bodies with no mass are static
        Vector3 localInertia;/*  w w w  .java 2s  . com*/
        if (mass == 0)
            localInertia = Vector3.Zero;
        else {
            shape.calculateLocalInertia(mass, tmpV);
            localInertia = tmpV;
        }

        // For now just pass null as the motionstate, we'll add that to the body in the entity itself
        bodyInfo = new btRigidBodyConstructionInfo(mass, null, shape, localInertia);
    }
}

From source file:com.bladecoder.engine.model.Sprite3DRenderer.java

License:Apache License

/**
 * Generates the Shadow Map/*from  www  .j  a v  a 2s. c om*/
 */
private void genShadowMap() {
    updateViewport();

    shadowLight.begin(Vector3.Zero, currentSource.camera3d.direction);
    shadowBatch.begin(shadowLight.getCamera());
    shadowBatch.render(currentSource.modelInstance);
    shadowBatch.end();
    shadowLight.end();

    Gdx.graphics.getGL20().glViewport((int) VIEWPORT.x, (int) VIEWPORT.y, (int) VIEWPORT.width,
            (int) VIEWPORT.height);
}

From source file:com.mbrlabs.mundus.editor.tools.ScaleTool.java

License:Apache License

public ScaleTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
        ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) {
    super(projectManager, goPicker, handlePicker, batch, history);

    this.shapeRenderer = shapeRenderer;

    ModelBuilder modelBuilder = new ModelBuilder();
    Model xPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_X)),
            Vector3.Zero, new Vector3(15, 0, 0));
    Model yPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Y)),
            Vector3.Zero, new Vector3(0, 15, 0));
    Model zPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Z)),
            Vector3.Zero, new Vector3(0, 0, 15));
    Model xyzPlaneHandleModel = modelBuilder.createBox(3, 3, 3,
            new Material(ColorAttribute.createDiffuse(COLOR_XYZ)),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);

    xHandle = new ScaleHandle(X_HANDLE_ID, xPlaneHandleModel);
    yHandle = new ScaleHandle(Y_HANDLE_ID, yPlaneHandleModel);
    zHandle = new ScaleHandle(Z_HANDLE_ID, zPlaneHandleModel);
    xyzHandle = new ScaleHandle(XYZ_HANDLE_ID, xyzPlaneHandleModel);

    handles = new ScaleHandle[] { xHandle, yHandle, zHandle, xyzHandle };
}

From source file:com.mbrlabs.mundus.tools.ScaleTool.java

License:Apache License

public ScaleTool(ProjectManager projectManager, GameObjectPicker goPicker, ToolHandlePicker handlePicker,
        Shader shader, ShapeRenderer shapeRenderer, ModelBatch batch, CommandHistory history) {
    super(projectManager, goPicker, handlePicker, shader, batch, history);

    this.shapeRenderer = shapeRenderer;
    this.projectContext = projectManager.current();

    ModelBuilder modelBuilder = new ModelBuilder();

    Model xPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_X)),
            Vector3.Zero, new Vector3(15, 0, 0));
    Model yPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Y)),
            Vector3.Zero, new Vector3(0, 15, 0));
    Model zPlaneHandleModel = UsefulMeshs.createArrowStub(new Material(ColorAttribute.createDiffuse(COLOR_Z)),
            Vector3.Zero, new Vector3(0, 0, 15));
    Model xyzPlaneHandleModel = modelBuilder.createBox(3, 3, 3,
            new Material(ColorAttribute.createDiffuse(COLOR_XYZ)),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);

    xHandle = new ScaleHandle(X_HANDLE_ID, xPlaneHandleModel);
    yHandle = new ScaleHandle(Y_HANDLE_ID, yPlaneHandleModel);
    zHandle = new ScaleHandle(Z_HANDLE_ID, zPlaneHandleModel);
    xyzHandle = new ScaleHandle(XYZ_HANDLE_ID, xyzPlaneHandleModel);

    handles = new ScaleHandle[] { xHandle, yHandle, zHandle, xyzHandle };
}

From source file:com.mygdx.game.objects.HumanCharacter.java

License:Apache License

public void throwStick() {
    GameScreen.screen.engine.addEntity(stick);
    stick.body.setLinearVelocity(Vector3.Zero);
    stick.body.setAngularVelocity(Vector3.Zero);
    Vector3 rightHandPos = getBoneMidpointWorldPosition(HumanArmature.RIGHT_HAND.id, TMP_V1);
    stick.modelTransform.setToRotation(Vector3.Z, 90);
    stick.modelTransform.rotate(Constants.V3_UP, getOrientation() * MathUtils.radiansToDegrees);
    stick.modelTransform.setTranslation(rightHandPos);
    stick.body.setWorldTransform(stick.modelTransform);

    Vector3 humanDirection = getDirection(TMP_V1);
    TMP_Q.setFromAxis(TMP_V2.set(humanDirection).crs(Constants.V3_UP), STICK_THROW_ANGLE);
    Vector3 impulse = TMP_Q.transform(humanDirection).nor();
    impulse.scl(STICK_THROW_IMPULSE_SCL);
    stick.body.applyImpulse(impulse, TMP_V2.set(Constants.V3_UP).scl(0.005f));

    stick.hasLanded = false;//w  w w  .j av a  2s .c om

    hasStick = false;
}

From source file:com.mygdx.game.objects.Ragdoll.java

License:Apache License

/**
 * Enable or disable ragdoll control. During ragdoll control, the animation armature nodes follow
 * the simulation of the rigid bodies. Otherwise, the rigid bodies follow the armature nodes.
 *
 * @param setRagdollControl/*from  w  w  w  .ja v a 2 s .  c  om*/
 */
public void setRagdollControl(boolean setRagdollControl) {

    if (setRagdollControl) {

        updateBodiesToArmature();

        // Ragdoll follows animation currently, set it to use physics control.
        // Animations should be paused for this model.
        ragdollControl = true;

        // Get the current translation of the base collision shape (the capsule)
        capsuleTransform.getTranslation(capsuleTranslation);

        // Reset any rotation of the model caused by the motion state from the physics engine,
        // but keep the translation.
        modelInstance.transform = resetRotationTransform.idt().inv().setToTranslation(capsuleTranslation);

        // Set the velocities of the ragdoll collision shapes to be the same as the base shape.
        for (btRigidBody bodyPart : bodyPartMap.keys()) {
            bodyPart.setLinearVelocity(body.getLinearVelocity().scl(1, 0, 1));
            bodyPart.setAngularVelocity(body.getAngularVelocity());
            bodyPart.setGravity(GameSettings.GRAVITY);
        }

        // We don't want to use the translation, rotation, scale values of the model when calculating the
        // model transform, and we don't want the nodes inherit the transform of the parent node,
        // since the physics engine will be controlling the nodes.
        for (Node node : ragdollMappedNodes) {
            node.isAnimated = true;
            node.inheritTransform = false;
        }

    } else {
        // Ragdoll physics control is enabled, disable it, reset nodes and ragdoll components to animation.
        ragdollControl = false;

        modelInstance.transform = motionState.transform;

        // Reset the nodes to default model animation state.
        for (Node node : ragdollMappedNodes) {
            node.isAnimated = false;
            node.inheritTransform = true;
        }
        modelInstance.calculateTransforms();

        // Disable gravity to prevent problems with the physics engine adding too much velocity
        // to the ragdoll
        for (btRigidBody bodyPart : bodyPartMap.keys()) {
            bodyPart.setGravity(Vector3.Zero);
        }
    }
}

From source file:com.mygdx.game.objects.SteerableBody.java

License:Apache License

/**
 * @param model            Model to instantiate
 * @param name               Name of model
 * @param location         World position at which to place the model instance
 * @param rotation         The rotation of the model instance in degrees
 * @param scale            Scale of the model instance
 * @param shape            Collision shape with which to construct a rigid body
 * @param mass             Mass of the body
 * @param belongsToFlag    Flag for which collision layers this body belongs to
 * @param collidesWithFlag Flag for which collision layers this body collides with
 * @param callback         If this body should trigger collision contact callbacks.
 * @param noDeactivate     If this body should never 'sleep'
 * @param steerSettings    Steerable settings
 *//*from  w w w.  ja  v  a  2  s .  c  o  m*/
public SteerableBody(Model model, String name, Vector3 location, Vector3 rotation, Vector3 scale,
        btCollisionShape shape, float mass, short belongsToFlag, short collidesWithFlag, boolean callback,
        boolean noDeactivate, SteerSettings steerSettings) {
    super(model, name, location, rotation, scale, shape, mass, belongsToFlag, collidesWithFlag, callback,
            noDeactivate);

    // Set the bounding radius used by steering behaviors like collision avoidance, 
    // raycast collision avoidance and some others. Note that calculation only takes
    // into account dimensions on the horizontal plane since we are steering in 2.5D
    this.boundingRadius = (boundingBox.getWidth() + boundingBox.getDepth()) / 4;

    this.steerSettings = steerSettings;
    setZeroLinearSpeedThreshold(steerSettings.getZeroLinearSpeedThreshold());

    // Don't allow physics engine to turn character around any axis.
    // This prevents it from gaining any angular velocity as a result of collisions, for instance.
    // Usually, you use angular factor Vector3.Y, which allows the engine to turn it only around
    // the up axis, but here we can use Vector3.Zero since we directly set linear and angular
    // velocity in applySteering() instead of using force and torque.
    // This gives us (almost?) total control over character's motion.
    // Of course, subclasses can specify different angular factor, if needed.
    body.setAngularFactor(Vector3.Zero);
}

From source file:com.mygdx.game.objects.SteerableBody.java

License:Apache License

/**
 * Stops steering; this restores normal friction so it cannot slide down most slopes.
 * Removes any angular velocity the body accumulated.
 * Sets the body to the orientation of the model.
 * @param clearLinearVelocity whether linear velocity should be cleared or not 
 *///from w w w.  ja  v a2 s  . c  o  m
protected void stopSteering(boolean clearLinearVelocity) {
    wasSteering = false;
    body.setFriction(steerSettings.getIdleFriction());
    body.setAngularVelocity(Vector3.Zero);
    // Since we were only rotating the model when steering, set body to
    // model rotation when finished moving.
    position = getPosition();
    modelTransform.setFromEulerAngles(currentOrientation.getYaw(), currentOrientation.getPitch(),
            currentOrientation.getRoll()).setTranslation(position);
    body.setWorldTransform(modelTransform);

    if (steerer != null) {
        clearLinearVelocity = steerer.stopSteering();
    }

    steerer = null;
    steeringOutput.setZero();
    if (clearLinearVelocity) {
        body.setLinearVelocity(Vector3.Zero);
    }
}

From source file:com.mygdx.game.utilities.ModelFactory.java

License:Apache License

public static Model buildCompassModel() {
    float compassScale = 5;
    ModelBuilder modelBuilder = new ModelBuilder();
    Model arrow = modelBuilder.createArrow(Vector3.Zero, Vector3.Y.cpy().scl(compassScale), null,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
    modelBuilder.begin();//from  w w w .  jav a2 s  . c om

    Mesh zArrow = arrow.meshes.first().copy(false);
    zArrow.transform(new Matrix4().rotate(Vector3.X, 90));
    modelBuilder.part("part1", zArrow, GL20.GL_TRIANGLES,
            new Material(ColorAttribute.createDiffuse(Color.BLUE)));

    modelBuilder.node();
    Mesh yArrow = arrow.meshes.first().copy(false);
    modelBuilder.part("part2", yArrow, GL20.GL_TRIANGLES,
            new Material(ColorAttribute.createDiffuse(Color.GREEN)));

    modelBuilder.node();
    Mesh xArrow = arrow.meshes.first().copy(false);
    xArrow.transform(new Matrix4().rotate(Vector3.Z, -90));
    modelBuilder.part("part3", xArrow, GL20.GL_TRIANGLES,
            new Material(ColorAttribute.createDiffuse(Color.RED)));

    arrow.dispose();
    return modelBuilder.end();
}

From source file:com.nsoft.boxuniverse.world.BaseBlock.java

License:Open Source License

@Override
public Vector3 getPosition() {
    return instance.transform.getTranslation(Vector3.Zero);
}