//---------------------------------------------------------------- void myobject3D::applyArmRotations(ofVec3f v, float angleA, ofVec3f axistbA, int modei) { //mode: //1 is for regular euler angle rotation inside rotateSlicer //2 is for quaternion rotate angle and vector info mode = modei; if(mode ==1 ) { armRot = (v)*-1; //apply armature axis rotations (x-y-z) to the real object SG_POINT rotP = {0,0,0}; SG_VECTOR rotV = {1,0,0}; object->InitTempMatrix()->Rotate(rotP,rotV,ofDegToRad(armRot.x)); SG_VECTOR rotV2 = {0,1,0}; object->GetTempMatrix()->Rotate(rotP,rotV2,ofDegToRad(armRot.y)); SG_VECTOR rotV3 = {0,0,1}; object->GetTempMatrix()->Rotate(rotP,rotV3,ofDegToRad(armRot.z)); object->ApplyTempMatrix(); object->DestroyTempMatrix(); } else if (mode == 2) { quatAngle = angleA; SG_POINT rotP = {0,0,0}; rotVQuat.x = axistbA.x; rotVQuat.y = axistbA.y; rotVQuat.z = axistbA.z; object->InitTempMatrix()->Rotate(rotP,rotVQuat,quatAngle); object->ApplyTempMatrix(); object->DestroyTempMatrix(); } }
//-------------------------------------------------------------- void ofApp::update(){ me.dotSize = dotSize; me.angleOffSetA= ofDegToRad(angleA); me.angleOffSetB= ofDegToRad(angleB); }
void testApp::generateVBOs() { // If the meshes have already been generated once, we need to clear their data vboMeshOriginal.clear(); vboMeshMirrored.clear(); // Shorthand to make the equations more readable // r is the radius of a circle that is inscribed by the display window // a is the current angle heading we will use to sample the image // da is half the span of the triangle float r = minWindowDimension/2.0; float a = ofDegToRad(imageSectionHeading); float da = ofDegToRad(triangleAngularWidth/2); // Define the vertices of the triangular face ofVec3f triangleBottom(0, 0, 0); ofVec3f triangleLeft(r*cos(a+da), -r*sin(a+da), 0); // Flip because of drawing ofVec3f triangleRight(r*cos(a-da), -r*sin(a-da), 0); // Flip because of drawing float cx = imageSectionCenter.x; float cy = imageSectionCenter.y; r = minImageDimension/2.0; // Define the triangular section of the image that we want to draw on the face ofVec2f textureBottom(cx, cy); ofVec2f textureLeft(cx+r*cos(a+da), cy-r*sin(a+da)); ofVec2f textureRight(cx+r*cos(a-da), cy-r*sin(a-da)); // Add the vertices to the VBO mesh to form a triangle addFace(vboMeshOriginal, triangleBottom, triangleLeft, triangleRight); addFace(vboMeshMirrored, triangleBottom, triangleLeft, triangleRight); // Add the texture coordinates to the mesh addTexture(vboMeshOriginal, textureBottom, textureLeft, textureRight); addTexture(vboMeshMirrored, textureBottom, textureRight, textureLeft); }
void ofxKsmrParallellinkDelta::setPlot(ofVec3f pos){ plot.setPosition(pos); for (int i = 0;i < 3;i++){ plots[i].set(cos(ofDegToRad(90-i*120))*plot_radius, 0.0, sin(ofDegToRad(90-i*120))*plot_radius); plots[i] += pos; float currentDist; const float degRes = 0.2; for (float deg = 0; deg < 90; deg+=degRes){ actuator[i].setOrientation(ofVec3f(0,0,0)); actuator[i].pan(i*120); actuator[i].tilt(-deg); currentDist = arm[i].getGlobalPosition().distance(plots[i]); if (currentDist > arm2_length/2){ actuator[i].tilt(degRes); break; } } } }
//-------------------------------------------------------------- void ofApp::setColorsToSend(){ /* * three different examples/demoModes that set/generate a color * the colorPicker is actually quite usefull! */ switch (demoMode) { case 0: //use the colorPicker pickColor(mouseX, mouseY); break; case 1: //static green! red = 255; green = 255; blue = 0; break; case 2: //something a bit more dynamic frames = ++frames % 360; //static const float DegRadFactor = PI / 180.0f; float radR = ofDegToRad(frames); float radG = ofDegToRad(frames + 120); float radB = ofDegToRad(frames + 240); float intensity = 255; red = ( cosf( radR ) + 1.0f ) * intensity / 2; green = ( sinf( radG ) + 1.0f ) * intensity / 2; blue = ( sinf( radB ) + 1.0f ) * intensity / 2; break; } }
void G_CircularRangeSlider::draw(){//ofEventArgs & args){ //if (visible) { ofColor color; //ofEnableAlphaBlending(); //scrollTrack: color = getScrollTrackFillColor(); ofSetColor(0, 0, 0);//color.r, color.g, color.b, color.a); ofFill(); ofBeginShape(); ofCircle(x, y, radius); ofEndShape(true); //thumb: color = getThumbFillColor(); ofSetColor(color.r, color.g, color.b, color.a); ofFill(); ofBeginShape(); GeometryUtils::drawArc(x, y, outerRadius, -ofDegToRad(lowAngle-90), -ofDegToRad(highAngle-90), true, true);//(x, y, width, height, this->getCornerRadius()); GeometryUtils::drawArc(x, y, innerRadius, -ofDegToRad(highAngle-90), -ofDegToRad(lowAngle-90), true, true);//(x, y, width, height, this->getCornerRadius()); ofEndShape(true); // //ofDisableAlphaBlending(); //} }
//-------------------------------------------------------------- void DroneAttack::jsonDataSetup(){ ofxJSONElement _drondata; _drondata.open("dropAttack_08102015_edit.json"); ofxJSONElement _dronStrike = _drondata["strike"]; float _radiusEarth = 700; dronData.resize(_dronStrike.size()); for (int i=0; i<_dronStrike.size(); i++){ float _lon = ofToFloat(_dronStrike[i]["lon"].asString()); float _lat = ofToFloat(_dronStrike[i]["lat"].asString()); float _d = ofToFloat(_dronStrike[i]["deaths_max"].asString()); ofVec3f _v; _v.x = _radiusEarth * cos(ofDegToRad(_lat)) * cos(ofDegToRad(_lon)); _v.y = _radiusEarth * cos(ofDegToRad(_lat)) * sin(ofDegToRad(_lon)); _v.z = _radiusEarth * sin(ofDegToRad(_lat)); dronData[i].deathMax = _d; dronData[i].coord = _v; } ofxJSONElement _jsonData; _jsonData.open("ne_110m_coastline.geojson"); ofxJSONElement _jsonDataChild = _jsonData["features"]; for (int i=0; i<_jsonDataChild.size(); i++) { ofxJSONElement _jsonGeoData = _jsonDataChild[i]["geometry"]["coordinates"]; ofPolyline _p; for (int j=0; j<_jsonGeoData.size(); j++) { float _lon = _jsonGeoData[j][0].asFloat(); float _lat = _jsonGeoData[j][1].asFloat(); ofVec3f _v; _v.x = _radiusEarth * cos(ofDegToRad(_lat)) * cos(ofDegToRad(_lon)); _v.y = _radiusEarth * cos(ofDegToRad(_lat)) * sin(ofDegToRad(_lon)); _v.z = _radiusEarth * sin(ofDegToRad(_lat)); _p.addVertex( _v ); } oceanLineCoord.push_back( _p ); } }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(1); ofEnableSmoothing(); me.dotSize = 6.0f; me.angleOffSetA = ofDegToRad(1.5); me.angleOffSetB = ofDegToRad(50); }
void YesNoObjectSoft::startFaceingToCam(ofxCamera* cam, ofxVec3f offset) { ofxVec3f faceCentroid = yesORno->getFaceCentroid(incomingSMSFaceID); ofxVec3f _objCentroid = yesORno->getBodyCentroid(); if (isnan(_objCentroid.x) || isnan(_objCentroid.y) || isnan(_objCentroid.z)) { _objCentroid = preservedObjCentroid; } ofxVec3f camPos = cam->getPosition()-offset; ofxVec3f center = _objCentroid; ofxVec3f tar = camPos; ofxVec3f normal = tar - center; normal.normalize(); ofxVec3f forward = _objCentroid - faceCentroid; forward.normalize(); ofxVec3f axis = normal.crossed(forward); axis.normalize(); float angle = normal.angle(forward); quatTween.setParameters(quatEasing, ofxTween::easeIn, 0.0, 1.0, 950, 0); ofAddListener(quatTween.end_E, this, &YesNoObjectSoft::addSMSCompleted); from = ofxQuaternion(prevFacingAxis.x, prevFacingAxis.y, prevFacingAxis.z, ofDegToRad(prevFaceAngle)); to = ofxQuaternion(axis.x, axis.y, axis.z, ofDegToRad(angle)); prevFaceAngle = angle; prevFacingAxis = axis; ofNotifyEvent(notifyStartCamOrbit, YesOrNo); }
void LaserManager:: drawLaserCircle(LaserCircle &circle){ float distanceTravelled = 2*PI*circle.radius + circle.overlapDistance; vector<float> unitDistances = getPointsAlongDistance(distanceTravelled, accelerationCircle, speedCircle); ofPoint p; ofColor segmentColour; for(int i = 0; i<unitDistances.size(); i++) { float unitDistance = unitDistances[i]; float angle; if(!circle.reversed) angle = ofMap(unitDistance,0,1,-circle.overlapAngle/2,360+(circle.overlapAngle/2)) ; else angle = ofMap(unitDistance,1,0,-circle.overlapAngle/2,360+(circle.overlapAngle/2)) ; segmentColour = circle.colour; if(angle<circle.overlapAngle/2) { segmentColour*= ofMap(angle, -circle.overlapAngle/2,circle.overlapAngle/2, 0, 1); } if(angle> 360 - circle.overlapAngle/2) { segmentColour *= ofMap(angle, 360 -circle.overlapAngle/2,360 + circle.overlapAngle/2, 1, 0); } p.set(circle.pos); p.x+=sin(ofDegToRad(angle))*circle.radius; p.y-=cos(ofDegToRad(angle))*circle.radius; addIldaPoint(p, circle.colour, circle.intensity); } }
//-------------------------------------------------------------- size_t DataSet::loadFragment(const std::string & filePath, const std::string & particleType) { static const int stride = 1; ofxHDF5File h5File; h5File.open(filePath, true); ofxHDF5GroupPtr h5Group = h5File.loadGroup(particleType); // Load the coordinate data and convert angles to radians. auto coordDataSet = h5Group->loadDataSet("Coordinates"); int coordCount = coordDataSet->getDimensionSize(0) / stride; coordDataSet->setHyperslab(0, coordCount, stride); vector<glm::vec3> coordData(coordCount); coordDataSet->read(coordData.data()); // Load the mass data. auto massDataSet = h5Group->loadDataSet("Masses"); int massCount = massDataSet->getDimensionSize(0) / stride; massDataSet->setHyperslab(0, massCount, stride); vector<float> massData(massCount); massDataSet->read(massData.data()); // Load the star formation rate data. auto sfrDataSet = h5Group->loadDataSet("StarFormationRate"); int sfrCount = sfrDataSet->getDimensionSize(0) / stride; sfrDataSet->setHyperslab(0, sfrCount, stride); vector<float> sfrData(sfrCount); sfrDataSet->read(sfrData.data()); // Add valid points to the data set. size_t total = 0; for (int i = 0; i < coordData.size(); ++i) { if (coordData[i].z > 0.0f) { this->coordinates.push_back(glm::vec3(ofDegToRad(coordData[i].x), ofDegToRad(coordData[i].y), coordData[i].z)); this->minRadius = std::min(this->minRadius, coordData[i].z); this->maxRadius = std::max(this->maxRadius, coordData[i].z); this->masses.push_back(massData[i]); if (particleType == "PartType6") { this->starFormationRates.push_back(sfrData[i]); } else { // These are stars so just put in dummy data. this->starFormationRates.push_back(-1.0f); } ++total; } } return total; }
void Firework::draw(){ if((launched)&&(!exploded)&&(!hidden)){ launchMaths(); // ofSetLineWidth(1); // ofSetColor(255); // ofLine(x,y,oldX,oldY); } if((!launched)&&(exploded)&&(!hidden)){ explodeMaths(); ofSetColor(flare[flareNum]); for(int i = 0; i < flareAmount + 1; i++){ ofPushMatrix(); ofTranslate(x,y); float posX = sin(ofDegToRad(i*flareAngle))*explodeTimer*3; float posY = cos(ofDegToRad(i*flareAngle))*explodeTimer*3; ofCircle(posX, posY, flareWeight*1.2); ofSetLineWidth(flareWeight); ofLine(posX*0.9,posY*0.9,posX*0.4,posY*0.4); //ofLine(posX*0.4,posY*0.4,posX*0.6,posY*0.6); ofPopMatrix(); } } if((!launched)&&(!exploded)&&(hidden)){ //do nothing } }
void SmartPoly::updateControlPoints(){ // Reset the contorl points vector. controlPoints = vector<ofPoint>(); // Get Polylinepts with pos vector<ofPoint> polyLinePrePts = polyLine.getVertices(); vector<ofPoint> polyLinePts = vector<ofPoint>(); for (vector<ofPoint>::iterator it = polyLinePrePts.begin() ; it != polyLinePrePts.end(); ++it){ ofPoint p = *it; // All points in the poly will be stored respective to pos. p = p + pos; polyLinePts.push_back(p); } for (vector<ofPoint>::iterator it = polyLinePts.begin() ; it != polyLinePts.end(); ++it){ ofPoint p = *it; // Control point position comes from the pos point and // the distance and angle of each point relative to the // pos point. float length = ofDist(p.x, p.y, pos.x, pos.y); float angle = atan2((p.y - pos.y),(p.x - pos.x)); p.x = pos.x + cos(angle + ofDegToRad(rotation)) * length; p.y = pos.y + sin(angle + ofDegToRad(rotation)) * length; controlPoints.push_back(p); } }
void Shape::Draw() { ofSetColor(mColor); ofPushMatrix(); ofRotate(mAngle); ofTranslate(0,mDistance); switch (mShape) { case ST_CIRCLE: ofCircle(ofPoint(0,0),mSize); break; case ST_SQUARE: ofRect(ofPoint(0,0), mSize, mSize); break; case ST_TRIANGLE: ofTriangle(ofPoint(0,0), ofPoint(mSize * cos(ofDegToRad(60)),mSize * sin(ofDegToRad(60))), ofPoint(-mSize * cos(ofDegToRad(60)), mSize * sin(ofDegToRad(60)))); break; default: break; } ofPopMatrix(); }
void Planet::drawPlanet(){ ofPushMatrix(); if (!orbiting){ ofTranslate(ofGetWidth()/2, ofGetHeight()/2, z); if (pushing_into_orbit){ if (z<= -radius){ pushing_into_orbit=false; orbiting = true; } else{ z-=4; } } } else{ int _x= radius*sin(ofDegToRad(theta)); int _z= radius*cos(ofDegToRad(theta)); ofTranslate(ofGetWidth()/2+_x, ofGetHeight()/2, _z); } ofRotate(ofGetFrameNum()/* *speed factor */ , 0, 1, 0); ofSetColor(ofColor::white); fbo.getTextureReference().bind(); ball.draw(); fbo.getTextureReference().unbind(); ofPopMatrix(); }
//-------------------------------------------------------------- void MoonCreator::setup(){ cam.setNearClip(0.0001f); cam.setFarClip(10000.0f); cam.toggleControl(); meshMoon.setMode(OF_PRIMITIVE_POINTS); csv.loadFile(ofToDataPath("MoonCreator.csv")); float _radiusMoon = 700; mesh.clear(); point3D.resize(csv.data.size()); lineLengthRandom.resize(csv.data.size()); for (int i=0; i<point3D.size(); i++) { float _lon = ofToFloat(csv.data[i][0]); float _lat = ofToFloat(csv.data[i][1]); float _size = ofToFloat(csv.data[i][1]); ofVec3f _v; _v.x = _radiusMoon * cos(ofDegToRad(_lat)) * cos(ofDegToRad(_lon)); _v.y = _radiusMoon * cos(ofDegToRad(_lat)) * sin(ofDegToRad(_lon)); _v.z = _radiusMoon *sin(ofDegToRad(_lat)); creatorCoord.push_back(_v); creatorSize.push_back(_size * 0.3); meshMoon.addVertex( _v ); meshMoon.addColor( ofColor(255) ); ofVec3f _point3D = _v; mesh.addVertex(_point3D); mesh.addNormal(_point3D); ofColor _c = ofColor(255); mesh.addColor(_c); point3D[i].point3DRaw = _point3D; lineLengthRandom[i] = ofRandom(0.5, 1.5); } creatorSetting(); returnBase(); lineFFTFactor = 1; }
//-------------------------------------------------------------- void ofApp::update(){ me.dotSize = dotsize; // for degrees and radiants me.angleOffSetA = ofDegToRad(angleA); me.angleOffSetB = ofDegToRad(angleB); }
void testApp::drawRotLine(float x, float y, float angle, float length){ float outerX = x + cos(ofDegToRad(angle)) *length; float outerY = y + sin(ofDegToRad(angle)) *length; ofLine(x, y, outerX, outerY); }
//-------------------------------------------------------------- void testApp::drawAndledLine(ofPoint center, float angle, float length){ ofPoint outer; outer.x =center.x+ cos(ofDegToRad(angle)) *length; outer.y =center.y+ sin(ofDegToRad(angle)) *length; ofLine(center, center + outer); }
//-------------------------------------------------------------- void testApp::update(){ x += cos(ofDegToRad(angle-90)) * v; y += sin(ofDegToRad(angle-90)) * v; if (abs(v) > .1) { v *= friction; } }
void Lyu::ArcBarNode::customDraw() { if(TimeStart<=0) { TimeStart = ofGetElapsedTimef(); return; } float TimeNow = ofGetElapsedTimef(); float PassedTime = TimeNow-TimeStart; float TimeNorm = StartPct+PassedTime/Duration; float pct(0); if(WMode==WrapMode::CLAMP) { pct = ofClamp(TimeNorm,0,1); } else if(WMode==WrapMode::REPEAT) { pct = ofWrap(TimeNorm,0,1); } else if(WMode==WrapMode::MIRRORED_REPEAT) { pct = ofWrap(TimeNorm,0,2); pct = pct>1.0f?2.0f-pct:pct; } float deg = pct*360.0f; ofPath P; float degStep = 360.0f/CircleRes; int IterNum = ceil(deg/degStep); float degStep2 = deg/IterNum; for(int i=0;i<=IterNum;i++) { float rad = ofDegToRad(degStep2*i); float x = Radius[0]*cos(rad); float y = Radius[0]*sin(rad); P.lineTo(ofVec2f(x,y)); } for(int i=IterNum;i>=0;i--) { float rad = ofDegToRad(degStep2*i); float x = Radius[1]*cos(rad); float y = Radius[1]*sin(rad); P.lineTo(ofVec2f(x,y)); } P.lineTo(ofVec2f(Radius[0],0)); P.setColor(Cr); ofPushStyle(); ofFill(); P.draw(); ofPopStyle(); }
void ball::update() { pos.x = cos(ofDegToRad(angle)) * radius; pos.y = sin(ofDegToRad(angle)) * radius; angle++; }
ofxCartesian& ofxCartesian::operator=(ofxLatLon ll) { //from ofxLatLon to ofxCartesian float phi = ofDegToRad(ll.lat + 90); float theta = ofDegToRad(ll.lon - 90); x = sin(phi) * cos(theta); y = sin(phi) * sin(theta); z = -cos(phi); if (ll.lat>=0) x=-x; return *this; }
void Attractor::update(){ float x = cos(ofDegToRad(angle))*radius; float y = sin(ofDegToRad(angle))*radius; rot.set(center.x + x, center.y + y); angle -= 5; }
void ofxSphereCam::update() { noiseCount += noiseSpeed; posTween.update(); ofVec3f mt; if (spherical) { float phiRad = ofDegToRad(posTween.getTarget(1)); float thetaRad = ofDegToRad(posTween.getTarget(2)); mt = ofVec3f( (posTween.getTarget(0) * sin(phiRad) * cos(thetaRad)) + lookedAt.x, (posTween.getTarget(0) * sin(phiRad) * sin(thetaRad)) + lookedAt.y, (posTween.getTarget(0) * cos(phiRad)) + lookedAt.z ); setPosition(mt); } else { mt = ofVec3f( posTween.getTarget(0), posTween.getTarget(1), posTween.getTarget(2) ); setPosition(mt); } lookAtTween.update(); ofVec3f la = ofVec3f( lookAtTween.update(), lookAtTween.getTarget(1), lookAtTween.getTarget(2) ); if (handheld) { lookAt(ofVec3f( la.x + handNoiseAmt * (ofNoise(noiseCount)), la.y + handNoiseAmt * (ofNoise(noiseCount, noiseCount)), la.z + handNoiseAmt * (ofNoise(noiseCount, noiseCount, noiseCount)))); } else { lookAt(ofVec3f(la)); } lookedAt=la; movedTo=mt; }
//-------------------------------------------------------------- void LineFFElement::draw() { ofPushMatrix(); ofTranslate(m_pos); ofTranslate(m_radius*cos(ofDegToRad(m_rot)), m_radius*sin(ofDegToRad(m_rot))); ofRotateZ(m_rot); ofSetColor(m_color); mp_meshPlane->draw(); ofPopMatrix(); }
void radar::draw(){ ofSetColor(255,255,0); //length of radar float x1 = 2000 * cos(ofDegToRad(angle + width)); float y1 = 2000 * sin(ofDegToRad(angle + width)); float x2 = 2000 * cos(ofDegToRad(angle - width)); float y2 = 2000 * sin(ofDegToRad(angle - width)); ofTriangle(ofGetWidth()/2,ofGetHeight()/2,x1,y1,x2,y2); }
//-------------------------------------------------------------- void ofApp::update(){ degrees++; if(degrees > 359) degrees = 0; sine = sin(ofDegToRad(degrees)); cosine = cos(ofDegToRad(degrees)); }
ofVec3f Projector::sphToCar(ofVec3f t) { float azi, ele, dis; float x, y, z; azi = ofDegToRad(t.x); ele = ofDegToRad(t.y+90); dis = t.z; x = sin(azi) * sin(ele) * dis; y = cos(ele) * dis; z = cos(azi) * sin(ele) * dis; return ofVec3f(x,y,z); };
//-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(1); ofEnableSmoothing(); me.dotSize = 9.0f; me.angleOffSetA= ofDegToRad(1.5); me.angleOffSetB = ofDegToRad(50); gui.setup(); gui.add(dotSize.setup("dotsize", 8, 1, 15)); gui.add(angleA.setup("angleA", 1.5, 1, 5)); gui.add(angleB.setup("angleB", 50, 1, 20)); }