public void drawBoundingVolume(Camera camera, final Matrix4 vpMatrix, final Matrix4 projMatrix, final Matrix4 vMatrix, final Matrix4 mMatrix) { if (mVisualBox == null) { mVisualBox = new Cube(1); Material material = new Material(); mVisualBox.setMaterial(material); mVisualBox.setColor(mBoundingColor.get()); mVisualBox.setDrawingMode(GLES20.GL_LINE_LOOP); mVisualBox.setDoubleSided(true); } mVisualBox.setScale( Math.abs(mTransformedMax.x - mTransformedMin.x), Math.abs(mTransformedMax.y - mTransformedMin.y), Math.abs(mTransformedMax.z - mTransformedMin.z) ); mVisualBox.setPosition( mTransformedMin.x + (mTransformedMax.x - mTransformedMin.x) * .5, mTransformedMin.y + (mTransformedMax.y - mTransformedMin.y) * .5, mTransformedMin.z + (mTransformedMax.z - mTransformedMin.z) * .5 ); mVisualBox.render(camera, vpMatrix, projMatrix, vMatrix, mTmpMatrix, null); }
@Override protected void doTask() { // ensure all cameras can see the far side of the skybox float out_radius = (float)skybox.getGeometry().getBoundingSphere().getRadius(); float in_radius = out_radius/(float)Math.sqrt(3); float median_diagonal = in_radius + out_radius; for (int i = 0, j = mCameras.size(); i < j; ++i) if(mCameras.get(i).getFarPlane() < median_diagonal) { mCameras.get(i).setFarPlane(median_diagonal); } } };
/** * Creates a cube primitive. * * @param size The size of the cube. * @param isSkybox A boolean that indicates whether this is a skybox or not. If set to true the normals will * be inverted. * @param hasCubemapTexture A boolean that indicates a cube map texture will be used (6 textures) or a regular * single texture. * @param createTextureCoordinates A boolean that indicates whether the texture coordinates should be calculated or not. * @param createVertexColorBuffer A boolean that indicates whether a vertex color buffer should be created or not. * @param createVBOs A boolean that indicates whether the VBOs should be created immediately. */ public Cube(float size, boolean isSkybox, boolean hasCubemapTexture, boolean createTextureCoordinates, boolean createVertexColorBuffer, boolean createVBOs) { super(); mIsSkybox = isSkybox; mSize = size; mHasCubemapTexture = hasCubemapTexture; mCreateTextureCoords = createTextureCoordinates; mCreateVertexColorBuffer = createVertexColorBuffer; init(createVBOs); }
}; setData(vertices, normals, mIsSkybox || mHasCubemapTexture ? skyboxTextureCoords : textureCoords, colors, indices, createVBOs); if(mIsSkybox) setDoubleSided(true);
/** * Creates a skybox with the specified single texture. * * @param resourceId int Resouce id of the skybox texture. * @throws TextureException * * @return {@code boolean} True if the clear task was queued successfully. */ public boolean setSkybox(int resourceId) throws TextureException { Cube skybox = new Cube(700, true, false); skybox.setDoubleSided(true); Texture texture = new Texture("skybox", resourceId); Material material = new Material(); material.setColorInfluence(0); material.addTexture(texture); skybox.setMaterial(material); return setSkybox(skybox, texture); }
/** * Creates a skybox with the specified 6 {@link Bitmap} textures. * * @param bitmaps {@link Bitmap} array containing the cube map textures. */ public boolean setSkybox(Bitmap[] bitmaps) throws TextureException { final Cube skybox = new Cube(700, true); final CubeMapTexture texture = new CubeMapTexture("bitmap_skybox", bitmaps); texture.isSkyTexture(true); final Material material = new Material(); material.setColorInfluence(0); material.addTexture(texture); skybox.setMaterial(material); return setSkybox(skybox, texture); }
final Cube cube = new Cube(0.25f); cube.setMaterial(material); cube.setColor(0xffffff00); // Yellow addChild(cube);
@Test public void testApplyCube() { Cube cube = new Cube(1, false, false, false, false, false); cube.getGeometry().getBoundingBox(); visitor.apply(cube); assertNull(visitor.getPickedObject()); }
GLES20.glDepthMask(false); mSkybox.setPosition(mCamera.getX(), mCamera.getY(), mCamera.getZ()); mSkybox.render(mCamera, mVPMatrix, mPMatrix, mVMatrix, null);
/** * Reloads this scene. */ public void reload() { reloadChildren(); if(mSkybox != null) mSkybox.reload(); reloadPlugins(); mReloadPickerInfo = true; }
public void setBoundingColor(int color) { mBoundingColor.set(color); if (mVisualBox != null) { mVisualBox.setColor(color); } }
/** * Creates a skybox with the specified 6 textures. * * @param posx int Resource id for the front face. * @param negx int Resource id for the right face. * @param posy int Resource id for the back face. * @param negy int Resource id for the left face. * @param posz int Resource id for the up face. * @param negz int Resource id for the down face. * @throws TextureException */ public boolean setSkybox(int posx, int negx, int posy, int negy, int posz, int negz) throws TextureException { Cube skybox = new Cube(700, true); int[] resourceIds = new int[] { posx, negx, posy, negy, posz, negz }; CubeMapTexture texture = new CubeMapTexture("skybox", resourceIds); texture.isSkyTexture(true); Material mat = new Material(); mat.setColorInfluence(0); mat.addTexture(texture); skybox.setMaterial(mat); return setSkybox(skybox, texture); }
/** * Creates a skybox with the specified single texture. * * @param resourceId int Resouce id of the skybox texture. * @throws TextureException */ public void setSkybox(int resourceId) throws TextureException { synchronized (mCameras) { for (int i = 0, j = mCameras.size(); i < j; ++i) mCameras.get(i).setFarPlane(1000); } synchronized (mNextSkyboxLock) { mNextSkybox = new Cube(700, true, false); mNextSkybox.setDoubleSided(true); mSkyboxTexture = new Texture("skybox", resourceId); Material material = new Material(); material.setColorInfluence(0); material.addTexture(mSkyboxTexture); mNextSkybox.setMaterial(material); } }
}; setData(vertices, normals, mIsSkybox || mHasCubemapTexture ? skyboxTextureCoords : textureCoords, colors, indices, createVBOs); if(mIsSkybox) setDoubleSided(true);
GLES20.glDepthMask(false); mSkybox.setPosition(mCamera.getX(), mCamera.getY(), mCamera.getZ()); mSkybox.render(mCamera, mVPMatrix, mPMatrix, mVMatrix, null);
/** * Reloads this scene. */ public void reload() { reloadChildren(); if (mSkybox != null) mSkybox.reload(); reloadPlugins(); mReloadPickerInfo = true; }
public void setBoundingColor(int color) { mBoundingColor.set(color); if (mVisualBox != null) { mVisualBox.setColor(color); } }
public void drawBoundingVolume(Camera camera, final Matrix4 vpMatrix, final Matrix4 projMatrix, final Matrix4 vMatrix, final Matrix4 mMatrix) { if (mVisualBox == null) { mVisualBox = new Cube(1); Material material = new Material(); mVisualBox.setMaterial(material); mVisualBox.setColor(mBoundingColor.get()); mVisualBox.setDrawingMode(GLES20.GL_LINE_LOOP); mVisualBox.setDoubleSided(true); } mVisualBox.setScale( Math.abs(mTransformedMax.x - mTransformedMin.x), Math.abs(mTransformedMax.y - mTransformedMin.y), Math.abs(mTransformedMax.z - mTransformedMin.z) ); mVisualBox.setPosition( mTransformedMin.x + (mTransformedMax.x - mTransformedMin.x) * .5, mTransformedMin.y + (mTransformedMax.y - mTransformedMin.y) * .5, mTransformedMin.z + (mTransformedMax.z - mTransformedMin.z) * .5 ); mVisualBox.render(camera, vpMatrix, projMatrix, vMatrix, mTmpMatrix, null); }
/** * Creates a skybox with the specified 6 textures. * * @param posx int Resource id for the front face. * @param negx int Resource id for the right face. * @param posy int Resource id for the back face. * @param negy int Resource id for the left face. * @param posz int Resource id for the up face. * @param negz int Resource id for the down face. * @throws TextureException */ public void setSkybox(int posx, int negx, int posy, int negy, int posz, int negz) throws TextureException { synchronized (mCameras) { for (int i = 0, j = mCameras.size(); i < j; ++i) mCameras.get(i).setFarPlane(1000); } synchronized (mNextSkyboxLock) { mNextSkybox = new Cube(700, true); int[] resourceIds = new int[]{posx, negx, posy, negy, posz, negz}; mSkyboxTexture = new CubeMapTexture("skybox", resourceIds); ((CubeMapTexture) mSkyboxTexture).isSkyTexture(true); Material mat = new Material(); mat.setColorInfluence(0); mat.addTexture(mSkyboxTexture); mNextSkybox.setMaterial(mat); } }
/** * Creates a cube primitive. * * @param size The size of the cube. * @param isSkybox A boolean that indicates whether this is a skybox or not. If set to true the normals will * be inverted. * @param hasCubemapTexture A boolean that indicates a cube map texture will be used (6 textures) or a regular * single texture. * @param createTextureCoordinates A boolean that indicates whether the texture coordinates should be calculated or not. * @param createVertexColorBuffer A boolean that indicates whether a vertex color buffer should be created or not. * @param createVBOs A boolean that indicates whether the VBOs should be created immediately. */ public Cube(float size, boolean isSkybox, boolean hasCubemapTexture, boolean createTextureCoordinates, boolean createVertexColorBuffer, boolean createVBOs) { super(); mIsSkybox = isSkybox; mSize = size; mHasCubemapTexture = hasCubemapTexture; mCreateTextureCoords = createTextureCoordinates; mCreateVertexColorBuffer = createVertexColorBuffer; init(createVBOs); }