コード例 #1
0
ファイル: View.java プロジェクト: karmelosng/KsimulatorDerby
  @Override
  public void create() {
    // Create ModelBatch that will render all models using a camera
    modelBatch = new ModelBatch();
    // Create a camera and point it to our model
    camera = new PerspectiveCamera(85, 0, 0);
    camera.position.set(1, 1, 1150);
    camera.lookAt(0, 0, 0);
    camera.near = 100f;
    camera.far = 2000f;
    camera.update();

    // Create the generic camera input controller to make the app interactive
    cameraController = new CameraInputController(camera);
    Gdx.input.setInputProcessor(cameraController);

    /// Create an asset manager that lets us dispose all assets at once

    for (int i = 0; i < listing.size(); i++) {
      assets.load("data/obj_" + listing.get(i).getId() + ".g3db", Model.class);
    }
    assets.finishLoading();
    // Create an instance of our crate model and put it in an array
    for (int i = 0; i < listing.size(); i++) {
      Model model = assets.get("data/obj_" + listing.get(i).getId() + ".g3db", Model.class);
      ModelInstance inst = new ModelInstance(model);
      instances.add(inst);
    }

    // Set up environment with simple lighting
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, 1f, 0.8f, -0.2f));
  }
コード例 #2
0
ファイル: BehindTheScenesTest.java プロジェクト: Boukil/blog
  @Override
  public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(2f, 2f, 2f);
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    ModelLoader modelLoader = new G3dModelLoader(new JsonReader());
    ModelData modelData =
        modelLoader.loadModelData(Gdx.files.internal(data + "/invaderscene.g3dj"));
    model = new Model(modelData, new TextureProvider.FileTextureProvider());

    NodePart blockPart = model.getNode("ship").parts.get(0);

    renderable = new Renderable();
    renderable.mesh = blockPart.meshPart.mesh;
    renderable.meshPartOffset = blockPart.meshPart.indexOffset;
    renderable.meshPartSize = blockPart.meshPart.numVertices;
    renderable.primitiveType = blockPart.meshPart.primitiveType;
    renderable.material = blockPart.material;
    renderable.environment = environment;
    renderable.worldTransform.idt();
  }
コード例 #3
0
  private void setStaticProjectionAndCamera(Graphics graphics, Application app, GL10 gl) {
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    // x=left-right, y=up-down, z=back-forward
    camera.far = 1000000;
    camera.position.set(0, 7f + 0, 9f + 0);
    // camera.direction.set(0, 0, -4f).sub(camera.position).nor();
    camera.fieldOfView = 67;
    float orbitRadius = (new Vector3(0, 0, 0).dst(camera.position));
    camera.position.set(new Vector3(0, 0, 0));

    camera.rotate(Splash.cameraHorizAngle, 0, 1, 0);
    Vector3 orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    camera.update();
    camera.apply(gl);

    orbitRadius = (new Vector3(0, 0, 0)).dst(camera.position);
    camera.position.set(new Vector3(0, 0, 0));
    camera.rotate(Splash.cameraVertAngle, 1, 0, 0);
    orbitReturnVector = new Vector3(0, 0, 0);
    orbitReturnVector.set(camera.direction.tmp().mul(-orbitRadius));
    camera.translate(orbitReturnVector.x, orbitReturnVector.y, orbitReturnVector.z);
    camera.update();
    camera.apply(gl);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    Splash.cameraHorizAngle = 0;
    Splash.cameraVertAngle = 0;
  }
コード例 #4
0
ファイル: CameraMan.java プロジェクト: rasgele/DogFight
 public CameraMan(float width, float height) {
   mCamera = new PerspectiveCamera(mFoV, width, height);
   mCamera.up.set(0, 0, 1);
   mCamera.near = 5;
   mCamera.far = 300000;
   mCamera.direction.set(1, 0, 0);
   Gdx.input.setInputProcessor(null);
 }
