void BotonMenu::actualizar()
{
    Vector2D* pMousePos = ManejadorDeEntrada::Instancia()->getMousePosition();

    if(pMousePos->getX() < (posicion.getX() + ancho) && pMousePos->getX() > posicion.getX()
       && pMousePos->getY() < (posicion.getY() + altura) && pMousePos->getY() > posicion.getY())
    {
        if(ManejadorDeEntrada::Instancia()->getMouseButtonState(LEFT) && bLiberado)
        {
            frameActual = CLICKED;

            if(callback != 0)
            {
                callback();
            }

            bLiberado = false;
        }
        else if(!ManejadorDeEntrada::Instancia()->getMouseButtonState(LEFT))
        {
            bLiberado = true;
            frameActual = MOUSE_OVER;
        }
    }
    else
    {
        frameActual = MOUSE_OUT;
    }
}
Example #2
0
bool BoundingBox::overlaps(const Vector2D &startOfLine, const Vector2D &endOfLine) {

  // FIXME: optimize me!
  RectangleGeo rect( Vector2D( box.x, box.y ),
		  Vector2D( box.x + box.w, box.y + box.h ) );
  // FIXME: optimize me!

  bool overlaps = false;

  overlaps = rect.isInside( endOfLine );
  if ( overlaps ) return true;
  overlaps = rect.isInside( startOfLine );
  if ( overlaps ) return true;

  // check some points between the two end points
  Vector2D delta((endOfLine.getX() - startOfLine.getX()) / 4.0,
		 (endOfLine.getY() - startOfLine.getY()) / 4.0);
  Vector2D actPoint = startOfLine + delta;
  int i = 1;
  while (!overlaps && i <= 3 ) {
    overlaps = rect.isInside(actPoint);
    actPoint += delta;
    i++;
  }
  return overlaps;
}
Example #3
0
void GraphicsBuffer::fillRegion( const Vector2D& ul, const Vector2D& lr, const ALLEGRO_COLOR& color )
{
	ALLEGRO_BITMAP* pOldTarget = GraphicsSystem::switchTargetBitmap( mpBitmap );
	al_draw_filled_rectangle( ul.getX(), ul.getY(), lr.getX(), lr.getY(), color );
	GraphicsSystem::switchTargetBitmap( pOldTarget );

}
Example #4
0
void MenuButton::update()
{
    Vector2D* pMousePos = TheInputHandler::Instance()->getMousePosition();
    
	if (pMousePos->getX() < (SDL_RATIO_X(m_position.getX()) + SDL_RATIO_X(m_width)) && pMousePos->getX() > SDL_RATIO_X(m_position.getX())
		&& pMousePos->getY() < (SDL_RATIO_Y(m_position.getY()) + SDL_RATIO_Y(m_height)) && pMousePos->getY() > SDL_RATIO_Y(m_position.getY()))
    {
        if(TheInputHandler::Instance()->getMouseButtonState(LEFT) && m_bReleased)
        {
            m_currentFrame = CLICKED;
            
            if(m_callback != 0)
            {
                m_callback();
            }
            
            m_bReleased = false;
        }
        else if(!TheInputHandler::Instance()->getMouseButtonState(LEFT))
        {
            m_bReleased = true;
            m_currentFrame = MOUSE_OVER;
        }
    }
    else
    {
        m_currentFrame = MOUSE_OUT;
    }
}
Example #5
0
void MenuButton::update(){
    Vector2D<double>* pMousePos = InputHandler::Instance()->getMousePosition();
    
    double zoom = Game::Instance()->getGlobalZoom();

    
    if (pMousePos->getX() < GetParams().getX() * zoom +
        GetParams().getWidth() * zoom &&
        pMousePos->getX() > GetParams().getX() * zoom  &&
        pMousePos->getY() < GetParams().getY()  * zoom +
        GetParams().getHeight() * zoom  &&
        pMousePos->getY() > GetParams().getY() * zoom
        ){
        GetParams().setFrame(MOUSE_OVER);
        
        if (InputHandler::Instance()->getMouseButtonState(LEFT)){
            GetParams().setFrame(MOUSE_CLICKED);
            if (m_bReleased && m_callback){
                m_callback();
                m_bReleased = false;
            }
        } else{
            m_bReleased = true;
        }
    } else {
        GetParams().setFrame(MOUSE_OUT);
    }
    
}
Example #6
0
int main(int argc, char** argv) {
    
    srand(time(NULL));    // seed random
    
    std::cout << CLEAR;
    
    // get 2 vector objects based on randomly generated 2D Vectors
    Vector2D vectorA = randVector();
    Vector2D vectorB = randVector();
    
    // output Vectors to console
    std::cout << "vectorA = " << vectorA.getX() << "x + " <<
            vectorA.getY() << "y\n";
    std::cout << "vectorB = " << vectorB.getX() << "x + " <<
            vectorB.getY() << "y\n";
    std::cout << "\nLAB ASSIGNMENT PART 1: VECTOR DOT PRODUCT WITH * "
            << "OPERATOR OVERLOAD\n";
    std::cout << "--------------------------------------------------------"
            <<"----------\n";
    std::cout << "Dot product = vectorA * vectorB = " << vectorA * vectorB
            << std::endl;
    
    // Lab part 2 - do vector addition overload with + operator
    std::cout << "\nLAB ASSIGNMENT PART 2: VECTOR ADDITION WITH + "
            << "OPERATOR OVERLOAD\n";
    std::cout << "-------------------------------------------------------"
            <<"--------\n";
    Vector2D vectorC = vectorA + vectorB;
    std::cout << "Vector addition = vectorA + vectorB = " <<
            (vectorC).getX() << "x + " <<
            (vectorC).getY() << "y\n";
            

    return 0;
}
Example #7
0
bool BoundingBox::isBound(Vector2D vector)
{
	if (vector.getX() < topLeft.getX())
		if (vector.getX() > bottomRight.getX())
			if (vector.getY() < topLeft.getY())
				if (vector.getY() > bottomRight.getY())
					return true;
	return false;
}
Example #8
0
        void VideoManager::setVideoMode(const Vector2D &size)
        {
            this->size = Vector2D((float)(int) size.getX(),
                    (float)(int) size.getY());

            SDL_SetVideoMode((int) size.getX(), (int) size.getY(), 0, flags);
            SDL_ShowCursor(0);
            
            setVideoDefaults();
        }
