Esempio n. 1
0
void DrawEERIEInter_ViewProjectTransform(EERIE_3DOBJ *eobj) {
	for(size_t i = 0 ; i < eobj->vertexlist.size(); i++) {

		Vec3f tempWorld;
		EE_RT(eobj->vertexlist3[i].v, tempWorld);
		EE_P(&tempWorld, &eobj->vertexlist[i].vert);
	}
}
Esempio n. 2
0
static void AddToShadowBatch(TexturedVertex * _pVertex1, TexturedVertex * _pVertex2,
                             TexturedVertex * _pVertex3) {
	
	TexturedVertex pPointAdd[3];
	EE_P(&_pVertex1->p, &pPointAdd[0]);
	EE_P(&_pVertex2->p, &pPointAdd[1]);
	EE_P(&_pVertex3->p, &pPointAdd[2]);
	pPointAdd[0].color = _pVertex1->color;
	pPointAdd[0].uv = _pVertex1->uv;
	pPointAdd[1].color = _pVertex2->color;
	pPointAdd[1].uv = _pVertex2->uv;
	pPointAdd[2].color = _pVertex3->color;
	pPointAdd[2].uv = _pVertex3->uv;

	g_shadowBatch.push_back(pPointAdd[0]);
	g_shadowBatch.push_back(pPointAdd[1]);
	g_shadowBatch.push_back(pPointAdd[2]);
}
Esempio n. 3
0
void drawTriangle(const RenderMaterial & mat, const TexturedVertex * vertices) {
	
	TexturedVertex projected[3];
	EE_P(&vertices[0].p, &projected[0]);
	EE_P(&vertices[1].p, &projected[1]);
	EE_P(&vertices[2].p, &projected[2]);
	projected[0].color = vertices[0].color;
	projected[0].specular = vertices[0].specular;
	projected[0].uv = vertices[0].uv;
	projected[1].color = vertices[1].color;
	projected[1].specular = vertices[1].specular;
	projected[1].uv = vertices[1].uv;
	projected[2].color = vertices[2].color;
	projected[2].specular = vertices[2].specular;
	projected[2].uv = vertices[2].uv;
	
	RenderBatcher::getInstance().add(mat, projected);
}
Esempio n. 4
0
void drawLineSphere(const Sphere & sphere, Color color) {

	if(sphere.radius <= 0)
		return;

	static const size_t sections = 64;

	size_t rings = sphere.radius / 10;
	if(rings < 7)
		rings = 7;

	std::vector<TexturedVertex> vertices;

	bool skip = false;

	for(size_t i = 1; i < rings - 1; i++) {
		float a = i * (glm::pi<float>() / (rings - 1));
		for(size_t j = 0; j <= sections; j++) {
			float b = j * ((2 * glm::pi<float>()) / sections);

			Vec3f pos;
			pos.x = glm::cos(b) * glm::sin(a);
			pos.y = glm::sin(b) * glm::sin(a);
			pos.z = glm::cos(a);

			pos *= sphere.radius;
			pos += sphere.origin;
			
			TexturedVertex out;
			Vec3f temp = EE_RT(pos);
			EE_P(temp, out);

			if(skip) {
				skip = false;
				out.color = Color(0, 0, 0, 0).toRGBA();
				vertices.push_back(out);
			}

			out.color = color.toRGBA();
			vertices.push_back(out);

			if(j == sections) {
				skip = true;
				out.color = Color(0, 0, 0, 0).toRGBA();
				vertices.push_back(out);
			}
		}
	}

	GRenderer->ResetTexture(0);
	EERIEDRAWPRIM(Renderer::LineStrip, &vertices[0], vertices.size());
}
Esempio n. 5
0
static void drawDebugMaterials() {
	
	if(!ACTIVEBKG || !ACTIVEBKG->exist) {
		return;
	}
	
	PolyType skip = POLY_NODRAW | POLY_HIDE;
	if(GInput->isKeyPressed(Keyboard::Key_LeftShift)) {
		skip |= POLY_TRANS | POLY_WATER;
	}
	
	Vec2f point(DANAEMouse);
	
	Entity * owner = GetFirstInterAtPos(Vec2s(point));
	TextureContainer * material = NULL;
	size_t count = 0;
	Vec2f pp[4];
	Vec2f puv[4];
	PolyType flags;
	
	float minz = std::numeric_limits<float>::max();
	
	for(size_t k = 1; k < entities.size(); k++) {
		
		EntityHandle h = EntityHandle(k);
		if(!entities[h] || !entities[h]->obj) {
			continue;
		}
		Entity * entity = entities[h];
		
		if((entity->ioflags & IO_CAMERA) || (entity->ioflags & IO_MARKER))
			continue;
		
		if(!(entity->gameFlags & GFLAG_ISINTREATZONE))
			continue;
		if((entity->gameFlags & GFLAG_INVISIBILITY))
			continue;
		if((entity->gameFlags & GFLAG_MEGAHIDE))
			continue;
		
		switch(entity->show) {
			case SHOW_FLAG_DESTROYED:    continue;
			case SHOW_FLAG_IN_INVENTORY: continue;
			case SHOW_FLAG_ON_PLAYER:    continue;
			case SHOW_FLAG_LINKED:       break;
			case SHOW_FLAG_NOT_DRAWN:    continue;
			case SHOW_FLAG_HIDDEN:       continue;
			case SHOW_FLAG_MEGAHIDE:     continue;
			case SHOW_FLAG_KILLED:       continue;
			case SHOW_FLAG_IN_SCENE:     break;
			case SHOW_FLAG_TELEPORTING:  break;
		}
		
		if(!entity->bbox2D.valid()) {
			continue;
		}
		
		for(size_t j = 0; j < entity->obj->facelist.size(); j++) {
			const EERIE_FACE & face = entity->obj->facelist[j];
			
			if(face.facetype & skip) {
				continue;
			}
			
			bool valid = true;
			bool bvalid = false;
			Vec3f p[3];
			Vec2f uv[3];
			for(size_t i = 0; i < 3; i++) {
				unsigned short v = face.vid[i];
				valid = valid && v < entity->obj->vertexlist3.size();
				if(valid) {
					if(entity->animlayer[0].cur_anim) {
						p[i] = entity->obj->vertexlist3[v].vert.p;
						uv[i] = entity->obj->vertexlist3[v].vert.uv;
					} else {
						p[i] = entity->obj->vertexlist[v].vert.p;
						uv[i] = entity->obj->vertexlist[v].vert.uv;
					}
					valid = valid && (p[i].z > 0.000001f);
					bvalid = bvalid || (p[i].x >= g_size.left && p[i].x < g_size.right
					                 && p[i].y >= g_size.top && p[i].y < g_size.bottom);
				}
			}
			
			if(!valid || !bvalid) {
				continue;
			}
			
			float z = pointInTriangle(point, p[0], p[1], p[2]);
			
			if(z > 0 && z <= minz) {
				count = 3;
				for(size_t i = 0; i < count; i++) {
					pp[i] = Vec2f(p[i].x, p[i].y);
					puv[i] = uv[i];
				}
				if(face.texid >= 0 && size_t(face.texid) < entity->obj->texturecontainer.size()) {
					material = entity->obj->texturecontainer[face.texid];
				} else {
					material = NULL;
				}
				owner = entity;
				minz = z;
				flags = face.facetype & ~(POLY_WATER | POLY_LAVA);
			}
			
		}
	}
	
	for(short z = 0; z < ACTIVEBKG->Zsize; z++)
	for(short x = 0; x < ACTIVEBKG->Xsize; x++) {
		const EERIE_BKG_INFO & feg = ACTIVEBKG->fastdata[x][z];
		
		if(!feg.treat) {
			continue;
		}
		
		for(long l = 0; l < feg.nbpolyin; l++) {
			EERIEPOLY * ep = feg.polyin[l];
			
			if(!ep) {
				continue;
			}
			
			if(ep->type & skip) {
				continue;
			}
			
			bool valid = true;
			bool bvalid = false;
			Vec3f p[4];
			for(size_t i = 0; i < ((ep->type & POLY_QUAD) ? 4u : 3u); i++) {
				TexturedVertex tv;
				tv.p = EE_RT(ep->v[i].p);
				valid = valid && (tv.p.z > 0.000001f);
				EE_P(tv.p, tv);
				bvalid = bvalid || (tv.p.x >= g_size.left && tv.p.x < g_size.right
				                 && tv.p.y >= g_size.top && tv.p.y < g_size.bottom);
				p[i] = tv.p;
			}
			
			if(!valid || !bvalid) {
				continue;
			}
			
			float z = pointInTriangle(point, p[0], p[1], p[2]);
			if(z <= 0 && (ep->type & POLY_QUAD)) {
				z = pointInTriangle(point, p[1], p[3], p[2]);
			}
			
			if(z > 0 && z <= minz) {
				count = ((ep->type & POLY_QUAD) ? 4 : 3);
				for(size_t i = 0; i < count; i++) {
					pp[i] = Vec2f(p[i].x, p[i].y);
					puv[i] = ep->v[i].uv;
				}
				material = ep->tex;
				owner = NULL;
				minz = z;
				flags = ep->type;
			}
			
		}
	}
	
	if(count) {
		
		GRenderer->SetRenderState(Renderer::DepthTest, false);
		
		drawLine2D(pp[0], pp[1], 0.1f, Color::magenta);
		drawLine2D(pp[2], pp[0], 0.1f, Color::magenta);
		if(count == 4) {
			drawLine2D(pp[2], pp[3], 0.1f, Color::magenta);
			drawLine2D(pp[3], pp[1], 0.1f, Color::magenta);
		} else {
			drawLine2D(pp[1], pp[2], 0.1f, Color::magenta);
		}
		
		Vec2f c = Vec2f(0.f);
		float miny = std::numeric_limits<float>::max();
		float maxy = std::numeric_limits<float>::min();
		for(size_t i = 0; i < count; i++) {
			c += pp[i];
			miny = std::min(miny, pp[i].y);
			maxy = std::max(maxy, pp[i].y);
		}
		c *= 1.f / count;
		
		Vec2f textpos(c.x, miny - 2 * hFontDebug->getLineHeight());
		
		std::ostringstream oss;
		
		if(owner) {
			textpos.y -= hFontDebug->getLineHeight();
		}
		if(material && material->m_pTexture) {
			textpos.y -= hFontDebug->getLineHeight();
		}
		if((flags & (POLY_WATER | POLY_LAVA)) && enviro && enviro->m_pTexture) {
			textpos.y -= hFontDebug->getLineHeight();
		}
		if(textpos.y < g_size.top + 5) {
			textpos.y = maxy + 2 * hFontDebug->getLineHeight();
		}
		
		
		if(owner) {
			drawTextCentered(hFontDebug, textpos, owner->idString(), Color::cyan);
			textpos.y += hFontDebug->getLineHeight();
		}
		if(material && material->m_pTexture) {
			drawDebugMaterialTexture(textpos, "Diffuse: ", *material->m_pTexture, Color::green);
		}
		if((flags & (POLY_WATER | POLY_LAVA)) && enviro && enviro->m_pTexture) {
			oss.str(std::string());
			oss << "Animation: ";
			oss << ((flags & (POLY_LAVA)) ? "lava" : "water");
			if(flags & POLY_FALL) {
				oss << " (flowing)";
			}
			drawDebugMaterialTexture(textpos, oss.str(), *enviro->m_pTexture, Color::yellow);
		}
		
		(void)textpos;
		
		for(size_t i = 0; i < count; i++) {
			
			oss.str(std::string());
			oss.setf(std::ios_base::fixed, std::ios_base::floatfield);
			oss.precision(2);
			oss << '(' << puv[i].x << ',' << puv[i].y << ')';
			std::string text = oss.str();
			
			Vec2f textpos = pp[i];
			if(pp[i].y < c.y) {
				textpos.y -= hFontDebug->getLineHeight();
			}
			
			if(pp[i].x < c.x) {
				Vec2i size = hFontDebug->getTextSize(text);
				textpos.x -= size.x;
			}
			
			hFontDebug->draw(textpos.x, textpos.y, text, Color::gray(0.7f));
		}
		
		GRenderer->SetRenderState(Renderer::DepthTest, true);
		
	}
	
}