Java Code Examples for javax.vecmath.Vector3f#normalize()
The following examples show how to use
javax.vecmath.Vector3f#normalize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FaceBakery.java From The-5zig-Mod with MIT License | 6 votes |
private void fillNormal(int[] faceData) { Vector3f v1 = new Vector3f(faceData[3 * 7 + 0], faceData[3 * 7 + 1], faceData[3 * 7 + 2]); Vector3f t = new Vector3f(faceData[1 * 7 + 0], faceData[1 * 7 + 1], faceData[1 * 7 + 2]); Vector3f v2 = new Vector3f(faceData[2 * 7 + 0], faceData[2 * 7 + 1], faceData[2 * 7 + 2]); v1.sub(t); t.set(faceData[0 * 7 + 0], faceData[0 * 7 + 1], faceData[0 * 7 + 2]); v2.sub(t, v1); v1.cross(v2, v1); v1.normalize(); int x = ((byte) (v1.x * 127)) & 0xFF; int y = ((byte) (v1.y * 127)) & 0xFF; int z = ((byte) (v1.z * 127)) & 0xFF; for (int i = 0; i < 4; i++) { faceData[i * 7 + 6] = x | (y << 0x08) | (z << 0x10); } }
Example 2
Source File: DrawAR.java From ar-drawing-java with Apache License 2.0 | 6 votes |
/** * Get a matrix usable for zero calibration (only position and compass direction) */ public float[] getCalibrationMatrix() { float[] t = new float[3]; float[] m = new float[16]; mFrame.getCamera().getPose().getTranslation(t, 0); float[] z = mFrame.getCamera().getPose().getZAxis(); Vector3f zAxis = new Vector3f(z[0], z[1], z[2]); zAxis.y = 0; zAxis.normalize(); double rotate = Math.atan2(zAxis.x, zAxis.z); Matrix.setIdentityM(m, 0); Matrix.translateM(m, 0, t[0], t[1], t[2]); Matrix.rotateM(m, 0, (float) Math.toDegrees(rotate), 0, 1, 0); return m; }
Example 3
Source File: DropItemAction.java From OpenModsLib with MIT License | 5 votes |
public DropItemAction(@Nonnull ItemStack stack, double x, double y, double z, float vx, float vy, float vz) { this.stack = stack; this.x = x; this.y = y; this.z = z; this.v = new Vector3f(vx, vy, vz); final Vector3f nv = new Vector3f(); nv.normalize(this.v); this.pitch = -(float)Math.toDegrees(Math.asin(nv.y)); this.yaw = -(float)Math.toDegrees(Math.atan2(nv.x, nv.z)); }
Example 4
Source File: Skylight_BulletPhysics_Cubes.java From PixelFlow with MIT License | 4 votes |
public void addShootingBody(){ float vel = 2000; float mass = 120000; float dimr = 30; PGraphics3D pg = (PGraphics3D) skylight.renderer.pg_render; mat_mvp.set(pg.modelview); mat_mvp.apply(mat_scene_view); mat_mvp_inv.set(mat_mvp); mat_mvp_inv.invert(); float[] cam_start = {0, 0, -0, 1}; float[] cam_aim = {0, 0, -400, 1}; float[] world_start = new float[4]; float[] world_aim = new float[4]; mat_mvp_inv.mult(cam_start, world_start); mat_mvp_inv.mult(cam_aim, world_aim); Vector3f pos = new Vector3f(world_start[0], world_start[1], world_start[2]); Vector3f aim = new Vector3f(world_aim[0], world_aim[1], world_aim[2]); Vector3f dir = new Vector3f(aim); dir.sub(pos); dir.normalize(); dir.scale(vel); BObject obj; // if((shooter_count % 2) == 0){ obj = new BSphere(this, mass, 0, 0, 0, dimr*0.5f); // } else { // obj = new BBox(this, mass, dimr, dimr, dimr); // } BObject body = new BObject(this, mass, obj, pos, true); body.setPosition(pos); body.setVelocity(dir); body.setRotation(new Vector3f(random(-1, 1),random(-1, 1),random(-1, 1)), random(PI)); body.rigidBody.setRestitution(0.1f); body.rigidBody.setFriction(0.91f); // body.rigidBody.setHitFraction(1); // body.rigidBody.setDamping(0.1f, 0.1f); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(255,200,0)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); if(obj instanceof BBox){ fixBoxNormals(body.displayShape); } physics.addBody(body); group_bulletbodies.addChild(body.displayShape); body.displayShape.setName("[shooter_"+shooter_count+"] [wire]"); shooter_count++; }
Example 5
Source File: Skylight_BulletPhysics_CellFracture.java From PixelFlow with MIT License | 4 votes |
public void addShootingBody(){ float vel = 2000; float mass = 100000; float dimr = 40; PGraphics3D pg = (PGraphics3D) skylight.renderer.pg_render; mat_mvp.set(pg.modelview); mat_mvp.apply(mat_scene_view); mat_mvp_inv.set(mat_mvp); mat_mvp_inv.invert(); float[] cam_start = {0, 0, -0, 1}; float[] cam_aim = {0, 0, -400, 1}; float[] world_start = new float[4]; float[] world_aim = new float[4]; mat_mvp_inv.mult(cam_start, world_start); mat_mvp_inv.mult(cam_aim, world_aim); Vector3f pos = new Vector3f(world_start[0], world_start[1], world_start[2]); Vector3f aim = new Vector3f(world_aim[0], world_aim[1], world_aim[2]); Vector3f dir = new Vector3f(aim); dir.sub(pos); dir.normalize(); dir.scale(vel); BObject obj; // if((shooter_count % 2) == 0){ obj = new BSphere(this, mass, 0, 0, 0, dimr*0.5f); // } else { // obj = new BBox(this, mass, dimr, dimr, dimr); // } BObject body = new BObject(this, mass, obj, pos, true); body.setPosition(pos); body.setVelocity(dir); body.setRotation(new Vector3f(random(-1, 1),random(-1, 1),random(-1, 1)), random(PI)); body.rigidBody.setRestitution(0.9f); body.rigidBody.setFriction(1); // body.rigidBody.setHitFraction(1); body.rigidBody.setDamping(0.1f, 0.1f); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(255,200,0)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); if(obj instanceof BBox){ fixBoxNormals(body.displayShape); } physics.addBody(body); group_bulletbodies.addChild(body.displayShape); body.displayShape.setName("[shooter_"+shooter_count+"] [wire]"); shooter_count++; }
Example 6
Source File: Skylight_BulletPhysics_MengerSponge.java From PixelFlow with MIT License | 4 votes |
public void addShootingBody(){ float vel = 1200; float mass = 300000; float dimr = 30; PGraphics3D pg = (PGraphics3D) skylight.renderer.pg_render; mat_mvp.set(pg.modelview); mat_mvp.apply(mat_scene_view); mat_mvp_inv.set(mat_mvp); mat_mvp_inv.invert(); float[] cam_start = {0, 0, -0, 1}; float[] cam_aim = {0, 0, -400, 1}; float[] world_start = new float[4]; float[] world_aim = new float[4]; mat_mvp_inv.mult(cam_start, world_start); mat_mvp_inv.mult(cam_aim, world_aim); Vector3f pos = new Vector3f(world_start[0], world_start[1], world_start[2]); Vector3f aim = new Vector3f(world_aim[0], world_aim[1], world_aim[2]); Vector3f dir = new Vector3f(aim); dir.sub(pos); dir.normalize(); dir.scale(vel); BObject obj; // if((shooter_count % 2) == 0){ obj = new BSphere(this, mass, 0, 0, 0, dimr*0.5f); // } else { // obj = new BBox(this, mass, dimr, dimr, dimr); // } BObject body = new BObject(this, mass, obj, pos, true); body.setPosition(pos); body.setVelocity(dir); body.setRotation(new Vector3f(random(-1, 1),random(-1, 1),random(-1, 1)), random(PI)); body.rigidBody.setRestitution(0.1f); body.rigidBody.setFriction(0.91f); // body.rigidBody.setHitFraction(1); // body.rigidBody.setDamping(0.1f, 0.1f); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(255,16,0)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); if(obj instanceof BBox){ fixBoxNormals(body.displayShape); } physics.addBody(body); group_bulletbodies.addChild(body.displayShape); body.displayShape.setName("[shooter_"+shooter_count+"] [wire]"); shooter_count++; }
Example 7
Source File: Skylight_BulletPhysics_Breakable.java From PixelFlow with MIT License | 4 votes |
public void addShootingBody(){ float vel = 1000; float mass = 300000; float dimr = 40; PGraphics3D pg = (PGraphics3D) skylight.renderer.pg_render; mat_mvp.set(pg.modelview); mat_mvp.apply(mat_scene_view); mat_mvp_inv.set(mat_mvp); mat_mvp_inv.invert(); float[] cam_start = {0, 0, -0, 1}; float[] cam_aim = {0, 0, -400, 1}; float[] world_start = new float[4]; float[] world_aim = new float[4]; mat_mvp_inv.mult(cam_start, world_start); mat_mvp_inv.mult(cam_aim, world_aim); Vector3f pos = new Vector3f(world_start[0], world_start[1], world_start[2]); Vector3f aim = new Vector3f(world_aim[0], world_aim[1], world_aim[2]); Vector3f dir = new Vector3f(aim); dir.sub(pos); dir.normalize(); dir.scale(vel); BObject body = new BSphere(this, mass, 0, 0, 0, dimr*0.5f); body.setPosition(pos); body.setVelocity(dir); body.setRotation(new Vector3f(random(-1, 1),random(-1, 1),random(-1, 1)), random(PI)); // body.rigidBody.setRestitution(0.9f); // body.rigidBody.setFriction(1); // body.rigidBody.setHitFraction(1); // body.rigidBody.setDamping(0.1f, 0.1f); body.rigidBody.setUserPointer(body); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(255,200,0)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); body.displayShape.setName("[bullet] [wire]"); physics.addBody(body); group_bulletbodies.addChild(body.displayShape); }
Example 8
Source File: Skylight_BulletPhysics_Breakable_VideoExport.java From PixelFlow with MIT License | 4 votes |
public void addShootingBody(){ float vel = 1000; float mass = 300000; float dimr = 40; PGraphics3D pg = (PGraphics3D) skylight.renderer.pg_render; mat_mvp.set(pg.modelview); mat_mvp.apply(mat_scene_view); mat_mvp_inv.set(mat_mvp); mat_mvp_inv.invert(); float[] cam_start = {0, 0, -0, 1}; float[] cam_aim = {0, 0, -400, 1}; float[] world_start = new float[4]; float[] world_aim = new float[4]; mat_mvp_inv.mult(cam_start, world_start); mat_mvp_inv.mult(cam_aim, world_aim); Vector3f pos = new Vector3f(world_start[0], world_start[1], world_start[2]); Vector3f aim = new Vector3f(world_aim[0], world_aim[1], world_aim[2]); Vector3f dir = new Vector3f(aim); dir.sub(pos); dir.normalize(); dir.scale(vel); BObject body = new BSphere(this, mass, 0, 0, 0, dimr*0.5f); body.setPosition(pos); body.setVelocity(dir); body.setRotation(new Vector3f(random(-1, 1),random(-1, 1),random(-1, 1)), random(PI)); // body.rigidBody.setRestitution(0.9f); // body.rigidBody.setFriction(1); // body.rigidBody.setHitFraction(1); // body.rigidBody.setDamping(0.1f, 0.1f); body.rigidBody.setUserPointer(body); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(255,200,0)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); body.displayShape.setName("[bullet] [wire]"); physics.addBody(body); group_bulletbodies.addChild(body.displayShape); }
Example 9
Source File: Skylight_BulletPhysics_Breakable3.java From PixelFlow with MIT License | 4 votes |
public void addShootingBody(){ float vel = 1000; float mass = 300000; float dimr = 40; PGraphics3D pg = (PGraphics3D) skylight.renderer.pg_render; mat_mvp.set(pg.modelview); mat_mvp.apply(mat_scene_view); mat_mvp_inv.set(mat_mvp); mat_mvp_inv.invert(); float[] cam_start = {0, 0, -0, 1}; float[] cam_aim = {0, 0, -400, 1}; float[] world_start = new float[4]; float[] world_aim = new float[4]; mat_mvp_inv.mult(cam_start, world_start); mat_mvp_inv.mult(cam_aim, world_aim); Vector3f pos = new Vector3f(world_start[0], world_start[1], world_start[2]); Vector3f aim = new Vector3f(world_aim[0], world_aim[1], world_aim[2]); Vector3f dir = new Vector3f(aim); dir.sub(pos); dir.normalize(); dir.scale(vel); BObject obj; // if((shooter_count % 2) == 0){ obj = new BSphere(this, mass, 0, 0, 0, dimr*0.5f); // } else { // obj = new BBox(this, mass, dimr, dimr, dimr); // } BObject body = new BObject(this, mass, obj, pos, true); body.setPosition(pos); body.setVelocity(dir); body.setRotation(new Vector3f(random(-1, 1),random(-1, 1),random(-1, 1)), random(PI)); body.rigidBody.setRestitution(0.9f); body.rigidBody.setFriction(1); // body.rigidBody.setHitFraction(1); body.rigidBody.setDamping(0.1f, 0.1f); body.rigidBody.setUserPointer(body); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(255,200,0)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); // body.displayShape.setName("bullet"); physics.addBody(body); group_bulletbodies.addChild(body.displayShape); body.displayShape.setName("[bullet_"+shooter_count+"] [wire]"); shooter_count++; }
Example 10
Source File: Skylight_BulletPhysics_TowerDemolition.java From PixelFlow with MIT License | 4 votes |
public void addShootingBody(){ PGraphics3D pg = (PGraphics3D) skylight.renderer.pg_render; mat_mvp.set(pg.modelview); mat_mvp.apply(mat_scene_view); mat_mvp_inv.set(mat_mvp); mat_mvp_inv.invert(); float[] cam_start = {0, 0, -0, 1}; float[] cam_aim = {0, 0, -400, 1}; float[] world_start = new float[4]; float[] world_aim = new float[4]; mat_mvp_inv.mult(cam_start, world_start); mat_mvp_inv.mult(cam_aim, world_aim); Vector3f pos = new Vector3f(world_start[0], world_start[1], world_start[2]); Vector3f aim = new Vector3f(world_aim[0], world_aim[1], world_aim[2]); Vector3f dir = new Vector3f(aim); dir.sub(pos); dir.normalize(); dir.scale(2000); float mass = 20000; float dimr = 80; BObject obj; // if((shooter_count % 2) == 0){ obj = new BSphere(this, mass, 0, 0, 0, dimr*0.5f); // } else { // obj = new BBox(this, mass, dimr, dimr, dimr); // } BObject body = new BObject(this, mass, obj, pos, true); body.setPosition(pos); body.setVelocity(dir); body.setRotation(new Vector3f(random(-1, 1),random(-1, 1),random(-1, 1)), random(PI)); body.rigidBody.setRestitution(0.9f); body.rigidBody.setFriction(1); // body.rigidBody.setHitFraction(1); body.rigidBody.setDamping(0.1f, 0.1f); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(255,8,0)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); if(obj instanceof BBox){ fixBoxNormals(body.displayShape); } physics.addBody(body); group_bulletbodies.addChild(body.displayShape); body.displayShape.setName("[shooter_"+shooter_count+"] [wire]"); shooter_count++; }
Example 11
Source File: Skylight_BulletPhysics_Basic.java From PixelFlow with MIT License | 4 votes |
public void addShootingBody(){ PGraphics3D pg = (PGraphics3D) skylight.renderer.pg_render; mat_mvp.set(pg.modelview); mat_mvp.apply(mat_scene_view); mat_mvp_inv.set(mat_mvp); mat_mvp_inv.invert(); float[] cam_start = {0, 0, -0, 1}; float[] cam_aim = {0, 0, -400, 1}; float[] world_start = new float[4]; float[] world_aim = new float[4]; mat_mvp_inv.mult(cam_start, world_start); mat_mvp_inv.mult(cam_aim, world_aim); Vector3f pos = new Vector3f(world_start[0], world_start[1], world_start[2]); Vector3f aim = new Vector3f(world_aim[0], world_aim[1], world_aim[2]); Vector3f dir = new Vector3f(aim); dir.sub(pos); dir.normalize(); dir.scale(1000); float mass = 600000; float dimr = 50; BObject obj; if((shooter_count % 2) == 0){ obj = new BSphere(this, mass, 0, 0, 0, dimr*0.5f); } else { obj = new BBox(this, mass, dimr, dimr, dimr); } BObject body = new BObject(this, mass, obj, pos, true); body.setPosition(pos); body.setVelocity(dir); body.setRotation(new Vector3f(random(-1, 1),random(-1, 1),random(-1, 1)), random(PI)); body.rigidBody.setRestitution(0.9f); body.rigidBody.setFriction(1); // body.rigidBody.setHitFraction(1); body.rigidBody.setDamping(0.1f, 0.1f); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(8,64,255)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); if(obj instanceof BBox){ fixBoxNormals(body.displayShape); } physics.addBody(body); group_bulletbodies.addChild(body.displayShape); body.displayShape.setName("[shooter_"+shooter_count+"] [wire]"); shooter_count++; }
Example 12
Source File: ModelLoadAndSaveAMF.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
@Override public boolean load(BufferedInputStream inputStream,Model model) throws Exception { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputStream); doc.getDocumentElement().normalize(); if(!doc.getDocumentElement().getNodeName().contains("amf")) { // uh oh! } else { ArrayList<Float> vertexArray = new ArrayList<Float>(); //ArrayList<Integer> faceArray = new ArrayList<Integer>(); NodeList coordinateList = doc.getElementsByTagName("coordinates"); int numCoordinates = coordinateList.getLength(); Log.message(numCoordinates + " coordinates."); for (int a = 0; a < numCoordinates; a++) { Element coordinate = (Element)coordinateList.item(a); //Log.message("x: "+coordinate.getElementsByTagName("x").item(0).getTextContent()); //Log.message("y: "+coordinate.getElementsByTagName("y").item(0).getTextContent()); //Log.message("z: "+coordinate.getElementsByTagName("z").item(0).getTextContent()); float x = Float.parseFloat(coordinate.getElementsByTagName("x").item(0).getTextContent()); float y = Float.parseFloat(coordinate.getElementsByTagName("y").item(0).getTextContent()); float z = Float.parseFloat(coordinate.getElementsByTagName("z").item(0).getTextContent()); vertexArray.add(x); vertexArray.add(y); vertexArray.add(z); } NodeList volumeList = doc.getElementsByTagName("volume"); Log.message(volumeList.getLength() + " volumes."); int numVolumes = volumeList.getLength(); for (int a = 0; a < numVolumes; a++) { Element volume = (Element)volumeList.item(a); NodeList triangleList = volume.getElementsByTagName("triangle"); int numTriangles = triangleList.getLength(); Log.message("\t"+ numTriangles + " triangles."); for (int b = 0; b < numTriangles; b++) { Element triangle = (Element)triangleList.item(b); int v1 = Integer.parseInt(triangle.getElementsByTagName("v1").item(0).getTextContent()); int v2 = Integer.parseInt(triangle.getElementsByTagName("v2").item(0).getTextContent()); int v3 = Integer.parseInt(triangle.getElementsByTagName("v3").item(0).getTextContent()); //Log.message("\t\t"+v1+", "+v2+", "+v3); float x1 = vertexArray.get(v1*3+0); float y1 = vertexArray.get(v1*3+1); float z1 = vertexArray.get(v1*3+2); float x2 = vertexArray.get(v2*3+0); float y2 = vertexArray.get(v2*3+1); float z2 = vertexArray.get(v2*3+2); float x3 = vertexArray.get(v3*3+0); float y3 = vertexArray.get(v3*3+1); float z3 = vertexArray.get(v3*3+2); model.addVertex(x1,y1,z1); model.addVertex(x2,y2,z2); model.addVertex(x3,y3,z3); // calculate normal from triangle face Vector3f p1 = new Vector3f(x1,y1,z1); Vector3f p2 = new Vector3f(x2,y2,z2); Vector3f p3 = new Vector3f(x3,y3,z3); p2.sub(p1); p3.sub(p1); p2.normalize(); p3.normalize(); p1.cross(p2, p3); p1.normalize(); model.addNormal(p1.x, p1.y, p1.z); model.addNormal(p1.x, p1.y, p1.z); model.addNormal(p1.x, p1.y, p1.z); } } model.hasNormals=true; } return true; }
Example 13
Source File: FaceClassifierTest.java From OpenModsLib with MIT License | 4 votes |
private static void test(FaceClassifier classifier, EnumFacing result, float x, float y, float z) { Vector3f v = new Vector3f(x, y, z); v.normalize(); Assert.assertEquals(Optional.of(result), classifier.classify(v)); }
Example 14
Source File: FaceClassifierTest.java From OpenModsLib with MIT License | 4 votes |
private static void test(FaceClassifier classifier, float x, float y, float z) { Vector3f v = new Vector3f(x, y, z); v.normalize(); Assert.assertEquals(Optional.empty(), classifier.classify(v)); }