Example #9
0
void Painter::drawLine(Vector2D& p1, Vector2D& p2)
{
	// no need to reinvent the wheel
	int x1 = static_cast<int>(p1.getX());
	int y1 = static_cast<int>(p1.getY());
	int x2 = static_cast<int>(p2.getX());
	int y2 = static_cast<int>(p2.getY());

	this->drawLine(x1, y1, x2, y2, lineColor_);
}
Example #10
0
void Items::GenerateItemNow( Vector2D pos, Vector2D vel )
{
	if( pos.getX() < 10 ) pos.setX( 10.f );
	if( pos.getX() > m_iScreenWidth-10 ) pos.setX( m_iScreenWidth-10.f );
	if( pos.getY() < 100 && vel.getY() < 5 ) vel.setY( 5 );

	int itemType = GetRandValue( ITEM_APPEAR_CHANCES, NR_ITEM_TYPES );
	Item *item = new Item( pos, vel, (ItemTypes)itemType, m_iItemLifeTime, m_iScreenWidth );
	AddItem( item );
}
Example #11
0
void Painter::drawRect(Vector2D& topleft, Vector2D& bottomright)
{
	Vector2D diff = bottomright - topleft;

	int x      = static_cast<int>(topleft.getX());
	int y      = static_cast<int>(topleft.getY());
	int width  = static_cast<int>(diff.getX());
	int height = static_cast<int>(diff.getY());

	drawRect(x, y, width, height);
}
Example #12
0
 bool BoundingBox::hasPoint(const Vector2D &point) const
 {
     if(point.getX() < topLeft.getX())
         return false;
     if(point.getX() > bottomRight.getX())
         return false;
     if(point.getY() < topLeft.getY())
         return false;
     if(point.getY() > bottomRight.getY())
         return false;
     return true;
 }