コード例 #5
0
 /** Method sets up camera and binds it to player. */
 public void cameraSetup(RigidBody body) {
   camera.near = 1;
   camera.far = 100;
   camera.position.set(
       body.motionState.resultSimulation.originPoint.x,
       body.motionState.resultSimulation.originPoint.y + 10.0f,
       body.motionState.resultSimulation.originPoint.z + 5.0f);
   // camera.position.set(position.x,30,position.y);
   camera.direction.set(0, -5, -3);
   camera.update();
   camera.apply(Gdx.gl10);
 }
コード例 #6
0
ファイル: MaterialTest.java プロジェクト: nayomnik/blog
  @Override
  public void create() {
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0f, 8f, 8f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    ModelBuilder modelBuilder = new ModelBuilder();
    model =
        modelBuilder.createSphere(
            2f,
            2f,
            2f,
            20,
            20,
            new Material(),
            Usage.Position | Usage.Normal | Usage.TextureCoordinates);

    for (int x = -5; x <= 5; x += 2) {
      for (int z = -5; z <= 5; z += 2) {
        ModelInstance instance = new ModelInstance(model, x, 0, z);
        ColorAttribute attrU =
            new TestColorAttribute(
                TestColorAttribute.DiffuseU, (x + 5f) / 10f, 1f - (z + 5f) / 10f, 0, 1);
        instance.materials.get(0).set(attrU);
        ColorAttribute attrV =
            new TestColorAttribute(
                TestColorAttribute.DiffuseV, 1f - (x + 5f) / 10f, 0, (z + 5f) / 10f, 1);
        instance.materials.get(0).set(attrV);
        instances.add(instance);
      }
    }

    shader = new TestShader();
    shader.init();

    modelBatch = new ModelBatch();
  }
コード例 #7
0
  @Override
  public void create() {
    modelBatch = new ModelBatch();
    lights = new Environment();
    lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    lights.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0f, 7f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    assets = new AssetManager();
    assets.load("data/g3d/invaders.g3dj", Model.class);
    loading = true;
  }
コード例 #8
0
  @Override
  public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0f, 7f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(camController);

    ModelLoader modelLoader = new G3dModelLoader(new JsonReader());
    ModelData modelData =
        modelLoader.loadModelData(Gdx.files.internal(data + "/invaderscene.g3dj"));
    model = new Model(modelData, new TextureProvider.FileTextureProvider());
    doneLoading();
  }
コード例 #9
0
  @Override
  public void create() {
    Gdx.app.setLogLevel(Application.LOG_DEBUG);
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 254f, 254f, 65f, 1.f));
    environment.add(new DirectionalLight().set(254f, 254f, 65f, -1f, -0.8f, -0.2f));
    // environment.add(new SpotLight().set(0.8f, 0.8f, 0.8f, new Vector3()));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0f, 20f, 20f);
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 1300f;
    cam.update();

    camController = new CameraInputController(cam);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, camController));
    loadTexture();
    assets = new AssetManager();
    assets.load(Config.Model.PLAYER_MODEL_NAME, Model.class);
    assets.load("models//pitch.g3db", Model.class);
    loading = true;
  }
コード例 #10
0
  @Override
  public void create() {
    modelBatch = new ModelBatch();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
    environment.add(
        (shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f))
            .set(0.8f, 0.8f, 0.8f, -1f, -.8f, -.2f));
    environment.shadowMap = shadowLight;

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(0f, 7f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 50f;
    cam.update();

    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder mpb =
        modelBuilder.part(
            "parts",
            GL20.GL_TRIANGLES,
            Usage.Position | Usage.Normal | Usage.ColorUnpacked,
            new Material(ColorAttribute.createDiffuse(Color.WHITE)));
    mpb.setColor(1f, 1f, 1f, 1f);
    mpb.box(0, -1.5f, 0, 10, 1, 10);
    mpb.setColor(1f, 0f, 1f, 1f);
    mpb.sphere(2f, 2f, 2f, 10, 10);
    model = modelBuilder.end();
    instance = new ModelInstance(model);

    shadowBatch = new ModelBatch(new DepthShaderProvider());

    Gdx.input.setInputProcessor(camController = new CameraInputController(cam));
  }
