本文整理汇总了C++中Portal::cullDraw方法的典型用法代码示例。如果您正苦于以下问题:C++ Portal::cullDraw方法的具体用法?C++ Portal::cullDraw怎么用?C++ Portal::cullDraw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Portal
的用法示例。
在下文中一共展示了Portal::cullDraw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createEnvironmentMap
void FunctionalPortal::createEnvironmentMap(const std::vector<Portal *> *portals){
Portal *destPortal = (*portals)[iDestPortal];
Vec3 portalPos = destPortal->getPos();
Vec3 eyePos;
vecAdd(&destPos_pcoord, &portalPos, &eyePos);
bool oldHide = isHidden();
setHide(true);
GL_CHECK(glMatrixMode(GL_MODELVIEW));
GL_CHECK(glPushMatrix());
GL_CHECK(glMatrixMode(GL_PROJECTION));
GL_CHECK(glPushMatrix());
GL_CHECK(glPushAttrib(GL_VIEWPORT_BIT));
//GL_CHECK(glBindTexture(GL_TEXTURE_2D, 0));
tgr->bind();
//GL_CHECK(glBindTexture(GL_TEXTURE_2D, dstDepthmap));
//GL_CHECK(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
//GL_TEXTURE_2D, dstDepthmap, 0));
/*GLuint id = renderTgr->genColorTexutre();
glFramebufferTexture2DEXT(
GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_2D,
id,
0);
struct MAZErectangle viewport;
viewport.left = 0;
viewport.bottom = 0;
viewport.width = width;
viewport.height = height;
struct Vec3 centerPos = vec2vecAdd(&eyePos, 0, 0, -10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyePos.x, eyePos.y, eyePos.z,
centerPos.x, centerPos.y, centerPos.z,
0, 1, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
struct MAZEmat projviewMat;
struct MAZEmat viewportMat;
getWindowProjMat(viewport, projviewMat, viewportMat);
hash_set<int *> visitedEdgeSet;
destPortal->cullDraw(&projviewMat, &viewportMat, viewport,
portals, visitedEdgeSet);
glBindTexture(GL_TEXTURE_2D, id);
//debug
sf::Uint8 *pixelArray = new sf::Uint8[width*height*4];
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixelArray); // to read from texture instead
sf::Image temp(width, height, pixelArray);
std::string filename = "envmap";
//char a[2] = {'a'+i, '\0'};
//filename.append(a);
filename.append(".jpg");
temp.SaveToFile(filename);
return;*/
glMatrixMode(GL_PROJECTION);
GLfloat aspectRatio = 1.;
GLfloat nearClip = 0.1f;
GLfloat farClip = 400.0f;
GLfloat fieldOfView = 90.0f; // Degrees
glLoadIdentity();
gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);
glViewport(0, 0, width, height);
float lookVectors[24] = {
1, 0, 0, 1,
-1, 0, 0, 1,
0, 1, 0, 1,
0, -1, 0, 1,
0, 0, 1, 1,
0, 0, -1, 1
};
float up[24] = {
0, -1, 0, 1,
0, -1, 0, 1,
0, 0, 1, 1,
0, 0, -1, 1,
0, -1, 0, 1,
0, -1, 0, 1
};
struct MAZErectangle viewport;
viewport.left = 0;
viewport.bottom = 0;
viewport.width = width;
viewport.height = height;
GL_CHECK(glBindTexture(GL_TEXTURE_CUBE_MAP, dstCubemap));
struct Vec3 centerPos = vec2vecAdd(&eyePos,
lookVectors[direction*4],
lookVectors[direction*4+1],
lookVectors[direction*4+2]);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//.........这里部分代码省略.........
示例2: cullDraw
bool Portal::cullDraw(struct MAZEmat *projviewMat, struct MAZEmat *viewportMat,
struct MAZErectangle &rec, const std::vector<Portal *> *portals, set<int *> &visitedEdgeSet){
MAZEmat finalProjViewMat;
multMat(projviewMat, &transformation, &finalProjViewMat);
//TODO: implement BV for objects
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
//glMultMatrixf(transformation.mat);
if(!portalObj->isHidden())
portalObj->draw(portals);
for(int i=0; i<objs.size(); i++)
if(!objs[i]->isHidden())
objs[i]->draw(portals);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
//What this portal looks like in its neighbors eye...
int posMap[4] = {1, 0, 3, 2};
for(int i=0; i<4; i++){
if(neighbors[i] < 0)
continue;
//Have we visited this undirected edge?
//I know the following code seems a little hack
//but I can't find any better way...
Portal *port = (*portals)[neighbors[i]];
if(visitedEdgeSet.count(port->getNeighbors()+posMap[i]) > 0 ||
visitedEdgeSet.count(neighbors+i))
continue;
//int size1 = visitedEdgeSet.size();
visitedEdgeSet.insert(neighbors+i);
//int size2 = visitedEdgeSet.size();
/*if(size2 == size1){
cout << "not right" << endl;
}*/
//assert(visitedEdgeSet.size()<4*(*portals).size());
//cout<<"visitedEdge " << visitedEdgeSet.size() << endl;
struct Vec3 p[4];
float left = MY_FLT_MAX, right = MY_FLT_MIN, top = MY_FLT_MIN, bottom = MY_FLT_MAX;
float nearC = MY_FLT_MAX, farC = MY_FLT_MIN;
for(int j=0; j<4; j++){
struct Vec3 tmp;
matMultVec3_normalize(&finalProjViewMat, &doorPoints[i][j], &tmp);
matMultVec3_normalize(viewportMat, &tmp, p+j);
if(p[j].x < left)
left = p[j].x;
if(p[j].x > right)
right = p[j].x;
if(p[j].y > top)
top = p[j].y;
if(p[j].y < bottom)
bottom = p[j].y;
if(p[j].z < nearC)
nearC = p[j].z;
if(p[j].z > farC)
farC = p[j].z;
}
if(farC < 0 || nearC > 1)
continue;
left = left > rec.left ? left : rec.left;
right = right < (rec.left+rec.width) ? right : rec.left+rec.width;
bottom = bottom > rec.bottom ? bottom : rec.bottom;
top = top < (rec.bottom + rec.height) ? top : rec.bottom+rec.height;
MAZErectangle neighborRect;
neighborRect.left = left;
neighborRect.bottom = bottom;
neighborRect.height = top-bottom;
neighborRect.width = right-left;
//This is necessary for edge condition
if(neighborRect.height <= -1e-5 || neighborRect.width <= -1e-5)
continue;
//Door status switched. If it is open from this cell to its
//neighbor, we might visit that neighbor. When we are visiting
//the neighbor, we will close the door and would not visit this
//cell. Is it still possible that we might loop back to visited portal?
//If the door is open, visit it.
//NOTE: Theorectically it's possible that a single object in a cell
//can be rendered several times from different doors. TODO: I might add some
//mask to handle this problem in the future. But, for this maze game,
//this scenario seems unlikely. So ignore it for now.
port->cullDraw(projviewMat, viewportMat, neighborRect, portals, visitedEdgeSet);
}
return true;
}