Example #13
0
void TripleAntenna::renderFeedback(Object *object, Environment *environment) {
    if (object == environment->getPlayer() && nearestObject) {
        if (nearestObject->isVisible()) {
            Vector2D windowPos = environment->getWindowPos(object->getPosition());        
            Vector2D objectWindowPos = environment->getWindowPos(nearestObjectPosition);
            al_draw_line(windowPos.getX(),
                         windowPos.getY(),
                         objectWindowPos.getX(),
                         objectWindowPos.getY(),
                         al_map_rgb(196, 196, 196), 2.0);
        }
    }
}
Example #14
0
bool Collision::AABBtoAABB(Box &a, Box &b, Vector2D &Nnormal)
{
	ManifoldAABBtoAABB m;
	//!Min and max collision. Checks if the two boxes have collided.
	Vector2D centreDist = b.getPosition().subtract(a.getPosition());
	//! Overlapping in X.
	float xLap =a.getWidth()/2 + b.getWidth()/2 - std::abs(centreDist.getX());
	float yLap = a.getHeight()/2 + b.getHeight()/2 - std::abs(centreDist.getY());
	//! Overlapping in Y.
	if(xLap > 0)
	{

		if (yLap > 0)
		{
			if (xLap > yLap)
			{

				if(centreDist.getY() < 0)
				{
					normal.setXandY(0,-1);//!< Collides Top of A with bottom of B
				}
				else
				{
					normal.setXandY(0,1);//!< Collides Bottom of box A with top of box B

				}
				penetrationDepth = yLap;//!< Sets the penetration depth according to the collision
			}
			else
			{
				//point normal towards b as n is from A to B on y axis
				if(centreDist.getX() < 0)
				{
					normal.setXandY(1,0);//!< Collides Left of box A with Right of Box B
				}
				else
				{
					normal.setXandY(-1,0);//!< Collides Right of box A with Left of Box B
				}
				penetrationDepth = xLap;//!< Sets the penetration depth
			}
		}
		else{ return false;}
	}
	else{ return false;}
	
	Nnormal = normal;//!< return the normal. To use for enemies.
	return true;

}
Example #15
0
        BoundingBox::BoundingBox(vector<Vector2D> *points)
        {
            MathManager *mathManager = MathManager::getInstance();
            if(points->size() >= 2) {
                vector<Vector2D>::iterator iterator = points->begin();
                Vector2D first = *iterator;
                iterator++;
                Vector2D second = *iterator;

                topLeft = Vector2D(mathManager->min<float>(first.getX(),
                        second.getX()),
                        mathManager->min<float>(first.getY(), second.getY()));
                bottomRight = Vector2D(mathManager->max<float>(
                        first.getX(), second.getX()),
                        mathManager->max<float>(first.getY(), second.getY()));

                /* Expand. */
                for(iterator = points->begin(); iterator != points->end();
                        iterator++) {
                    Vector2D point = *iterator;
                    if(point.getX() < topLeft.getX())
                        topLeft.setX(point.getX());
                    if(point.getX() > bottomRight.getX())
                        bottomRight.setX(point.getX());
                    if(point.getY() < topLeft.getY())
                        topLeft.setY(point.getY());
                    if(point.getY() > bottomRight.getY())
                        bottomRight.setY(point.getY());
                }
            } else {
                LogManager::getInstance()->warning(
                        "Boundingbox based on < 2 points."); 
            }
        }