コード例 #11
0
ファイル: HybridLightTest.java プロジェクト: small-ant/libgdx
  public void create() {

    lightManager = new LightManager(LIGHTS_NUM, LightQuality.FRAGMENT);
    for (int i = 0; i < LIGHTS_NUM; i++) {
      PointLight l = new PointLight();
      l.position.set(MathUtils.random(8) - 4, MathUtils.random(6), MathUtils.random(8) - 4);
      l.color.r = MathUtils.random();
      l.color.b = MathUtils.random();
      l.color.g = MathUtils.random();
      l.intensity = 1 + MathUtils.random() * LIGHT_INTESITY;
      lightManager.addLigth(l);
    }
    lightManager.dirLight = new DirectionalLight();
    lightManager.dirLight.color.set(0.15f, 0.15f, 0.15f, 1);
    lightManager.dirLight.direction.set(-.4f, -1, 0.03f).nor();

    lightManager.ambientLight.set(.1f, 0.09f, 0.09f, 0f);

    cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.near = 0.1f;
    cam.far = 264f;
    cam.position.set(0, 0.5f, -2f);
    cam.update();

    camController = new PerspectiveCamController(cam);
    Gdx.input.setInputProcessor(camController);

    texture = new Texture(Gdx.files.internal("data/multipleuvs_1.png"), Format.RGB565, true);
    texture.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);
    texture2 = new Texture(Gdx.files.internal("data/texture2UV1N.png"), Format.RGB565, true);
    texture2.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);

    model = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/models/sphere.obj"));
    model2 = ModelLoaderRegistry.loadStillModel(Gdx.files.internal("data/models/basicscene.obj"));

    instance = new StillModelNode();
    instance.getTransform().translate(2, 0, -5);
    instance2 = new StillModelNode();

    BoundingBox box = new BoundingBox();
    model.getBoundingBox(box);
    instance.radius = box.getDimensions().len() / 2;

    model2.getBoundingBox(box);
    instance2.radius = box.getDimensions().len() / 2;

    protoRenderer = new PrototypeRendererGL20(lightManager);
    protoRenderer.cam = cam;

    MaterialAttribute c1 =
        new ColorAttribute(new Color(0.75f, 0.75f, 0.75f, 0.6f), ColorAttribute.diffuse);
    MaterialAttribute c2 =
        new ColorAttribute(new Color(0.35f, 0.35f, 0.35f, 0.35f), ColorAttribute.specular);
    MaterialAttribute t1 = new TextureAttribute(texture, 0, TextureAttribute.diffuseTexture);
    MaterialAttribute t2 = new TextureAttribute(texture2, 1, TextureAttribute.specularTexture);

    // MaterialAttribute b = new BlendingAttribute(BlendingAttribute.translucent);

    Material material2 = new Material("basic", c2, t1, t2);
    model2.setMaterial(material2);

    Material material = new Material("shiningBall", c1, c2);
    model.setMaterial(material);

    model3 = ModelLoaderRegistry.loadKeyframedModel(Gdx.files.internal("data/models/knight.md2"));
    animInstance = new AnimatedModelNode();
    animInstance.animation = model3.getAnimations()[0].name;
    animInstance.looping = true;
    model3.getBoundingBox(box);

    animInstance.matrix.trn(-1.75f, 0f, -5.5f);
    animInstance.matrix.scale(0.05f, 0.05f, 0.05f);
    box.mul(animInstance.matrix);
    animInstance.radius = (box.getDimensions().len() / 2);
    texture3 = new Texture(Gdx.files.internal("data/models/knight.jpg"), Format.RGB565, true);
    texture3.setFilter(TextureFilter.MipMapLinearNearest, TextureFilter.Linear);

    MaterialAttribute t3 = new TextureAttribute(texture3, 0, TextureAttribute.diffuseTexture);
    Material material3 = new Material("", c2, t3, t2);
    model3.setMaterial(material3);
  }