Java 类com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute 实例源码

项目:ZombieInvadersVR    文件:GameObject.java   
public GameObject(ScreenBase context, Model model, BoundingBox bounds) {
super(model);
this.context = context;
this.customBounds = bounds;

      this.bounds = this.customBounds != null ? this.customBounds : new BoundingBox();
      this.center = new Vector3();
      this.enabled = true;
      updateBox();

      this.animations = new AnimationController(this);
      this.blending = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

      for(Material item : materials){
        item.set(new DepthTestAttribute(GL20.GL_LEQUAL, 0.01f, 25f, true));
    item.set(FloatAttribute.createAlphaTest(0.01f));
        item.set(blending);
      }
  }
项目:Alien-Ark    文件:MaterialInterpreter.java   
public MaterialInterpreter() {

        waterColor = new Color(0.13f, 0.05f, 0.8f, 1);
        waterMaterial = new Material(
                ColorAttribute.createDiffuse(waterColor),
                ColorAttribute.createSpecular(1, 1, 1, 1),
                FloatAttribute.createShininess(8f));

        sandColor = new Color(0.9f, 0.733f, 0.58f, 1);
        sandMaterial = new Material(ColorAttribute.createDiffuse(sandColor),
                ColorAttribute.createSpecular(1, 1, 1, 1),
                FloatAttribute.createShininess(8f));

        grassColor = new Color(0f, 1f, 0f, 1f);
        grassMaterial = new Material(ColorAttribute.createDiffuse(grassColor),
                ColorAttribute.createSpecular(1, 1, 1, 1),
                FloatAttribute.createShininess(8f));

    }
项目:libgdxcn    文件:DepthShader.java   
@Override
public void render (final Renderable renderable) {
    if (renderable.material.has(BlendingAttribute.Type)) {
        final BlendingAttribute blending = (BlendingAttribute)renderable.material.get(BlendingAttribute.Type);
        renderable.material.remove(BlendingAttribute.Type);
        final boolean hasAlphaTest = renderable.material.has(FloatAttribute.AlphaTest);
        if (!hasAlphaTest)
            renderable.material.set(alphaTestAttribute);
        if (blending.opacity >= ((FloatAttribute)renderable.material.get(FloatAttribute.AlphaTest)).value)
            super.render(renderable);
        if (!hasAlphaTest)
            renderable.material.remove(FloatAttribute.AlphaTest);
        renderable.material.set(blending);
    } else
        super.render(renderable);
}
项目:eamaster    文件:BasicShapesTest.java   
@Override
public void create () {
    super.create();

    final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    disposables.add(texture);
    final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1),
        FloatAttribute.createShininess(8f));
    final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;

    final Model sphere = modelBuilder.createSphere(4f, 4f, 4f, 24, 24, material, attributes);
    disposables.add(sphere);
    world.addConstructor("sphere", new BulletConstructor(sphere, 10f, new btSphereShape(2f)));

    final Model cylinder = modelBuilder.createCylinder(4f, 6f, 4f, 16, material, attributes);
    disposables.add(cylinder);
    world.addConstructor("cylinder", new BulletConstructor(cylinder, 10f, new btCylinderShape(tmpV1.set(2f, 3f, 2f))));

    final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
    disposables.add(capsule);
    world.addConstructor("capsule", new BulletConstructor(capsule, 10f, new btCapsuleShape(2f, 2f)));

    final Model box = modelBuilder.createBox(4f, 4f, 2f, material, attributes);
    disposables.add(box);
    world.addConstructor("box2", new BulletConstructor(box, 10f, new btBoxShape(tmpV1.set(2f, 2f, 1f))));

    final Model cone = modelBuilder.createCone(4f, 6f, 4f, 16, material, attributes);
    disposables.add(cone);
    world.addConstructor("cone", new BulletConstructor(cone, 10f, new btConeShape(2f, 6f)));

    // Create the entities
    world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
        0.25f + 0.5f * (float)Math.random(), 1f);
    world.add("sphere", 0, 5, 5);
    world.add("cylinder", 5, 5, 0);
    world.add("box2", 0, 5, 0);
    world.add("capsule", 5, 5, 5);
    world.add("cone", 10, 5, 0);
}
项目:Radix    文件:GameRenderer.java   
private void drawBlockSelection() {
    int curProgressInt = Math.round(RadixClient.getInstance().getPlayer().getBreakPercent() * 10) - 1;
    if ((blockBreakModel == null || blockBreakStage != curProgressInt) && curProgressInt >= 0) {
        if (blockBreakModel != null)
            blockBreakModel.dispose();

        blockBreakStage = curProgressInt;

        ModelBuilder builder = new ModelBuilder();
        blockBreakModel = builder.createBox(1f, 1f, 1f,
                new Material(TextureAttribute.createDiffuse(blockBreakStages[blockBreakStage]),
                        new BlendingAttribute(),
                        FloatAttribute.createAlphaTest(0.25f)),
                VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates);
        blockBreakModelInstance = new ModelInstance(blockBreakModel);
    }

    Vec3i curBlk = RadixClient.getInstance().getSelectedBlock();
    if (curBlk != null && curProgressInt >= 0) {
        Gdx.gl.glPolygonOffset(100000, 2000000);
        blockOverlayBatch.begin(RadixClient.getInstance().getCamera());
        blockBreakModelInstance.transform.translate(curBlk.x + 0.5f, curBlk.y + 0.5f, curBlk.z + 0.5f);
        blockOverlayBatch.render(blockBreakModelInstance);
        blockBreakModelInstance.transform.translate(-(curBlk.x + 0.5f), -(curBlk.y + 0.5f), -(curBlk.z + 0.5f));
        blockOverlayBatch.end();
        Gdx.gl.glPolygonOffset(100000, -2000000);
    }
}
项目:Mundus    文件:ModelShader.java   
@Override
public void render(Renderable renderable) {
    final MundusEnvironment env = (MundusEnvironment) renderable.environment;

    setLights(env);
    set(UNIFORM_TRANS_MATRIX, renderable.worldTransform);

    // texture uniform
    TextureAttribute diffuseTexture = ((TextureAttribute) (renderable.material.get(TextureAttribute.Diffuse)));
    ColorAttribute diffuseColor = ((ColorAttribute) (renderable.material.get(ColorAttribute.Diffuse)));

    if (diffuseTexture != null) {
        set(UNIFORM_MATERIAL_DIFFUSE_TEXTURE, diffuseTexture.textureDescription.texture);
        set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 1);
    } else {
        set(UNIFORM_MATERIAL_DIFFUSE_COLOR, diffuseColor.color);
        set(UNIFORM_MATERIAL_DIFFUSE_USE_TEXTURE, 0);
    }

    // shininess
    float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value;
    set(UNIFORM_MATERIAL_SHININESS, shininess);

    // Fog
    final Fog fog = env.getFog();
    if (fog == null) {
        set(UNIFORM_FOG_DENSITY, 0f);
        set(UNIFORM_FOG_GRADIENT, 0f);
    } else {
        set(UNIFORM_FOG_DENSITY, fog.density);
        set(UNIFORM_FOG_GRADIENT, fog.gradient);
        set(UNIFORM_FOG_COLOR, fog.color);
    }

    // bind attributes, bind mesh & render; then unbinds everything
    renderable.meshPart.render(program);
}
项目:Mundus    文件:MaterialAsset.java   
/**
 * Applies this material asset to the libGDX material.
 *
 * @param material
 * @return
 */
