/** * VectorAvatar is my Avatar-derived class that displays & moves a custom vector PShape. * STUDENT must update getBoundingBox() to work with their PShape. **/ class VectorAvatar extends CollisionDetector { /* The data fields store the state of the Avatar. */ PShape customPShape ; float rotXspeed = .005 ; float rotYspeed = .0025 ; float myrotX = 0, myrotY = 0 ; final int sidelength, sidelimit ; VectorAvatar(int avx, int avy, int avz, float spdx, float spdy, float spdz, float avscale, int size, int limit) { super(avx,avy,avz,0,0,0,/*spdx,spdy,spdz,*/avscale,0,0,0); sidelength = size ; sidelimit = limit ; // Call the base class constructor to initialize its data fields, // then initialize this class' data fields. xlimitright = width ; ylimitbottom = height ; // limit off-screen motion to xlimitleft = 0 ; // one width or height off the display ylimittop = 0 ; // in either direction rotZspeed = .005 ; customPShape = makeCustomPShape(sidelength, sidelimit); } void shuffle() { forceshuffle(); // always do it. } // The display() function simply draws the Avatar object. // The move() function updates the Avatar object's state. void display() { // Draw the avatar. pushMatrix(); // STUDENT *MUST* use pushMatrix() & translate first in display(). translate(myx, myy, myz); scale(myscale); rotateX(myrotX); rotateY(myrotY); rotateZ(myrotZ); shape(customPShape, 0, 0); popMatrix(); // STUDENT *MUST* use popMatrix() last in display(). } // The move() function updates the Avatar object's state. void move() { // get ready for movement in next frame. myx = round(myx + speedX) ; myy = round(myy + speedY) ; myz = round(myz + speedZ); myrotX += rotZspeed ; myrotY += rotYspeed ; myrotZ += rotZspeed ; detectCollisions(); } int [] getBoundingBox() { // These limits do not account for rotation, but the // Pyramid PShape is -sidelength to +sidelength in all 3 dimensions. // You may have to adjust this to work with your PShape. int [] result = new int[6]; // customPShape.depth does not work. /* println("DEBUG customPShape width,height,depth: " + customPShape.width + "," + customPShape.height + "," + customPShape.depth); */ // float sl = sidelength / 2.0 ; result[0] = round(myx - sidelength * myscale) ; //round(myx-myscale*customPShape.width/2.0); result[1] = round(myy - sidelength * myscale) ; //round(myy-myscale*customPShape.height/2.0); result[2] = round(myz - sidelength * myscale) ; //round(myz-myscale*customPShape.depth/2.0); result[3] = round(myx + sidelength * myscale) ; //round(myx+myscale*customPShape.width/2.0); result[4] = round(myy + sidelength * myscale) ; //round(myy-myscale*customPShape.width/2.0); result[5] = round(myz + sidelength* myscale) ; // round(myz-myscale*customPShape.depth/2.0); return result ; } }