示例#1
0
void Player::onUpdate(float frametime)
{
    static const EntityManager& manager = EntityManager::getInstance();

    // Animation
    m_animator.updateSubRect(*this, frametime);

    // Weapons
    if (!m_overheat)
    {
        float h = 0.f;
        if (Input::isPressed(Action::USE_LASER))
        {
            h += m_weapon.shoot(0);
        }

        m_heat += h;
        if (m_heat >= m_max_heat)
        {
            m_overheat = true;
            m_panel.setOverheat(true);
            MessageSystem::write(_t("panel.overheat"), getPosition());
        }
        if (h > 0)
            overheatAudioHint();
    }

    // Compute position
    sf::Vector2f pos = getPosition();
    float delta = m_speed * frametime;

    if (Input::isPressed(Action::UP))
        pos.y -= delta;

    if (Input::isPressed(Action::DOWN))
        pos.y += delta;

    if (Input::isPressed(Action::LEFT))
        pos.x -= delta;

    if (Input::isPressed(Action::RIGHT))
        pos.x += delta;

    // Ensure new position is within screen's limits
    const int X_BOUND = manager.getWidth() - getWidth();
    const int Y_BOUND = manager.getHeight() - getHeight();

    if (pos.y < 0)
        pos.y = 0;
    else if (pos.y > Y_BOUND)
        pos.y = Y_BOUND;

    if (pos.x < 0)
        pos.x = 0;
    else if (pos.x > X_BOUND)
        pos.x = X_BOUND;

    // Apply new position
    setPosition(pos);
    m_smoke_emitter.setPosition(getX(), getY() + getHeight() / 2);
    m_shield_emitter.setPosition(getCenter());

    // Cooling heatsink
    if (m_heat > 0.f)
    {
        m_heat -= frametime * m_max_heat / COOLING_DELAY;
        if (m_heat <= 0.f)
        {
            m_heat = 0.f;
            if (m_overheat )
            {
                m_overheat = false;
                m_panel.setOverheat(false);
            }
        }
    }
    m_panel.setHeat(m_heat);

    // Decrase powerups timers
    for (int i = 0; i < TIMED_BONUS_COUNT; ++i)
    {
        if (bonus_[i] > 0)
        {
            bonus_[i] -= frametime;
            if (bonus_[i] <= 0)
            {
                bonus_[i] = 0;
                DisableTimedPowerUp((TimedPowerUp) i);
            }
        }
    }

    updateDamageFlash(frametime);
}
示例#2
0
 void Polygon::sort() {
     AngleXYComparator angleXYComparator(getCenter());
     std::sort(m_listOfVertices.begin(), m_listOfVertices.end(), angleXYComparator);
 }
