@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)); }
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; }
@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(); }
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); }
@Override public void update(float delta) { PerspectiveCamera cam = worldView.getRenderer().getCam(); cam.position.x = status.position().x + 0.5f; cam.position.y = status.position().y; cam.position.z = status.position().z + WorldView.CAM_OFFSET; cam.update(); }
@Override public void create() { Bullet.init(); 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(3f, 7f, 10f); cam.lookAt(0, 4f, 0); cam.update(); camController = new CameraInputController(cam); Gdx.input.setInputProcessor(camController); ModelBuilder mb = new ModelBuilder(); mb.begin(); mb.node().id = "ground"; mb.part( "box", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal, new Material(ColorAttribute.createDiffuse(Color.RED))) .box(5f, 1f, 5f); mb.node().id = "ball"; mb.part( "sphere", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal, new Material(ColorAttribute.createDiffuse(Color.GREEN))) .sphere(1f, 1f, 1f, 10, 10); model = mb.end(); ground = new ModelInstance(model, "ground"); ball = new ModelInstance(model, "ball"); ball.transform.setToTranslation(0, 9f, 0); instances = new Array<ModelInstance>(); instances.add(ground); instances.add(ball); ballShape = new btSphereShape(0.5f); groundShape = new btBoxShape(new Vector3(2.5f, 0.5f, 2.5f)); groundObject = new btCollisionObject(); groundObject.setCollisionShape(groundShape); groundObject.setWorldTransform(ground.transform); ballObject = new btCollisionObject(); ballObject.setCollisionShape(ballShape); ballObject.setWorldTransform(ball.transform); collisionConfig = new btDefaultCollisionConfiguration(); dispatcher = new btCollisionDispatcher(collisionConfig); }
@Override public void resize(int width, int height) { // Update screen dimensions screenWidth = width; screenHeight = height; // Update viewport size and refresh camera matrices camera.viewportWidth = width; camera.viewportHeight = height; camera.update(true); }
/** 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); }
@Override public boolean touchDragged(int x, int y, int pointer) { Ray ray = camera.getPickRay(x, y); Intersector.intersectRayPlane(ray, plane, curr); if (!(last.x == -1 && last.y == -1 && last.z == -1)) { ray = camera.getPickRay(last.x, last.y); Intersector.intersectRayPlane(ray, plane, delta); delta.sub(curr); camera.position.add(delta.x, delta.y, delta.z); } last.set(x, y, 0); return false; }
private int getObject(int screenX, int screenY) { Ray ray = cam.getPickRay(screenX, screenY); int result = -1; float distance = -1; for (int i = 0; i < instances.size; ++i) { final ObjectInstance instance = (ObjectInstance) instances.get(i); if (instance.equals(pitchInstance)) continue; instance.transform.getTranslation(position); position.add(instance.center); final float len = ray.direction.dot( position.x - ray.origin.x, position.y - ray.origin.y, position.z - ray.origin.z); if (len < 0f) continue; float dist2 = position.dst2( ray.origin.x + ray.direction.x * len, ray.origin.y + ray.direction.y * len, ray.origin.z + ray.direction.z * len); if (distance >= 0f && dist2 > distance) continue; if (dist2 <= instance.radius * instance.radius) { result = i; distance = dist2; } } return result; }
public PerspectiveCamera update(float deltaTime) { switch (getMode()) { case TRACKMODE: { if (mTrackedObjFrom == null) break; Vector3 trackPos = mTrackedObjFrom.getLocation(); Vector3 trackDir = mTrackedObjFrom.getDirection().tmp().nor(); getCamera() .position .set( calculateCamPos(trackPos, trackDir) .add(getCamera().up.tmp().scl(trackOffsetHeight))); getCamera().lookAt(trackPos.x, trackPos.y, trackPos.z); break; } case FRONTOMODE: { Vector3 trackFromPos = mTrackedObjFrom.getLocation(); Vector3 fromToToDir = mTrackedObjTo.getLocation().tmp().sub(mTrackedObjFrom.getLocation()).nor(); mCamera.position.set(calculateCamPos(trackFromPos, fromToToDir)); mCamera.direction.set(fromToToDir); break; } } mCamera.update(); return mCamera; }
@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(); }
public void shoot(final float x, final float y) { // Shoot a box Ray ray = camera.getPickRay(x, y); Entity entity = world.add("box", ray.origin.x, ray.origin.y, ray.origin.z); entity.color.set( 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f); entity.body.applyCentralImpulse(ray.direction.mul(30f)); }
@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; }
@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(); }
@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; }
@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)); }
@Override public void render() { GL10 gl = Gdx.gl10; gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glDepthFunc(GL10.GL_LEQUAL); gl.glEnable(GL10.GL_COLOR_MATERIAL); gl.glEnable(GL10.GL_LIGHTING); gl.glEnable(GL10.GL_LIGHT0); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient, 0); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPosition, 0); gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse, 0); camera.apply(Gdx.gl10); world.update(); }
public void update(Vector3 basePosition, Vector3 direction, float delta) { cam.direction.set(direction); setPosition(basePosition, delta); cam.update(); }
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); }
@Override public void create() { world = new World(); final float width = Gdx.graphics.getWidth(); final float height = Gdx.graphics.getHeight(); if (width > height) camera = new PerspectiveCamera(67f, 3f * width / height, 3f); else camera = new PerspectiveCamera(67f, 3f, 3f * height / width); camera.position.set(10f, 10f, 10f); camera.lookAt(0, 0, 0); camera.update(); // Create some simple meshes final Mesh groundMesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "a_position")); groundMesh.setVertices( new float[] {20f, 0f, 20f, 20f, 0f, -20f, -20f, 0f, 20f, -20f, 0f, -20f}); groundMesh.setIndices(new short[] {0, 1, 2, 1, 2, 3}); final Mesh boxMesh = new Mesh(true, 8, 36, new VertexAttribute(Usage.Position, 3, "a_position")); boxMesh.setVertices( new float[] { 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, -0.5f, -0.5f, -0.5f, 0.5f, -0.5f, -0.5f, -0.5f }); boxMesh.setIndices( new short[] { 0, 1, 2, 1, 2, 3, // top 4, 5, 6, 5, 6, 7, // bottom 0, 2, 4, 4, 6, 2, // front 1, 3, 5, 5, 7, 3, // back 2, 3, 6, 6, 7, 3, // left 0, 1, 4, 4, 5, 1 // right }); // Add the constructers world.constructors.put( "ground", new Entity.ConstructInfo(groundMesh, 0f)); // mass = 0: static body world.constructors.put( "box", new Entity.ConstructInfo(boxMesh, 1f)); // mass = 1kg: dynamic body }