void Graphics3DExtrude::drawQuad(const Pnt2f& p1, const Pnt2f& p2, const Pnt2f& p3, const Pnt2f& p4, 
						const Vec2f& t1, const Vec2f& t2, const Vec2f& t3, const Vec2f& t4,
						const MaterialUnrecPtr Material,
						const Real32& Opacity) const
{
	Real32 Alpha( Opacity * getOpacity());
	if(Alpha < 1.0 || Material->isTransparent())
	{
		//Setup the Blending equations properly
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_BLEND);
	}

    StateUnrecPtr state = NULL;
    if(Material != NULL)
    {
        state = Material->finalize(MaterialMapKey(),getDrawEnv()->getWindow())->getState();

        state->activate(getDrawEnv());
    }
	
	glBegin(GL_QUADS);
	   glColor4f(1.0, 1.0, 1.0, Alpha );
	   glTexCoord2fv(t1.getValues());
	   glVertex2fv(p1.getValues());
	   glTexCoord2fv(t2.getValues());
	   glVertex2fv(p2.getValues());
	   glTexCoord2fv(t3.getValues());
	   glVertex2fv(p3.getValues());
	   glTexCoord2fv(t4.getValues());
	   glVertex2fv(p4.getValues());
	glEnd();
	
	if(state != NULL)
	{
		state->deactivate(getDrawEnv());
	}

	if(Alpha < 1.0 || Material->isTransparent())
	{
		glDisable(GL_BLEND);
	}
}
void Graphics3DExtrude::drawQuad(const Pnt2f& p1, const Pnt2f& p2, const Pnt2f& p3, const Pnt2f& p4, 
						const Vec2f& t1, const Vec2f& t2, const Vec2f& t3, const Vec2f& t4,
						const Color4f& color, const TextureObjChunkUnrecPtr Texture,
						const Real32& Opacity) const
{
	Real32 Alpha( Opacity * getOpacity() * color.alpha());
	if(Alpha < 1.0 || Texture->getImage()->hasAlphaChannel())
	{
		//Setup the Blending equations properly
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_BLEND);
	}

	if(Texture != NULL)
	{
		Texture->activate(getDrawEnv());
	}
	
	glBegin(GL_QUADS);
	   glColor4f(color.red(), color.green(), color.blue(), Alpha );
	   glTexCoord2fv(t1.getValues());
	   glVertex2fv(p1.getValues());
	   glTexCoord2fv(t2.getValues());
	   glVertex2fv(p2.getValues());
	   glTexCoord2fv(t3.getValues());
	   glVertex2fv(p3.getValues());
	   glTexCoord2fv(t4.getValues());
	   glVertex2fv(p4.getValues());
	glEnd();
	
	if(Texture != NULL)
	{
		Texture->deactivate(getDrawEnv());
	}

	if(Alpha < 1.0 || Texture->getImage()->hasAlphaChannel())
	{
		glDisable(GL_BLEND);
	}
}
示例#3
0
// returns how much line A has to be scaled to hit the intersection
// || false if the lines do not intersect
pair<bool, float> Vec2Helper::lineIntersection(Vec2f startLineA, Vec2f dirLineA, Vec2f startLineB, Vec2f dirLineB) {
    float u_b = dirLineB.getValues()[1] * dirLineA.getValues()[0] - dirLineB.getValues()[0] * dirLineA.getValues()[1];

    if (u_b != 0) {
        float uaT = (dirLineB.getValues()[0] * (startLineA.getValues()[1] - startLineB.getValues()[1])) - (dirLineB.getValues()[1] * (startLineA.getValues()[0] - startLineB.getValues()[0]));
        //float ubT = (dirLineA.getValues()[0] * (startLineA.getValues()[1] - startLineB.getValues()[1])) - (dirLineA.getValues()[1] * (startLineA.getValues()[0] - startLineB.getValues()[0]));

        float ua = uaT / u_b;
        //float ub = ubT / u_b;

        //if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
            return make_pair(true, ua);
        //}
    }

    return make_pair(false, 0);
}
示例#4
0
void ModuleBuildings::addBuildingWallLevel(Vec2f pos1, Vec2f pos2, int level, int bNum, float elevation) {
    srand(bNum); //seed for random windows
    float len = (pos2 - pos1).length();
    Vec2f wallDir = (pos2 - pos1);
    wallDir.normalize();

    float wall_segment = Config::get()->WINDOW_DOOR_WIDTH;
    float FLOOR_HEIGHT = Config::get()->BUILDING_FLOOR_HEIGHT;

    int segN = floor(len / wall_segment);
    segN = max(segN, 1);
    wall_segment = len / segN;

    float low = level * FLOOR_HEIGHT + elevation;
    float high = low + FLOOR_HEIGHT;

    // insert a door at a random place (when on level 0 && there is enough room)
    int doorIndex = -1;
    if (level == 0 && segN > 2) doorIndex = bNum % segN;

    int N = 4;
    float _N = 1./N;
    float e = 0.01;

    int di = N*float(rand()) / RAND_MAX;
    int wi = N*float(rand()) / RAND_MAX;
    int fi = N*float(rand()) / RAND_MAX;

    float d_tc1 = di * _N + e;
    float d_tc2 = di * _N - e + _N;
    float w_tc1 = wi * _N + e;
    float w_tc2 = wi * _N - e + _N;
    float f_tc1 = fi * _N + e;
    float f_tc2 = fi * _N - e + _N;

    for (int i=0; i<segN; i++) {
        Vec2f w1 = pos1 + (wallDir * (i*wall_segment));
        Vec2f w2 = pos1 + (wallDir * ((i+1)*wall_segment));

        Vec2f wallVector = w2-w1;
        Vec3f normal = Vec3f(-wallVector.getValues()[1], 0, wallVector.getValues()[0]);

        b_geo_d->pos->addValue(Vec3f(w1.getValues()[0], low, w1.getValues()[1]));
        b_geo_d->pos->addValue(Vec3f(w2.getValues()[0], low, w2.getValues()[1]));
        b_geo_d->pos->addValue(Vec3f(w2.getValues()[0], high, w2.getValues()[1]));
        b_geo_d->pos->addValue(Vec3f(w1.getValues()[0], high, w1.getValues()[1]));

        for (int k=0; k<4; k++) {
            b_geo_d->inds->addValue(b_geo_d->inds->size());
            b_geo_d->norms->addValue(normal);
        }

        if (i == doorIndex) { // door
            b_geo_d->texs2->addValue(Vec2f(d_tc1, 0.5+e));
            b_geo_d->texs2->addValue(Vec2f(d_tc2, 0.5+e));
            b_geo_d->texs2->addValue(Vec2f(d_tc2, 0.75-e));
            b_geo_d->texs2->addValue(Vec2f(d_tc1, 0.75-e));
        } else { // window
            b_geo_d->texs2->addValue(Vec2f(w_tc1, 0.25+e));
            b_geo_d->texs2->addValue(Vec2f(w_tc2, 0.25+e));
            b_geo_d->texs2->addValue(Vec2f(w_tc2, 0.5-e));
            b_geo_d->texs2->addValue(Vec2f(w_tc1, 0.5-e));
        }

        // wall
        b_geo_d->texs->addValue(Vec2f(f_tc1, e));
        b_geo_d->texs->addValue(Vec2f(f_tc2, e));
        b_geo_d->texs->addValue(Vec2f(f_tc2, 0.25-e));
        b_geo_d->texs->addValue(Vec2f(f_tc1, 0.25-e));
    }
}