示例#3
0
文件: Box.cpp 项目: npapier/vgsdk
const Vec3f Box3f::getClosestPoint( const Vec3f& point )
{
	Vec3f result;
	
	// trivial cases first
	if ( isEmpty() ) 
	{
		return point;
	}
	else if (point == getCenter()) 
	{
		// middle of z side
		result[0] = (m_max[0] + m_min[0])/2.0f;
		result[1] = (m_max[1] + m_min[1])/2.0f;
		result[2] = m_max[2];
	}
	else
	{
		// Find the closest point on a unit box (from -1 to 1),
		// then scale up.

		// Find the vector from center to the point, then scale
		// to a unit box.
		Vec3f vec = point - getCenter();
		float sizeX, sizeY, sizeZ;
		getSize(sizeX, sizeY, sizeZ);
		float halfX = sizeX/2.0f;
		float halfY = sizeY/2.0f;
		float halfZ = sizeZ/2.0f;
		
		if (halfX > 0.0)	vec[0] /= halfX;
		if (halfY > 0.0)	vec[1] /= halfY;
		if (halfZ > 0.0)	vec[2] /= halfZ;

		// Side to snap side that has greatest magnitude in the vector.
		Vec3f mag;
		mag[0] = fabs(vec[0]);
		mag[1] = fabs(vec[1]);
		mag[2] = fabs(vec[2]);

		result = mag;

		// Check if beyond corners
		if (result[0] > 1.0)	result[0] = 1.0;
		if (result[1] > 1.0)	result[1] = 1.0;
		if (result[2] > 1.0)	result[2] = 1.0;

		// snap to appropriate side
		if ((mag[0] > mag[1]) && (mag[0] >  mag[2])) 
		{
			result[0] = 1.0;
		}
		else if ((mag[1] > mag[0]) && (mag[1] >  mag[2])) 
		{
			result[1] = 1.0;
		}
		else if ((mag[2] > mag[0]) && (mag[2] >  mag[1])) 
		{
			result[2] = 1.0;
		}
		else if ((mag[0] == mag[1]) && (mag[0] == mag[2])) 
		{
			// corner
			result = Vec3f(1,1,1);
		}
		else if (mag[0] == mag[1]) 
		{
			// edge parallel with z
			result[0] = 1.0;
			result[1] = 1.0;
		}
		else if (mag[0] == mag[2]) 
		{
			// edge parallel with y
			result[0] = 1.0;
			result[2] = 1.0;
		}
		else if (mag[1] == mag[2]) 
		{
			// edge parallel with x
			result[1] = 1.0;
			result[2] = 1.0;
		}
		else
		{
			assert( false );
			// Can't determine vector to point.
		}

		// Now make everything point the right way
		for (int32 i=0; i < 3; i++)
		{
			if (vec[i] < 0.0)	result[i] = -result[i];
		}

		// scale back up and move to center
		result[0] *= halfX;
		result[1] *= halfY;
		result[2] *= halfZ;

		result += getCenter();
	}

	return result;
}
示例#4
0
void MgBaseRect::setCenter(const Point2d& pt)
{
    Point2d old = getCenter();
    for (int i = 0; i < 4; i++)
        _points[i].offset(pt.x - old.x, pt.y - old.y);
}
示例#5
0
kmVec3 BoundingBox::getCenter() const
{
    kmVec3 center = vec3Zero;
    getCenter(&center);
    return center;
}
示例#6
0
bool BF3PointCircle::getRobustCircle(const BFContour& contour, const unsigned int maxVotes, const unsigned int maxAccu, const int maxInvalidVotesInSeries, BFCircle& circle) {

	unsigned int nContourPoints = contour.getPixelCount();
	BFRectangle rect = contour.getBounds();

	BFRectangle zeroRect;
	if(rect.equals(zeroRect)) {
		return false;
	}

	int nRows = bfRound(rect.getHeight());
	int nCols = bfRound(rect.getWidth());

	int x0 = bfRound(rect.getX0());
	int y0 = bfRound(rect.getY0());
	BFCoordinate<int> topLeft(x0,y0);

	int invalidVotesInSeries = 0;

	// generate 2d histogram for circle center estimation
	Eigen::MatrixXi H = Eigen::MatrixXi::Zero(nRows, nCols);
	unsigned int votes = 0;
	for(votes; votes <= maxVotes; ++votes) {
		// random index number in range [0,nContourPoints-1]
		unsigned int randIndex1 = (rand() % nContourPoints);
		unsigned int randIndex2 = (rand() % nContourPoints);
		while(randIndex2 == randIndex1)
			randIndex2 = (rand() % nContourPoints);
		unsigned int randIndex3 = (rand() % nContourPoints);
		while(randIndex3 == randIndex2 || randIndex3 == randIndex1)
			randIndex3 = (rand() % nContourPoints);

		BFCoordinate<int> c1 = contour.getCoordinate(randIndex1) - topLeft;
		BFCoordinate<int> c2 = contour.getCoordinate(randIndex2) - topLeft;
		BFCoordinate<int> c3 = contour.getCoordinate(randIndex3) - topLeft;

		BFCoordinate<double> center;
		bool validCenter = getCenter(c1,c2,c3,center);

		if(!validCenter) {
			votes--;
			invalidVotesInSeries++;

			if(invalidVotesInSeries > maxInvalidVotesInSeries) {
				return false;
			}
			continue;
		}

		invalidVotesInSeries = 0;

		double cxD = center.getX();
		double cyD = center.getY();

		int cx = bfRound(cxD);
		int cy = bfRound(cyD);

		if(cx < 0 || cy < 0 || cx >= nRows || cy >= nCols) {
			votes--;
			continue;
		}
		else {
			H(cx,cy) += 1;

			if(H(cx,cy) >= static_cast<int>(maxAccu)) {
				break;
			}
		}
	}

	int finalX = 0;
	int finalY = 0;
	H.maxCoeff(&finalX,&finalY);
	finalX += bfRound(x0);
	finalY += bfRound(y0);

	// generate 1d histogram for circle radius estimation
	Eigen::VectorXi K = Eigen::VectorXi::Zero(bfMax(nRows,nCols));
	const std::vector<BFCoordinate<int> >& cont = contour.getContour();
	std::vector<BFCoordinate<int> >::const_iterator iter = cont.begin();

	int x;
	int y;

	while(iter != cont.end()) {

		x = bfRound((*iter).getX());
		y = bfRound((*iter).getY());

		int r = bfRound(sqrt(pow(static_cast<double>(x-finalX),2) + pow(static_cast<double>(y-finalY),2)));

		if(r < K.rows()) {
			K(r) += 1;
		}

		iter++;
	}

	int finalR = 0;
	K.maxCoeff(&finalR);

	// return result
	circle.set(finalX,finalY,finalR);
	return true;
}
示例#7
0
文件: NPC.cpp 项目: igorventorim/UFES
/*
	POSITION 0: ROTATE RIGHT
	POSITION 1: ROTATE LEFT
	POSITION 2: MOVE UP
	POSITION 3: MOVE DOWN
	POSITION 4: JUMP
*/
double NPC::movementEvaluate(vector<int> individual,int size_vector)
{
	srand(time(NULL));
	Stadium* stadium = NPC::stadium;
	Circle *c = stadium->getLimiteExterior();
	double playerX = player->getX();
	double playerY = player->getY();
	double score = 0;
	double afterAngle = 0;
	// double angle = atan2(playerY, playerX ) - atan2(getCoord_y(), getCoord_y()); 
	double afterX = getCenter()->getX();
	double afterY = getCenter()->getY();
	double current_distance = player->distance2D(afterX,afterY);

	// if(individual[0] == 1)
	// {
	// 	afterAngle = getAfterPersonAngle(1,0);
	// 	// score +=4;
	// 	score++;
		
	// }
	// if(individual[1] == 1)
	// {
	// 	afterAngle = getAfterPersonAngle(0,1);
	// 	score++;
	// }
	
	if(individual[2] == 1)
	{
    	// afterX = getAfterX(1,0);
    	// afterY = getAfterY(1,0);
		score += 3;
		// score++;
	}

	if(individual[3] == 1)
	{
    // 	afterX = getAfterX(-1,afterAngle);
	// 	afterY = getAfterY(-1,afterAngle);
		// score += 2;
		score++;
	}

	// // if(individual[4] == 1)
  	// // {
	// //   if(stadium->inObstacle(afterX, afterY, getRadius() && !stadium->inObstacle(getCenter()->getX(),getCenter()->getY() , getRadius() )))
	// //   {
	// // 	score += 30;
	// //   }else{
	// // 	score -=2;
	// //   }
  	// // 	score--;

	// // }
	
	double x,y;
	simulateLook(afterX,afterY, afterAngle, x,y);
	
	// if(!stadium->isValidMoveNPC(this,afterX,afterY))
	// {
	// 	score -= 999999;
	// }else

	// double norma = atan2(playerY, playerX ) - atan2(afterY, afterX) * getRadius() / current_distance;
	double norma = player->distance2D(afterX,afterY) / current_distance;
	 if(norma < 1)
	 {
		score += (1 - norma)*3;
	 }
  	// cout << afterX << ":"<<afterY<< ":"<< score<<endl;
    
	 score += ((double) rand() / (RAND_MAX)) + 1;
	return score;
}
示例#8
0
void TextBlock::draw(){
    float yAlig = y;
    
    if (vAlignment == OF_TEXT_ALIGN_BOTTOM){
        yAlig = y + height - getTextHeight();
    } else if (vAlignment == OF_TEXT_ALIGN_MIDDLE){
        yAlig = getCenter().y - getTextHeight()*0.5;
    }
    
    if (hAlignment == OF_TEXT_ALIGN_LEFT){
        string  strToDraw;
        int     currentWordID;
        float   drawX;
        float   drawY;
        
        float currX = 0;
        
        if (words.size() > 0){
            for(int l=0;l < lines.size(); l++){
                for(int w=0;w < lines[l].wordsID.size(); w++){
                    
                    currentWordID = lines[l].wordsID[w];
                    
                    drawX = x + currX;
                    drawY = yAlig + (font->getLineHeight() * (l + 1));
                    
                    ofPushMatrix();
                    font->drawString(words[currentWordID].rawWord.c_str(), drawX, drawY);
                    currX += words[currentWordID].width;
                    ofPopMatrix();
                    
                }
                currX = 0;
            }
        }
    } else if (hAlignment == OF_TEXT_ALIGN_RIGHT){
        string  strToDraw;
        int     currentWordID;
        float   drawX;
        float   drawY;
        
        float currX = 0;
        
        if (words.size() > 0) {
            
            for(int l=0;l < lines.size(); l++){
                for(int w=lines[l].wordsID.size() - 1; w >= 0; w--){
                    
                    currentWordID = lines[l].wordsID[w];
                    
                    drawX = -currX - words[currentWordID].width;
                    drawY = font->getLineHeight() * (l + 1);
                    
                    ofPushMatrix();
                    
                    //Move to top left point using pre-scaled co-ordinates
                    ofTranslate(x + width, yAlig, 0.0f);
                    
                    font->drawString(words[currentWordID].rawWord.c_str(), drawX, drawY);
                    currX += words[currentWordID].width;
                    
                    ofPopMatrix();
                    
                }
                currX = 0;
                
            }
        }
    } else if (hAlignment == OF_TEXT_ALIGN_JUSTIFIED){
        string  strToDraw;
        int     currentWordID;
        float   drawX;
        float   drawY;
        int     spacesN;
        float   nonSpaceWordWidth;
        float   pixelsPerSpace;
        
        float currX = 0;
        
        if (words.size() > 0) {
            for(int l=0;l < lines.size(); l++){
                //Find number of spaces and width of other words;
                spacesN = 0;
                nonSpaceWordWidth = 0;
                
                for(int w = 0; w < lines[l].wordsID.size(); w++){
                    currentWordID = lines[l].wordsID[w];
                    if (words[currentWordID].rawWord == " ") spacesN++;
                    else nonSpaceWordWidth += words[currentWordID].width;
                }
                
                pixelsPerSpace = (width - x - nonSpaceWordWidth) / spacesN;
                
                for(int w=0;w < lines[l].wordsID.size(); w++){
                    currentWordID = lines[l].wordsID[w];
                    
                    drawX = currX;
                    drawY = font->getLineHeight() * (l + 1);
                    
                    ofPushMatrix();
                    //Move to top left point using pre-scaled co-ordinates
                    ofTranslate(x, yAlig, 0.0f);
                    
                    if (words[currentWordID].rawWord != " ") {
                        font->drawString(words[currentWordID].rawWord.c_str(), drawX, drawY);
                        currX += words[currentWordID].width;
                    } else {
                        currX += pixelsPerSpace;
                    }
                    ofPopMatrix();
                    
                }
                currX = 0;
                
            }
        }
    } else if (hAlignment == OF_TEXT_ALIGN_CENTER ){
        string  strToDraw;
        int     currentWordID;
        float   drawX;
        float   drawY;
        float   lineWidth;
        
        float currX = 0;
        
        if (words.size() > 0) {
            for(int l=0;l < lines.size(); l++){
                
                //Get the length of the line.
                lineWidth = 0;
                for(int w=0;w < lines[l].wordsID.size(); w++){
                    currentWordID = lines[l].wordsID[w];
                    lineWidth += words[currentWordID].width;
                }
                
                for(int w=0;w < lines[l].wordsID.size(); w++){
                    currentWordID = lines[l].wordsID[w];
                    
                    drawX = -(lineWidth / 2) + currX;
                    drawY = font->getLineHeight() * (l + 1);
                    
                    ofPushMatrix();
                    //Move to central point using pre-scaled co-ordinates
                    ofTranslate(getCenter().x, yAlig, 0.0f);
                    font->drawString(words[currentWordID].rawWord.c_str(), drawX, drawY);
                    currX += words[currentWordID].width;
                    ofPopMatrix();
                    
                }
                currX = 0;
            }
        }
    }
}
示例#9
0
AnnularRegion::AnnularRegion(const MinorCircleRegion &mcr, Radian w) :
    MinorCircleRegion(mcr), width(w) {

    // Make a second MCR with a smaller radius
    inner = new MinorCircleRegion( getCenter(), getRadius() - w );
}
示例#10
0
Cube Cube::boundingBox()
{

    return Cube(getMin(),getMax(),getCenter());
}
示例#11
0
 Scalar radius() const
 {
     return (getCenter() - min).norm();
 }
