示例#1
0
// needs improvement. right now it just looks for the biggest cross product
void approximatePlane(const vector<ofVec3f>& points, int iterations, ofVec3f& center, ofVec3f& normal)
{
	int n = points.size();
	for(int i = 0; i < n; i++)
	{
		center += points[i];
	}
	center /= n;
	float maxLength = 0;
	for(int i = 0; i < n; i++)
	{
		ofVec3f side1 = points[i] - center;
		for(int j = i + 1; j < n; j++)
		{
			ofVec3f side2 = points[j] - center;
			ofVec3f curNormal = side1.getCrossed(side2);
			if(curNormal.z < 0) {
				curNormal *= -1;
			}
			float length = curNormal.length();
			if(length > maxLength)
			{
				normal = curNormal;
				maxLength = length;
			}
		}
	}
	normal.normalize();
}
示例#2
0
//--------------------------------------------------------------
void rotateToNormal(ofVec3f normal) {
	normal.normalize();

	float rotationAmount;
	ofVec3f rotationAngle;
	ofQuaternion rotation;

	ofVec3f axis(0, 0, 1);
	rotation.makeRotate(axis, normal);
	rotation.getRotate(rotationAmount, rotationAngle);
	ofRotateDeg(rotationAmount, rotationAngle.x, rotationAngle.y, rotationAngle.z);
}
示例#3
0
	void Graphics2552::rotateToNormal(ofVec3f normal) {
		normal.normalize();

		float rotationAmount;
		ofVec3f rotationAngle;
		ofQuaternion rotation;

		ofVec3f axis(0, 0, 1);
		rotation.makeRotate(axis, normal);
		rotation.getRotate(rotationAmount, rotationAngle);
		logVerbose("ofRotate " + ofToString(rotationAmount));
		ofRotate(rotationAmount, rotationAngle.x, rotationAngle.y, rotationAngle.z);
	}
