Java 类com.badlogic.gdx.math.collision.Sphere 实例源码

项目:gdx-toolbox    文件:IntersectionTester.java   
public static boolean test(Ray ray, Sphere sphere, Vector3 outFirstIntersection) {
    tmp1.set(ray.origin).sub(sphere.center);

    float b = tmp1.dot(ray.direction);
    float c = tmp1.dot(tmp1) - (sphere.radius * sphere.radius);

    if (c > 0.0f && b > 0.0f)
        return false;

    float discriminant = b * b - c;
    if (discriminant < 0.0f)
        return false;

    float t = -b - (float)Math.sqrt(discriminant);
    if (t < 0.0f)
        t = 0.0f;

    if (outFirstIntersection != null)
        ray.getEndPoint(outFirstIntersection, t);

    return true;
}
项目:gdx-cclibs    文件:SphereSerializer.java   
@Override
public void write(Kryo kryo, Output output, Sphere sphere) {
    Vector3 center = sphere.center;
    output.writeFloat(center.x);
    output.writeFloat(center.y);
    output.writeFloat(center.z);
    output.writeFloat(sphere.radius);
}
项目:gdx-cclibs    文件:SphereSerializer.java   
@Override
public Sphere read(Kryo kryo, Input input, Class<Sphere> type) {
    Vector3 center = new Vector3();
    center.x = input.readFloat();
    center.y = input.readFloat();
    center.z = input.readFloat();
    float radius = input.readFloat();
    return new Sphere(center, radius);
}
项目:gdx-cclibs    文件:MathTest.java   
public void testCollisionClasses (){
    Object[] objects = new Object[4];

    objects[0] = new BoundingBox(new Vector3(randFloat(), randFloat(), randFloat()), new Vector3(randFloat(), randFloat(), randFloat()));
    objects[1] = new Ray(new Vector3(randFloat(), randFloat(), randFloat()), new Vector3(randFloat(), randFloat(), randFloat()).nor());
    objects[2] = new Segment(randFloat(), randFloat(), randFloat(), randFloat(), randFloat(), randFloat());
    objects[3] = new Sphere(new Vector3(randFloat(), randFloat(), randFloat()), randFloat());

    simpleRoundTrip(objects);
}
项目:gdx-toolbox    文件:IntersectionTester.java   
public static boolean test(Sphere sphere, Vector3[] vertices, Vector3 outFirstIntersection) {
    for (int i = 0; i < vertices.length; ++i) {
        if (Math.abs(vertices[i].dst2(sphere.center)) < (sphere.radius * sphere.radius)) {
            if (outFirstIntersection != null)
                outFirstIntersection.set(vertices[i]);
            return true;
        }
    }
    return false;
}
项目:gdx-toolbox    文件:IntersectionTester.java   
public static boolean test(Sphere a, Sphere b) {
    tmp1.set(a.center).sub(b.center);
    float distanceSquared = tmp1.dot(tmp1);
    float radiusSum = a.radius + b.radius;
    if (distanceSquared <= (radiusSum * radiusSum))
        return true;
    else
        return false;
}
项目:gdx-toolbox    文件:IntersectionTester.java   
public static boolean test(Sphere sphere, Plane plane) {
    float distance = sphere.center.dot(plane.normal) - plane.d;
    if (Math.abs(distance) <= sphere.radius)
        return true;
    else
        return false;
}
项目:gdx-toolbox    文件:IntersectionTester.java   
public static boolean test(BoundingBox box, Sphere sphere) {
    float distanceSq = getSquaredDistanceFromPointToBox(sphere.center, box);
    if (distanceSq <= (sphere.radius * sphere.radius))
        return true;
    else
        return false;
}
项目:gdx-cclibs    文件:SphereSerializer.java   
@Override
public Sphere copy (Kryo kryo, Sphere original) {
    return new Sphere(original.center, original.radius);
}
项目:gdx-toolbox    文件:IntersectionTester.java   
public static boolean test(Sphere sphere, Vector3 point) {
    if (Math.abs(point.dst2(sphere.center)) < (sphere.radius * sphere.radius))
        return true;
    else
        return false;
}