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

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

Introduction

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

Prototype

@Override
    public float dot(final Vector3 vector) 

Source Link

Usage

From source file:com.badlogic.gdx.physics.bullet.demo.BulletDemoMath.java

public static float angle(Vector3 first, Vector3 second) {
    double vDot = first.dot(second) / (first.len() * second.len());

    if (vDot < -1.0) {
        vDot = -1.0;//from  ww  w.j  ava  2 s .co  m
    }

    if (vDot > 1.0) {
        vDot = 1.0;
    }
    return ((float) (Math.acos(vDot)));
}

From source file:com.cyphercove.doublehelix.Particle.java

License:Apache License

float distanceToAxis(Vector3 point, Vector3 pointOnAxis, Vector3 axisDirection) {
    TMPV.set(point).sub(pointOnAxis);/*from   w w w . j  a v a2  s.  c  o  m*/
    float c1 = TMPV.dot(axisDirection);
    float c2 = axisDirection.dot(axisDirection);
    TMPV.set(axisDirection).scl(c1 / c2).add(pointOnAxis);
    return TMPV.dst(point);
}

From source file:com.digitale.sim.Simulation.java

License:Open Source License

public static void Collide(float frameDuration, Ship object1, Actor object2) {
    // Calculate the difference between the two objects.
    Vector3 difference = object1.position.sub(object2.position);
    float distanceAtFrameEnd = difference.len();
    frameDuration = frameDuration * 100000;
    // Calculate the distance that a collision would occur at.
    float collisionDistance = (object1.SHIP_RADIUS / 2f) + (object2.INVADER_RADIUS / 2f);

    // Check of the objects are closer that the collision distance.
    if (distanceAtFrameEnd < collisionDistance) {
        // Move both objects back to the exact point of collision.
        float millisecondsAfterCollision = MoveBackToCollisionPoint(frameDuration, object1, object2,
                distanceAtFrameEnd, collisionDistance);
        if (Stardust3d.DEBUG)
            System.out.println(LOG_TAG + "milli after coll: " + millisecondsAfterCollision);
        // Calculate the normal of the collision plane.
        Vector3 normalPlane = difference;
        normalPlane.nor();/*from  w  w w  .  j  ava  2s.c om*/

        // Calculate the collision plane.
        Vector3 collisionPlane = new Vector3(-normalPlane.x, normalPlane.y, normalPlane.z);

        // Calculate prior velocities relative the the collision plane and normal.
        float n_vel1 = (normalPlane.dot(object1.heading));
        float c_vel1 = (collisionPlane.dot(object1.heading));
        float n_vel2 = (normalPlane.dot(object2.heading));
        float c_vel2 = (collisionPlane.dot(object2.heading));

        // Calculate the scaler velocities of each object after the collision.
        float n_vel1_after = ((n_vel1 * (object1.mass - object2.mass)) + (2 * object2.mass * n_vel2))
                / (object2.mass + object1.mass);
        float n_vel2_after = ((n_vel2 * (object2.mass - object1.mass)) + (2 * object1.mass * n_vel1))
                / (object2.mass + object1.mass);
        //float velObject2Tangent_After = c_vel2;
        //float velObject1Tangent_After = c_vel1;

        // Convert the scalers to vectors by multiplying by the normalised plane vectors.
        Vector3 vec_n_vel2_after = normalPlane.mul(n_vel2_after);
        Vector3 vec_c_vel2 = collisionPlane.mul(c_vel2);
        Vector3 vec_n_vel1_after = normalPlane.mul(n_vel1_after);
        Vector3 vec_c_vel1 = collisionPlane.mul(c_vel1);

        // Combine the vectors back into a single vector in world space.
        Vector3 vel1_after = vec_n_vel1_after.add(vec_c_vel1);
        Vector3 vel2_after = vec_n_vel2_after.add(vec_c_vel2);

        // Reapply the move-back from before the collision (using the post collision velocity)
        Vector3 object1AdjustedPositionAfterCollision = object1.position
                .add(vel1_after.mul(millisecondsAfterCollision));
        Vector3 object2AdjustedPositionAfterCollision = object2.position
                .add(vel2_after.mul(millisecondsAfterCollision));

        // Set the objects new positions and velocities.
        object1.position = (object1AdjustedPositionAfterCollision);
        object1.heading = vel1_after;
        object2.position = object2AdjustedPositionAfterCollision;
        object2.heading = vel2_after;
    }
}