示例#4
0
//--------------------------------------------------
void ofPolyline::calcData(int index, ofVec3f &tangent, float &angle, ofVec3f &rotation, ofVec3f &normal) const {
    int i1 = getWrappedIndex(index - 1);
    int i2 = getWrappedIndex(index);
    int i3 = getWrappedIndex(index + 1);
    
    ofPoint p1(points[i1]);
    ofPoint p2(points[i2]);
    ofPoint p3(points[i3]);
    
    ofVec3f v1(p1 - p2); // vector to previous point
    ofVec3f v2(p3 - p2); // vector to next point
    v1.normalize();
    v2.normalize();
    
    tangent = (v2 - v1);
    tangent.normalize();
    
    rotation = v1.getCrossed(v2);
    angle = 180 - ofRadToDeg(acos(ofClamp(v1.x * v2.x + v1.y * v2.y + v1.z * v2.z, -1, 1)));

    normal = rightVector.getCrossed(tangent);
    normal.normalize();
}
示例#5
0
文件: Flock.cpp 项目: Dewb/radome
Boid::Boid(ofVec3f pos, ofVec3f vel, radomeModel* pMod) {
    position = pos;
    velocity = vel;
    velocity = vel.normalize();
    acceleration = ofVec3f(0,0,0);
    
	neighborPosition = ofVec3f(0,0,0);
	numNeighbors = 0;
    
	decay = 0.99;
	crowdFactor	= 1.0;
    speedRange = ofVec2f(ofRandom(1.0, 1.5), ofRandom(2.5, 4.0));
    speedRangeSquared = ofVec2f(speedRange[0] * speedRange[0], speedRange[1] * speedRange[1]);
    
    pModel = pMod;
}
示例#6
0
//--------------------------------------------------------------
void DeviceNode::createChain(ofVec3f ptAttach, ofVec3f dir)
{
    if (mp_device)
    {
        // Physics setup
        physics.clear();
        physics.setGravity(ofVec3f(0, -0.00075, 0));

        // Normalize
        dir.normalize();
        
        ofVec3f posLed  = ptAttach;
        msa::physics::Particle3D* prev=0;
        for (int i=0; i<mp_device->getNbLEDs(); i++ )
        {
            // Create particles
            msa::physics::Particle3D *p = physics.makeParticle(posLed,0.0025f);
            
            // Attach first one
            if (i==0)
                p->makeFixed();
            
            // Spring
            if (prev){
                msa::physics::Spring3D* sp = physics.makeSpring(prev, p, 1.0f, mp_device->getDistLEDs());
                sp->setForceCap(1.0f);
            }
                
            prev = p;
            posLed += mp_device->getDistLEDs() * dir;
            //printf("mp_device->getDistLEDs()=%.3f\n", mp_device->getDistLEDs());
        }
        
        if (prev)
            prev->makeFixed();
        
    }
}
示例#7
0
ofVec3f Player::moveToNextVert(ofVec3f gPoint, float dist){
	ofVec3f ng = gPoint.normalize();
	float dotX = ng.dot(ofVec3f(1.0, 0.0, 0.0));
	float dotY = ng.dot(ofVec3f(0.0, 1.0, 0.0));
	playerMoved = true;
	
	turn.clear();
	if(dotX > 0.0 && dotY > 0.0)
	{
		// 1st quadrant
		ofLog() << "1st quadrant";
		zRotDeg = 45.0;
		gameObject.setOrientation(ofVec3f(0.0, 0.0, 45.0));
	}
	else if(dotX < 0.0 && dotY > 0.0)
	{
		// 2nd quadrant
		ofLog() << "2nd quadrant";
		zRotDeg = 45.0+90.0;
		gameObject.setOrientation(ofVec3f(0.0, 0.0, 45.0+90.0));
	}
	else if(dotX < 0.0 && dotY < 0.0)
	{
		// 3rd quadrant
		ofLog() << "3rd quadrant";
		zRotDeg = 180.0 + 45.0;
		gameObject.setOrientation(ofVec3f(0.0, 0.0, 180.0 + 45.0));
	}
	else if(dotX > 0.0 && dotY < 0.0)
	{
		// 4th quadrant
		ofLog() << "4th quadrant";
		zRotDeg = 270.0 + 45.0;
		gameObject.setOrientation(ofVec3f(0.0, 0.0, 270.0 + 45.0));
	}
	ofVec3f to = gameObject.getGlobalPosition() + (gameObject.getXAxis() * dist);
	ofLog() << "to: " << to;
	
	if(grid->checkMoveToPoint(gameObject.getGlobalPosition(), to))
	{
		ofLog() << "direction open";
		slide.addKeyFrame(Playlist::Action::tween(0.0f, 400.0f, &gPosX, to.x,
				Playlist::TweenType::TWEEN_QUART , TweenTransition::TWEEN_EASE_IN_OUT));
		slide.addToKeyFrame(Playlist::Action::tween(0.0f, 400.0f, &gPosY, to.y,
				Playlist::TweenType::TWEEN_QUART , TweenTransition::TWEEN_EASE_IN_OUT));
		return  to;
	}
	else 
	{
		to = gameObject.getGlobalPosition() + (gameObject.getXAxis() * (dist/2.0f));
		ofLog() << "direction blocked";
		slide.addKeyFrame(Playlist::Action::tween(0.0f, 200.0f, &gPosX, to.x,
				Playlist::TweenType::TWEEN_QUART, TweenTransition::TWEEN_EASE_IN_OUT));
		slide.addToKeyFrame(Playlist::Action::tween(0.0f, 200.0f, &gPosY, to.y,
				Playlist::TweenType::TWEEN_QUART, TweenTransition::TWEEN_EASE_IN_OUT));
		slide.addToKeyFrame(Playlist::Action::tween(200.0f, 200.0f, &gPosX, gameObject.getGlobalPosition().x,
				Playlist::TweenType::TWEEN_QUART, TweenTransition::TWEEN_EASE_IN_OUT));
		slide.addToKeyFrame(Playlist::Action::tween(200.0f, 200.0f, &gPosY, gameObject.getGlobalPosition().y,
				Playlist::TweenType::TWEEN_QUART, TweenTransition::TWEEN_EASE_IN_OUT));
		return gameObject.getGlobalPosition();
	}

	// player anim call
	
	
	
}
示例#8
0
//--------------------------------------------------------------
void ofxFatLine::pushNewVertex(ofVec3f v, ofVec3f p, ofVec3f r1, ofVec3f r2, float maxLength, int index, float cos, bool bFlipped){
    
    ofFloatColor c(colors[index]);
    c.a =0;
    if (cos == 0){
        cos = FLT_EPSILON;
    }
    r1.normalize();
    r2.normalize();
    bool bAligned = false;
    if (abs(cos) == 1) {
        bAligned = true;
        p = r1;
    }
    cos = 1/cos;
    
    midVectors.push_back(p);
    if (bFlipped) {
        p *=-1;
    }
    flippepMidVectors.push_back(p);
    if (bAligned) {
		cout << "vertexAligned" << endl;
		pushNewAnchors(v, p*-1, colors[index], weights[index], feathering, true);
        pushNewAnchor(v, colors[index]);
        pushNewAnchors(v, p, colors[index], weights[index], feathering, false);
        if (index != 0) {
            if (meshVertices.size() >5) {
                for (int i = meshVertices.size()-4; i<meshVertices.size(); i++) {
                    pushQuadIndices(i);
                }
            }
        }
        
    }else{
        
        if (midVectors.back().dot(r1)>0) {
            r1 *=-1;
        }
        if (midVectors.back().dot(r2)>0) {
            r2 *=-1;
        }    
        float midLength = weights[index]*cos;
        if (midLength > maxLength) {
            midLength = maxLength;
        }
        if (bFlipped) {
            pushNewAnchors(v, r1, colors[index], weights[index], feathering, !bFlipped);
            pushNewAnchors(v, midVectors.back(), colors[index], midLength, feathering*cos, bFlipped);
            pushNewAnchor(v, colors[index]);
            pushNewAnchors(v, r2, colors[index], weights[index], feathering, !bFlipped);
            
            
        }else{
            pushNewAnchors(v, r1, colors[index], weights[index], feathering, !bFlipped);
            pushNewAnchors(v, r2, colors[index], weights[index], feathering, !bFlipped);
            pushNewAnchor(v, colors[index]);
            pushNewAnchors(v, midVectors.back(), colors[index], midLength, feathering*cos, bFlipped);        
        }
        int l = meshVertices.size();
        if (l >11) {
            if (bFlipped) {
                pushQuadIndices(l - 12, l -11, l - 5, l - 4);
                pushQuadIndices(l - 11, l -10, l - 4, l - 3);
                pushQuadIndices(l - 10, l - 9, l - 3, l - 7);
                pushQuadIndices(l -  9, l - 8, l - 7, l - 6);
            }else{
                pushQuadIndices(l - 12, l -11, l - 7, l - 6);
                pushQuadIndices(l - 11, l -10, l - 6, l - 3);
                pushQuadIndices(l - 10, l - 9, l - 3, l - 2);
                pushQuadIndices(l -  9, l - 8, l - 2, l - 1);
            }
        }
        updateJoint(index,bFlipped);
    }

    /*
     ofVec3f pp = p * 50 * cos;
     ofVec3f pa = pp + p * 2 * cos;
     
     meshVertices.push_back(pa + v);
     meshColors.push_back(c);
     
     meshVertices.push_back(pp + v);
     meshColors.push_back(colors[index]); 
     
     meshVertices.push_back(v);
     meshColors.push_back(colors[index]);
     
     meshVertices.push_back(v - pp);
     meshColors.push_back(colors[index]);
     
     meshVertices.push_back(v - pa);
     meshColors.push_back(c);
     
     if (meshVertices.size() >5) {
     for (int i = meshVertices.size()-4; i<meshVertices.size(); i++) {
     pushQuadIndices(i);
     }
     }
     //*/
    
}