public Material applyToMaterial(Material material) {
    if (diffuseColor != null) {
        material.set(new ColorAttribute(ColorAttribute.Diffuse, diffuseColor));
    }
    if (diffuseTexture != null) {
        material.set(new TextureAttribute(TextureAttribute.Diffuse, diffuseTexture.getTexture()));
    } else {
        material.remove(TextureAttribute.Diffuse);
    }
    material.set(new FloatAttribute(FloatAttribute.Shininess, shininess));

    return material;
}
项目:libgdxcn    文件:DepthShader.java   
public DepthShader (final Renderable renderable, final Config config, final ShaderProgram shaderProgram) {
    super(renderable, config, shaderProgram);
    this.numBones = renderable.bones == null ? 0 : config.numBones;
    int w = 0;
    final int n = renderable.mesh.getVertexAttributes().size();
    for (int i = 0; i < n; i++) {
        final VertexAttribute attr = renderable.mesh.getVertexAttributes().get(i);
        if (attr.usage == Usage.BoneWeight) w |= (1 << attr.unit);
    }
    weights = w;
    alphaTestAttribute = new FloatAttribute(FloatAttribute.AlphaTest, config.defaultAlphaTest);
}
项目:libgdxcn    文件:DefaultShader.java   
protected void bindMaterial (final Renderable renderable) {
    if (currentMaterial == renderable.material) return;

    int cullFace = config.defaultCullFace == -1 ? defaultCullFace : config.defaultCullFace;
    int depthFunc = config.defaultDepthFunc == -1 ? defaultDepthFunc : config.defaultDepthFunc;
    float depthRangeNear = 0f;
    float depthRangeFar = 1f;
    boolean depthMask = true;

    currentMaterial = renderable.material;
    for (final Attribute attr : currentMaterial) {
        final long t = attr.type;
        if (BlendingAttribute.is(t)) {
            context.setBlending(true, ((BlendingAttribute)attr).sourceFunction, ((BlendingAttribute)attr).destFunction);
            set(u_opacity, ((BlendingAttribute)attr).opacity);
        } else if ((t & IntAttribute.CullFace) == IntAttribute.CullFace)
            cullFace = ((IntAttribute)attr).value;
        else if ((t & FloatAttribute.AlphaTest) == FloatAttribute.AlphaTest)
            set(u_alphaTest, ((FloatAttribute)attr).value);
        else if ((t & DepthTestAttribute.Type) == DepthTestAttribute.Type) {
            DepthTestAttribute dta = (DepthTestAttribute)attr;
            depthFunc = dta.depthFunc;
            depthRangeNear = dta.depthRangeNear;
            depthRangeFar = dta.depthRangeFar;
            depthMask = dta.depthMask;
        } else if (!config.ignoreUnimplemented) throw new GdxRuntimeException("Unknown material attribute: " + attr.toString());
    }

    context.setCullFace(cullFace);
    context.setDepthTest(depthFunc, depthRangeNear, depthRangeFar);
    context.setDepthMask(depthMask);
}
项目:libgdxcn    文件:BasicShapesTest.java   
@Override
public void create () {
    super.create();

    final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    disposables.add(texture);
    final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1),
        FloatAttribute.createShininess(8f));
    final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;

    final Model sphere = modelBuilder.createSphere(4f, 4f, 4f, 24, 24, material, attributes);
    disposables.add(sphere);
    world.addConstructor("sphere", new BulletConstructor(sphere, 10f, new btSphereShape(2f)));

    final Model cylinder = modelBuilder.createCylinder(4f, 6f, 4f, 16, material, attributes);
    disposables.add(cylinder);
    world.addConstructor("cylinder", new BulletConstructor(cylinder, 10f, new btCylinderShape(tmpV1.set(2f, 3f, 2f))));

    final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
    disposables.add(capsule);
    world.addConstructor("capsule", new BulletConstructor(capsule, 10f, new btCapsuleShape(2f, 2f)));

    final Model box = modelBuilder.createBox(4f, 4f, 2f, material, attributes);
    disposables.add(box);
    world.addConstructor("box2", new BulletConstructor(box, 10f, new btBoxShape(tmpV1.set(2f, 2f, 1f))));

    final Model cone = modelBuilder.createCone(4f, 6f, 4f, 16, material, attributes);
    disposables.add(cone);
    world.addConstructor("cone", new BulletConstructor(cone, 10f, new btConeShape(2f, 6f)));

    // Create the entities
    world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
        0.25f + 0.5f * (float)Math.random(), 1f);
    world.add("sphere", 0, 5, 5);
    world.add("cylinder", 5, 5, 0);
    world.add("box2", 0, 5, 0);
    world.add("capsule", 5, 5, 5);
    world.add("cone", 10, 5, 0);
}
项目:gaiasky    文件:StarGroup.java   
private static void initModel() {
    if (mc == null) {
        Texture tex = new Texture(Gdx.files.internal(GlobalConf.TEXTURES_FOLDER + "star.jpg"));
        Texture lut = new Texture(Gdx.files.internal(GlobalConf.TEXTURES_FOLDER + "lut.jpg"));
        tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        Map<String, Object> params = new TreeMap<String, Object>();
        params.put("quality", 120l);
        params.put("diameter", 1d);
        params.put("flip", false);

        Pair<Model, Map<String, Material>> pair = ModelCache.cache.getModel("sphere", params, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
        Model model = pair.getFirst();
        Material mat = pair.getSecond().get("base");
        mat.clear();
        mat.set(new TextureAttribute(TextureAttribute.Diffuse, tex));
        mat.set(new TextureAttribute(TextureAttribute.Normal, lut));
        // Only to activate view vector (camera position)
        mat.set(new TextureAttribute(TextureAttribute.Specular, lut));
        mat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
        modelTransform = new Matrix4();
        mc = new ModelComponent(false);
        mc.env = new Environment();
        mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 1f, 1f));
        mc.env.set(new FloatAttribute(FloatAttribute.Shininess, 0f));
        mc.instance = new ModelInstance(model, modelTransform);
    }
}
项目:gaiasky    文件:StarGroup.java   
/**
 * Model rendering
 */
