void LayoutShowUnit::CalcTransformToScalePosition()
{
	b2Fixture *outsideFixture=GetOutsideFixture(this->body);
	b2PolygonShape *polygonShape=(b2PolygonShape*)outsideFixture->GetShape();
	b2Transform tx=outsideFixture->GetBody()->GetTransform();
	bee::Point b1=GetWorldPoint(polygonShape->m_vertices[0],tx);
	bee::Point b2=GetWorldPoint(polygonShape->m_vertices[1],tx);
	bee::Point b3=GetWorldPoint(polygonShape->m_vertices[3],tx);
	b2Mat33 transform_matrix(b2Vec3(b1.x,b2.x,b3.x),b2Vec3(b1.y,b2.y,b3.y),b2Vec3(1,1,1));
	this->xDirectionVector=transform_matrix.Solve33(b2Vec3(0,1,0));
	this->yDirectionVector=transform_matrix.Solve33(b2Vec3(0,0,1));
}
Exemple #2
0
void Projectile::track()
{
	std::string shortTag;

	bool found = false;
	for (b2ContactEdge* ed = body_->GetContactList(); ed != nullptr; ed = ed->next)
	{
		Shape* s = nullptr;
		float dist = FLT_MAX;
		std::string tag;

		if (ed->contact->GetFixtureA()->GetUserData() == "projtracking")
		{
			tag = std::string(static_cast<char*>(ed->contact->GetFixtureB()->GetUserData()));

			if (tag == enemyTag_)
			{
				b2Vec2 pos = ed->contact->GetFixtureB()->GetBody()->GetPosition();
				if (pos.Length() < dist)
				{
					target_ = b2Vec3(pos.x, pos.y, 1);
					dist = pos.Length();
					shortTag = tag;
				}
			}
		}

		else if (ed->contact->GetFixtureB()->GetUserData() == "projtracking")
		{
			tag = std::string(static_cast<char*>(ed->contact->GetFixtureA()->GetUserData()));

			if (tag == enemyTag_)
			{
				b2Vec2 pos = ed->contact->GetFixtureA()->GetBody()->GetPosition();
				if (pos.Length() < dist)
				{
					found = true;
					target_ = b2Vec3(pos.x, pos.y, 1);
					dist = pos.Length();
					shortTag = tag;
				}
			}
		}
	}

	if (found == false)
		target_.z = 0;

	std::cout  << target_.x << "\t" << target_.y << "\t " << target_.z << "\t" << shortTag.c_str() << ::endl;
}
b2AABB b2dJsonImage::getAABB()
{
    b2Mat33 r, t, m;
    if ( body ) {
        _setMat33Rotation(r, body->GetAngle());
        _setMat33Translation(t, body->GetPosition());
        m = _b2Mul(r,t);
    }
    else
        m = b2Mat33( b2Vec3(1,0,0), b2Vec3(0,1,0), b2Vec3(0,0,1) ); //identity Matrix

    b2AABB aabb;
    aabb.lowerBound.Set(FLT_MAX, FLT_MAX);
    aabb.upperBound.Set(-FLT_MAX, -FLT_MAX);
    for (int i = 0; i < 4; i++) {
        aabb.lowerBound = b2Min(aabb.lowerBound, _b2Mul(m, corners[i]));
        aabb.upperBound = b2Max(aabb.upperBound, _b2Mul(m, corners[i]));
    }
    return aabb;
}
Exemple #4
0
AutoPaddle::AutoPaddle(b2World& world, float width)
{
    b2Vec2 extents = 1./2. * b2Vec2(width, getHeight());
    b2Vec2 origin(Game::getSize().x / 2., Game::getSize().y - (getHeight() + 0.25));

    // TODO: Move the creation of the b2Body into a component.
    body = createBoxBody (world, origin, extents);

    addComponent(new BoxRenderer(*this, b2Vec3(extents.x, extents.y, 0.5)));
    addComponent(new BallFollower(*this, 3.));
}
Exemple #5
0
Render::Render(Init *init){
	this->init = init;
	init->SDL();
	init->OpenGL();
	cameraX = 0;
	cameraY = 0;
	ledR = ledG = ledB = 1;

	//loop = &Render::mainMenu;
	menuObjects = new vector<button>;
	pauseObjects = new vector<button>;
	scoreButtons = new vector<button>;
	scoreTexts = new vector<button>;
	settingsButtons = new vector<button>;
	//popupButtons = new vector<button>;
	TTF_Init();
	screenHeight = init->getScreenHeight();
	screenWidth = init->getScreenWidth();
	float scale = 1080.0 / screenHeight;
	font = TTF_OpenFont("./Font/CaviarDreams.ttf", 42 / scale);
	menuFont = TTF_OpenFont("./Font/CaviarDreams.ttf", 60 / scale);
	titleFont = TTF_OpenFont("./Font/CaviarDreams.ttf", 80 / scale);
	popupFont = TTF_OpenFont("./Font/CaviarDreams.ttf", 20 / scale);
	renderNow = false;
	shutDown = false;

	platformVBO = new PlatformVBO();
	particleVBO = new ParticleVBO();
	backgroundVBO = new PlatformVBO(); 
	//pauseVBO = new PlatformVBO();	
	mainCharParticleVBO = new ParticleVBO();
	b2Vec2 vx[4];
	vx[0].x = 0;
	vx[0].y = 0;

	vx[1].x = screenWidth;
	vx[1].y = 0;

	vx[2].x = screenWidth;
	vx[2].y = screenHeight;

	vx[3].x = 0;
	vx[3].y = screenHeight;
	
	//pauseVBO->pushBackground(vx, b2Vec2(screenHeight / 2, screenWidth / 2), b2Vec3(255, 0, 255));
//	setBackgroundSquare(0, 0, screenWidth, screenHeight, b2Vec3(0, 0, 0), pauseVBO);
	setBackgroundSquare(0, 0, screenWidth, screenHeight, b2Vec3(0, 255, 255), backgroundVBO);
	shader = new Shader("./Shaders/ligthShader.vert", "./Shaders/ligthShader.frag");
	platformShader =  new Shader("./Shaders/platformShader.vert", "./Shaders/platformShader.frag");
//	colorShader = new Shader("./Shaders/colorShader.vert", "./Shaders/colorShader.frag");
	setUniforms(shader);
	
	
}
Exemple #6
0
bool Projectile::collide(Entity * other, b2Contact& contact, std::string tag)
{
	bool handled = false;
	
	//Get fixture string
	std::string tig = std::string(static_cast<char*>(contact.GetFixtureA()->GetUserData()));

	//If it's the other, get what we are in contact
	if (tig == tag)
		tig = std::string(static_cast<char*>(contact.GetFixtureB()->GetUserData()));

	//If it's our tracking, don't bother
	if (tig == "projtracking")
	{
		handled = true;
	}

	else if (tag == "player" || tag == "enemy" || tag == "shape")////
	{
		Shape* shape = static_cast<Shape*>(other);
		//Projectiles do get hurt by their friends
		if (faction_ != shape->getFaction() && shape->getFaction() != GOD)
		{
			//Onehit projectiles die on hit, precedence over all
			if (oneHit_)
			{
				alive_ = false;
			}

			//If we can't penetrate
			if (penetration_-- <= 0)
			{
				takeDamage(1);
				if (size_.y > 0)
				{
					//b2Vec2 vel = body_->GetLinearVelocity();
					//vel *= (0.1* size_.x * size_.y);
					//
					//body_->SetLinearVelocity(vel);
				}
			}

			//Do our force on penetration
			else
			{
				lastPen_ = b2Vec3(body_->GetPosition().x, body_->GetPosition().y, 1);
			}

			if (alive_ == false)
				contact.SetEnabled(false);
		}

		else contact.SetEnabled(false);

		handled = true;
	}

	else if (tag == "projectile")
	{
		Projectile* proj = static_cast<Projectile*>(other);
		//If we're not friends
		if (faction_ != proj->getFaction())
		{
			//If we can't penetrate
			if (--penetration_ < 0)
			{
				takeDamage(proj->getDamage());

				if (alive_ == false)
					contact.SetEnabled(false);
			}

			//Do our force on penetration
			else
			{
				lastPen_ = b2Vec3(body_->GetPosition().x, body_->GetPosition().y, 1);
			}
			//Maybe set contact to false so stronger proj continues?
		}

		//Else we must have same owner, do not interact
		else contact.SetEnabled(false);

		handled = true;
	}

	else if (tag == "pickup")
	{
		contact.SetEnabled(false);
		handled = true;
	}

	else if (tag == "shield")
	{
		Pickup::Shield* shield = static_cast<Pickup::Shield*>(other);

		//If we don't own the shield
		if (shield->getOwner() != owner_)
		{
			//Penetrate if we can
			if (penetration_ > 0)
			{
				//Shields block more pen
				penetration_ -= shield->getStrength();
			}
		
			//if (contact.IsEnabled())
			//{
			//	b2Vec2 back = body_->GetLinearVelocity();
			//	back *= -0.5;
			//	body_->SetLinearVelocity(back);
			//}
		}
		
		handled = true;
	}

	else if (tag == "bounds")
	{
		takeDamage(1);
		handled = true;
	}

	return handled;
}