Beispiel #1
0
WalkVect ofApp::createWalkVect(ofPoint velocity, ofPoint vector, IsLine line) {
    ofPoint dir = vector.normalize();
    if(velocity.y < 0) dir *= -1;
    WalkVect vect;
    vect.dir = dir;
    vect.spd = velocity.length();
    vect.line = line;
    return vect;
}
void ofApp::update(){
	mouse = ofPoint(mouseX, mouseY); 
	mouse -= center; 
	
	m = mouse.length(); 


	cout << m << " is the magnitude of m" <<endl; 
	//unit vectors 
	mouse.normalize(); 
	mouse*=50;
}
Beispiel #3
0
//--------------------------------------------------------------
void testApp::drawGravity(ofPoint p, ofPoint gravity) {
    
    float angle = (atan2(gravity.y, gravity.x) * 180 / PI) - 90;
    float len   = MIN(200, gravity.length()*10); // scale it up a bit
    
    ofPushMatrix();
    ofTranslate(p.x, p.y);
    ofRotate(angle);
    ofLine(0, 0, 0, len);
    ofTriangle(0, len, 
               -5, len-10, 
               5, len-10);
    ofPopMatrix();
}
Beispiel #4
0
void ofApp::drawVector(ofPoint v, ofPoint loc, float scayl){
    ofPushMatrix();
        float arrowsize = 4;
        // Translate to location to render vector
        ofTranslate(loc);
        ofColor(255);
        // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
        float angle = (float)atan2(-v.y, v.x);
        float theta =  -1.0*angle;
        float heading2D = ofRadToDeg(theta);
        
        ofRotateZ(heading2D);
        
        // Calculate length of vector & scale it to be bigger or smaller if necessary
        float len = v.length()*scayl;
        // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
        ofDrawLine(0,0,len,0);
        ofDrawLine(len,0,len-arrowsize,+arrowsize/2);
        ofDrawLine(len,0,len-arrowsize,-arrowsize/2);
    ofPopMatrix();
}