List of usage examples for com.badlogic.gdx.math Matrix3 Matrix3
public Matrix3()
From source file:com.github.fauu.helix.core.MapRegionMesh.java
License:Open Source License
public void update() { ready = false;/* ww w .j a v a 2 s . co m*/ tileOffsets = new int[tiles.length]; final float[] vertices = new float[numVertices]; int vertexCount = 0; for (int i = 0; i < tiles.length; i++) { final Tile tile = tiles[i]; final Model tileGeometryModel = geometrySet.getGeometry(tile.getGeometryId()).getModel(); float[] geometryVertices = new float[(NUM_COMPONENTS - NUM_COLOR_COMPONENTS) * tileGeometryModel.meshes.first().getNumVertices()]; final Texture texture = textureAtlas.getTextures().first(); final TextureRegion tileTextureRegion = textureAtlas.getRegions().get(tile.getTextureId()); final Vector2 tileTextureCoords = new Vector2(tileTextureRegion.getU(), tileTextureRegion.getV2()); final Vector2 tileTextureScaling = new Vector2( (float) tileTextureRegion.getRegionWidth() / texture.getWidth(), (float) tileTextureRegion.getRegionHeight() / texture.getHeight()); float rotationDegrees = 0; switch (tile.getFacing()) { case SOUTH: rotationDegrees = -90; break; case WEST: rotationDegrees = -180; break; case NORTH: rotationDegrees = 90; break; case EAST: rotationDegrees = 0; break; default: } final Matrix3 transformationMatrixUV = new Matrix3().translate(tileTextureCoords) .scale(1 * tileTextureScaling.x, -1 * tileTextureScaling.y).translate(0, -1); final Matrix4 transformationMatrix = new Matrix4().translate( new Vector3(0.5f + tile.getPosition().x, tile.getElevation(), 0.5f + tile.getPosition().y)) .rotate(new Vector3(0, 1, 0), rotationDegrees); // Not sure if copying isn't slower than detransforming the original, but it fixes glitchy // edges final Mesh tileGeometryMesh = tileGeometryModel.meshes.first().copy(true); tileGeometryMesh.transform(transformationMatrix); tileGeometryMesh.transformUV(transformationMatrixUV); tileGeometryMesh.getVertices(geometryVertices); final float[] coloredVertices = new float[NUM_COMPONENTS * tileGeometryModel.meshes.get(0).getNumVertices()]; final Color tileColor = tile.getColor(); for (int j = 0, k = 0; j < coloredVertices.length; j++) { if ((j + 1) % 6 != 0) { coloredVertices[j] = geometryVertices[k++]; } else { coloredVertices[j] = tileColor.toFloatBits(); } } tileOffsets[i] = vertexCount; System.arraycopy(coloredVertices, 0, vertices, vertexCount, coloredVertices.length); vertexCount += coloredVertices.length; } setVertices(vertices, 0, vertexCount); ready = true; }
From source file:ve.ucv.ciens.ccg.nxtar.components.GeometryComponent.java
License:Apache License
public GeometryComponent() { this.position = new Vector3(); this.rotation = new Matrix3(); this.scaling = new Vector3(1.0f, 1.0f, 1.0f); }
From source file:ve.ucv.ciens.ccg.nxtar.MainActivity.java
License:Apache License
@Override public MarkerData findMarkersInFrame(byte[] frame) { if (ocvOn) {// ww w . j av a2s . c o m if (cameraCalibrated) { int[] codes = new int[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS]; float[] translations = new float[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS * 3]; float[] rotations = new float[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS * 9]; MarkerData data; Bitmap tFrame, mFrame; Mat inImg = new Mat(); Mat outImg = new Mat(); // Fill the codes array with -1 to indicate markers that were not found; for (int i : codes) codes[i] = -1; // Decode the input image and convert it to an OpenCV matrix. tFrame = BitmapFactory.decodeByteArray(frame, 0, frame.length); Utils.bitmapToMat(tFrame, inImg); // Find the markers in the input image. getMarkerCodesAndLocations(inImg.getNativeObjAddr(), outImg.getNativeObjAddr(), codes, cameraMatrix.getNativeObjAddr(), distortionCoeffs.getNativeObjAddr(), translations, rotations); // Encode the output image as a JPEG image. mFrame = Bitmap.createBitmap(outImg.cols(), outImg.rows(), Bitmap.Config.RGB_565); Utils.matToBitmap(outImg, mFrame); mFrame.compress(CompressFormat.JPEG, 100, outputStream); // Create and fill the output data structure. data = new MarkerData(); data.outFrame = outputStream.toByteArray(); data.markerCodes = codes; data.rotationMatrices = new Matrix3[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS]; data.translationVectors = new Vector3[ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS]; for (int i = 0, p = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++, p += 3) { data.translationVectors[i] = new Vector3(translations[p], translations[p + 1], translations[p + 2]); } for (int k = 0; k < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; k++) { data.rotationMatrices[k] = new Matrix3(); for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { data.rotationMatrices[k].val[col + (row * 3)] = rotations[col + (row * 3) + (9 * k)]; } } } // Clean up memory. tFrame.recycle(); mFrame.recycle(); outputStream.reset(); return data; } else { Gdx.app.debug(TAG, CLASS_NAME + ".findMarkersInFrame(): The camera has not been calibrated."); return null; } } else { Gdx.app.debug(TAG, CLASS_NAME + ".findMarkersInFrame(): OpenCV is not ready or failed to load."); return null; } }
From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameEntityCreator.java
License:Apache License
private void addRobotArm(EntityParameters parameters) { Entity robotArm = world.createEntity(); robotArm.addComponent(/*from w ww . j av a 2 s . c om*/ new GeometryComponent(new Vector3(ROBOT_ARM_START_POINT), new Matrix3(), new Vector3(1, 1, 1))); robotArm.addComponent(new EnvironmentComponent(parameters.environment)); robotArm.addComponent(new ShaderComponent(parameters.shader)); robotArm.addComponent(new RenderModelComponent(robotArmModel)); robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel)); robotArm.addComponent(new CollisionDetectionComponent()); robotArm.addComponent(new AutomaticMovementComponent()); robotArm.addToWorld(); entities.add(robotArm); }
From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameEntityCreator.java
License:Apache License
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException { Entity bomb;// ww w.j a v a 2s .com // Create a bomb entity and add it's generic components. bomb = world.createEntity(); bomb.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1))); bomb.addComponent(new EnvironmentComponent(parameters.environment)); bomb.addComponent(new ShaderComponent(parameters.shader)); bomb.addComponent(new MarkerCodeComponent(parameters.markerCode)); bomb.addComponent(new BombComponent(currentBombId, type)); bomb.addComponent(new VisibilityComponent()); // Add the collision and render models depending on the bomb type. if (type == bomb_type_t.COMBINATION) { bomb.addComponent(new RenderModelComponent(combinationBombModel)); bomb.addComponent(new CollisionModelComponent(combinationBombCollisionModel)); addBombCombinationButtons(parameters); if (DEBUG_RENDER_BOMB_COLLISION_MODELS) addDebugCollisionModelRenderingEntity(combinationBombCollisionModel, parameters, false); } else if (type == bomb_type_t.INCLINATION) { bomb.addComponent(new RenderModelComponent(inclinationBombModel)); bomb.addComponent(new CollisionModelComponent(inclinationBombCollisionModel)); addBombInclinationButton(parameters); if (DEBUG_RENDER_BOMB_COLLISION_MODELS) addDebugCollisionModelRenderingEntity(inclinationBombCollisionModel, parameters, false); } else if (type == bomb_type_t.WIRES) { bomb.addComponent(new RenderModelComponent(wiresBombModel)); bomb.addComponent(new CollisionModelComponent(wiresBombCollisionModel)); addBombWires(parameters); if (DEBUG_RENDER_BOMB_COLLISION_MODELS) addDebugCollisionModelRenderingEntity(wiresBombCollisionModel, parameters, false); } else throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue())); // Add the bomb to the world and the respective marker group. Then increase the id for the next bomb. groupManager.add(bomb, Integer.toString(parameters.markerCode)); bomb.addToWorld(); entities.add(bomb); currentBombId++; NUM_BOMBS++; }
From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameEntityCreator.java
License:Apache License
private Entity addBombParaphernalia(Model renderModel, Model collisionModel, EntityParameters parameters) { Entity thing;// w w w . j a v a 2 s. c o m thing = world.createEntity(); thing.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1))); thing.addComponent(new EnvironmentComponent(parameters.environment)); thing.addComponent(new ShaderComponent(parameters.shader)); thing.addComponent(new RenderModelComponent(renderModel)); thing.addComponent(new CollisionModelComponent(collisionModel)); thing.addComponent(new VisibilityComponent()); thing.addComponent(new MarkerCodeComponent(parameters.markerCode)); thing.addComponent(new CollisionDetectionComponent()); groupManager.add(thing, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP); groupManager.add(thing, Integer.toString(parameters.markerCode)); if (DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS) addDebugCollisionModelRenderingEntity(collisionModel, parameters, false); entities.add(thing); return thing; }
From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameEntityCreator.java
License:Apache License
private void addDoor(EntityParameters parameters) { ModelInstance doorInstance, doorColInstance; Entity frame, door;/*from w w w.j ava 2 s . co m*/ frame = world.createEntity(); frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1))); frame.addComponent(new RenderModelComponent(doorFrameModel)); frame.addComponent(new CollisionModelComponent(doorFrameCollisionModel)); frame.addComponent(new CollisionDetectionComponent()); frame.addComponent(new EnvironmentComponent(parameters.environment)); frame.addComponent(new ShaderComponent(parameters.shader)); frame.addComponent(new VisibilityComponent()); frame.addComponent(new MarkerCodeComponent(parameters.markerCode)); frame.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.DOOR_FRAME)); groupManager.add(frame, Integer.toString(parameters.markerCode)); frame.addToWorld(); door = world.createEntity(); door.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1))); door.addComponent(new RenderModelComponent(doorModel)); door.addComponent(new CollisionModelComponent(doorCollisionModel)); door.addComponent(new EnvironmentComponent(parameters.environment)); door.addComponent(new ShaderComponent(parameters.shader)); door.addComponent(new MarkerCodeComponent(parameters.markerCode)); door.addComponent(new VisibilityComponent()); doorInstance = door.getComponent(RenderModelComponent.class).instance; doorColInstance = door.getComponent(CollisionModelComponent.class).instance; door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation, doorColInstance)); door.addComponent(new CollisionDetectionComponent()); door.addComponent(new BombGameEntityTypeComponent(BombGameEntityTypeComponent.DOOR)); groupManager.add(door, CollisionDetectionSystem.COLLIDABLE_OBJECTS_GROUP); groupManager.add(door, Integer.toString(parameters.markerCode)); groupManager.add(door, DOORS_GROUP); door.addToWorld(); entities.add(frame); entities.add(door); if (DEBUG_RENDER_DOOR_COLLISION_MODELS) { addDebugCollisionModelRenderingEntity(doorFrameCollisionModel, parameters, false); addDebugCollisionModelRenderingEntity(doorCollisionModel, parameters, true); } }
From source file:ve.ucv.ciens.ccg.nxtar.scenarios.bombgame.BombGameEntityCreator.java
License:Apache License
private void addDebugCollisionModelRenderingEntity(Model collisionModel, EntityParameters parameters, boolean animation) { ModelInstance instance;/*w w w . j a v a2 s . com*/ Entity thing; thing = world.createEntity(); thing.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1))); thing.addComponent(new EnvironmentComponent(parameters.environment)); thing.addComponent(new ShaderComponent(parameters.shader)); thing.addComponent(new RenderModelComponent(collisionModel)); thing.addComponent(new VisibilityComponent()); thing.addComponent(new MarkerCodeComponent(parameters.markerCode)); if (animation) { instance = thing.getComponent(RenderModelComponent.class).instance; thing.addComponent( new AnimationComponent(instance, parameters.nextAnimation, parameters.loopAnimation)); } thing.addToWorld(); entities.add(thing); }