@Override
public void render(ModelBatch modelBatch, float alpha, double t) {
    mc.touch();
    float opct = (float) MathUtilsd.lint(closestDist, modelDist / 50f, modelDist, 1f, 0f);
    if (alpha * opct > 0) {
        mc.setTransparency(alpha * opct);
        float[] col = closestCol;
        ((ColorAttribute) mc.env.get(ColorAttribute.AmbientLight)).color.set(col[0], col[1], col[2], 1f);
        ((FloatAttribute) mc.env.get(FloatAttribute.Shininess)).value = (float) t;
        // Local transform
        mc.instance.transform.idt().translate((float) closestPos.x, (float) closestPos.y, (float) closestPos.z).scl((float) (getRadius(active[0]) * 2d));
        modelBatch.render(mc.instance, mc.env);
    }
}
项目:gaiasky    文件:StarCluster.java   
public void initModel() {
    if (clusterTex == null) {
        clusterTex = new Texture(Gdx.files.internal("data/tex/cluster-tex.png"), true);
        clusterTex.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);
    }
    if (model == null) {
        Material mat = new Material(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA), new ColorAttribute(ColorAttribute.Diffuse, col[0], col[1], col[2], col[3]));
        ModelBuilder2 modelBuilder = ModelCache.cache.mb;
        modelBuilder.begin();
        // create part
        MeshPartBuilder2 bPartBuilder = modelBuilder.part("sph", GL20.GL_LINES, Usage.Position, mat);
        bPartBuilder.icosphere(1, 3, false, true);

        model = (modelBuilder.end());
        modelTransform = new Matrix4();
    }

    mc = new ModelComponent(false);
    mc.dlight = new DirectionalLight();
    mc.dlight.set(1, 1, 1, 1, 1, 1);
    mc.env = new Environment();
    mc.env.add(mc.dlight);
    mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    mc.env.set(new FloatAttribute(FloatAttribute.Shininess, 0.2f));
    mc.instance = new ModelInstance(model, modelTransform);

}
项目:gaiasky    文件:Star.java   
public static void initModel() {
    if (mc == null) {
        Texture tex = new Texture(Gdx.files.internal(GlobalConf.TEXTURES_FOLDER + "star.jpg"));
        Texture lut = new Texture(Gdx.files.internal(GlobalConf.TEXTURES_FOLDER + "lut.jpg"));
        tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        Map<String, Object> params = new TreeMap<String, Object>();
        params.put("quality", 120l);
        params.put("diameter", 1d);
        params.put("flip", false);

        Pair<Model, Map<String, Material>> pair = ModelCache.cache.getModel("sphere", params, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
        Model model = pair.getFirst();
        Material mat = pair.getSecond().get("base");
        mat.clear();
        mat.set(new TextureAttribute(TextureAttribute.Diffuse, tex));
        mat.set(new TextureAttribute(TextureAttribute.Normal, lut));
        // Only to activate view vector (camera position)
        mat.set(new TextureAttribute(TextureAttribute.Specular, lut));
        mat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
        modelTransform = new Matrix4();
        mc = new ModelComponent(false);
        mc.env = new Environment();
        mc.env.set(new ColorAttribute(ColorAttribute.AmbientLight, 1f, 1f, 1f, 1f));
        mc.env.set(new FloatAttribute(FloatAttribute.Shininess, 0f));
        mc.instance = new ModelInstance(model, modelTransform);
    }
}
项目:gaiasky    文件:Star.java   
@Override
public void render(ModelBatch modelBatch, float alpha, double t) {
    mc.touch();
    mc.setTransparency(alpha * (float) MathUtilsd.lint(distToCamera, modelDistance / 50f, modelDistance, 1f, 0f));
    float[] col = GlobalConf.scene.STAR_COLOR_TRANSIT ? ccTransit : cc;
    ((ColorAttribute) mc.env.get(ColorAttribute.AmbientLight)).color.set(col[0], col[1], col[2], 1f);
    ((FloatAttribute) mc.env.get(FloatAttribute.Shininess)).value = (float) t;
    // Local transform
    transform.getMatrix(mc.instance.transform).scl((float) (getRadius() * 2d));
    modelBatch.render(mc.instance, mc.env);
}
项目:amatsukaze    文件:MikuMaterial.java   
public MikuMaterial(PMD_MATERIAL_RECORD pMaterial) {
    this.m_material = pMaterial;

    //Gdx material
    gdxMaterial = new Material();
    gdxMaterial.set(ColorAttribute.createAmbient(pMaterial.ambient.toColor()));
    gdxMaterial.set(ColorAttribute.createDiffuse(pMaterial.diffuse.toColor()));
    gdxMaterial.set(ColorAttribute.createSpecular(pMaterial.specular.toColor()));
    gdxMaterial.set(FloatAttribute.createShininess(pMaterial.shininess));
    String texFileName = pMaterial.getTextureFileName();
    if(texFileName.length() > 0) {
        Texture texture = new Texture(Gdx.files.internal(texFileName));
        gdxMaterial.set(TextureAttribute.createDiffuse(texture));
    }
}
项目:gdx-tilemap3d    文件:TileChunk.java   
public TileChunk(int x, int y, int z, int width, int height, int depth, TileMap tileMap) {
    if (tileMap == null)
        throw new IllegalArgumentException();

    this.tileMap = tileMap;
    this.x = x;
    this.y = y;
    this.z = z;
    this.width = width;
    this.height = height;
    this.depth = depth;
    this.position = new Vector3(x, y, z);
    bounds = new BoundingBox();
    bounds.min.set(x, y, z);
    bounds.max.set(x + width, y + height, z + depth);

    int numTiles = width * height * depth;
    data = new Tile[numTiles];
    for (int i = 0; i < numTiles; ++i)
        data[i] = new Tile();

    opaqueMesh = null;
    alphaMesh = null;
    opaqueMaterial.set(TextureAttribute.createDiffuse(tileMap.tileMeshes.atlas.texture));
    alphaMaterial.set(TextureAttribute.createDiffuse(tileMap.tileMeshes.atlas.texture));
    alphaMaterial.set(new BlendingAttribute());
    alphaMaterial.set(FloatAttribute.createAlphaTest(0.0f));
}
项目:eamaster    文件:SoftBodyTest.java   
@Override
    public void create () {
        super.create();

        world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
            0.25f + 0.5f * (float)Math.random(), 1f);

        float x0 = -2f, y0 = 6f, z0 = -2f;
        float x1 = 8f, y1 = 6f, z1 = 8f;
        Vector3 patch00 = new Vector3(x0, y0, z0);
        Vector3 patch10 = new Vector3(x1, y1, z0);
        Vector3 patch01 = new Vector3(x0, y0, z1);
        Vector3 patch11 = new Vector3(x1, y1, z1);
        softBody = btSoftBodyHelpers.CreatePatch(worldInfo, patch00, patch10, patch01, patch11, 15, 15, 15, false);
        softBody.takeOwnership();
        softBody.setTotalMass(100f);
//        softBody.setConfig_kDP(0.2f);
//        softBody.setConfig_kCHR(0.99f);
//        softBody.setConfig_kKHR(0.99f);
//        softBody.setConfig_kSHR(0.99f);
        ((btSoftRigidDynamicsWorld)(world.collisionWorld)).addSoftBody(softBody);

        final int vertCount = softBody.getNodeCount();
        final int faceCount = softBody.getFaceCount();
        mesh = new Mesh(false, vertCount, faceCount * 3, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
            new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2,
                ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
        final int vertSize = mesh.getVertexSize() / 4;
        mesh.getVerticesBuffer().position(0);
        mesh.getVerticesBuffer().limit(vertCount * vertSize);
        mesh.getIndicesBuffer().position(0);
        mesh.getIndicesBuffer().limit(faceCount * 3);
        softBody.getVertices(mesh.getVerticesBuffer(), vertCount, mesh.getVertexSize(), 0);
        softBody.getIndices(mesh.getIndicesBuffer(), faceCount);

        final float[] verts = new float[vertCount * vertSize];
        final int uvOffset = mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4;
        final int normalOffset = mesh.getVertexAttribute(Usage.Normal).offset / 4;
        mesh.getVertices(verts);
        for (int i = 0; i < vertCount; i++) {
            verts[i * vertSize + normalOffset] = 0f;
            verts[i * vertSize + normalOffset + 1] = 1f;
            verts[i * vertSize + normalOffset + 2] = 0f;
            verts[i * vertSize + uvOffset] = (verts[i * vertSize] - x0) / (x1 - x0);
            verts[i * vertSize + uvOffset + 1] = (verts[i * vertSize + 2] - z0) / (z1 - z0);
        }
        mesh.setVertices(verts);
        texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));

        model = ModelBuilder.createFromMesh(mesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(texture),
            ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f), IntAttribute.createCullFace(0)));
        instance = new ModelInstance(model);
        world.add(new BulletEntity(instance, null));

        shoot(320f, 240f, 20f);
    }
