public void checkCollision(Paddle[] pads) { // check against walls if (y >= height || y < 0) { speed.y *= -1; } if (x >= width) { restart(); paddles[1].addPoint(); timer = 40; } if (x < 0) { restart(); paddles[0].addPoint(); timer = 40; } // check against paddles for (int i = 0; i < pads.length; i++) { if (x > pads[i].x - (pads[i].w / 2) && x < pads[i].x + (pads[i].w / 2) && y > pads[i].y - (pads[i].h / 2) && y < pads[i].y + (pads[i].h / 2)) { speed.x *= -1; float friction = 0.5f; println(pads[i].vel.y); speed.y += friction * pads[i].vel.y; } } }
public void update(float newY) { y = newY; vel.x = x - px; vel.y = y - py; px = x; py = y; }
public PVector getSmoothedVelocity() { PVector total = new PVector(0, 0, 0); for (int i = 0; i < buffer.length; i++) { total.x += buffer[i].x; total.y += buffer[i].y; total.z += buffer[i].z; } PVector smthd = new PVector(total.x / buffer.length, total.y / buffer.length, total.z / buffer.length); return smthd; }
public void updateAll(PVector newPos) { // update current joint position currentPos = newPos; // map velocity to depth image size - I can't find how to get the depth of this context velocity.x = map(newPos.x - prevPos.x, -context.depthWidth(), context.depthWidth(), -1, 1); velocity.y = map(newPos.y - prevPos.y, -context.depthHeight(), context.depthHeight(), -1, 1); velocity.z = newPos.z - prevPos.z; // overwrite the circular buffer buffer[bufferIndex] = velocity; // and incrememnt the buffer index bufferIndex++; if (bufferIndex >= buffer.length) { bufferIndex = 0; } prevPos = newPos; smoothedVelocity = getSmoothedVelocity(); }
public void mouseDragged() { if (paused) { ArrayList objects = timeline.getStatefulObjects(); for (int i = 0; i < objects.size(); i++) { CelestialObject obj = (CelestialObject) objects.get(i); if (obj.isMouseOver()) { dragging = true; PVector pos = obj.getPosition(); pos.x = mouseX; pos.y = mouseY; timeline.reset(); timeline.setCurrentState(objects); sliderTimeline.setValue(0); break; } } } }