Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F81553786
Mover.pde
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Sep 6, 17:17
Size
2 KB
Mime Type
text/x-c++
Expires
Sun, Sep 8, 17:17 (2 d)
Engine
blob
Format
Raw Data
Handle
20593826
Attached To
rBAFOURPROJECT InfoVisuGit
Mover.pde
View Options
class Mover {
float normalForce = 1;
float gravityConstant = 1;
float mu = 0.10;
float eps=0.92;
float frictionMagnitude;
PVector location= new PVector(0, 0);
PVector velocity= new PVector(0, 0);
PVector friction;
PVector gravity=new PVector(0, 0);
Cylinder cyl=new Cylinder();
float rotX=0;
float rotZ=0;
Mover() {
}
void update() {
velocity.add(gravity);
gravity.x = sin(rz) * gravityConstant;
gravity.y = -sin(rx) * gravityConstant;
frictionMagnitude = normalForce * mu;
friction = velocity.copy();
friction.mult(-1);
friction.normalize();
friction.mult(frictionMagnitude);
velocity.add(friction);
location.add(velocity);
//rotX+=velocity.x/cyl.cylinderBaseSize;
rotX+=velocity.x/cyl.cylinderBaseSize;
//rotZ+=velocity.y/cyl.cylinderBaseSize;
rotZ+=velocity.y/cyl.cylinderBaseSize;
}
float getX() {
return location.x;
}
float getY() {
return location.y;
}
float getRotX() {
return -rotZ;
}
float getRotY() {
return 0;
}
float getRotZ() {
return rotX;
}
void checkEdges() {
if (location.x > plate_w/2|| location.x < -plate_w/2) {
velocity.x*=-eps;
}
if (location.y > plate_w/2 || location.y < -plate_w/2) {
velocity.y*=-eps;
}
location.y=Math.max(-plate_w/2, Math.min(plate_w/2, location.y));
location.x=Math.max(-plate_w/2, Math.min(plate_w/2, location.x));
}
private void checkCylinderCollision(ArrayList<PVector> arr, float r) {
ArrayList<PVector> touchingSet=new ArrayList();
for (PVector p : arr) {
if (dist(p.x, p.y, location.x, location.y)<=cyl.cylinderBaseSize+r) {//if too close
lastVelocity = velocity.copy().mag();
score += lastVelocity;
touchingSet.add(p);
PVector nRadius=location.copy().sub(p).normalize();
location=nRadius.copy().mult(cyl.cylinderBaseSize+r).add(p);
velocity.sub(nRadius.mult(2*velocity.dot(nRadius))).mult(eps);//V2 = V1 − 2(V1 · n)n
}
}
arr.removeAll(touchingSet);
}
}
Event Timeline
Log In to Comment