项目:eamaster    文件:VehicleTest.java   
@Override
public void create () {
    super.create();
    instructions = "Tap to shoot\nArrow keys to drive\nR to reset\nLong press to toggle debug mode\nSwipe for next test";

    final Model chassisModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
    disposables.add(chassisModel);
    chassisModel.materials.get(0).clear();
    chassisModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE));
    final Model wheelModel = objLoader.loadModel(Gdx.files.internal("data/wheel.obj"));
    disposables.add(wheelModel);
    wheelModel.materials.get(0).clear();
    wheelModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.BLACK), ColorAttribute.createSpecular(Color.WHITE),
        FloatAttribute.createShininess(128));
    Texture checkboard = new Texture(Gdx.files.internal("data/g3d/checkboard.png"));
    final Model largeGroundModel = modelBuilder.createBox(
        1000f,
        2f,
        1000f,
        new Material(TextureAttribute.createDiffuse(checkboard), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute
            .createShininess(16f)), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    largeGroundModel.manageDisposable(checkboard);
    disposables.add(largeGroundModel);
    world.addConstructor("largeground", new BulletConstructor(largeGroundModel, 0f));

    BoundingBox bounds = new BoundingBox();
    Vector3 chassisHalfExtents = new Vector3(chassisModel.calculateBoundingBox(bounds).getDimensions()).scl(0.5f);
    Vector3 wheelHalfExtents = new Vector3(wheelModel.calculateBoundingBox(bounds).getDimensions()).scl(0.5f);

    world.addConstructor("chassis", new BulletConstructor(chassisModel, 5f, new btBoxShape(chassisHalfExtents)));
    world.addConstructor("wheel", new BulletConstructor(wheelModel, 0, null));

    world.add("largeground", 0, -1f, 0f);

    chassis = world.add("chassis", 0, 3f, 0);
    wheels[0] = world.add("wheel", 0, 0, 0);
    wheels[1] = world.add("wheel", 0, 0, 0);
    wheels[2] = world.add("wheel", 0, 0, 0);
    wheels[3] = world.add("wheel", 0, 0, 0);

    // Create the vehicle
    raycaster = new btDefaultVehicleRaycaster((btDynamicsWorld)world.collisionWorld);
    tuning = new btVehicleTuning();
    vehicle = new btRaycastVehicle(tuning, (btRigidBody)chassis.body, raycaster);
    chassis.body.setActivationState(Collision.DISABLE_DEACTIVATION);
    ((btDynamicsWorld)world.collisionWorld).addVehicle(vehicle);

    vehicle.setCoordinateSystem(0, 1, 2);

    btWheelInfo wheelInfo;
    Vector3 point = new Vector3();
    Vector3 direction = new Vector3(0, -1, 0);
    Vector3 axis = new Vector3(-1, 0, 0);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, 0.7f), direction, axis,
        wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, 0.7f), direction, axis,
        wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, -0.5f), direction, axis,
        wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, -0.5f), direction, axis,
        wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
}
项目:eamaster    文件:CharacterTest.java   
@Override
public void create () {
    super.create();
    instructions = "Tap to shoot\nArrow keys to move\nR to reset\nLong press to toggle debug mode\nSwipe for next test";

    // Create a visual representation of the character (note that we don't use the physics part of BulletEntity, we'll do that manually)
    final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    disposables.add(texture);
    final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1,1,1,1), FloatAttribute.createShininess(8f));
    final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
    final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
    disposables.add(capsule);
    world.addConstructor("capsule", new BulletConstructor(capsule, null));
    character = world.add("capsule", 5f, 3f, 5f);
    characterTransform = character.transform; // Set by reference

    // Create the physics representation of the character
    ghostObject = new btPairCachingGhostObject();
    ghostObject.setWorldTransform(characterTransform);
    ghostShape = new btCapsuleShape(2f, 2f);
    ghostObject.setCollisionShape(ghostShape);
    ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT);
    characterController = new btKinematicCharacterController(ghostObject, ghostShape, .35f);

    // And add it to the physics world
    world.collisionWorld.addCollisionObject(ghostObject, 
        (short)btBroadphaseProxy.CollisionFilterGroups.CharacterFilter,
        (short)(btBroadphaseProxy.CollisionFilterGroups.StaticFilter | btBroadphaseProxy.CollisionFilterGroups.DefaultFilter));
    ((btDiscreteDynamicsWorld)(world.collisionWorld)).addAction(characterController);

    // Add the ground
    (ground = world.add("ground", 0f, 0f, 0f))
        .setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
    // Create some boxes to play with
    for (int x = 0; x < BOXCOUNT_X; x++) {
        for (int y = 0; y < BOXCOUNT_Y; y++) {
            for (int z = 0; z < BOXCOUNT_Z; z++) {
                world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z)
                    .setColor(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
            }
        }
    }
}
项目:Radix    文件:Chunk.java   
private void updateModelInstances() {
    if(opaqueFaces != null) {
        if(opaqueModel != null)
            opaqueModel.dispose();

        Mesh opaqueMesh = mesher.meshFaces(opaqueFaces, meshBuilder);
        modelBuilder.begin();
        modelBuilder.part(String.format("c-%d,%d", startPosition.x, startPosition.z), opaqueMesh, GL20.GL_TRIANGLES,
                new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap())));
        opaqueModel = modelBuilder.end();

        opaqueModelInstance = new ModelInstance(opaqueModel) {
            @Override
            public Renderable getRenderable(final Renderable out, final Node node,
                                            final NodePart nodePart) {
                super.getRenderable(out, node, nodePart);
                if(RadixClient.getInstance().isWireframe()) {
                    out.primitiveType = GL20.GL_LINES;
                } else {
                    out.primitiveType = GL20.GL_TRIANGLES;
                }
                return out;
            }
        };

        opaqueFaces = null;
    }

    if(translucentFaces != null) {
        if(translucentModel != null)
            translucentModel.dispose();

        Mesh translucentMesh = mesher.meshFaces(translucentFaces, meshBuilder);
        modelBuilder.begin();
        modelBuilder.part(String.format("c-%d,%d-t", startPosition.x, startPosition.z), translucentMesh, GL20.GL_TRIANGLES,
                new Material(TextureAttribute.createDiffuse(NormalBlockRenderer.getBlockMap()),
                        new BlendingAttribute(),
                        FloatAttribute.createAlphaTest(0.25f)));
        translucentModel = modelBuilder.end();

        translucentModelInstance = new ModelInstance(translucentModel) {
            @Override
            public Renderable getRenderable(final Renderable out, final Node node,
                                            final NodePart nodePart) {
                super.getRenderable(out, node, nodePart);
                if(RadixClient.getInstance().isWireframe()) {
                    out.primitiveType = GL20.GL_LINES;
                } else {
                    out.primitiveType = GL20.GL_TRIANGLES;
                }
                return out;
            }
        };

        translucentFaces = null;
    }
}
项目:libgdxcn    文件:DefaultShader.java   
@Override
public void set (BaseShader shader, int inputID, Renderable renderable, Attributes combinedAttributes) {
    shader.set(inputID, ((FloatAttribute)(combinedAttributes.get(FloatAttribute.Shininess))).value);
}
项目:libgdxcn    文件:DefaultShader.java   
public static String createPrefix (final Renderable renderable, final Config config) {
    String prefix = "";
    final long mask = renderable.material.getMask();
    final long attributes = renderable.mesh.getVertexAttributes().getMask();
    if (and(attributes, Usage.Position)) prefix += "#define positionFlag\n";
    if (or(attributes, Usage.Color | Usage.ColorPacked)) prefix += "#define colorFlag\n";
    if (and(attributes, Usage.BiNormal)) prefix += "#define binormalFlag\n";
    if (and(attributes, Usage.Tangent)) prefix += "#define tangentFlag\n";
    if (and(attributes, Usage.Normal)) prefix += "#define normalFlag\n";
    if (and(attributes, Usage.Normal) || and(attributes, Usage.Tangent | Usage.BiNormal)) {
        if (renderable.environment != null) {
            prefix += "#define lightingFlag\n";
            prefix += "#define ambientCubemapFlag\n";
            prefix += "#define numDirectionalLights " + config.numDirectionalLights + "\n";
            prefix += "#define numPointLights " + config.numPointLights + "\n";
            if (renderable.environment.has(ColorAttribute.Fog)) {
                prefix += "#define fogFlag\n";
            }
            if (renderable.environment.shadowMap != null) prefix += "#define shadowMapFlag\n";
            if (renderable.material.has(CubemapAttribute.EnvironmentMap)
                || renderable.environment.has(CubemapAttribute.EnvironmentMap)) prefix += "#define environmentCubemapFlag\n";
        }
    }
    final int n = renderable.mesh.getVertexAttributes().size();
    for (int i = 0; i < n; i++) {
        final VertexAttribute attr = renderable.mesh.getVertexAttributes().get(i);
        if (attr.usage == Usage.BoneWeight)
            prefix += "#define boneWeight" + attr.unit + "Flag\n";
        else if (attr.usage == Usage.TextureCoordinates) prefix += "#define texCoord" + attr.unit + "Flag\n";
    }
    if ((mask & BlendingAttribute.Type) == BlendingAttribute.Type) prefix += "#define " + BlendingAttribute.Alias + "Flag\n";
    if ((mask & TextureAttribute.Diffuse) == TextureAttribute.Diffuse) {
        prefix += "#define " + TextureAttribute.DiffuseAlias + "Flag\n";
        prefix += "#define " + TextureAttribute.DiffuseAlias + "Coord texCoord0\n"; // FIXME implement UV mapping
    }
    if ((mask & TextureAttribute.Specular) == TextureAttribute.Specular) {
        prefix += "#define " + TextureAttribute.SpecularAlias + "Flag\n";
        prefix += "#define " + TextureAttribute.SpecularAlias + "Coord texCoord0\n"; // FIXME implement UV mapping
    }
    if ((mask & TextureAttribute.Normal) == TextureAttribute.Normal) {
        prefix += "#define " + TextureAttribute.NormalAlias + "Flag\n";
        prefix += "#define " + TextureAttribute.NormalAlias + "Coord texCoord0\n"; // FIXME implement UV mapping
    }
    if ((mask & TextureAttribute.Emissive) == TextureAttribute.Emissive) {
        prefix += "#define " + TextureAttribute.EmissiveAlias + "Flag\n";
        prefix += "#define " + TextureAttribute.EmissiveAlias + "Coord texCoord0\n"; // FIXME implement UV mapping
    }
    if ((mask & TextureAttribute.Reflection) == TextureAttribute.Reflection) {
        prefix += "#define " + TextureAttribute.ReflectionAlias + "Flag\n";
        prefix += "#define " + TextureAttribute.ReflectionAlias + "Coord texCoord0\n"; // FIXME implement UV mapping
    }
    if ((mask & TextureAttribute.Ambient) == TextureAttribute.Ambient) {
        prefix += "#define " + TextureAttribute.AmbientAlias + "Flag\n";
        prefix += "#define " + TextureAttribute.AmbientAlias + "Coord texCoord0\n"; // FIXME implement UV mapping
    }
    if ((mask & ColorAttribute.Diffuse) == ColorAttribute.Diffuse)
        prefix += "#define " + ColorAttribute.DiffuseAlias + "Flag\n";
    if ((mask & ColorAttribute.Specular) == ColorAttribute.Specular)
        prefix += "#define " + ColorAttribute.SpecularAlias + "Flag\n";
    if ((mask & ColorAttribute.Emissive) == ColorAttribute.Emissive)
        prefix += "#define " + ColorAttribute.EmissiveAlias + "Flag\n";
    if ((mask & ColorAttribute.Reflection) == ColorAttribute.Reflection)
        prefix += "#define " + ColorAttribute.ReflectionAlias + "Flag\n";
    if ((mask & FloatAttribute.Shininess) == FloatAttribute.Shininess)
        prefix += "#define " + FloatAttribute.ShininessAlias + "Flag\n";
    if ((mask & FloatAttribute.AlphaTest) == FloatAttribute.AlphaTest)
        prefix += "#define " + FloatAttribute.AlphaTestAlias + "Flag\n";
    if (renderable.bones != null && config.numBones > 0) prefix += "#define numBones " + config.numBones + "\n";
    return prefix;
}
项目:libgdxcn    文件:Model.java   
private Material convertMaterial (ModelMaterial mtl, TextureProvider textureProvider) {
    Material result = new Material();
    result.id = mtl.id;
    if (mtl.ambient != null) result.set(new ColorAttribute(ColorAttribute.Ambient, mtl.ambient));
    if (mtl.diffuse != null) result.set(new ColorAttribute(ColorAttribute.Diffuse, mtl.diffuse));
    if (mtl.specular != null) result.set(new ColorAttribute(ColorAttribute.Specular, mtl.specular));
    if (mtl.emissive != null) result.set(new ColorAttribute(ColorAttribute.Emissive, mtl.emissive));
    if (mtl.reflection != null) result.set(new ColorAttribute(ColorAttribute.Reflection, mtl.reflection));
    if (mtl.shininess > 0f) result.set(new FloatAttribute(FloatAttribute.Shininess, mtl.shininess));
    if (mtl.opacity != 1.f) result.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, mtl.opacity));

    ObjectMap<String, Texture> textures = new ObjectMap<String, Texture>();

    // FIXME uvScaling/uvTranslation totally ignored
    if (mtl.textures != null) {
        for (ModelTexture tex : mtl.textures) {
            Texture texture;
            if (textures.containsKey(tex.fileName)) {
                texture = textures.get(tex.fileName);
            } else {
                texture = textureProvider.load(tex.fileName);
                textures.put(tex.fileName, texture);
                disposables.add(texture);
            }

            TextureDescriptor descriptor = new TextureDescriptor(texture);
            descriptor.minFilter = texture.getMinFilter();
            descriptor.magFilter = texture.getMagFilter();
            descriptor.uWrap = texture.getUWrap();
            descriptor.vWrap = texture.getVWrap();

            float offsetU = tex.uvTranslation == null ? 0f : tex.uvTranslation.x;
            float offsetV = tex.uvTranslation == null ? 0f : tex.uvTranslation.y;
            float scaleU = tex.uvScaling == null ? 1f : tex.uvScaling.x;
            float scaleV = tex.uvScaling == null ? 1f : tex.uvScaling.y;

            switch (tex.usage) {
            case ModelTexture.USAGE_DIFFUSE:
                result.set(new TextureAttribute(TextureAttribute.Diffuse, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_SPECULAR:
                result.set(new TextureAttribute(TextureAttribute.Specular, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_BUMP:
                result.set(new TextureAttribute(TextureAttribute.Bump, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_NORMAL:
                result.set(new TextureAttribute(TextureAttribute.Normal, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_AMBIENT:
                result.set(new TextureAttribute(TextureAttribute.Ambient, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_EMISSIVE:
                result.set(new TextureAttribute(TextureAttribute.Emissive, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            case ModelTexture.USAGE_REFLECTION:
                result.set(new TextureAttribute(TextureAttribute.Reflection, descriptor, offsetU, offsetV, scaleU, scaleV));
                break;
            }
        }
    }

    return result;
}
项目:libgdxcn    文件:SoftBodyTest.java   
@Override
public void create () {
    super.create();

    world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
        0.25f + 0.5f * (float)Math.random(), 1f);

    float x0 = -2f, y0 = 6f, z0 = -2f;
    float x1 = 8f, y1 = 6f, z1 = 8f;
    Vector3 patch00 = new Vector3(x0, y0, z0);
    Vector3 patch10 = new Vector3(x1, y1, z0);
    Vector3 patch01 = new Vector3(x0, y0, z1);
    Vector3 patch11 = new Vector3(x1, y1, z1);
    softBody = btSoftBodyHelpers.CreatePatch(worldInfo, patch00, patch10, patch01, patch11, 15, 15, 15, false);
    softBody.takeOwnership();
    softBody.setTotalMass(100f);
    ((btSoftRigidDynamicsWorld)(world.collisionWorld)).addSoftBody(softBody);

    final int vertCount = softBody.getNodeCount();
    final int faceCount = softBody.getFaceCount();
    mesh = new Mesh(false, vertCount, faceCount * 3, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE),
        new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2,
            ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
    final int vertSize = mesh.getVertexSize() / 4;
    mesh.getVerticesBuffer().position(0);
    mesh.getVerticesBuffer().limit(vertCount * vertSize);
    mesh.getIndicesBuffer().position(0);
    mesh.getIndicesBuffer().limit(faceCount * 3);
    softBody.getVertices(mesh.getVerticesBuffer(), vertCount, mesh.getVertexSize(), 0);
    softBody.getIndices(mesh.getIndicesBuffer(), faceCount);

    final float[] verts = new float[vertCount * vertSize];
    final int uvOffset = mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4;
    final int normalOffset = mesh.getVertexAttribute(Usage.Normal).offset / 4;
    mesh.getVertices(verts);
    for (int i = 0; i < vertCount; i++) {
        verts[i * vertSize + normalOffset] = 0f;
        verts[i * vertSize + normalOffset + 1] = 1f;
        verts[i * vertSize + normalOffset + 2] = 0f;
        verts[i * vertSize + uvOffset] = (verts[i * vertSize] - x0) / (x1 - x0);
        verts[i * vertSize + uvOffset + 1] = (verts[i * vertSize + 2] - z0) / (z1 - z0);
    }
    mesh.setVertices(verts);
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));

    model = ModelBuilder.createFromMesh(mesh, GL20.GL_TRIANGLES, new Material(TextureAttribute.createDiffuse(texture),
        ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f), IntAttribute.createCullFace(0)));
    instance = new ModelInstance(model);
    world.add(new BulletEntity(instance, null));
}
项目:libgdxcn    文件:VehicleTest.java   
@Override
public void create () {
    super.create();
    instructions = "Tap to shoot\nArrow keys to drive\nR to reset\nLong press to toggle debug mode\nSwipe for next test";

    final Model chassisModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
    disposables.add(chassisModel);
    chassisModel.materials.get(0).clear();
    chassisModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE));
    final Model wheelModel = objLoader.loadModel(Gdx.files.internal("data/wheel.obj"));
    disposables.add(wheelModel);
    wheelModel.materials.get(0).clear();
    wheelModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.BLACK), ColorAttribute.createSpecular(Color.WHITE),
        FloatAttribute.createShininess(128));
    Texture checkboard = new Texture(Gdx.files.internal("data/g3d/checkboard.png"));
    final Model largeGroundModel = modelBuilder.createBox(
        1000f,
        2f,
        1000f,
        new Material(TextureAttribute.createDiffuse(checkboard), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute
            .createShininess(16f)), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    largeGroundModel.manageDisposable(checkboard);
    disposables.add(largeGroundModel);
    world.addConstructor("largeground", new BulletConstructor(largeGroundModel, 0f));

    BoundingBox bounds = new BoundingBox();
    Vector3 chassisHalfExtents = new Vector3(chassisModel.calculateBoundingBox(bounds).getDimensions()).scl(0.5f);
    Vector3 wheelHalfExtents = new Vector3(wheelModel.calculateBoundingBox(bounds).getDimensions()).scl(0.5f);

    world.addConstructor("chassis", new BulletConstructor(chassisModel, 5f, new btBoxShape(chassisHalfExtents)));
    world.addConstructor("wheel", new BulletConstructor(wheelModel, 0, null));

    world.add("largeground", 0, -1f, 0f);

    chassis = world.add("chassis", 0, 3f, 0);
    wheels[0] = world.add("wheel", 0, 0, 0);
    wheels[1] = world.add("wheel", 0, 0, 0);
    wheels[2] = world.add("wheel", 0, 0, 0);
    wheels[3] = world.add("wheel", 0, 0, 0);

    // Create the vehicle
    raycaster = new btDefaultVehicleRaycaster((btDynamicsWorld)world.collisionWorld);
    tuning = new btVehicleTuning();
    vehicle = new btRaycastVehicle(tuning, (btRigidBody)chassis.body, raycaster);
    chassis.body.setActivationState(Collision.DISABLE_DEACTIVATION);
    ((btDynamicsWorld)world.collisionWorld).addVehicle(vehicle);

    vehicle.setCoordinateSystem(0, 1, 2);

    btWheelInfo wheelInfo;
    Vector3 point = new Vector3();
    Vector3 direction = new Vector3(0, -1, 0);
    Vector3 axis = new Vector3(-1, 0, 0);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, 0.7f), direction, axis,
        wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, 0.7f), direction, axis,
        wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, -0.5f), direction, axis,
        wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, -0.5f), direction, axis,
        wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
}
项目:libgdxcn    文件:CharacterTest.java   
@Override
public void create () {
    super.create();
    instructions = "Tap to shoot\nArrow keys to move\nR to reset\nLong press to toggle debug mode\nSwipe for next test";

    // Create a visual representation of the character (note that we don't use the physics part of BulletEntity, we'll do that manually)
    final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    disposables.add(texture);
    final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1,1,1,1), FloatAttribute.createShininess(8f));
    final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
    final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
    disposables.add(capsule);
    world.addConstructor("capsule", new BulletConstructor(capsule, null));
    character = world.add("capsule", 5f, 3f, 5f);
    characterTransform = character.transform; // Set by reference

    // Create the physics representation of the character
    ghostObject = new btPairCachingGhostObject();
    ghostObject.setWorldTransform(characterTransform);
    ghostShape = new btCapsuleShape(2f, 2f);
    ghostObject.setCollisionShape(ghostShape);
    ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT);
    characterController = new btKinematicCharacterController(ghostObject, ghostShape, .35f);

    // And add it to the physics world
    world.collisionWorld.addCollisionObject(ghostObject, 
        (short)btBroadphaseProxy.CollisionFilterGroups.CharacterFilter,
        (short)(btBroadphaseProxy.CollisionFilterGroups.StaticFilter | btBroadphaseProxy.CollisionFilterGroups.DefaultFilter));
    ((btDiscreteDynamicsWorld)(world.collisionWorld)).addAction(characterController);

    // Add the ground
    (ground = world.add("ground", 0f, 0f, 0f))
        .setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(), 1f);
    // Create some boxes to play with
    for (int x = 0; x < BOXCOUNT_X; x++) {
        for (int y = 0; y < BOXCOUNT_Y; y++) {
            for (int z = 0; z < BOXCOUNT_Z; z++) {
                world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z)
                    .setColor(0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 0.5f + 0.5f * (float)Math.random(), 1f);
            }
        }
    }
}
项目:Vloxlands    文件:VxiLoader.java   
private void loadMaterial(FileHandle file) {
    String line;
    String[] tokens;
    Color difcolor = Color.WHITE;
    Color speccolor = Color.WHITE;
    float opacity = 1.f;
    float shininess = 0.f;

    BufferedReader reader = new BufferedReader(new InputStreamReader(file.read()), 4096);
    try {
        while ((line = reader.readLine()) != null) {

            if (line.length() > 0 && line.charAt(0) == '\t') line = line.substring(1).trim();

            tokens = line.split("\\s+");

            if (tokens[0].length() == 0) {
                continue;
            } else if (tokens[0].charAt(0) == '#') continue;
            else {
                final String key = tokens[0].toLowerCase();
                if (key.equals("kd") || key.equals("ks")) // diffuse or specular
                {
                    float r = Float.parseFloat(tokens[1]);
                    float g = Float.parseFloat(tokens[2]);
                    float b = Float.parseFloat(tokens[3]);
                    float a = 1;
                    if (tokens.length > 4) a = Float.parseFloat(tokens[4]);

                    if (tokens[0].toLowerCase().equals("kd")) {
                        difcolor = new Color();
                        difcolor.set(r, g, b, a);
                    } else {
                        speccolor = new Color();
                        speccolor.set(r, g, b, a);
                    }
                } else if (key.equals("tr") || key.equals("d")) {
                    opacity = Float.parseFloat(tokens[1]);
                } else if (key.equals("ns")) {
                    shininess = Float.parseFloat(tokens[1]);
                }
            }
        }
        reader.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    material.set(new ColorAttribute(ColorAttribute.Diffuse, difcolor));
    material.set(new ColorAttribute(ColorAttribute.Specular, speccolor));
    material.set(new FloatAttribute(FloatAttribute.Shininess, shininess));
    if (opacity != 1) material.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, opacity));
}