List of usage examples for com.badlogic.gdx.math Vector3 crs
public Vector3 crs(final Vector3 vector)
From source file:com.badlogic.gdx.physics.bullet.demo.simulationobjects.StaticPlaneSimulationObject.java
@Override public void render(SimulationScreen screen) { /*/* w w w.j av a2 s . com*/ * Our StaticPlaneShape holds the plane vector and scalar. Use it instead of the applied render transform from * the kinematic (not updated/calculated for static planes). */ Gdx.gl10.glPushMatrix(); // Get the plane normal final Vector3 planeNormal = Pools.VECTOR3.obtain(); planeNormal.set(staticPlaneShape.getPlaneNormal()); final float planeConstant = staticPlaneShape.getPlaneConstant(); // Calculate the plane origin final Vector3 planeOrigin = Pools.VECTOR3.obtain(); planeOrigin.set(planeNormal); planeOrigin.scale(planeConstant, planeConstant, planeConstant); // Move to the origin Gdx.gl10.glTranslatef(planeOrigin.x, planeOrigin.y, planeOrigin.z); // Compute the angle difference between the plane and mesh normal ("up") float angle = MathUtils.radiansToDegrees * BulletDemoMath.angle(planeNormal, MESH_NORMAL); // Cross product gives us the vector around which to rotate planeNormal.crs(MESH_NORMAL); // Rotate by that angle Gdx.gl10.glRotatef(angle, planeNormal.x, planeNormal.y, planeNormal.z); Gdx.gl10.glColor4f(1, 1, 1, 1); Gdx.gl10.glEnable(GL10.GL_TEXTURE_2D); Gdx.gl10.glEnable(GL10.GL_COLOR_MATERIAL); screen.enableLights(); texture.bind(); mesh.render(GL10.GL_TRIANGLE_STRIP); Gdx.gl10.glPopMatrix(); Pools.VECTOR3.free(planeNormal); Pools.VECTOR3.free(planeOrigin); }
From source file:com.lyeeedar.Roguelike3D.Game.GameObject.java
License:Open Source License
public void Yrotate(float angle) { Vector3 dir = Pools.obtain(Vector3.class); dir.set(rotation).nor();/*from w w w. ja v a2s . c om*/ if (dir.y > -0.7 && angle < 0 || dir.y < +0.7 && angle > 0) { Vector3 localAxisX = Pools.obtain(Vector3.class).set(rotation); localAxisX.crs(up).nor(); rotate(localAxisX.x, localAxisX.y, localAxisX.z, angle); Pools.free(localAxisX); } Pools.free(dir); }
From source file:gaia.cu9.ari.gaiaorbit.util.g3d.MeshBuilder2.java
License:Apache License
@Override public void arrow(float x1, float y1, float z1, float x2, float y2, float z2, float capLength, float stemThickness, int divisions) { Vector3 begin = tmp(x1, y1, z1), end = tmp(x2, y2, z2); float length = begin.dst(end); float coneHeight = length * capLength; float coneDiameter = 2 * (float) (coneHeight * Math.sqrt(1f / 3)); float stemLength = length - coneHeight; float stemDiameter = coneDiameter * stemThickness; Vector3 up = tmp(end).sub(begin).nor(); Vector3 forward = tmp(up).crs(Vector3.Z); if (forward.isZero()) forward.set(Vector3.X);//www . jav a2 s .co m forward.crs(up).nor(); Vector3 left = tmp(up).crs(forward).nor(); Vector3 direction = tmp(end).sub(begin).nor(); // Matrices Matrix4 userTransform = getVertexTransform(tmp()); Matrix4 transform = tmp(); float[] val = transform.val; val[Matrix4.M00] = left.x; val[Matrix4.M01] = up.x; val[Matrix4.M02] = forward.x; val[Matrix4.M10] = left.y; val[Matrix4.M11] = up.y; val[Matrix4.M12] = forward.y; val[Matrix4.M20] = left.z; val[Matrix4.M21] = up.z; val[Matrix4.M22] = forward.z; Matrix4 temp = tmp(); // Stem transform.setTranslation(tmp(direction).scl(stemLength / 2).add(x1, y1, z1)); setVertexTransform(temp.set(transform).mul(userTransform)); cylinder(stemDiameter, stemLength, stemDiameter, divisions); // Cap transform.setTranslation(tmp(direction).scl(stemLength).add(x1, y1, z1)); setVertexTransform(temp.set(transform).mul(userTransform)); cone(coneDiameter, coneHeight, coneDiameter, divisions); setVertexTransform(userTransform); cleanup(); }
From source file:mobi.shad.s3lib.gfx.g3d.simpleobject.TorusKnot.java
License:Apache License
/** * @param radius//from w w w .ja v a2s .c om * @param tube * @param radialSegments * @param tubularSegments * @param p * @param q * @param heightScale * @return */ public static ObjectMesh torusKnot(float radius, float tube, int radialSegments, int tubularSegments, float p, float q, float heightScale) { init(); tube = tube * 0.1f; Vector3[][] grid = new Vector3[radialSegments][tubularSegments]; Vector3 tang = new Vector3(); Vector3 n = new Vector3(); Vector3 bitan = new Vector3(); float cx = 0; float cy = 0; for (int i = 0; i < radialSegments; ++i) { for (int j = 0; j < tubularSegments; ++j) { float u = (float) ((float) i / (float) radialSegments * 2 * p * Math.PI); float v = (float) ((float) j / (float) tubularSegments * 2 * q * Math.PI); Vector3 p1 = getTorusKnotVector(u, v, q, p, radius, heightScale); Vector3 p2 = getTorusKnotVector(u + 0.01f, v, q, p, radius, heightScale); tang.set(p2); tang.sub(p1); n.set(p2); n.add(p1); bitan.set(tang); bitan.crs(n); n.set(bitan); n.crs(tang); bitan.nor(); n.nor(); cx = (float) (-tube * Math.cos(v)); cy = (float) (tube * Math.sin(v)); p1.x += cx * n.x + cy * bitan.x; p1.y += cx * n.y + cy * bitan.y; p1.z += cx * n.z + cy * bitan.z; grid[i][j] = p1; } } for (int i = 0; i < radialSegments; ++i) { for (int j = 0; j < tubularSegments; ++j) { int ip = (i + 1) % radialSegments; int jp = (j + 1) % tubularSegments; Vector3 a = grid[i][j]; Vector3 b = grid[ip][j]; Vector3 c = grid[ip][jp]; Vector3 d = grid[i][jp]; Vector2 uva = new Vector2((float) i / (float) radialSegments, (float) j / (float) tubularSegments); Vector2 uvb = new Vector2((float) (i + 1) / (float) radialSegments, (float) j / (float) tubularSegments); Vector2 uvc = new Vector2((float) (i + 1) / (float) radialSegments, (float) (j + 1) / (float) tubularSegments); Vector2 uvd = new Vector2((float) i / (float) radialSegments, (float) (j + 1) / (float) tubularSegments); mesh.addVertex(a, uva); mesh.addVertex(b, uvb); mesh.addVertex(c, uvc); mesh.addVertex(d, uvd); // // What wrong ? // mesh.addVertex(a, uva); // mesh.addVertex(b, uvb); // mesh.addVertex(c, uvc); // mesh.addVertex(d, uvd); mesh.indicesBuffer.ensureCapacity(6); mesh.indicesBuffer.add((short) (mesh.vertexIndex - 4)); mesh.indicesBuffer.add((short) (mesh.vertexIndex - 3)); mesh.indicesBuffer.add((short) (mesh.vertexIndex - 2)); mesh.indicesBuffer.add((short) (mesh.vertexIndex - 2)); mesh.indicesBuffer.add((short) (mesh.vertexIndex - 1)); mesh.indicesBuffer.add((short) (mesh.vertexIndex - 4)); } } return mesh; }
From source file:mobi.shad.s3lib.gfx.g3d.simpleobject.VertexTorusKnot.java
License:Apache License
/** * @param radius/*from w ww. ja v a2s . c om*/ * @param tube * @param radialSegments * @param tubularSegments * @param p * @param q * @param heightScale * @return */ public static S3Mesh torusKnot(float radius, float tube, int radialSegments, int tubularSegments, float p, float q, float heightScale) { init(); tube = tube * 0.1f; Vector3[][] grid = new Vector3[radialSegments][tubularSegments]; Vector3 tang = new Vector3(); Vector3 n = new Vector3(); Vector3 bitan = new Vector3(); float cx = 0; float cy = 0; for (int i = 0; i < radialSegments; ++i) { for (int j = 0; j < tubularSegments; ++j) { float u = (float) ((float) i / (float) radialSegments * 2 * p * Math.PI); float v = (float) ((float) j / (float) tubularSegments * 2 * q * Math.PI); Vector3 p1 = getTorusKnotVector(u, v, q, p, radius, heightScale); Vector3 p2 = getTorusKnotVector(u + 0.01f, v, q, p, radius, heightScale); tang.set(p2); tang.sub(p1); n.set(p2); n.add(p1); bitan.set(tang); bitan.crs(n); n.set(bitan); n.crs(tang); bitan.nor(); n.nor(); cx = (float) (-tube * Math.cos(v)); cy = (float) (tube * Math.sin(v)); p1.x += cx * n.x + cy * bitan.x; p1.y += cx * n.y + cy * bitan.y; p1.z += cx * n.z + cy * bitan.z; grid[i][j] = p1; } } for (int i = 0; i < radialSegments; ++i) { for (int j = 0; j < tubularSegments; ++j) { int ip = (i + 1) % radialSegments; int jp = (j + 1) % tubularSegments; Vector3 a = grid[i][j]; Vector3 b = grid[ip][j]; Vector3 c = grid[ip][jp]; Vector3 d = grid[i][jp]; Vector2 uva = new Vector2((float) i / (float) radialSegments, (float) j / (float) tubularSegments); Vector2 uvb = new Vector2((float) (i + 1) / (float) radialSegments, (float) j / (float) tubularSegments); Vector2 uvc = new Vector2((float) (i + 1) / (float) radialSegments, (float) (j + 1) / (float) tubularSegments); Vector2 uvd = new Vector2((float) i / (float) radialSegments, (float) (j + 1) / (float) tubularSegments); addTrilange(a, b, c, uva, uvb, uvc); addTrilange(a, c, d, uva, uvc, uvd); } } return dataToMesh(); }