示例#12
0
QList<QSharedPointer<RShape> > RDimAngularData::getShapes(const RBox& queryBox, bool ignoreComplex, bool segment) const {
    Q_UNUSED(queryBox)
    Q_UNUSED(ignoreComplex)
    Q_UNUSED(segment)

    QSharedPointer<RBlockReferenceEntity> dimBlockReference = getDimensionBlockReference();
    if (!dimBlockReference.isNull()) {
        return dimBlockReference->getShapes(queryBox, ignoreComplex);
    }

    QList<QSharedPointer<RShape> > ret;

    double dimexo = getDimexo();
    double dimexe = getDimexe();
    double dimtxt = getDimtxt();
    double dimgap = getDimgap();
    double dimasz = getDimasz();

    // find out center:
    RVector center = getCenter();

    if (!center.isValid()) {
        return ret;
    }

    double ang1 = 0.0;
    double ang2 = 0.0;
    bool reversed = false;
    RVector p1;
    RVector p2;

    getAngles(ang1, ang2, reversed, p1, p2);

    double rad = dimArcPosition.getDistanceTo(center);

    RLine line;
    RVector dir;
    double len;
    double dist;

    // 1st extension line:
    dist = center.getDistanceTo2D(p1);
    len = rad - dist + dimexe;
    dir.setPolar(1.0, ang1);
    line = RLine(center + dir*dist + dir*dimexo, center + dir*dist + dir*len);
    ret.append(QSharedPointer<RShape>(new RLine(line)));

    // 2nd extension line:
    dist = center.getDistanceTo2D(p2);
    len = rad - dist + dimexe;
    dir.setPolar(1.0, ang2);
    line = RLine(center + dir*dist + dir*dimexo, center + dir*dist + dir*len);
    ret.append(QSharedPointer<RShape>(new RLine(line)));

    // Create dimension line (arc):
    RArc arc(center, rad, ang1, ang2, reversed);
    ret.append(QSharedPointer<RShape>(new RArc(arc)));

    // length of dimension arc:
    double distance = arc.getLength();

    // do we have to put the arrows outside of the arc?
    bool outsideArrows = (distance<dimasz*2);

    // arrow angles:
    double arrowAngle1, arrowAngle2;
    double arrowAng;
    if (rad>1.0e-6) {
        arrowAng = getDimasz() / rad;
    }
    else {
        arrowAng = 0.0;
    }

    if (outsideArrows) {
        arrowAngle1 = arc.getDirection1();
        arrowAngle2 = arc.getDirection2();
    }
    else {
        RVector v1, v2;
        if (!arc.isReversed()) {
            v1.setPolar(rad, arc.getStartAngle()+arrowAng);
        } else {
            v1.setPolar(rad, arc.getStartAngle()-arrowAng);
        }
        v1+=arc.getCenter();
        arrowAngle1 = arc.getStartPoint().getAngleTo(v1);


        if (!arc.isReversed()) {
            v2.setPolar(rad, arc.getEndAngle()-arrowAng);
        } else {
            v2.setPolar(rad, arc.getEndAngle()+arrowAng);
        }
        v2+=arc.getCenter();
        arrowAngle2 = arc.getEndPoint().getAngleTo(v2);

        arrowAngle1 = arrowAngle1+M_PI;
        arrowAngle2 = arrowAngle2+M_PI;
    }

    // Arrows:
    //RTriangle arrow = RTriangle::createArrow(arc.getStartPoint(), arrowAngle1, dimasz);
    QList<QSharedPointer<RShape> > arrow = getArrow(arc.getStartPoint(), arrowAngle1);
    ret.append(arrow);
    //arrow = RTriangle::createArrow(arc.getEndPoint(), arrowAngle2, dimasz);
    arrow = getArrow(arc.getEndPoint(), arrowAngle2);
    ret.append(arrow);
    //ret.append(QSharedPointer<RShape>(new RTriangle(arrow)));

    //RVector oldMot = textPosition;
    //textPosition = RVector(0,0);
    //defaultAngle = 0.0;
    //dimLineLength = RNANDOUBLE;
    //getTextData();
    //textPosition = oldMot;

    RVector textPos = arc.getMiddlePoint();
    double dimAngle1 = textPos.getAngleTo(arc.getCenter())-M_PI/2.0;
    if (!autoTextPos) {
        dimAngle1 = textPositionCenter.getAngleTo(arc.getCenter())-M_PI/2.0;
    }

    RVector distV;
    double textAngle;
    // rotate text so it's readable from the bottom or right (ISO)
    // quadrant 1 & 4
    if (dimAngle1>M_PI/2.0*3.0+0.001 ||
        dimAngle1<M_PI/2.0+0.001) {

        distV.setPolar(dimgap + dimtxt/2, dimAngle1+M_PI/2.0);
        textAngle = dimAngle1;
    }
    // quadrant 2 & 3
    else {
        distV.setPolar(dimgap + dimtxt/2, dimAngle1-M_PI/2.0);
        textAngle = dimAngle1+M_PI;
    }

    if (!autoTextPos) {
        textPos = textPositionCenter;
    } else {
        // move text away from dimension line:
        textPos+=distV;

        textPositionCenter = textPos;
    }
    defaultAngle = textAngle;
    //getTextData();
    //textData.rotate(textAngle, RVector(0,0));
    //textData.move(textPos);

    return ret;
}
示例#13
0
void bulletClass::applyMove()
{
    oldCenter = getCenter();
    sprite.move(velocity);
}
示例#14
0
void Player::onCollision(PowerUp& powerup)
{
    switch (powerup.getType())
    {
        // timed bonus
        case PowerUp::DOUBLE_SHOT:
            if (bonus_[T_DOUBLESHOT] == 0)
                m_weapon.setMultiply(2);

            bonus_[T_TRISHOT] = 0;
            bonus_[T_DOUBLESHOT] += TIMED_BONUS_DURATION;
            m_panel.activeAttackPowerUp(bonus_[T_DOUBLESHOT], powerup.getType());
            break;

        case PowerUp::TRIPLE_SHOT:
            if (bonus_[T_TRISHOT] == 0)
                m_weapon.setMultiply(3);

            bonus_[T_DOUBLESHOT] = 0;
            bonus_[T_TRISHOT] += TIMED_BONUS_DURATION;
            m_panel.activeAttackPowerUp(bonus_[T_TRISHOT], powerup.getType());
            break;

        case PowerUp::SPEED:
            if (bonus_[T_SPEED] == 0)
            {
                m_speed *= BONUS_SPEED_FACTOR;
                m_smoke_emitter.createParticles(120);
            }
            bonus_[T_SPEED] += TIMED_BONUS_DURATION;
            m_panel.activeSpeedPowerUp(bonus_[T_SPEED]);
            break;

        // immediate bonus
        case PowerUp::REPAIR:
            if (getHP() < m_max_hp)
                m_panel.setHP(updateHP(1));
            break;

        case PowerUp::FULL_REPAIR:
            setHP(m_max_hp);
            m_panel.setHP(m_max_hp);
            m_powerup_emitter.setPosition(getCenter());
            m_powerup_emitter.createParticles(50);
            break;

        case PowerUp::SHIELD:
            if (m_shield < m_max_shield)
                setShield(m_shield + 1);
            break;

        case PowerUp::FULL_SHIELD:
            setShield(m_max_shield);
            m_panel.setShield(m_max_shield);
            m_powerup_emitter.setPosition(getCenter());
            m_powerup_emitter.createParticles(50);
            break;

        case PowerUp::ICECUBE:
            if (m_icecubes < MAX_ICECUBES)
                m_panel.setIcecubes(++m_icecubes);
            break;

        case PowerUp::MISSILE:
            if (m_missiles < MAX_MISSILES)
                m_panel.setMissiles(++m_missiles);
            break;

        default:
            break;
    }

    powerup.kill();
    MessageSystem::write(powerup.getDescription(), powerup.getPosition());
    SoundSystem::playSound("power-up.ogg");
}
示例#15
0
bool BoundingBox::overlapsWith(const BoundingBox& other)
{
   if(!use || !other.use) return false;

   float wa = getWidth()/2;
   float ha = getHeight()/2;
   float da = getDepth()/2;

   glm::vec3 Ca = getCenter();
   glm::vec3 Az = getFrontNormal();
   glm::vec3 Ay = getUpNormal();
   glm::vec3 Ax = getRightNormal();

   glm::vec3 Cb = other.getCenter();
   glm::vec3 Bz = other.getFrontNormal();
   glm::vec3 By = other.getUpNormal();
   glm::vec3 Bx = other.getRightNormal();
   float wb = other.getWidth()/2;
   float hb = other.getHeight()/2;
   float db = other.getDepth()/2;

   glm::vec3 T = Cb - Ca;

   float lhs = 0, rhs = 0;

   float Rxx = glm::dot(Ax, Bx);
   float Rxy = glm::dot(Ax, By);
   float Rxz = glm::dot(Ax, Bz);

   // Case 1: L = Ax
   lhs = glm::dot(T, Ax);
   rhs = wa + fabs(wb * Rxx) + fabs(hb * Rxy) + fabs(db * Rxz);
   if(lhs > rhs) return false;

   float Ryx = glm::dot(Ay, Bx);
   float Ryy = glm::dot(Ay, By);
   float Ryz = glm::dot(Ay, Bz);

   // Case 2: L = Ay
   lhs = glm::dot(T, Ay);
   rhs = ha + fabs(wb * Ryx) + fabs(hb * Ryy) + fabs(db * Ryz);
   if(lhs > rhs) return false;

   float Rzx = glm::dot(Az, Bx);
   float Rzy = glm::dot(Az, By);
   float Rzz = glm::dot(Az, Bz);

   // Case 3: L = Az
   lhs = glm::dot(T, Az);
   rhs = da + fabs(wb * Rzx) + fabs(hb * Rzy) + fabs(db * Rzz);
   if(lhs > rhs) return false;

   // Case 4: L = Bx
   lhs = glm::dot(T, Bx);
   rhs = fabs(wa * Rxx) + fabs(ha * Ryx) + fabs(da * Rzx) + wb;
   if(lhs > rhs) return false;

   // Case 5: L = By
   lhs = glm::dot(T, By);
   rhs = fabs(wa * Rxy) + fabs(ha * Ryy) + fabs(da * Rzy) + hb;
   if(lhs > rhs) return false;

   // Case 6: L = Bz
   lhs = glm::dot(T, Bz);
   rhs = fabs(wa * Rxz) + fabs(ha * Ryz) + fabs(da * Rzz) + db;
   if(lhs > rhs) return false;

   // Case 7: L = Ax x Bx
   lhs = glm::dot(T, glm::cross(Ax, Bx));
   rhs = fabs(ha * Rzx) + fabs(da * Ryx) + fabs(hb * Rxz) + fabs(db * Rxy);
   if(lhs > rhs) return false;

   // Case 8: L = Ax x By
   lhs = glm::dot(T, glm::cross(Ax, By));
   rhs = fabs(ha * Rzy) + fabs(da * Ryy) + fabs(wb * Rxz) + fabs(db * Rxx);
   if(lhs > rhs) return false;

   // Case 9: L = Ax x Bz
   lhs = glm::dot(T, glm::cross(Ax, Bz));
   rhs = fabs(ha * Rzz) + fabs(da * Ryz) + fabs(wb * Rxy) + fabs(hb * Rxx);
   if(lhs > rhs) return false;

   // Case 10: L = Ay x Bx
   lhs = glm::dot(T, glm::cross(Ay, Bx));
   rhs = fabs(wa * Rzx) + fabs(da * Rxx) + fabs(hb * Ryz) + fabs(db * Ryy);
   if(lhs > rhs) return false;

   // Case 11: L = Ay x By
   lhs = glm::dot(T, glm::cross(Ay, By));
   rhs = fabs(wa * Rzy) + fabs(da * Rxy) + fabs(wb * Ryz) + fabs(db * Ryx);
   if(lhs > rhs) return false;

   // Case 12: L = Ay x Bz
   lhs = glm::dot(T, glm::cross(Ay, Bz));
   rhs = fabs(wa * Rzz) + fabs(da * Rxz) + fabs(wb * Ryy) + fabs(hb * Ryx);
   if(lhs > rhs) return false;

   // Case 13: L = Az x Bx
   lhs = glm::dot(T, glm::cross(Az, Bx));
   rhs = fabs(wa * Ryx) + fabs(ha * Rxx) + fabs(hb * Rzz) + fabs(db * Rzy);
   if(lhs > rhs) return false;

   // Case 14: L = Az x By
   lhs = glm::dot(T, glm::cross(Az, By));
   rhs = fabs(wa * Ryy) + fabs(ha * Rxy) + fabs(wb * Rzz) + fabs(db * Rzx);
   if(lhs > rhs) return false;

   // Case 15: L = Az x Bz
   lhs = glm::dot(T, glm::cross(Az, Bz));
   rhs = fabs(wa * Ryz) + fabs(ha * Rxz) + fabs(wb * Rzy) + fabs(hb * Rzx);
   if(lhs > rhs) return false;

   return true;
}
示例#16
0
void CloudsHUDController::drawLayer3D(CloudsHUDLayerSet layer, ofCamera* cam, ofVec2f& offset){
    ofPushMatrix();
    
    // Hook up to the camera to keep the layer steady.
    ofMatrix4x4 baseRotation;
    ofTranslate(cam->getPosition());
    baseRotation.makeRotationMatrix(cam->getOrientationQuat());
    ofMultMatrix(baseRotation);
    
    ofVec3f camPos = ofVec3f();  //cam->getPosition();
    
    // Calculate the base position.
    static ofVec3f yAxis = ofVec3f(0.0, 1.0, 0.0);
    static ofVec3f xAxis = ofVec3f(1.0, 0.0, 0.0);
//    ofVec3f basePos = camPos + (cam->getLookAtDir().getScaled(layerDistance[layer]));
//    ofVec3f basePos(0, 0, -layerDistance[layer]);
    ofVec3f basePos(offset.x, offset.y, -layerDistance[layer]);
    basePos.rotate(layerRotationH[layer], camPos, yAxis);
    basePos.rotate(layerRotationV[layer], camPos, xAxis);
    
    // Get the total layer bounds.
    ofRectangle layerBounds;
	for(int i = 0; i < layerSets[layer].size(); i++){
        if (i == 0) layerBounds = layerSets[layer][i]->svg.getBounds();
        else layerBounds.growToInclude(layerSets[layer][i]->svg.getBounds());
	}
    
    // Translate to the layer center pos.
    ofVec3f layerPos = basePos + (getCenter(false) - layerBounds.getCenter());
    ofTranslate(layerPos);

    if (layerBillboard[layer] == CLOUDS_HUD_BILLBOARD_OCULUS) {
        // Billboard rotation using the Oculus orientation.
        float angle;
        ofVec3f axis;
        CloudsVisualSystem::getOculusRift().getOrientationQuat().getRotate(angle, axis);
        ofRotate(angle, axis.x, axis.y, axis.z);
        ofScale(-1, 1, 1);
    }
    else if (layerBillboard[layer] == CLOUDS_HUD_BILLBOARD_CAMERA) {
        // Billboard rotation using the camera.
        ofNode node;
        node.setPosition(layerPos);
        node.lookAt(camPos);
        ofVec3f axis;
        float angle;
        node.getOrientationQuat().getRotate(angle, axis);
        ofRotate(angle, axis.x, axis.y, axis.z);
    }
    else {
//        ofRotateY(layerRotationH[layer]);
//        ofRotateX(layerRotationV[layer]);
        ofScale(-1, 1, 1);
    }
    
    // Debug circle.
//    ofSetColor(255);
//    ofCircle(0, 0, 25);
    
    // Transform for rendering the layer.
    ofScale(-scaleAmt, -scaleAmt, 1);
    ofTranslate(-layerBounds.getCenter());

    // Draw the video player if we're on the right layer.
    if (layer == CLOUDS_HUD_PROJECT_EXAMPLE && videoPlayer.isPlaying()) {
        ofSetColor(255, 255, 255, 255*0.7);
        if( !bSkipAVideoFrame ){
//            videoPlayer.draw( videoBounds.x, videoBounds.y, videoBounds.width, videoBounds.height );
        }
    }
    
    // Draw the layer.
    ofSetColor(255);
    drawLayer(layer);
    
    // Draw the home button if we're on the right layer.
    if (layer == CLOUDS_HUD_LOWER_THIRD && bDrawHome && hudOpenMap[CLOUDS_HUD_LOWER_THIRD]) {
        home.draw();
    }
    
    // Draw the associated text labels.
    for( map<string, CloudsHUDLabel*>::iterator it=hudLabelMap.begin(); it!= hudLabelMap.end(); ++it ){
        bool bFound = false;
        for(int i = 0; i < layerSets[layer].size(); i++){
            if (layerSets[layer][i]->svg.getMeshByID(it->first) != NULL) {
                bFound = true;
                break;
            }
        }
        if (bFound) {
            (it->second)->draw();
        }
    }
    
    ofPopMatrix();
}
示例#17
0
void TentaculatBoss::onDestroy()
{
	EntityManager::getInstance().createGreenParticles(getCenter(), 150);
	// Low-pitched explosion
	SoundSystem::playSound("boom.ogg", 0.3f);
}
示例#18
0
void Wisp::attack(Selector target, centimicrosecond now)
{
	lastAttack = now;
	target.selected()->addIncoming(new WispAttack(getCenter(), t(), attackDamage));
}
示例#19
0
bool BF3PointCircle::getRobustCircle(const cvb::CvContourChainCode& contour, const unsigned int maxVotes, const unsigned int maxAccu, const int maxInvalidVotesInSeries, BFCircle& circle) {

	cvb::CvChainCodes::const_iterator it 		= contour.chainCode.begin();
	cvb::CvChainCodes::const_iterator it_beg	= contour.chainCode.begin();
	cvb::CvChainCodes::const_iterator it_end 	= contour.chainCode.end();

	unsigned int x = contour.startingPoint.x;
	unsigned int y = contour.startingPoint.y;

	BFContour bfContour;
	while(it != it_end) {

		bfContour.add(BFCoordinate<int>(static_cast<int>(x),static_cast<int>(y)));

		x += cvb::cvChainCodeMoves[*it][0];
		y += cvb::cvChainCodeMoves[*it][1];

		it++;
	}
	const unsigned int nContourPoints = bfContour.getPixelCount();

	BFRectangle rect = bfContour.getBounds();
	int nRows = bfRound(rect.getHeight());
	int nCols = bfRound(rect.getWidth());
	int x0 = bfRound(rect.getX0());
	int y0 = bfRound(rect.getY0());
	BFCoordinate<int> topLeft(x0,y0);

	// generate 2d histogram for circle center estimation
	Eigen::MatrixXi H = Eigen::MatrixXi::Zero(nRows, nCols);

	unsigned int votes = 0;
	int invalidVotesInSeries = 0;
	while(votes < maxVotes) {

		unsigned int randIndex1 = (rand() % nContourPoints);
		unsigned int randIndex2 = (rand() % nContourPoints);
		while(randIndex2 == randIndex1)
			randIndex2 = (rand() % nContourPoints);
		unsigned int randIndex3 = (rand() % nContourPoints);
		while(randIndex3 == randIndex2 || randIndex3 == randIndex1)
			randIndex3 = (rand() % nContourPoints);

		BFCoordinate<int> c1 = bfContour.getCoordinate(randIndex1) - topLeft;
		BFCoordinate<int> c2 = bfContour.getCoordinate(randIndex2) - topLeft;
		BFCoordinate<int> c3 = bfContour.getCoordinate(randIndex3) - topLeft;

		BFCoordinate<double> center;
		bool validCenter = getCenter(c1,c2,c3,center);

		if(!validCenter) {
			votes--;
			invalidVotesInSeries++;

			if(invalidVotesInSeries > maxInvalidVotesInSeries) {
				return false;
			}
			continue;
		}
		invalidVotesInSeries = 0;

		double cxD = center.getX();
		double cyD = center.getY();

		int cx = bfRound(cxD);
		int cy = bfRound(cyD);

		if(cx < 0 || cy < 0 || cx >= nRows || cy >= nCols) {
			continue;
		}
		else {
			H(cx,cy) += 1;

			if(H(cx,cy) >= static_cast<int>(maxAccu)) {
				break;
			}
		}

		votes++;
	}

	int finalX = 0;
	int finalY = 0;
	H.maxCoeff(&finalX,&finalY);
	finalX += bfRound(x0);
	finalY += bfRound(y0);

	// generate 1d histogram for circle radius estimation
	Eigen::VectorXi K = Eigen::VectorXi::Zero(bfMax(nRows,nCols));

	it = it_beg;
	x = contour.startingPoint.x;
	y = contour.startingPoint.y;

	while(it != it_end) {

		int r = bfRound(sqrt(pow(static_cast<double>(static_cast<int>(x)-finalX),2.0) + pow(static_cast<double>(static_cast<int>(y)-finalY),2.0)));

		if(r < K.rows()) {
			K(r) += 1;
		}

		x += cvb::cvChainCodeMoves[*it][0];
		y += cvb::cvChainCodeMoves[*it][1];

		it++;
	}

	int finalR = 0;
	K.maxCoeff(&finalR);
	circle.set(finalX,finalY,finalR);

	return true;
}
示例#20
0
   void CylinderMesh::construct()
   {
      int i, firstTop ;
      int steps = (unsigned int)(complexity * 64.0f) ;
      float angle ;
      Point normal ;
      Box   bounds = getBounds() ;
      Point center = getCenter() ;
      float radius = getRadius() ;

      Primitive p ;
      p.type = Primitive::NoMaterial | Primitive::Strip | Primitive::Indexed ;

      if (steps < 4)  steps = 4 ;
      if (steps > 64) steps = 64 ;
      steps &= ~1 ;

      // Bottom
      addVertex (center.x(), center.y(), bounds.min.z()) ;
      for (angle = 0.0f, i = 0 ; i < steps ; i++, angle += 2.0f*M_PI/(float)steps)
      {
         addVertex (cosf(angle)*radius + center.x(), sinf(angle)*radius + center.y(), 
                    bounds.min.z()) ;
      }

      for (i = 1 ; i <= steps ; i++)
      {
         p.firstElement = indices.size() ;
         p.numElements  = 3 ;
         indices.push_back (0) ;
         indices.push_back (i) ;
         indices.push_back (i == steps ? 1 : i+1) ;
         primitives.push_back(p) ;
      }

      // Top
      firstTop = verts.size() ;
      addVertex (center.x(), center.y(), bounds.max.z()) ;
      for (angle = 0.0f, i = 0 ; i < steps ; i++, angle += 2.0f*M_PI/(float)steps)
      {
         addVertex (cosf(angle)*radius + center.x(), sinf(angle)*radius + center.y(), 
                    bounds.max.z()) ;
      }

      for (i = 1 ; i <= steps ; i++)
      {
         p.firstElement = indices.size() ;
         p.numElements  = 3 ;
         indices.push_back (firstTop) ;
         indices.push_back (firstTop+(i == steps ? 1 : i+1)) ;
         indices.push_back (firstTop+i) ;
         primitives.push_back(p) ;
      }

      // Walls
      int pos ;
      for (pos = indices.size(), i = 0 ; i < steps-1 ; i++, pos += 4)
      {
         indices.push_back (i+1) ;
         indices.push_back (firstTop+i+1) ;
         indices.push_back (i+2) ;
         indices.push_back (firstTop+i+2) ;
         p.firstElement = pos ;
         p.numElements  = 4 ;
         primitives.push_back(p) ;
      }
      indices.push_back (i+1) ;
      indices.push_back (firstTop+i+1) ;
      indices.push_back (1) ;
      indices.push_back (firstTop+1) ;
      p.firstElement = pos ;
      p.numElements  = 4 ;
      primitives.push_back(p) ;

      // Other stuff

      setFrames (1) ;
      setParent (-1) ;
      calculateBounds() ;
      calculateCenter() ;
      calculateRadius() ;
   }
