/* Perform Simulation */ public void simulate(float dt) { // Accelerate angular speed float requiredSpeed = targetAngularSpeed - angularSpeed; float angularAccel = requiredSpeed / dt; angularAccel = PApplet.constrain(angularAccel, -maxAngularAccel, maxAngularAccel); // Limit Angular speed angularSpeed += angularAccel * dt; angularSpeed = PApplet.constrain(angularSpeed, -maxAngularSpeed, maxAngularSpeed); // Orientation Simulation orientation += angularSpeed * dt; // Position simulation PVector worldRequiredSpeed = targetSpeed.get(); worldRequiredSpeed.rotate(orientation); worldRequiredSpeed.sub(speed); // PVector worldRequiredSpeed = worldTargetSpeed.get(); float dSpeed = worldRequiredSpeed.mag(); float dAcell = dSpeed / dt; float dForce = Math.min(dAcell * getMass(), motorForce); worldRequiredSpeed.normalize(); worldRequiredSpeed.mult(dForce); force.add(worldRequiredSpeed); super.simulate(dt); }
/** * Retrieves the data associated with a given audio frame. * * @param inpFrameIdx Index of the desired audio frame. * @return Array of float values representing the data for this audio frame. */ private float[] rtrvAudioFrameData(int inpFrameIdx) { float[] rtnFrameData = new float[_frameDataCntNbr]; inpFrameIdx = PApplet.constrain(inpFrameIdx, 0, _audioFrameCnt - 1); for (int bufferIdx = 0; bufferIdx < _frameDataCntNbr; bufferIdx++) { rtnFrameData[bufferIdx] = _musicData[inpFrameIdx][bufferIdx]; } return rtnFrameData; }
private final float constrain(float v, float l, float u) { return parent.constrain(v, l, u); }