public void get( final IVerhaltenEntity[] theNeighbors, final Engine theEngine, final Vector3f theDirection) { theDirection.set(0, 0, 0); if (theNeighbors.length != 0) { for (int i = 0; i < theNeighbors.length; i++) { theDirection.add(theNeighbors[i].position()); } theDirection.scale(1.0f / (float) theNeighbors.length); _mySeek.setPoint(theDirection); _mySeek.get(theEngine, theDirection); } }
public void pre_step() { Vector3f ab = mathematik.Util.sub(mParticleA.position(), mParticleB.position()); Vector3f cb = mathematik.Util.sub(mParticleC.position(), mParticleB.position()); final float mCurrentAngle = ab.angle(cb); if (mCurrentAngle < mMinAngle) { final int TINY_FACTOR_MODELL = 0; final int TRIG_MODELL = 1; final int MAX_DISTANCE_MODELL = 2; final int mModell = TRIG_MODELL; switch (mModell) { case TINY_FACTOR_MODELL: { final float TINY_FACTOR = 1.1f; final float mDistance = mParticleA.position().distance(mParticleC.position()) * TINY_FACTOR; restlength(mDistance); } break; case TRIG_MODELL: { // a = sqrt ( b*b + c*c - 2bc*cosA ) final float b = ab.length(); final float c = cb.length(); final float mDistance = (float) Math.sqrt(b * b + c * c - 2 * b * c * (float) Math.cos(mMinAngle)); restlength(mDistance); } break; case MAX_DISTANCE_MODELL: { final float mDistance = mParticleA.position().distance(mParticleB.position()) + mParticleC.position().distance(mParticleB.position()); restlength(mDistance); } break; } active(true); } }
public <E extends IVerhaltenEntity> void get( final Vector<E> theNeighbors, final int theNumberOfEntities, final Engine theEngine, final Vector3f theDirection) { final int myNumberOfEntities; if (theNumberOfEntities < theNeighbors.size()) { myNumberOfEntities = theNumberOfEntities; } else { myNumberOfEntities = theNeighbors.size(); } theDirection.set(0, 0, 0); if (!theNeighbors.isEmpty()) { for (int i = 0; i < myNumberOfEntities; i++) { theDirection.add(theNeighbors.get(i).position()); } theDirection.scale(1.0f / (float) myNumberOfEntities); _mySeek.setPoint(theDirection); _mySeek.get(theEngine, theDirection); } }
public void loop() { for (int i = 0; i < particles.length; i++) { /* check if particle is active. * if so, animate the particle, if not, reset the particle * to a random start position */ if (particles[i].isActive) { Vector3f myDirection = new Vector3f(event().mouseX, event().mouseY, 0); myDirection.sub(particles[i].position); final float myDistance = myDirection.length(); myDirection.scale(particles[i].speed / myDistance); particles[i].position.add(myDirection); particles[i].color.a = 1 - myDistance / (-1.5f * SPAWN_DEPTH); if (myDistance < 1) { particles[i].isActive = false; } } else { particles[i].isActive = true; particles[i].position.set( _myRandom.getFloat(-640, 640), _myRandom.getFloat(-480, 480), SPAWN_DEPTH); particles[i].color.a = 0; } /* map position to backup array */ positionbackuparray[i * 3 + 0] = particles[i].position.x; positionbackuparray[i * 3 + 1] = particles[i].position.y; positionbackuparray[i * 3 + 2] = particles[i].position.z; /* map color4f to backup array */ colorbackuparray[i * 4 + 0] = particles[i].color.r; colorbackuparray[i * 4 + 1] = particles[i].color.g; colorbackuparray[i * 4 + 2] = particles[i].color.b; colorbackuparray[i * 4 + 3] = particles[i].color.a; } }
public Vector3f getV3fLoc() { Vector3f v = new Vector3f(); v.set(loc.x, loc.y, loc.z); return v; }
static Vector3f getCenter(final Vector<Vector3f> theVertices, final Triangle theTriangle) { final Vector3f myCenter = new Vector3f(); final Vector3f v0 = theVertices.get(theTriangle.p[0]); final Vector3f v1 = theVertices.get(theTriangle.p[1]); final Vector3f v2 = theVertices.get(theTriangle.p[2]); final Vector3f myNormal = new Vector3f(0, 0, 1); final Vector3f pA = mathematik.Util.sub(v2, v0); pA.scale(0.5f); Vector3f pAc = new Vector3f(); pAc.cross(pA, myNormal); pAc.add(v0); pAc.add(pA); pA.add(v0); final Vector3f pB = mathematik.Util.sub(v2, v1); pB.scale(0.5f); Vector3f pBc = new Vector3f(pB); pBc.cross(pB, myNormal); pBc.add(v1); pBc.add(pB); pB.add(v1); mathematik.Intersection.lineLineIntersect(pA, pAc, pB, pBc, myCenter, new Vector3f(), null); return myCenter; }
private static boolean getCircumCircle( float xp, float yp, float x1, float y1, float x2, float y2, float x3, float y3, Vector3f circle) { /* * Return TRUE if a point (xp,yp) is inside the circumcircle made up * of the points (x1, y1), (x2, y2), (x3, y3) * The circumcircle centre is returned in (xc, yc) and the radius r * NOTE: A point on the edge is inside the circumcircle */ float m1, m2, mx1, mx2, my1, my2; float dx, dy, rsqr, drsqr; float xc, yc, r; /* Check for coincident points */ if (Math.abs(y1 - y2) < mathematik.Mathematik.EPSILON && Math.abs(y2 - y3) < mathematik.Mathematik.EPSILON) { if (VERBOSE) { System.out.println("### points are coincident."); } return false; } if (Math.abs(y2 - y1) < mathematik.Mathematik.EPSILON) { m2 = -(x3 - x2) / (y3 - y2); mx2 = (x2 + x3) / 2.0f; my2 = (y2 + y3) / 2.0f; xc = (x2 + x1) / 2.0f; yc = m2 * (xc - mx2) + my2; } else if (Math.abs(y3 - y2) < mathematik.Mathematik.EPSILON) { m1 = -(x2 - x1) / (y2 - y1); mx1 = (x1 + x2) / 2.0f; my1 = (y1 + y2) / 2.0f; xc = (x3 + x2) / 2.0f; yc = m1 * (xc - mx1) + my1; } else { m1 = -(x2 - x1) / (y2 - y1); m2 = -(x3 - x2) / (y3 - y2); mx1 = (x1 + x2) / 2.0f; mx2 = (x2 + x3) / 2.0f; my1 = (y1 + y2) / 2.0f; my2 = (y2 + y3) / 2.0f; xc = (m1 * mx1 - m2 * mx2 + my2 - my1) / (m1 - m2); yc = m1 * (xc - mx1) + my1; } dx = x2 - xc; dy = y2 - yc; rsqr = dx * dx + dy * dy; r = (float) Math.sqrt(rsqr); dx = xp - xc; dy = yp - yc; drsqr = dx * dx + dy * dy; circle.x = xc; circle.y = yc; circle.z = r; return (drsqr <= rsqr ? true : false); }