示例#21
0
SphereF Box3F::getBoundingSphere() const
{
   return SphereF( getCenter(), getGreatestDiagonalLength() / 2.f );
}
示例#22
0
XnBoundingBox3D RectPrism::getBoundingBox() {
    return calcBoundingBox(getCenter(), getBoundingBoxSize());
}
示例#23
0
Box2d MgBaseRect::getRect() const
{
    return Box2d(getCenter(), getWidth(), getHeight());
}
示例#24
0
float RectPrism::getCenterDistSq(XnPoint3D p)
{
    return dist_sq(p, getCenter());
}
示例#25
0
/**
 * Overrides drawing of subentities. This is only ever called for solid fills.
 */
void RS_Hatch::draw(RS_Painter* painter, RS_GraphicView* view, double& /*patternOffset*/) {

    if (!data.solid) {
        for (RS_Entity* se=firstEntity();
                se!=NULL;
                se = nextEntity()) {

            view->drawEntity(painter,se);
        }
        return;
    }

    QPainterPath path;
    QList<QPolygon> paClosed;
    QPolygon pa;
//    QPolygon jp;   // jump points

    // loops:
    if (needOptimization==true) {
        for (RS_Entity* l=firstEntity(RS2::ResolveNone);
                l!=NULL;
                l=nextEntity(RS2::ResolveNone)) {

            if (l->rtti()==RS2::EntityContainer) {
                RS_EntityContainer* loop = (RS_EntityContainer*)l;

                loop->optimizeContours();
            }
        }
        needOptimization = false;
    }

    // loops:
    for (RS_Entity* l=firstEntity(RS2::ResolveNone);
         l!=NULL;
         l=nextEntity(RS2::ResolveNone)) {

        l->setLayer(getLayer());

        if (l->rtti()==RS2::EntityContainer) {
            RS_EntityContainer* loop = (RS_EntityContainer*)l;

            // edges:
            for (RS_Entity* e=loop->firstEntity(RS2::ResolveNone);
                 e!=NULL;
                 e=loop->nextEntity(RS2::ResolveNone)) {

                e->setLayer(getLayer());
                switch (e->rtti()) {
                case RS2::EntityLine: {
                    QPoint pt1(RS_Math::round(view->toGuiX(e->getStartpoint().x)),
                               RS_Math::round(view->toGuiY(e->getStartpoint().y)));
                    QPoint pt2(RS_Math::round(view->toGuiX(e->getEndpoint().x)),
                               RS_Math::round(view->toGuiY(e->getEndpoint().y)));

//                    if (! (pa.size()>0 && (pa.last() - pt1).manhattanLength()<=2)) {
//                        jp<<pt1;
//                    }

                    pa<<pt1<<pt2;
                }
                    break;

                case RS2::EntityArc: {
//                    QPoint pt1(RS_Math::round(view->toGuiX(e->getStartpoint().x)),
//                               RS_Math::round(view->toGuiY(e->getStartpoint().y)));
//                    if (! (pa.size()>0 && (pa.last() - pt1).manhattanLength()<=2)) {
//                        jp<<pt1;
//                    }

                    QPolygon pa2;
                    RS_Arc* arc=static_cast<RS_Arc*>(e);
                    painter->createArc(pa2, view->toGui(arc->getCenter()),
                                       view->toGuiDX(arc->getRadius()),
                                       arc->getAngle1(),
                                       arc->getAngle2(),
                                       arc->isReversed());
                    pa<<pa2;

                }
                    break;

                case RS2::EntityCircle: {
                    RS_Circle* circle = static_cast<RS_Circle*>(e);
//                    QPoint pt1(RS_Math::round(view->toGuiX(circle->getCenter().x+circle->getRadius())),
//                               RS_Math::round(view->toGuiY(circle->getCenter().y)));
//                    if (! (pa.size()>0 && (pa.last() - pt1).manhattanLength()<=2)) {
//                        jp<<pt1;
//                    }

                    RS_Vector c=view->toGui(circle->getCenter());
                    double r=view->toGuiDX(circle->getRadius());
#if QT_VERSION >= 0x040400
                    path.addEllipse(QPoint(c.x,c.y),r,r);
#else
                    path.addEllipse(c.x - r, c.y + r, 2.*r, 2.*r);
//                    QPolygon pa2;
//                    painter->createArc(pa2, view->toGui(circle->getCenter()),
//                                       view->toGuiDX(circle->getRadius()),
//                                       0.0,
//                                       2*M_PI,
//                                       false);
//                    pa<<pa2;
#endif
                }
                    break;
                case RS2::EntityEllipse:
                if(static_cast<RS_Ellipse*>(e)->isArc()) {
                    QPolygon pa2;
                    auto ellipse=static_cast<RS_Ellipse*>(e);
                    painter->createEllipse(pa2,
                                           view->toGui(ellipse->getCenter()),
                                           view->toGuiDX(ellipse->getMajorRadius()),
                                           view->toGuiDX(ellipse->getMinorRadius()),
                                           ellipse->getAngle(),
                                           ellipse->getAngle1(), ellipse->getAngle2(),
                                           ellipse->isReversed()
                                           );
                    pa<<pa2;
                }else{
                    QPolygon pa2;
                    auto ellipse=static_cast<RS_Ellipse*>(e);
                    painter->createEllipse(pa2,
                                           view->toGui(ellipse->getCenter()),
                                           view->toGuiDX(ellipse->getMajorRadius()),
                                           view->toGuiDX(ellipse->getMinorRadius()),
                                           ellipse->getAngle(),
                                           ellipse->getAngle1(), ellipse->getAngle2(),
                                           ellipse->isReversed()
                                           );
                    path.addPolygon(pa2);
                }
                    break;
                default:
                    break;
                }
                if( pa.size()>2 && pa.first() == pa.last()) {
                    paClosed<<pa;
                    pa.clear();
                }

            }

        }
    }
    if(pa.size()>2){
        pa<<pa.first();
        paClosed<<pa;
    }
    for(int i=0;i<paClosed.size();i++){
        path.addPolygon(paClosed.at(i));
    }
        painter->setBrush(painter->getPen().getColor());
        painter->disablePen();
        painter->drawPath(path);

//    pa<<jp;

//    painter->setBrush(painter->getPen().getColor());
//    painter->disablePen();
//    painter->drawPolygon(pa);

}
示例#26
0
文件: RArc.cpp 项目: VixMobile/qcad
QList<RVector> RArc::getCenterPoints() const {
    QList<RVector> ret;
    ret.append(getCenter());
    return ret;
}
示例#27
0
BSphere AABB::getBSphere() const {
	Point3 center = getCenter();
	return BSphere(center, (center - max).length());
}
Vec3f CylinderDistribution3D::generate(void) const
{
    Vec3f Result;

    switch(getSurfaceOrVolume())
    {
    case SURFACE:
        {
            std::vector<Real32> Areas;
            //Min Cap
            Areas.push_back(0.5*osgAbs(getMaxTheta() - getMinTheta())*(getOuterRadius()*getOuterRadius() - getInnerRadius()*getInnerRadius()));
            //Max Cap
            Areas.push_back(Areas.back() + 0.5*osgAbs(getMaxTheta() - getMinTheta())*(getOuterRadius()*getOuterRadius() - getInnerRadius()*getInnerRadius()));
            //Inner Tube
            Areas.push_back(Areas.back() + getInnerRadius()*osgAbs(getMaxTheta() - getMinTheta()) * getHeight());
            //Outer Tube
            Areas.push_back(Areas.back() + getOuterRadius()*osgAbs(getMaxTheta() - getMinTheta()) * getHeight());

            bool HasTubeSides(osgAbs(getMaxTheta() - getMinTheta()) - 6.283185 < -0.000001);
            if(HasTubeSides)
            {
                //MinTheta Tube Side
                Areas.push_back(Areas.back() + (getOuterRadius() - getInnerRadius()) * getHeight());

                //MaxTheta Tube Side
                Areas.push_back(Areas.back() + (getOuterRadius() - getInnerRadius()) * getHeight());
            }

            Real32 PickEdge(RandomPoolManager::getRandomReal32(0.0,1.0));
            if(PickEdge < Areas[0]/Areas.back())
            {
                //Max Cap
                Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
                Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
                Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
                Result = getCenter().subZero()
                    + (Radius*osgSin(Theta))*getTangent()
                    + (Radius*osgCos(Theta))*getBinormal()
                    + (getHeight()/static_cast<Real32>(2.0))*getNormal();
            }
            else if(PickEdge < Areas[1]/Areas.back())
            {
                //Min Cap
                Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
                Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
                Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
                Result = getCenter().subZero()
                    + (Radius*osgSin(Theta))*getTangent()
                    + (Radius*osgCos(Theta))*getBinormal()
                    + (-getHeight()/static_cast<Real32>(2.0))*getNormal();
            }
            else if(PickEdge < Areas[2]/Areas.back())
            {
                //Inner Tube
                Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
                Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
                Result =  getCenter().subZero()
                    + getInnerRadius()*osgSin(Theta)*getTangent()
                    + getInnerRadius()*osgCos(Theta)*getBinormal()
                    + Height*getNormal();
            }
            else if(PickEdge < Areas[3]/Areas.back())
            {
                //Outer Tube
                Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
                Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
                Result =  getCenter().subZero()
                    + getOuterRadius()*osgSin(Theta)*getTangent()
                    + getOuterRadius()*osgCos(Theta)*getBinormal()
                    + Height*getNormal();
            }
            else if(HasTubeSides && PickEdge < Areas[4]/Areas.back())
            {
                //MinTheta Tube Side
                Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
                Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
                Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
                Result = getCenter().subZero()
                    + (Radius*osgSin(getMinTheta()))*getTangent()
                    + (Radius*osgCos(getMinTheta()))*getBinormal()
                    + Height*getNormal();
            }
            else if(HasTubeSides && PickEdge < Areas[5]/Areas.back())
            {
                //MaxTheta Tube Side
                Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
                Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
                Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
                Result = getCenter().subZero()
                    + (Radius*osgSin(getMaxTheta()))*getTangent()
                    + (Radius*osgCos(getMaxTheta()))*getBinormal()
                    + Height*getNormal();
            }
            else
            {
                assert(false && "Should never reach this point");
            }
            break;
        }
    case VOLUME:
    default:
        {
            //To get a uniform distribution across the disc get a uniformly distributed allong 0.0 - 1.0
            //Then Take the square root of that.  This gives a square root distribution from 0.0 - 1.0
            //This square root distribution is used for the random radius because the area of a disc is 
            //dependant on the square of the radius, i.e it is a quadratic function
            Real32 Temp(osgSqrt(RandomPoolManager::getRandomReal32(0.0,1.0)));
            Real32 Radius(getInnerRadius() + Temp*(getOuterRadius() - getInnerRadius()));
            Real32 Height(RandomPoolManager::getRandomReal32(-getHeight()/2.0,getHeight()/2.0));
            Real32 Theta( RandomPoolManager::getRandomReal32(getMinTheta(),getMaxTheta()) );
            Result = getCenter().subZero()
                   + (Radius*osgSin(Theta))*getTangent()
                   + (Radius*osgCos(Theta))*getBinormal()
                   + Height*getNormal();
            break;
        }
    }

    return Result;
}
int center(int pos)
{
    getSize(pos,0);
    return getCenter(pos,0, sz[pos]);
}
示例#30
0
void Player::onActionDown(Action::ID action)
{
    switch (action)
    {
        case Action::UP:
            m_animator.setAnimation(*this, m_animation_up);
            break;
        case Action::DOWN:
            m_animator.setAnimation(*this, m_animation_down);
            break;
        case Action::USE_COOLER:
            if (m_icecubes > 0)
            {
                // Play sound effect and launch particles
                SoundSystem::playSound("cooler.ogg");
                m_snowflakes_emitter.setPosition(getCenter());
                m_snowflakes_emitter.createParticles(40);

                // Reset heat
                m_panel.setIcecubes(--m_icecubes);
                m_heat = 0.f;
                m_overheat = false;
                m_panel.setOverheat(false);
            }
            else
            {
                SoundSystem::playSound("disabled.ogg");
            }
            break;
        case Action::USE_MISSILE:
            if (m_missiles > 0 && m_missile_launcher.isReady())
            {
                m_panel.setMissiles(--m_missiles);
                m_missile_launcher.shoot<Missile>(0);
            }
            else
            {
                SoundSystem::playSound("disabled.ogg");
            }
            break;
        case Action::USE_LASER:
            if (m_overheat)
            {
                SoundSystem::playSound("disabled.ogg");
            }
            break;
        default:
            break;
    }

    // Detect Konami code sequence
    if (action == m_konami_code[m_current_konami_index])
    {
        ++m_current_konami_index;
        if (m_current_konami_index == KONAMI_CODE_LENGTH)
        {
            applyKonamiCode();
            m_current_konami_index = 0; // Reset
        }
    }
    else
    {
        m_current_konami_index = 0;
    }
}