@Override public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) { ImmutableMap<TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper.getTransforms(state); TRSRTransformation transform = state.apply(Optional.empty()).orElse(TRSRTransformation.identity()); TextureAtlasSprite widgetSprite = bakedTextureGetter.apply(getWidgetTexture(widget)); ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder(); int width = widget.getWidth() + (widget.getParameters() != null && widget.getParameters().length > 0 ? 10 : 0); int height = widget.getHeight() + (widget.hasStepOutput() ? 5 : 0); Pair<Double, Double> maxUV = widget.getMaxUV(); int textureSize = widget.getTextureSize(); float scale = 1F / (float) Math.max(maxUV.getLeft(), maxUV.getRight()); float transX = 0;//maxUV.getLeft().floatValue(); float transY = -1 + maxUV.getRight().floatValue(); transform = transform.compose(new TRSRTransformation(new Vector3f(0, 0, 0), null, new Vector3f(scale, scale, 1), null)); transform = transform.compose(new TRSRTransformation(new Vector3f(transX, transY, 0), null, new Vector3f(1, 1, 1), null)); builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16 * maxUV.getLeft().floatValue(), 16 * maxUV.getRight().floatValue(), NORTH_Z_BASE, widgetSprite, EnumFacing.NORTH, 0xffffffff)); builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16 * maxUV.getLeft().floatValue(), 16 * maxUV.getRight().floatValue(), SOUTH_Z_BASE, widgetSprite, EnumFacing.SOUTH, 0xffffffff)); return new BakedProgrammingPuzzle(this, builder.build(), widgetSprite, format, Maps.immutableEnumMap(transformMap), Maps.newHashMap()); }
public EntityCrazyCube(World world, Vec3f pos){ super(world, getModel0(), pos); float s=Rand.f()+1; scale.set(s, s, s); // model.getMaterial(2).getDiffuse().set(177/256F, 0, 177/256F, 1); // model.getMaterial(1).getDiffuse().set(0x00C7E7); // model.getMaterial(1).getAmbient().set(0x00C7E7).a(1); // model.getMaterial(0).getDiffuse().set(0x0000FF); float massKg=0.5F*scale.x*scale.y*scale.z; if(CAM==null) CAM=this; getPhysicsObj().init(massKg, new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(pos.x, pos.y, pos.z), 0.5F)), new SphereShape(scale.x/2), Vec3f.single(0.9F)); // getPhysicsObj().init(massKg, new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(pos.x, pos.y, pos.z), 0.5F)), new BoxShape(new Vector3f(scale.x/2, scale.y/2, scale.z/2)), Vec3f.single(0.9F)); getPhysicsObj().body.setDamping(0.15F, 0.15F); getPhysicsObj().hookPos(this.pos); getPhysicsObj().hookRot(rot); }
/** * Move the position of the player by the specified deltaX, * deltaY and deltaZ using the specified camera rotation. * * @param deltaX - Value to move the x position by. * @param deltaY - Value to move the y position by. * @param deltaZ - Value to move the z position by. * @param camY - Camera y rotation to use for movement. */ public void movePosition(float deltaX, float deltaY, float deltaZ, float camY) { deltaX *= WALK_SPEED; deltaY *= WALK_SPEED; deltaZ *= WALK_SPEED; Vector3f position = new Vector3f(0, 0, 0); if (deltaZ != 0) { position.x += (float)Math.sin(Math.toRadians(camY)) * -1.0f * deltaZ; position.z += (float)Math.cos(Math.toRadians(camY)) * deltaZ; } if (deltaX != 0) { position.x += (float)Math.sin(Math.toRadians(camY - 90)) * -1.0f * deltaX; position.z += (float)Math.cos(Math.toRadians(camY - 90)) * deltaX; } position.y += deltaY; characterController.setWalkDirection(position); }
/** * 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.getPose().getTranslation(t, 0); float[] z = mFrame.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; }
/** * * setMemory is a helper method used to add the stroke data to the float[] buffers * @param index * @param pos * @param prev * @param next * @param counter * @param width * @param side */ private void setMemory(int index, Vector3f pos, Vector3f prev, Vector3f next, float counter, float width, float side){ mPositions[index*3] = pos.x; mPositions[index*3+1] = pos.y; mPositions[index*3+2] = pos.z; mNext[index*3] = next.x; mNext[index*3+1] = next.y; mNext[index*3+2] = next.z; mPrevious[index*3] = prev.x; mPrevious[index*3+1] = prev.y; mPrevious[index*3+2] = prev.z; mCounters[index] = counter; mSide[index] = side; mWidth[index] = width; }
/** * internal, relies on fixed format of FaceBakery */ public static void fillNormal(int[] faceData, EnumFacing facing) { 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.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); } }
public static Matrix4f mul(Vector3f translation, Quat4f leftRot, Vector3f scale, Quat4f rightRot) { Matrix4f res = new Matrix4f(), t = new Matrix4f(); res.setIdentity(); if(leftRot != null) { t.set(leftRot); res.mul(t); } if(scale != null) { t.setIdentity(); t.m00 = scale.x; t.m11 = scale.y; t.m22 = scale.z; res.mul(t); } if(rightRot != null) { t.set(rightRot); res.mul(t); } if(translation != null) res.setTranslation(translation); return res; }
/** * Add an element to a keyframe. If the keyframe does exist it's created. * * @param keyFrame * Key of the keyframe. * @param type * Type of the element. See {@link CSReadedAnimBlock}. * @param value * Value of the element. */ public void addKFElement(int keyFrame, EnumFrameType type, Vector3f value) { if (!this.keyFrames.containsKey(keyFrame)) this.keyFrames.put(keyFrame, new ReadedKeyFrame()); switch (type) { case POSITION: this.keyFrames.get(keyFrame).position = value; break; case ROTATION: this.keyFrames.get(keyFrame).rotation = value; break; case OFFSET: this.keyFrames.get(keyFrame).offset = value; break; case SIZE: this.keyFrames.get(keyFrame).size = value; break; case STRETCH: this.keyFrames.get(keyFrame).stretching = value; break; } }
/** * * @param tokType * @param qType * @param mStep * @return helix data of some sort */ public Object getHelixData(int tokType, char qType, int mStep) { switch (tokType) { case Token.point: return new Point3f(); case Token.axis: case Token.radius: return new Vector3f(); case Token.angle: return new Float(Float.NaN); case Token.array: case Token.list: return new String[] {}; } return ""; }
@Override public double nearestDistance(Vector3f p, Vector3f pNormal, boolean useRelative) { Vector3f found = nearestNeighbour(p); if(found == null){ //error return Double.MAX_VALUE; } float sign = 1f; if(useRelative){ sign = getSign(p, found, pNormal); } return sign * MathUtils.instance().distancePoints(found, p); }
private int calchull(ObjectArrayList<Vector3f> verts, int verts_count, IntArrayList tris_out, int[] tris_count, int vlimit) { int rc = calchullgen(verts, verts_count, vlimit); if (rc == 0) return 0; IntArrayList ts = new IntArrayList(); for (int i=0; i<tris.size(); i++) { if (tris.getQuick(i) != null) { for (int j = 0; j < 3; j++) { ts.add((tris.getQuick(i)).getCoord(j)); } deAllocateTriangle(tris.getQuick(i)); } } tris_count[0] = ts.size() / 3; MiscUtil.resize(tris_out, ts.size(), 0); for (int i=0; i<ts.size(); i++) { tris_out.set(i, ts.get(i)); } MiscUtil.resize(tris, 0, Tri.class); return 1; }
static public boolean isVariableType(Object x) { return (x instanceof ScriptVariable || x instanceof BitSet || x instanceof Boolean || x instanceof Float || x instanceof Integer || x instanceof Point3f // stored as point3f || x instanceof Vector3f // stored as point3f || x instanceof Point4f // stored as point4f || x instanceof Quaternion // stored as point4f || x instanceof String || x instanceof Map<?, ?> // stored as Map<String, ScriptVariable> || x instanceof List<?> // stored as list || x instanceof ScriptVariable[] // stored as list || x instanceof double[] // stored as list || x instanceof float[] // stored as list || x instanceof Float[] // stored as list || x instanceof int[] // stored as list || x instanceof int[][] // stored as list || x instanceof Point4f[] // stored as list || x instanceof String[]); // stored as list }
@Override public void update() { accum += Engine.deltaTime; //spawns cubes and lights, test if accum is a certain length if (Input.isButtonDown(1) && accum > 0.1f) { Camera cam = Engine.camera; MeshObject c = new MeshObject(cam.getPosition(), cam.front.multiply(30), new Quat4f(1.0f, 0.3f, 0.5f, 0f), new BoxShape(new Vector3f(0.5f, 0.5f, 0.5f)), 1f, cubeMesh, 1f, crateMaterial); Engine.scene.add(c); accum = 0; } if (Input.isButtonDown(2) && accum > 1f) { PointLight p = new PointLight(Engine.camera.getPosition(), vec3(1.0f, 1.0f, 2.0f), 5f, 10f); Engine.scene.add(p); accum = 0; } }
private void drawCylinder(Vector3f from, Vector3f to, GL2 gl, GLUT glut) { Vector3f zAxis = new Vector3f(0, 0, 1); Vector3f vector = new Vector3f(to.x - from.x, to.y - from.y, to.z - from.z); float length = vector.length(); vector.normalize(); float angle = zAxis.angle(vector); Vector3f axis = new Vector3f(); axis.cross(zAxis, vector); float convert = (float) (180f / Math.PI); gl.glPushMatrix(); gl.glTranslatef(from.x, from.y, from.z); gl.glRotatef(angle * convert, axis.x, axis.y, axis.z); glut.glutSolidCylinder(info.getPointSize() / 4.5, length - info.getPointSize(), 20, 20); gl.glPopMatrix(); }
/** * Optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb. */ public BvhTriangleMeshShape(StridingMeshInterface meshInterface, boolean useQuantizedAabbCompression, Vector3f bvhAabbMin, Vector3f bvhAabbMax, boolean buildBvh) { super(meshInterface); this.bvh = null; this.useQuantizedAabbCompression = useQuantizedAabbCompression; this.ownsBvh = false; // construct bvh from meshInterface //#ifndef DISABLE_BVH if (buildBvh) { bvh = new OptimizedBvh(); bvh.build(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax); ownsBvh = true; } // JAVA NOTE: moved from TriangleMeshShape recalcLocalAabb(); //#endif //DISABLE_BVH }
private void renderLonePair(boolean isRadical) { pt2f.set(imesh.vertices[1]); viewer.transformPoint(pt2f, pt2f); int r = viewer.scaleToScreen((int)pt2f.z, 100); if (r < 1) r = 1; if (!isRadical) { Vector3f v1 = new Vector3f(); Vector3f v2 = new Vector3f(); pt1f.set(imesh.vertices[0]); viewer.transformPoint(pt1f, pt1f); v1.sub(pt2f, pt1f); v2.set(v1.x, v1.y, v1.z + 1); v2.cross(v2,v1); v2.normalize(); float f = viewer.scaleToScreen((int)pt1f.z, 100); v2.scale(f); pt1f.set(pt2f); pt1f.add(v2); pt2f.sub(v2); screens[0].set((int)pt1f.x,(int)pt1f.y,(int)pt1f.z); g3d.fillSphere(r, screens[0]); } screens[1].set((int)pt2f.x,(int)pt2f.y,(int)pt2f.z); g3d.fillSphere(r, screens[1]); }
public void SignedExpand(Vector3f e) { if (e.x > 0) { mx.x += e.x; } else { mi.x += e.x; } if (e.y > 0) { mx.y += e.y; } else { mi.y += e.y; } if (e.z > 0) { mx.z += e.z; } else { mi.z += e.z; } }
/** * Angular constraint between two different rigidbodies. */ public void init(Vector3f jointAxis, Matrix3f world2A, Matrix3f world2B, Vector3f inertiaInvA, Vector3f inertiaInvB) { linearJointAxis.set(0f, 0f, 0f); aJ.set(jointAxis); world2A.transform(aJ); bJ.set(jointAxis); bJ.negate(); world2B.transform(bJ); VectorUtil.mul(m_0MinvJt, inertiaInvA, aJ); VectorUtil.mul(m_1MinvJt, inertiaInvB, bJ); Adiag = m_0MinvJt.dot(aJ) + m_1MinvJt.dot(bJ); assert (Adiag > 0f); }
public void computeToAge(double targetAge) { this.target = targetAge; FpModel alignToPoints = getMeanModel(gender, age); ArrayList<Vector3f> templateVerts = new ArrayList<>(); for(FacialPoint p : alignToPoints.getFacialPoints()) { templateVerts.add(p.getPosition()); } ArrayList<List<FacialPoint>> modelPointsList = new ArrayList<>(1); ArrayList<ArrayList<Vector3f>> models = new ArrayList<>(1); models.add(model.getVerts()); modelPointsList.add(modelPoints); Procrustes1ToMany proc = new Procrustes1ToMany(alignToPoints.getFacialPoints(), templateVerts, modelPointsList, models, false); proc.align1withN(); model.setVerts(proc.getPa2().get(0).getVertices()); targetPoints = getMeanModel(gender, targetAge).getFacialPoints(); ModelLoader l = new ModelLoader(); targetModel = l.loadModel(model.getFile(), false, false); targetModel.setVerts(new ArrayList<>(model.getVerts())); transform(targetModel, modelPoints, targetPoints); }
private static short getVertex(short v1, short v2) { if (v1 > v2) { short t = v1; v1 = v2; v2 = t; } Integer hashKey = Integer.valueOf((v1 << 16) + v2); Short iv = htVertex.get(hashKey); if (iv != null) { return iv.shortValue(); } Vector3f newVertexVector = new Vector3f(vertexVectors[v1]); vertexVectors[vertexNext] = newVertexVector; newVertexVector.add(vertexVectors[v2]); newVertexVector.scale(0.5f); newVertexVector.normalize(); htVertex.put(hashKey, Short.valueOf(vertexNext)); return vertexNext++; }
public static List<FacialPoint> reverse(List<FacialPoint> facialPoints, List<ICPTransformation> transformations) { List<Vector3f> reversedVerts = new ArrayList<>(); for (FacialPoint facialPoint : facialPoints) { reversedVerts.add(new Vector3f(facialPoint.getCoords())); } Icp.instance().reverseAllTransformations(transformations, reversedVerts, SCALE); List<FacialPoint> transformedFacialPoints = new ArrayList<>(); int index = 0; for (Vector3f vert : reversedVerts) { FacialPointType originalType = facialPoints.get(index).getType(); transformedFacialPoints.add(new FacialPoint(originalType, vert)); } return transformedFacialPoints; }
private boolean getClosestNormal(IsosurfaceMesh m, Point3f toPt, Point3f ptRet, Vector3f normalRet) { Point3f[] centers = m.getCenters(); float d; float dmin = Float.MAX_VALUE; int imin = -1; for (int i = centers.length; --i >= 0; ) { if ((d = centers[i].distance(toPt)) >= dmin) continue; dmin = d; imin = i; } if (imin < 0) return false; getClosestPoint(m, imin, toPt, ptRet, normalRet); return true; }
public void gimpact_vs_concave(CollisionObject body0, CollisionObject body1, GImpactShapeInterface shape0, ConcaveShape shape1, boolean swapped) { // create the callback GImpactTriangleCallback tricallback = new GImpactTriangleCallback(); tricallback.algorithm = this; tricallback.body0 = body0; tricallback.body1 = body1; tricallback.gimpactshape0 = shape0; tricallback.swapped = swapped; tricallback.margin = shape1.getMargin(); // getting the trimesh AABB Transform gimpactInConcaveSpace = Stack.alloc(Transform.class); body1.getWorldTransform(gimpactInConcaveSpace); gimpactInConcaveSpace.inverse(); gimpactInConcaveSpace.mul(body0.getWorldTransform(Stack.alloc(Transform.class))); Vector3f minAABB = Stack.alloc(Vector3f.class), maxAABB = Stack.alloc(Vector3f.class); shape0.getAabb(gimpactInConcaveSpace, minAABB, maxAABB); shape1.processAllTriangles(tricallback, minAABB, maxAABB); }
/** * * @param pl line point * @param u line vector * @param n plane normal * @param p point from plane * @return intersection of line and plane, if it doesn't exist returns null */ public static Vector3f findLinePlaneIntersection(Vector3f pl, Vector3f u, Vector3f n, Vector3f p) { Vector3f w = new Vector3f(pl); w.sub(p); float D = n.dot(u); float N = -n.dot(w); if (Math.abs(D) == 0) { // segment is parallel to plane if (N == 0) // segment lies in plane { return pl; } else { return null; // no intersection } } // they are not parallel // compute intersect param float sI = N / D; Vector3f intersection = new Vector3f(u); intersection.scale(sI); intersection.add(pl); return intersection; }
public static Matrix3f setEllipsoidMatrix(Vector3f[] unitAxes, float[] lengths, Vector3f vTemp, Matrix3f mat) { /* * Create a matrix that transforms cartesian coordinates * into ellipsoidal coordinates, where in that system we * are drawing a sphere. * */ for (int i = 0; i < 3; i++) { vTemp.set(unitAxes[i]); vTemp.scale(lengths[i]); mat.setColumn(i, vTemp); } mat.invert(mat); return mat; }
@Override public PhysicsObjJBullet rayTrace(IVec3fR start, IVec3fR end, IVec3fW dest){ ClosestRayResultCallback v=new ClosestRayResultCallback(new Vector3f(start.x(), start.y(), start.z()), new Vector3f(end.x(), end.y(), end.z())); bulletWorld.rayTest(v.rayFromWorld, v.rayToWorld, v); if(!v.hasHit()) return null; if(dest!=null){ dest.x(v.hitPointWorld.x); dest.y(v.hitPointWorld.y); dest.z(v.hitPointWorld.z); } return (PhysicsObjJBullet)v.collisionObject.getUserPointer(); }
private static BakedModelKnowledgeBook rebake(ModelKnowledgeBook model, String name) { Matrix4f m = new Matrix4f(); m.m20 = 1f / 128f; m.m01 = m.m12 = -m.m20; m.m33 = 1; Matrix3f rotation = new Matrix3f(); m.getRotationScale(rotation); Matrix3f angleZ = new Matrix3f(); angleZ.rotZ(-1.5708F); rotation.mul(rotation, angleZ); m.setRotationScale(rotation); m.setScale(0.66666666667F * m.getScale()); m.setTranslation(new Vector3f(0.1875F, 0.2505F, 0.125F)); SimpleModelFontRenderer fontRenderer = new SimpleModelFontRenderer(Minecraft.getMinecraft().gameSettings, font, Minecraft.getMinecraft().getTextureManager(), false, m, DefaultVertexFormats.ITEM) { @Override protected float renderUnicodeChar(char c, boolean italic) { return super.renderDefaultChar(126, italic); } }; int maxLineWidth = 96; TextureAtlasSprite fontSprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(font2.toString()); List<BakedQuad> textQuads = new ArrayList<BakedQuad>(); fontRenderer.setSprite(fontSprite); fontRenderer.setFillBlanks(false); int yOffset = 2; String title = I18n.translateToLocal(name); List<String> lines = fontRenderer.listFormattedStringToWidth(title, maxLineWidth); for (int line = 0; line < lines.size(); line++) { int offset = ((maxLineWidth - fontRenderer.getStringWidth(lines.get(line))) / 2); fontRenderer.drawString(lines.get(line), offset, yOffset, 0x00000000); yOffset += (fontRenderer.FONT_HEIGHT - 1 + 4); } textQuads.addAll(fontRenderer.build()); return new BakedModelKnowledgeBook(model, textQuads); }
@Override public void updatePhysics() { Transform t = new Transform(); this.ghostObject.getWorldTransform(t); Vector3f v = t.origin; Quat4f r = new Quat4f(); r = t.getRotation(r); //TODO: FIX ROTATION. - Oskar Mendel 2017-07-05 this.setPosition(v.x, v.y, v.z); this.setRotation(r.x, r.y, r.z, r.w); }
/** * */ @Override public void initPhysics() { DefaultMotionState groundMotionState = new DefaultMotionState(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(0, -1, 0), 1.0f))); //TODO: Un uglify this code. TriangleIndexVertexArray vertArray = new TriangleIndexVertexArray(); for (Mesh mesh : this.getMeshes()) { // Construct collision shape based on the mesh vertices in the Mesh. float[] positions = mesh.getPositions(); int[] indices = mesh.getIndices(); IndexedMesh indexedMesh = new IndexedMesh(); indexedMesh.numTriangles = indices.length / 3; indexedMesh.triangleIndexBase = ByteBuffer.allocateDirect(indices.length*4).order(ByteOrder.nativeOrder()); indexedMesh.triangleIndexBase.asIntBuffer().put(indices); indexedMesh.triangleIndexStride = 3 * 4; indexedMesh.numVertices = positions.length / 3; indexedMesh.vertexBase = ByteBuffer.allocateDirect(positions.length*4).order(ByteOrder.nativeOrder()); indexedMesh.vertexBase.asFloatBuffer().put(positions); indexedMesh.vertexStride = 3 * 4; vertArray.addIndexedMesh(indexedMesh); } BvhTriangleMeshShape collShape = new BvhTriangleMeshShape(vertArray, false); System.out.println("SCALE: " + this.getScale()); //collisionShape = new ScaledBvhTriangleMeshShape(collShape, new Vector3f(this.getcale(), this.getScale(), this.getScale())); collisionShape = collShape; collisionShape.setLocalScaling(new Vector3f(this.getScale(), this.getScale(), this.getScale())); RigidBodyConstructionInfo groundRigidBodyCI = new RigidBodyConstructionInfo(0, groundMotionState, collisionShape, new Vector3f(0,0,0)); rigidBody = new RigidBody(groundRigidBodyCI); this.rigidBody.activate(); }
/** * Method to initialize all physics related * values. */ @Override public void initPhysics() { motionState = new DefaultMotionState(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(-2, -400, 0), 1.0f))); // Construct collision shape based on the mesh vertices in the Mesh. fallInertia = new Vector3f(0,0,0); collisionShape = new BoxShape(new Vector3f(1, 1, 1)); collisionShape.calculateLocalInertia(mass,fallInertia); // Construct the RigidBody. RigidBodyConstructionInfo rigidBodyCI = new RigidBodyConstructionInfo(mass, motionState, collisionShape, fallInertia); rigidBody = new RigidBody(rigidBodyCI); }
/** * Method to update physics logic for this MassterBall. */ @Override public void updatePhysics() { Vector3f v = this.rigidBody.getWorldTransform(new Transform()).origin; Quat4f r = new Quat4f(); this.rigidBody.getWorldTransform(new Transform()).getRotation(r); this.setPosition(v.x, v.y, v.z); this.setRotation(r.w, r.x, r.y, r.z); }
/** * */ public PhysicsSpace() { // TODO: Comments on stuff. broadPhase = new DbvtBroadphase(); collisionConfiguration = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(collisionConfiguration); solver = new SequentialImpulseConstraintSolver(); dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadPhase, solver, collisionConfiguration); dynamicsWorld.getBroadphase().getOverlappingPairCache().setInternalGhostPairCallback(new GhostPairCallback()); dynamicsWorld.setGravity(new Vector3f(0, -10, 0)); }
/** * addStroke creates a new stroke * * @param newPoint a 3D point in world space */ private void addStroke(Vector3f newPoint) { biquadFilter = new BiquadFilter(mLineSmoothing); for (int i = 0; i < 1500; i++) { biquadFilter.update(newPoint); } Vector3f p = biquadFilter.update(newPoint); mLastPoint = new Vector3f(p); mStrokes.add(new ArrayList<Vector3f>()); mStrokes.get(mStrokes.size() - 1).add(mLastPoint); }
/** * @param newPoint * @param lastPoint * @return */ public static boolean distanceCheck(Vector3f newPoint, Vector3f lastPoint) { Vector3f temp = new Vector3f(); temp.sub(newPoint, lastPoint); if (temp.length() > AppSettings.getMinDistance()) { return true; } return false; }
@Override public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType type) { if(instrument != null) { HashMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = new HashMap<>(); map.put(ItemCameraTransforms.TransformType.FIRST_PERSON_LEFT_HAND, new TRSRTransformation(new Vector3f(1F, 0F, 1F), TRSRTransformation.quatFromXYZDegrees(new Vector3f(0F, 180F, 0F)), new Vector3f(1F, 1F, 1F), new Quat4f())); map.put(ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, new TRSRTransformation(new Vector3f(0.1F, 0F + (instrument.handImg.getHeight() <= 16F ? 0F : MathHelper.clamp((float)instrument.info.activeHandPosition[1], -0.3F, 0.3F)), 0.025F - (instrument.handImg.getWidth() <= 16F ? 0F : MathHelper.clamp((float)instrument.info.activeHandPosition[0], -0.5F, 0.5F))), TRSRTransformation.quatFromXYZDegrees(new Vector3f(0F, 80F, 0F)), new Vector3f(-1F, 1F, 1F), TRSRTransformation.quatFromXYZDegrees(new Vector3f(0F, 0F, 0F)))); map.put(ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, new TRSRTransformation(new Vector3f(-0.1F, 0F + (instrument.handImg.getHeight() <= 16F ? 0F : MathHelper.clamp((float)instrument.info.activeHandPosition[1], -0.3F, 0.3F)), 1F - (instrument.handImg.getWidth() <= 16F ? 0F : MathHelper.clamp((float)instrument.info.activeHandPosition[0], -0.5F, 0.5F))), TRSRTransformation.quatFromXYZDegrees(new Vector3f(0F, 80F, 0F)), new Vector3f(1F, 1F, 1F), TRSRTransformation.quatFromXYZDegrees(new Vector3f(0F, 0F, 0F)))); ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> transforms = ImmutableMap.copyOf(map); return PerspectiveMapWrapper.handlePerspective(ModelBaseWrapper.isEntityRender(type) ? instrument.handModel : instrument.iconModel, transforms, type); } return PerspectiveMapWrapper.handlePerspective(this, transforms, type); }
protected static void putVertexData(UnpackedBakedQuad.Builder builder, Vector3f pos, EnumFacing facing, float u, float v, TextureAtlasSprite sprite, Color col, TRSRTransformation transform) { for (int e = 0; e < builder.getVertexFormat().getElementCount(); e++) switch (builder.getVertexFormat().getElement(e).getUsage()) { case POSITION: if (transform == TRSRTransformation.identity()) { builder.put(e, pos.getX(), pos.getY(), pos.getZ(), 1F); } else { Vector4f vec = new Vector4f(); vec.x = pos.x; vec.y = pos.y; vec.z = pos.z; vec.w = 1; transform.getMatrix().transform(vec); builder.put(e, vec.x, vec.y, vec.z, vec.w); } break; case COLOR: float r = ((col.getRGB() >> 16) & 0xFF) / 255f; // red float g = ((col.getRGB()>> 8) & 0xFF) / 255f; // green float b = ((col.getRGB() >> 0) & 0xFF) / 255f; // blue float a = ((col.getRGB() >> 24) & 0xFF) / 255f; // alpha builder.put(e, r, g, b, a); break; case UV: if (builder.getVertexFormat().getElement(e).getIndex() == 0) { builder.put(e, u, v, 0F, 1F); break; } break; case NORMAL: Normal normal = new Normal(facing.getDirectionVec().getX(), facing.getDirectionVec().getY(), facing.getDirectionVec().getZ()); builder.put(e, normal.x, normal.y, normal.z, 0); break; default: builder.put(e); } }
public void GradientPerturbFractal(Vector3f v3) { int seed = m_seed; float amp = m_gradientPerturbAmp * m_fractalBounding; float freq = m_frequency; SingleGradientPerturb(seed, amp, m_frequency, v3); for (int i = 1; i < m_octaves; i++) { freq *= m_lacunarity; amp *= m_gain; SingleGradientPerturb(++seed, amp, freq, v3); } }
public static void transform(org.lwjgl.util.vector.Vector3f vec, Matrix4f m) { Vector4f tmp = new Vector4f(vec.x, vec.y, vec.z, 1f); m.transform(tmp); if(Math.abs(tmp.w - 1f) > 1e-5) tmp.scale(1f / tmp.w); vec.set(tmp.x, tmp.y, tmp.z); }
public Normal getNormal() { Vector3f a = this.verts[2].getPos3(); a.sub(this.verts[0].getPos3()); Vector3f b = this.verts[3].getPos3(); b.sub(this.verts[1].getPos3()); a.cross(a, b); a.normalize(); return new Normal(a); }
private static TRSRTransformation get(float tx, float ty, float tz, float ax, float ay, float az, float s) { return TRSRTransformation.blockCenterToCorner(new TRSRTransformation( new Vector3f(tx / 16, ty / 16, tz / 16), TRSRTransformation.quatFromXYZDegrees(new Vector3f(ax, ay, az)), new Vector3f(s, s, s), null)); }