boolean hitStep = false; float stepSlope = 1f; Vector3f lookAheadOffset = new Vector3f(direction.x, direction.y, direction.z); lookAheadOffset.y = 0; lookAheadOffset.normalize(); lookAheadOffset.scale(checkForwardDistance); Vector3f fromWorld = new Vector3f(hitPointWorld); fromWorld.y += stepHeight + 0.05f; fromWorld.add(lookAheadOffset); Vector3f toWorld = new Vector3f(hitPointWorld); toWorld.y -= 0.05f; toWorld.add(lookAheadOffset); CollisionWorld.ClosestRayResultCallback rayResult = new CollisionWorld.ClosestRayResultCallback(fromWorld, toWorld); Transform transformFrom = new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), fromWorld, 1.0f)); if (rayResult.hasHit()) { hitStep = true; stepSlope = rayResult.hitNormalWorld.dot(new Vector3f(0, 1, 0)); fromWorld.add(lookAheadOffset); toWorld.add(lookAheadOffset); rayResult = new CollisionWorld.ClosestRayResultCallback(fromWorld, toWorld); transformFrom = new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), fromWorld, 1.0f)); if (rayResult.hasHit()) { hitStep = true; stepSlope = Math.min(stepSlope, rayResult.hitNormalWorld.dot(new Vector3f(0, 1, 0)));
/** * used internally, not safe */ public void calculateLocalInertia(float mass, javax.vecmath.Vector3f vector) { if (cShape == null) { return; } if (this instanceof MeshCollisionShape) { vector.set(0, 0, 0); } else { cShape.calculateLocalInertia(mass, vector); } }
@Override public void awakenArea(org.terasology.math.geom.Vector3f pos, float radius) { Vector3f min = new Vector3f(VecMath.to(pos)); min.sub(new Vector3f(0.6f, 0.6f, 0.6f)); Vector3f max = new Vector3f(VecMath.to(pos)); max.add(new Vector3f(0.6f, 0.6f, 0.6f)); discreteDynamicsWorld.awakenRigidBodiesInArea(min, max); }
@Override public CollisionShape rotate(Quat4f rot) { javax.vecmath.Vector3f halfExtentsWithMargin = boxShape.getHalfExtentsWithMargin(new javax.vecmath.Vector3f()); com.bulletphysics.linearmath.QuaternionUtil.quatRotate(VecMath.to(rot), halfExtentsWithMargin, halfExtentsWithMargin); halfExtentsWithMargin.absolute(); return new BulletBoxShape(halfExtentsWithMargin); }
/** * Re-calculates the Orientation of this quad, * optionally the normal vector. * * @param setNormal If the normal vector should be updated. */ public void calculateOrientation( boolean setNormal ) { this.v1.set( this.vertices[3].vec ); this.t.set( this.vertices[1].vec ); this.v1.sub( this.t ); this.v2.set( this.vertices[2].vec ); this.t.set( this.vertices[0].vec ); this.v2.sub( this.t ); this.normal.cross( this.v2, this.v1 ); this.normal.normalize(); if( this.format.hasNormal && setNormal) { for( Vertex vertex : this.vertices ) { vertex.normal[0] = this.normal.x; vertex.normal[1] = this.normal.y; vertex.normal[2] = this.normal.z; vertex.normal[3] = 0; } } this.orientation = EnumFacing.getFacingFromVector( this.normal.x, this.normal.y, this.normal.z ); }
Vector3f normal = new Vector3f( Float.intBitsToFloat( newData[i * stride + normalIdx] ), Float .intBitsToFloat( newData[i * stride + normalIdx + 1] ), Float.intBitsToFloat( newData[i * stride + normalIdx + 2] ) ); newData[i * stride + normalIdx] = Float.floatToIntBits( normal.getX() ); newData[i * stride + normalIdx + 1] = Float.floatToIntBits( normal.getY() ); newData[i * stride + normalIdx + 2] = Float.floatToIntBits( normal.getZ() ); Vector3f normal = new Vector3f( getByte( newData, idx ) / 127.0f, getByte( newData, idx + 1 ) / 127.0f, getByte( newData, idx + 2 ) / 127.0f ); setByte( newData, idx, (int) ( normal.getX() * 127 ) ); setByte( newData, idx + 1, (int) ( normal.getY() * 127 ) ); setByte( newData, idx + 2, (int) ( normal.getZ() * 127 ) );
public static void setScale(javax.vecmath.Vector3f vec, javax.vecmath.Matrix4f src, javax.vecmath.Matrix4f dest) { if (dest == null) { dest = new javax.vecmath.Matrix4f(); } dest.m00 = src.m00 * vec.getX(); dest.m01 = src.m01 * vec.getX(); dest.m02 = src.m02 * vec.getX(); dest.m03 = src.m03 * vec.getX(); dest.m10 = src.m10 * vec.getY(); dest.m11 = src.m11 * vec.getY(); dest.m12 = src.m12 * vec.getY(); dest.m13 = src.m13 * vec.getY(); dest.m20 = src.m20 * vec.getZ(); dest.m21 = src.m21 * vec.getZ(); dest.m22 = src.m22 * vec.getZ(); dest.m23 = src.m23 * vec.getZ(); }
@Override public void put(int element, float... data) { VertexFormatElement.EnumUsage usage = parent.getVertexFormat().getElement(element).getUsage(); // transform normals and position if(usage == VertexFormatElement.EnumUsage.POSITION && data.length >= 3) { Vector4f vec = new Vector4f(data[0], data[1], data[2], 1f); transformation.transform(vec); data = new float[4]; vec.get(data); } else if(usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) { Vector3f vec = new Vector3f(data); normalTransformation.transform(vec); vec.normalize(); data = new float[4]; vec.get(data); } super.put(element, data); }
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)); }
p0tx.setTranslation(new Vector3f(p0.getX(),p0.getY(),p0.getZ())); scaletx.setScale(new Vector3d(1,length,1)); Vector3f yunit = new Vector3f(0,1,0); Vector3f v = new Vector3f(p1.getX()-p0.getX(), p1.getY()-p0.getY(), p1.getZ()-p0.getZ()); Vector3f cross = new Vector3f(); cross.cross(yunit, v); float angle = yunit.angle(v); rot.setRotation(new AxisAngle4f(cross.getX(),cross.getY(),cross.getZ(),angle)); tx.mul(rot); tx.setTranslation(new Vector3f(p0.getX(),p0.getY(),p0.getZ()));
public Point3f getNearestIntersection(Point3f origin, Vector3f direction) direction.normalize(); float dx, dy, dz, dot; double distanceToLine, distance; dz = origin.getZ() - p.getZ(); dot = dx * direction.getX() + dy * direction.getY() + dz * direction.getZ(); dx = dx - dot * direction.getX(); dy = dy - dot * direction.getY(); dz = dz - dot * direction.getZ();
/** * @param point * @param viewportSize * @param viewProjMtx * @return */ public static Ray screenPointToRay(Vector2f point, Vector2f viewportSize, float[] viewProjMtx) { point.y = viewportSize.y - point.y; float x = point.x * 2.0F / viewportSize.x - 1.0F; float y = point.y * 2.0F / viewportSize.y - 1.0F; float[] farScreenPoint = new float[]{x, y, 1.0F, 1.0F}; float[] nearScreenPoint = new float[]{x, y, -1.0F, 1.0F}; float[] nearPlanePoint = new float[4]; float[] farPlanePoint = new float[4]; float[] invertedProjectionMatrix = new float[16]; Matrix.setIdentityM(invertedProjectionMatrix, 0); Matrix.invertM(invertedProjectionMatrix, 0, viewProjMtx, 0); Matrix.multiplyMV(nearPlanePoint, 0, invertedProjectionMatrix, 0, nearScreenPoint, 0); Matrix.multiplyMV(farPlanePoint, 0, invertedProjectionMatrix, 0, farScreenPoint, 0); Vector3f direction = new Vector3f(farPlanePoint[0] / farPlanePoint[3], farPlanePoint[1] / farPlanePoint[3], farPlanePoint[2] / farPlanePoint[3]); Vector3f origin = new Vector3f(new Vector3f(nearPlanePoint[0] / nearPlanePoint[3], nearPlanePoint[1] / nearPlanePoint[3], nearPlanePoint[2] / nearPlanePoint[3])); direction.sub(origin); direction.normalize(); return new Ray(origin, direction); }
/** * Computes the normal of this triangle. This method only computes the * normal if the normal is not up to date. The normal is defined as outdated * whenever a new node has been assigned. */ private void computeNormal() { if (!normalUpToDate) { Point3f p1 = nodeOne.getLocation(); Point3f p2 = nodeTwo.getLocation(); Point3f p3 = nodeThree.getLocation(); Vector3f v1 = new Vector3f( p2.x - p1.x, p2.y - p1.y, p2.z - p1.z); Vector3f v2 = new Vector3f(p3.x - p1.x, p3.y - p1.y, p3.z - p1.z); normal = new Vector3f(); normal.cross(v1, v2); normal.normalize(); normalUpToDate = true; } }
public void mouseClicked(final MouseEvent _evt) { if (SwingUtilities.isLeftMouseButton(_evt)) { final Vector3f old = new Vector3f(vecteur_); final int x = _evt.getX(); final int y = _evt.getY(); switch (((Carre) _evt.getSource()).getMode()) { case 0: vecteur_.x = x - centreX_; vecteur_.z = y - centreY_; break; case 1: vecteur_.y = x - centreX_; vecteur_.z = y - centreY_; break; case 2: vecteur_.z = x - centreX_; vecteur_.x = y - centreY_; break; default: // TODO ajouter des instructions au cas "default" } repaint(); if (!old.equals(vecteur_)) { final Vector3f v = new Vector3f(-vecteur_.x, vecteur_.y, vecteur_.z); v.normalize(); pcs_.firePropertyChange("direction", old, v); } } }
BoxShapeComponent box = entity.getComponent(BoxShapeComponent.class); if (box != null) { Vector3f halfExtents = new Vector3f(VecMath.to(box.extents)); halfExtents.scale(0.5f); return new BoxShape(halfExtents); return new CylinderShape(new Vector3f(cylinder.radius, 0.5f * cylinder.height, cylinder.radius)); TFloatIterator iterator = hull.sourceMesh.getVertices().iterator(); while (iterator.hasNext()) { Vector3f newVert = new Vector3f(); newVert.x = iterator.next(); newVert.y = iterator.next();