Example #16
0
bool CardObject::isInside(Vector2D pos) {
    
    //check to see if it is inside
    Vector2D currPos = this->getPosition();
    
    //check x
    if((pos.getX() > currPos.getX()) && (pos.getX() < (currPos.getX() + this->getWidth()))) {
        //now check y
        if((pos.getY() > currPos.getY()) && (pos.getY() < (currPos.getY() + this->getHeight()))) {
            return true;
        }
    }
    
    return false;
}
Example #17
0
void Shoot_get_aim_direction_callback(void *pUserData, float *pfDirection)
{
	
	Shoot * bullet = (Shoot*)pUserData;
	Vector2D aimAt = bullet->getBarrageInstance()->getBarrageManager()->getAimAtPosition();
	float adj = (aimAt.getX() - bullet->getPosition().getX());
	float opp = (aimAt.getY() - bullet->getPosition().getY());
	float deg;

	       /*             
	if (adj >= 0.0)
		deg = FastMath::fastArcTan(adj/opp) * (float)FastMath::M_180_PI;
	else
		deg =  180 + FastMath::fastArcTan(-adj/opp) * (float)FastMath::M_180_PI;
		*/
	
	if (opp >= 0.0)
		deg = FastMath::fastArcTan(adj/opp) * (float)FastMath::M_180_PI;
	else
		deg =  180 - FastMath::fastArcTan(adj/-opp) * (float)FastMath::M_180_PI;
	
	//deg = FastMath::fastArcTan(adj/opp) * (float)FastMath::M_180_PI;
	int tmpdir =(int)(*pfDirection)%360;
	if (abs(tmpdir - deg) > abs(tmpdir - 360.f + deg)) {
		//printf("pfDirection=%f\n",*pfDirection);
		*pfDirection = 360.f - deg;

	} else {
		*pfDirection = deg;
	}
	
	//*pfDirection = deg;
	//printf("Shoot_get_aim_direction_callback %f %f %f target(%f,%f)\n",deg,opp,adj,aimAt.getX(),aimAt.getY());
}
Example #18
0
bool OverlapTester::isPointInTriangle(Vector2D &p, Triangle &tr)
{
    float pX = p.getX();
    float pY = p.getY();
    float p0X = tr.getPointA().getX();
    float p0Y = tr.getPointA().getY();
    float p1X = tr.getPointB().getX();
    float p1Y = tr.getPointB().getY();
    float p2X = tr.getPointC().getX();
    float p2Y = tr.getPointC().getY();
    
    /* Calculate area of triangle ABC */
    float a = calcArea(p0X, p0Y, p1X, p1Y, p2X, p2Y);
    
    /* Calculate area of triangle PBC */
    float a1 = calcArea (pX, pY, p1X, p1Y, p2X, p2Y);
    
    /* Calculate area of triangle PAC */
    float a2 = calcArea (p0X, p0Y, pX, pY, p2X, p2Y);
    
    /* Calculate area of triangle PAB */
    float a3 = calcArea (p0X, p0Y, p1X, p1Y, pX, pY);
    
    float aSum = a1 + a2 + a3;
    
    /* Check if sum of A1, A2 and A3 is same as A */
    return a < (aSum + 0.1f) && a > (aSum - 0.1f);
}
Example #19
0
Vector2D operator*(const TransformMatrix2D &M, Vector2D &v)
{
	double x = M.k_[0][0] * v.getX() + M.k_[0][1] * v.getY() + M.k_[0][2];
	double y = M.k_[1][0] * v.getX() + M.k_[1][1] * v.getY() + M.k_[1][2];

	return Vector2D(x, y);
}
Example #20
0
void MenuButton::update()
{
    InputHandler* pIH = InputHandler::Instance();
    Vector2D* pMousePos = pIH->getMousePosition();

    if (pMousePos->getX() >= m_position.getX() &&
            pMousePos->getX() <= m_position.getX() + m_width &&
            pMousePos->getY() >= m_position.getY() &&
            pMousePos->getY() <= m_position.getY() + m_height)
    {
        m_currentFrame = MOUSE_OVER;

        if (pIH->getMouseButtonState(LEFT))
        {
            m_currentFrame = CLICKED;
            if (m_bReleased)
            {
                m_callback();
                m_bReleased = false;
            }
        }
        else
        {
            m_bReleased = true;
        }
    }
    else
    {
        m_currentFrame = MOUSE_OUT;
        m_bReleased = true;
    }
}
Example #21
0
void MenuButton::update() {

	Vector2D pMousePos = InputHandler::Instance()->getMousePosition();

	//check to make sure that it is within the bounds of the button
	if (pMousePos.getX() < (m_position.getX() + m_width)
		&& pMousePos.getX() > m_position.getX()
		&& pMousePos.getY() < (m_position.getY() + m_height)
		&& pMousePos.getY() > m_position.getY()) {

		m_currentFrame = (int)button_state::MOUSE_OVER;

		if (InputHandler::Instance()->getMouseButtonState(LEFT) && m_bReleased) {
			m_currentFrame = (int)button_state::CLICKED;

			//now callback
			m_callback();
			m_bReleased = false;
		}
		else if (!InputHandler::Instance()->getMouseButtonState(LEFT)) {
			m_bReleased = true;
			m_currentFrame = (int)button_state::CLICKED;
		}
		else {
			m_currentFrame = (int)button_state::MOUSE_OVER;
		}
	}
	else {
		m_currentFrame = (int)button_state::MOUSE_OUT;
	}
    
    SDLGameObject::update();
}
void MenuButton::update()
{
    Vector2D* pMousePos =TheInputHandler::Instance()->getMousePosition();
    if (pMousePos->getX() < (m_position.getX() + m_width)
        && pMousePos->getX() > m_position.getX()
        && pMousePos->getY() < (m_position.getY()) + m_height
        && pMousePos->getY() > m_position.getY()) {
        m_currentFrame = MOUSE_OVER;
        
        if (TheInputHandler::Instance()->getMouseButtonState(LEFT)) {
            //std::cout << "Mouse clicked" << std::endl;
            m_currentFrame = CLICKED;
            m_bReleased = false;
        }
        else if (!TheInputHandler::Instance()->getMouseButtonState(LEFT) && !m_bReleased)
        {
            //std::cout << "Mouse was released." << std::endl;
            m_bReleased = true;
            m_currentFrame = MOUSE_OVER;
            m_callback();
        }
        else if (!TheInputHandler::Instance()->getMouseButtonState(LEFT))
        {
            //std::cout << "Mouse over" << std::endl;
            m_bReleased = true;
            m_currentFrame = MOUSE_OVER;
        }
    }
    else
    {
        m_bReleased = true;
        m_currentFrame = MOUSE_OUT;
    }
}
void CollisionManager::checkPlayerTileCollision(Player* pPlayer, 
        const std::vector<TileLayer*>& collisionLayers) {
    for(auto it = collisionLayers.begin(); 
            it != collisionLayers.end(); ++it) {
        TileLayer* pTileLayer = (*it);
        std::vector<std::vector<int>> tiles = pTileLayer->getTileIDs();
        
        Vector2D layerPos = pTileLayer->getPosition();
        
        int x, y, tileColumn, tileRow, tileid = 0;
        
        x = layerPos.getX() / pTileLayer->getTileSize();
        y = layerPos.getY() / pTileLayer->getTileSize();
        
        if(pPlayer->getVelocity().getX() >= 0 || pPlayer->getVelocity().getY() >= 0) {
            tileColumn = ((pPlayer->getPosition().getX() + 
                pPlayer->getWidth()) / pTileLayer->getTileSize());
            tileRow = ((pPlayer->getPosition().getY() + 
                pPlayer->getHeight()) / pTileLayer->getTileSize());
            tileid = tiles[tileRow + y][tileColumn + x];
        }
        else if(pPlayer->getVelocity().getX() < 0 || 
                pPlayer->getVelocity().getY() < 0) {
            tileColumn = pPlayer->getPosition().getX() / pTileLayer->getTileSize();
            tileRow = pPlayer->getPosition().getY() / pTileLayer->getTileSize();
            tileid = tiles[tileRow + y][tileColumn + x];
        }
        
        if(tileid != 0) { pPlayer->collision(); }
    }
}
Example #24
0
void MenuButton::update()
{
	Vector2D* pMousePos = InputHandler::Instance()->getMousePosition();

	if (pMousePos->getX() < (Params->getX() + Params->getWidth())
		&& pMousePos->getX() > Params->getX()
		&& pMousePos->getY() < (Params->getY() + Params->getHeight())	
		&& pMousePos->getY() > Params->getY())
	{
		m_currentFrame = MOUSE_OVER;
		if (InputHandler::Instance()->getMouseButtonState(0) && m_bR)
		{
			m_currentFrame = CLICKED;
			m_callback();
			m_bR = false;
		}
		else if (!InputHandler::Instance()->getMouseButtonState(0)) {
			m_bR = true;
			m_currentFrame = MOUSE_OVER;
		}
	}
	else
	{
		m_currentFrame = MOUSE_OUT;
		m_bR = false;
	}
}
Example #25
0
bool CollisionObject::isCollisionWithTileRight() {
	// iterate through collision layers
	for (std::vector<TileLayer*>::const_iterator it = m_pCollisionLayers->begin(); it != m_pCollisionLayers->end(); ++it) {
		TileLayer* pTileLayer = (*it);
		std::vector<std::vector<int>> tiles = pTileLayer->getTileIDs();
		// get this layers position
		Vector2D layerPos = pTileLayer->getPosition();
		int x, y, tileColumn, tileRow, tileid = 0;
		// calculate position on tile map
		x = layerPos.getX() / pTileLayer->getTileSize();
		y = layerPos.getY() / pTileLayer->getTileSize();

		if (getVelocity().getX() > 0) //dreta
		{
			tileColumn = ((getPosition().getX() + Camera::Instance()->getPosition().getX() + getWidth()) / pTileLayer->getTileSize());
			tileRow = (getPosition().getY() / pTileLayer->getTileSize());
			tileid = tiles[tileRow+y][tileColumn + x];//Li restem 1 a la y perque quan estiguem asobre la plataforma no ens doni colisio
		}
		if (tileid != 0) // if the tile id not blank then collide
		{
			return true;
		}
	}
	return false;
}
Example #26
0
bool Vector2D::operator==(const Vector2D &v2) const
{
    if (this->getX() != v2.getX() || this->getY() != v2.getY())
        return false;
    else
        return true;
}
bool PhongMetalMaterial::specularDirection(const ONB& uvw, const Vector3D& v_in, const Vector3D& p, const Vector2D& uv,
        Vector2D& seed, ColorRGB& color, Vector3D& v_out)
{
    float phi = 2* PI* seed.getX();
    //the phong exponent is stored in the red value for the texture at that point
    float exponent = phong_exp->value(uv, p).getRed();
    float cosTheta = pow(1-seed.getY(), 1.0/(exponent+1));
    float sinTheta = sqrt(1-cosTheta*cosTheta);
    float x = cos(phi) * sinTheta;
    float y = sin(phi) * sinTheta;
    float z = cosTheta;


    ONB basis;
    Vector3D w = v_in - 2*dotProduct(v_in, uvw.w())*uvw.w();
    basis.initFromW(w);

    //color = R->value(uv, p);
    ColorRGB r = R->value(uv, p);
    float c = 1 - (dotProduct(v_in, uvw.w()));
    color = r + (ColorRGB(1, 1, 1) + (-r))*(c*c*c*c*c);
    v_out = x*basis.u() + y*basis.v() + z*basis.w();

    if(exponent <10000) seed.scramble();
    return (dotProduct(v_out, uvw.w()) >0 );

}
Example #28
0
Oro::Oro(int x,int y) {
	TheTextureManager::Instance()->load("assets/resources.png","oro", TheGame::Instance()->getRenderer());


	float possx = (x+1) * TheGame::TILE_WIDTH/2;
	float possy = (y+1) * TheGame::TILE_HEIGHT;
	Vector2D* vec = new Vector2D(0,0);
	vec->setX(possx);
	vec->setY(possy);
	vec->toIsometric();
	GameObject::load( vec->getX(), vec->getY(),  width, height, destWidth, destHeight, numFrames, "oro",false);
	m_mapPosition2.setX(x);
	m_mapPosition2.setY(y);
	GameObject::setFrame(frame);
	GameObject::setOffset(offsetX,offsetY);
	GameObject::setRow(row);
	GameObject::setAlto(1);
	GameObject::setAncho(1);

	this->recurso = true;
	this->name = "Oro";
	this->cantidad = 1;

	delete vec;
}
Example #29
0
void MenuButton::update()
{
	Vector2D* pMousePos = TheInputHandler::Instance()->getMousePosition();
	if (pMousePos->getX() < (m_position.getX() + m_width)
		&& pMousePos->getX() > m_position.getX()
		&& pMousePos->getY() < (m_position.getY() + m_height)
		&& pMousePos->getY() > m_position.getY())
	{
		if (TheInputHandler::Instance()->getMouseButtonState(LEFT) && m_bReleased)
		{
			m_currentFrame = CLICKED;
			m_callback(); // call our callback function
			m_bReleased = false;
		}
		else if (!TheInputHandler::Instance()->getMouseButtonState(LEFT))
		{
			m_bReleased = true;
			m_currentFrame = MOUSE_OVER;
		}
	}
	else
	{
		m_currentFrame = MOUSE_OUT;
	}
}
//static
float Kinematic::getOrientationFromVelocity( float currentOrientation, const Vector2D& velocity )
{
	if( velocity.hasNonZeroLength() )
	{
		currentOrientation = atan2(velocity.getX(), -velocity.getY()); 
	}
	return currentOrientation;
}