From source file:com.lyeeedar.Roguelike3D.Game.Actor.AI_Enemy_VFFG.java

License:Open Source License

public double angle(Vector3 v1, Vector3 v2) {
    Vector3 referenceForward = v1;
    Vector3 referenceRight = up.tmp2().crs(referenceForward);
    Vector3 newDirection = v2;/*  w w w .ja v  a 2s.c  o m*/
    float angle = (float) Math.toDegrees(Math.acos(v1.dot(v2) / (v1.len() * v2.len())));
    float sign = (newDirection.dot(referenceRight) > 0.0f) ? 1.0f : -1.0f;
    float finalAngle = sign * angle;
    return finalAngle;
}

From source file:com.lyeeedar.Roguelike3D.Graphics.Lights.LightManager.java

License:Open Source License

private Color calculateLight(Vector3 l_vector, Color l_colour, float l_attenuation, float l_power,
        Vector3 n_dir) {
    float distance = l_vector.len();
    Vector3 l_dir = l_vector.cpy().div(distance);

    float NdotL = n_dir.dot(l_dir);
    float intensity = MathUtils.clamp(NdotL, 0.0f, 1.0f);

    float attenuation = 1.0f;
    if (l_attenuation != 0)
        attenuation /= (l_attenuation * distance + l_attenuation / 10 * distance * distance);

    return l_colour.mul(intensity).mul(l_power).mul(attenuation);
}

From source file:com.lyeeedar.Roguelike3D.Graphics.Models.Shapes.java

License:Open Source License

public static Vector3 orthoNormalize(Vector3 vec1, Vector3 vec2) {
    vec1.nor();//w  w w  .  j a  va  2 s.c om
    vec1.mul(vec2.dot(vec1));

    vec2.sub(vec1);

    vec2.nor();
    return vec2;
}

From source file:sound.paulscode.libraries.SourceJavaSound.java

License:Open Source License

/**
 * Calculates the panning for this source based on its position in relation to 
 * the listener.//  ww  w .ja  v a  2  s . co m
 */
public void calculatePan() {
    Vector3 side = listener.up.crs(listener.lookAt);
    side.nor();
    Vector3 deltaPosition = position.cpy().sub(listener.position);
    float x = deltaPosition.dot(side);
    float z = deltaPosition.dot(listener.lookAt);
    side = null;
    float angle = (float) Math.atan2(x, z);
    pan = (float) -Math.sin(angle);

    if (channel != null && channel.attachedSource == this && channelJavaSound != null) {
        if (attModel == SoundSystemConfig.ATTENUATION_NONE)
            channelJavaSound.setPan(0);
        else
            channelJavaSound.setPan(pan);
    }
}

From source file:sound.paulscode.libraries.SourceJavaSound.java

License:Open Source License

/**
 * Calculates the pitch for this source based on its position in relation to
 * the listener./* www  .j  ava2 s. com*/
 */
public void calculatePitch() {
    if (channel != null && channel.attachedSource == this && channelJavaSound != null) {
        // If not using Doppler effect, save some calculations:
        if (SoundSystemConfig.getDopplerFactor() == 0) {
            channelJavaSound.setPitch(pitch);
        } else {
            float SS = 343.3f;

            Vector3 SV = velocity;
            Vector3 LV = listener.velocity;
            float DV = SoundSystemConfig.getDopplerVelocity();
            float DF = SoundSystemConfig.getDopplerFactor();
            Vector3 SL = listener.position.cpy().sub(position);

            float vls = SL.dot(LV) / SL.len();
            float vss = SL.dot(SV) / SL.len();

            vss = min(vss, SS / DF);
            vls = min(vls, SS / DF);
            float newPitch = pitch * (SS * DV - DF * vls) / (SS * DV - DF * vss);

            if (newPitch < 0.5f)
                newPitch = 0.5f;
            else if (newPitch > 2.0f)
                newPitch = 2.0f;

            channelJavaSound.setPitch(newPitch);
        }
    }
}