@Override public void create() { rotationSpeed = 0.5f; mesh = new Mesh(true, 4, 6, new VertexAttribute(VertexAttributes.Usage.Position, 3,"attr_Position"), new VertexAttribute(Usage.TextureCoordinates, 2, "attr_texCoords")); texture = new Texture(Gdx.files.internal("data/Jellyfish.jpg")); mesh.setVertices(new float[] { -1024f, -1024f, 0, 0, 1, 1024f, -1024f, 0, 1, 1, 1024f, 1024f, 0, 1, 0, -1024f, 1024f, 0, 0, 0 }); mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 }); cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); xScale = Gdx.graphics.getWidth()/(float)TARGET_WIDTH; yScale = Gdx.graphics.getHeight()/(float)TARGET_HEIGHT; font = loadBitmapFont("default.fnt", "default.png"); scale = Math.min(xScale, yScale); cam.zoom = 1/scale; // cam.project(start_position); cam.position.set(0, 0, 0); batch = new SpriteBatch(); }
/** * Instantiates a new ShaderEffect. The ShaderEffect will NOT own shader * program, so it will not dispose it either! * * @param program * the ShaderProgram to use for this effect */ public ShaderEffect(ShaderProgram program) { this.program = program; if (meshRefCount++ <= 0) { mesh = new Mesh(VertexDataType.VertexArray, true, 4, 0, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); // @formatter:off float[] verts = { // vertex texture -1, -1, 0f, 0f, 1, -1, 1f, 0f, 1, 1, 1f, 1f, -1, 1, 0f, 1f, }; // @formatter:on mesh.setVertices(verts); } }
@Deprecated //Only for creating the first one private void createEntity(float f, float g, float h) { Vector3 position=new Vector3(f,g,h); List<EntityStatic> collidingEntities=space.getWithin(position, 0.03); if(collidingEntities.size() == 0) { EntityStatic entity=new EntityStatic(new ModelInstance( Assets.modelBuilder.createBox(0.03f, 0.03f, 0.06f, new Material(StrategyGame.blueAttr), Usage.Normal | Usage.Position)), position); space.addEntity(entity); } else { for(EntityStatic e:collidingEntities){ e.damage(2); } } }
public PositionalLight (RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree) { super(rayHandler, rays, color, directionDegree, distance); start.x = x; start.y = y; sin = new float[rays]; cos = new float[rays]; endX = new float[rays]; endY = new float[rays]; lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); setMesh(); }
/** Directional lights simulate light source that locations is at infinite distance. Direction and intensity is same everywhere. * -90 direction is straight from up. * * @param rayHandler * @param rays * @param color * @param directionDegree */ public DirectionalLight (RayHandler rayHandler, int rays, Color color, float directionDegree) { super(rayHandler, rays, color, directionDegree, Float.POSITIVE_INFINITY); vertexNum = (vertexNum - 1) * 2; start = new Vector2[rayNum]; end = new Vector2[rayNum]; for (int i = 0; i < rayNum; i++) { start[i] = new Vector2(); end[i] = new Vector2(); } setDirection(direction); lightMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); update(); }
/** Creates chain light from specified vertices * * @param rayHandler not {@code null} instance of RayHandler * @param rays number of rays - more rays make light to look more realistic but will decrease performance, can't be less than * MIN_RAYS * @param color color, set to {@code null} to use the default color * @param distance distance of light * @param rayDirection direction of rays * <ul> * <li>1 = left</li> * <li>-1 = right</li> * </ul> * @param chain float array of (x, y) vertices from which rays will be evenly distributed */ public RavChainLight (RayHandler rayHandler, int rays, Color color, float distance, int rayDirection, float[] chain) { super(rayHandler, rays, color, distance, 0f); rayStartOffset = ChainLight.defaultRayStartOffset; this.rayDirection = rayDirection; vertexNum = (vertexNum - 1) * 2; endX = new float[rays]; endY = new float[rays]; startX = new float[rays]; startY = new float[rays]; this.chain = (chain != null) ? new FloatArray(chain) : new FloatArray(); lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"), new VertexAttribute(Usage.Generic, 1, "s")); setMesh(); }
public static Model createAxes() { final float GRID_MIN = -10f; final float GRID_MAX = 10f; final float GRID_STEP = 1f; ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material()); builder.setColor(Color.LIGHT_GRAY); for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) { builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX); builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t); } builder = modelBuilder.part("axes", GL20.GL_LINES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material()); builder.setColor(Color.RED); builder.line(0, 0, 0, 100, 0, 0); builder.setColor(Color.GREEN); builder.line(0, 0, 0, 0, 100, 0); builder.setColor(Color.BLUE); builder.line(0, 0, 0, 0, 0, 100); return modelBuilder.end(); }
@Override public boolean canRender (Renderable renderable) { if (renderable.material.has(BlendingAttribute.Type)) { if ((materialMask & BlendingAttribute.Type) != BlendingAttribute.Type) return false; if (renderable.material.has(TextureAttribute.Diffuse) != ((materialMask & TextureAttribute.Diffuse) == TextureAttribute.Diffuse)) return false; } final boolean skinned = ((renderable.mesh.getVertexAttributes().getMask() & Usage.BoneWeight) == Usage.BoneWeight); if (skinned != (numBones > 0)) return false; if (!skinned) return true; 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); } return w == weights; }
/** @param usage bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal and * TextureCoordinates is supported. */ public static VertexAttributes createAttributes (long usage) { final Array<VertexAttribute> attrs = new Array<VertexAttribute>(); if ((usage & Usage.Position) == Usage.Position) attrs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE)); if ((usage & Usage.Color) == Usage.Color) attrs.add(new VertexAttribute(Usage.Color, 4, ShaderProgram.COLOR_ATTRIBUTE)); if ((usage & Usage.ColorPacked) == Usage.ColorPacked) attrs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE)); if ((usage & Usage.Normal) == Usage.Normal) attrs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); if ((usage & Usage.TextureCoordinates) == Usage.TextureCoordinates) attrs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); final VertexAttribute attributes[] = new VertexAttribute[attrs.size]; for (int i = 0; i < attributes.length; i++) attributes[i] = attrs.get(i); return new VertexAttributes(attributes); }
@Override public void setMesh(Mesh mesh, Model model){ super.setMesh(mesh, model); vertexSize = mesh.getVertexSize()/4; positionOffset = mesh.getVertexAttribute(Usage.Position).offset/4; int indicesCount = mesh.getNumIndices(); if(indicesCount >0){ indices = new short[indicesCount]; mesh.getIndices(indices); triangleCount = indices.length/3; } else indices = null; vertexCount = mesh.getNumVertices(); vertices = new float[ vertexCount* vertexSize]; mesh.getVertices(vertices); }
@Override public void create () { modelBatch = new ModelBatch(); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f)); environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 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(30f, 10f, 30f); cam.lookAt(0, 0, 0); cam.near = 0.1f; cam.far = 45f; cam.update(); ModelBuilder modelBuilder = new ModelBuilder(); model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal); instance = new ModelInstance(model); Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam))); }
/** Constructs a new PolygonSpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards, * x-axis point to the right and the origin being in the bottom left corner of the screen. The projection will be pixel perfect * with respect to the current screen resolution. * <p> * The defaultShader specifies the shader to use. Note that the names for uniforms for this default shader are different than * the ones expect for shaders set with {@link #setShader(ShaderProgram)}. See {@link SpriteBatch#createDefaultShader()}. * @param size The max number of vertices and number of triangles in a single batch. Max of 10920. * @param defaultShader The default shader to use. This is not owned by the PolygonSpriteBatch and must be disposed separately. */ public PolygonSpriteBatch (int size, ShaderProgram defaultShader) { // 32767 is max index, so 32767 / 3 - (32767 / 3 % 3) = 10920. if (size > 10920) throw new IllegalArgumentException("Can't have more than 10920 triangles per batch: " + size); mesh = new Mesh(VertexDataType.VertexArray, false, size, size * 3, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); vertices = new float[size * VERTEX_SIZE]; triangles = new short[size * 3]; if (defaultShader == null) { shader = SpriteBatch.createDefaultShader(); ownsShader = true; } else shader = defaultShader; projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); }
@Override public void create () { modelBatch = new ModelBatch(new BaseShaderProvider() { @Override protected Shader createShader (Renderable renderable) { return new TestShader(); } }); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(10f, 10f, 10f); cam.lookAt(0, 0, 0); cam.near = 0.1f; cam.far = 300f; cam.update(); camController = new CameraInputController(cam); Gdx.input.setInputProcessor(camController); Material material = new Material(new TestAttribute(1f)); ModelBuilder builder = new ModelBuilder(); model = builder.createCone(5, 5, 5, 20, material, Usage.Position); instance = new ModelInstance(model); testAttribute = (TestAttribute)instance.materials.get(0).get(TestAttribute.ID); }
@Override public void create () { modelBatch = new ModelBatch(new DefaultShaderProvider()); // modelBatch = new ModelBatch(); environment = new Environment(); environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .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(10f, 10f, 10f); cam.lookAt(0, 0, 0); cam.near = 0.1f; cam.far = 300f; cam.update(); ModelBuilder modelBuilder = new ModelBuilder(); model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal); instance = new ModelInstance(model); // model = new G3dModelLoader(new UBJsonReader()).loadModel(Gdx.files.internal("data/g3d/knight.g3db")); // instance = new ModelInstance(model); Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam))); }
@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(10f, 10f, 10f); cam.lookAt(0, 0, 0); cam.near = 1f; cam.far = 300f; cam.update(); camController = new CameraInputController(cam); Gdx.input.setInputProcessor(camController); ModelBuilder modelBuilder = new ModelBuilder(); model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal); instance = new ModelInstance(model); }
private void createAxes () { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.Color, new Material()); builder.setColor(Color.LIGHT_GRAY); for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) { builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX); builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t); } builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.Color, new Material()); builder.setColor(Color.RED); builder.line(0, 0, 0, 100, 0, 0); builder.setColor(Color.GREEN); builder.line(0, 0, 0, 0, 100, 0); builder.setColor(Color.BLUE); builder.line(0, 0, 0, 0, 0, 100); axesModel = modelBuilder.end(); axesInstance = new ModelInstance(axesModel); }
public void setupScene () { plane = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute( Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); plane.setVertices(new float[] {-10, -1, 10, 0, 1, 0, 10, -1, 10, 0, 1, 0, 10, -1, -10, 0, 1, 0, -10, -1, -10, 0, 1, 0}); plane.setIndices(new short[] {3, 2, 1, 1, 0, 3}); texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true); texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest); cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam.position.set(0, 5, 10); cam.lookAt(0, 0, 0); cam.update(); controller = new PerspectiveCamController(cam); projector = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); projector.position.set(2, 3, 2); projector.lookAt(0, 0, 0); projector.normalizeUp(); projector.update(); }
@Override public void create () { mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); float c1 = Color.toFloatBits(255, 0, 0, 255); float c2 = Color.toFloatBits(255, 0, 0, 255); float c3 = Color.toFloatBits(0, 0, 255, 255); mesh.setVertices(new float[] {-0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1}); stencilMesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute( Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords")); stencilMesh.setVertices(new float[] {-0.5f, 0.5f, 0, c1, 0, 0, 0.5f, 0.5f, 0, c2, 1, 0, 0, -0.5f, 0, c3, 0.5f, 1}); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); spriteBatch = new SpriteBatch(); frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false); stencilFrameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false, true); createShader(Gdx.graphics); }
@Override public void create () { ModelBuilder builder = new ModelBuilder(); sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), Usage.Position | Usage.Normal); // cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); cam = new OrthographicCamera(45, 45 * (Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight())); cam.near = 1; cam.far = 200; Random rand = new Random(); for (int i = 0; i < instances.length; i++) { pos.set(rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3); instances[i] = new ModelInstance(sphere, pos); } modelBatch = new ModelBatch(); batch = new SpriteBatch(); font = new BitmapFont(); // Gdx.graphics.setVSync(true); // Gdx.app.log("CullTest", "" + Gdx.graphics.getBufferFormat().toString()); }
public ModelInstance createAxes () { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.Color, new Material()); builder.setColor(Color.LIGHT_GRAY); for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) { builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX); builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t); } builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.Color, new Material()); builder.setColor(Color.RED); builder.line(0, 0, 0, 100, 0, 0); builder.setColor(Color.GREEN); builder.line(0, 0, 0, 0, 100, 0); builder.setColor(Color.BLUE); builder.line(0, 0, 0, 0, 0, 100); Model axesModel = modelBuilder.end(); ModelInstance axesInstance = new ModelInstance(axesModel); return axesInstance; }
public Renderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) { this.maxVertices = maxVertices; this.numTexCoords = numTexCoords; this.shader = shader; VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords); mesh = new Mesh(false, maxVertices, 0, attribs); vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)]; vertexSize = mesh.getVertexAttributes().vertexSize / 4; normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0; colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh .getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; }
public Game3d(){ ship = Asset.loadModelObj("ship");//loads an obj model ship.scale(3f); skydome = Asset.loadModel("skydome"); //loads a g3db model builder = new ModelBuilder(); builder.begin(); MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material()); for (float x = -200f; x < 200f; x += 10f) { for (float z = -200f; z < 200f; z += 10f) { part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0); } } floor = new Actor3d(builder.end()); floor.materials.get(0).set(TextureAttribute.createDiffuse(Asset.tex("concrete").getTexture())); knight = Asset.loadModel("knight"); knight.setPosition(-20f, 18f, 0f); knight.setPitch(-90f); addActor3d(floor); addActor3d(skydome); addActor3d(ship); addActor3d(knight); stage3d.getCamera().position.set(knight.getX()+ 13f, knight.getY() + 24f, knight.getZ() + 45f); //Camera3d.followOffset(20f, 20f, -20f); // Camera3d.followActor3d(knight, false); }
@Override public void create() { assets = new AssetManager(); String model = "Bambo_House.g3db"; assets.load(model, Model.class); assets.finishLoading(); modelInstance = new ModelInstance(assets.get(model, Model.class), new Matrix4().setToScaling(0.6f, 0.6f, 0.6f)); DefaultShader.Config config = new Config(); config.defaultCullFace = GL20.GL_NONE; ShaderProvider shaderProvider = new DefaultShaderProvider(config); modelBatch = new ModelBatch(shaderProvider); ModelBuilder builder = new ModelBuilder(); float groundSize = 1000f; ground = new ModelInstance(builder.createRect(-groundSize, 0, groundSize, groundSize, 0, groundSize, groundSize, 0, -groundSize, -groundSize, 0, -groundSize, 0, 1, 0, new Material(), Usage.Position | Usage.Normal), new Matrix4().setToTranslation(0, -0.01f, 0)); 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)); VirtualReality.renderer.listeners.add(this); // VirtualReality.head.setCyclops(true); }
@Override public void create () { // Init camera this.camera = new PerspectiveCamera(70, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); this.camera.position.set(0,0,-20); this.camera.lookAt(0,0,0); this.camera.near = 0.05f; this.camera.far = 600.0f; this.camera.update(); // Init test shader this.testShader = ShaderLoader.loadShader("test"); // Init test buffer this.testBufferObject = new DynamicVertexBufferObject(3, new VertexAttributes(new VertexAttribute(Usage.Position, 4, "a_position"))); float[] vertices = new float[] { -10,0,0,1,0,2.5f,0,1,10,0,0,1 }; this.testBufferObject.setVertices(vertices, 0, vertices.length); }
private void init(String tex0, float w, float h) { setTexture0(tex0); // Init comparator comp = new DistToCameraComparator<IRenderable>(); // Init vertices float[] vertices = new float[20]; fillVertices(vertices, w, h); // We wont need indices if we use GL_TRIANGLE_FAN to draw our quad // TRIANGLE_FAN will draw the verts in this order: 0, 1, 2; 0, 2, 3 mesh = new Mesh(VertexDataType.VertexArray, true, 4, 6, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); mesh.setVertices(vertices, 0, vertices.length); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(6); short[] indices = new short[] { 0, 1, 2, 0, 2, 3 }; mesh.setIndices(indices); quaternion = new Quaternion(); aux = new Vector3(); }
@Override protected void initVertices() { meshes = new MeshData[2]; maxVertices = MAX_VERTICES; // ORIGINAL LINES curr = new MeshData(); meshes[0] = curr; VertexAttribute[] attribs = buildVertexAttributes(); curr.mesh = new Mesh(false, maxVertices, 0, attribs); curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)]; curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4; curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; }
private void initVertices(int index) { if (meshes[index] == null) { currext = new MeshDataExt(); meshes[index] = currext; curr = currext; maxVertices = MAX_VERTICES; currext.maxIndices = maxVertices + maxVertices / 2; VertexAttribute[] attribs = buildVertexAttributes(); currext.mesh = new Mesh(Mesh.VertexDataType.VertexArray, false, maxVertices, currext.maxIndices, attribs); currext.indices = new short[currext.maxIndices]; currext.vertexSize = currext.mesh.getVertexAttributes().vertexSize / 4; currext.vertices = new float[maxVertices * currext.vertexSize]; currext.colorOffset = currext.mesh.getVertexAttribute(Usage.ColorPacked) != null ? currext.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; currext.uvOffset = currext.mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? currext.mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; } else { currext = (MeshDataExt) meshes[index]; curr = currext; } }
public StaticPlaneSimulationObject(Vector3 planeNormal, float planeConstant, float friction, int width, int height, Texture texture, boolean disposeTexture) { super(); this.texture = texture; this.disposeTexture = disposeTexture; this.mesh = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, "position"), new VertexAttribute( Usage.TextureCoordinates, 2, "texture")); this.mesh.setVertices(new float[] { // Bottom left, tex -width / 2f, -height / 2f, 0, 0, 0, // Bottom right, tex width / 2f, -height / 2f, 0, width, 0, // Top right, tex width / 2f, height / 2f, 0, width, height, // Top left, tex -width / 2f, height / 2f, 0, 0, height }); this.mesh.setIndices(new short[] { 0, 1, 2, 0, 3, 2 }); this.staticPlaneShape = new btStaticPlaneShape(planeNormal, planeConstant); initialize(this.staticPlaneShape, 0, -1, DEFAULT_START_TRANSFORM); }
private void init(float w, float h) { // Init comparator comp = new DistToCameraComparator<IRenderable>(); // Init vertices float[] vertices = new float[20]; fillVertices(vertices, w, h); // We wont need indices if we use GL_TRIANGLE_FAN to draw our quad // TRIANGLE_FAN will draw the verts in this order: 0, 1, 2; 0, 2, 3 mesh = new Mesh(VertexDataType.VertexArray, true, 4, 6, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); mesh.setVertices(vertices, 0, vertices.length); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(6); short[] indices = new short[] { 0, 1, 2, 0, 2, 3 }; mesh.setIndices(indices); quaternion = new Quaternion(); aux = new Vector3(); }
@Override protected void initVertices() { /** STARS **/ meshes = new MeshData[1]; curr = new MeshData(); meshes[0] = curr; aux1 = new Vector3(); maxVertices = 10000000; VertexAttribute[] attribs = buildVertexAttributes(); curr.mesh = new Mesh(false, maxVertices, 0, attribs); curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)]; curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4; curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; pmOffset = curr.mesh.getVertexAttribute(Usage.Tangent) != null ? curr.mesh.getVertexAttribute(Usage.Tangent).offset / 4 : 0; additionalOffset = curr.mesh.getVertexAttribute(Usage.Generic) != null ? curr.mesh.getVertexAttribute(Usage.Generic).offset / 4 : 0; }
/** @param usage bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal and * TextureCoordinates is supported. */ public static VertexAttributes createAttributes(long usage) { final Array<VertexAttribute> attrs = new Array<VertexAttribute>(); if ((usage & Usage.Position) == Usage.Position) attrs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE)); if ((usage & Usage.ColorUnpacked) == Usage.ColorUnpacked) attrs.add(new VertexAttribute(Usage.ColorUnpacked, 4, ShaderProgram.COLOR_ATTRIBUTE)); if ((usage & Usage.ColorPacked) == Usage.ColorPacked) attrs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE)); if ((usage & Usage.Normal) == Usage.Normal) attrs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE)); if ((usage & Usage.TextureCoordinates) == Usage.TextureCoordinates) attrs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); final VertexAttribute attributes[] = new VertexAttribute[attrs.size]; for (int i = 0; i < attributes.length; i++) attributes[i] = attrs.get(i); return new VertexAttributes(attributes); }
public ImmediateRenderer(int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) { this.maxVertices = maxVertices; this.numTexCoords = numTexCoords; this.shader = shader; VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords); mesh = new Mesh(false, maxVertices, 0, attribs); vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)]; vertexSize = mesh.getVertexAttributes().vertexSize / 4; normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0; colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0; texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0; shaderUniformNames = new String[numTexCoords]; for (int i = 0; i < numTexCoords; i++) { shaderUniformNames[i] = "u_sampler" + i; } }
public static void createFloor() { 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, -0.1f, 0, 10, .2f, 10); mpb.rect(-10, 0, -10, -10, 0, 10, 10, 0, 10, 10, 0, -10, 0, 1, 0); floorModel = modelBuilder.end(); floorInstance = new ModelInstance(floorModel); // TODO Set only when FBO is active floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)); }
private static void createAxes() { ModelBuilder modelBuilder = new ModelBuilder(); modelBuilder.begin(); MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material()); builder.setColor(Color.LIGHT_GRAY); for (float t = GRID_MIN; t <= GRID_MAX; t+=GRID_STEP) { builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX); builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t); } builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material()); builder.setColor(Color.RED); builder.line(0, 0, 0, 10, 0, 0); builder.setColor(Color.GREEN); builder.line(0, 0, 0, 0, 10, 0); builder.setColor(Color.BLUE); builder.line(0, 0, 0, 0, 0, 10); axesModel = modelBuilder.end(); axesInstance = new ModelInstance(axesModel); }
/** Generate vertex attributes suitable for multi-texturing and vertex color. 32 bit floats are used for each position * component and texture coordinate. The four color components are packed into a single 32 bit float. * @param textureCount The number of textures to support. * @param position3D Whether the position attribute should include a Z component. * @param textureCoordinates3D Whether the texture coordinate attribute(s) should include a third component. * @param attributes The array to add the vertex attributes to. They are added with position and color in the first two * available positions, followed by texture coordinates. */ public static void addBaseAttributes (Array<VertexAttribute> attributes, int textureCount, boolean position3D, boolean textureCoordinates3D) { attributes.add(new VertexAttribute(Usage.Position, position3D ? 3 : 2, ShaderProgram.POSITION_ATTRIBUTE)); attributes.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE)); for (int i = 0; i < textureCount; i++) { attributes.add( new VertexAttribute(Usage.TextureCoordinates, textureCoordinates3D ? 3 : 2, ShaderProgram.TEXCOORD_ATTRIBUTE + i, i)); } }
public FullScreenFader(float delay, float fadeTime, Color initialColor){ this.delay = delay; this.fadeTime = fadeTime; mesh=new Mesh(true, 4, 0, new VertexAttribute(Usage.Position, 3,"a_position")); mesh.setVertices(vertices); this.color.set(initialColor); color.a = 1f; }