- added initial code from willvar for visible quad calc (but disabled for now till we have time to fix issues)

This commit is contained in:
Mark Vejvoda 2011-07-23 23:22:30 +00:00
parent 7bc9394e85
commit a2e6f81a0d
4 changed files with 106 additions and 58 deletions

View File

@ -1868,14 +1868,18 @@ void Game::render3d(){
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [reset3d]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
renderer.computeVisibleQuad();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [computeVisibleQuad]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
// renderer.computeVisibleQuad();
// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [computeVisibleQuad]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
// if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
renderer.loadGameCameraMatrix();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [loadGameCameraMatrix]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
renderer.computeVisibleQuad();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [computeVisibleQuad]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
renderer.setupLighting();
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [setupLighting]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis());
if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start();
@ -2147,6 +2151,12 @@ void Game::render2d(){
renderer.renderUnitTitles(coreData.getMenuFontNormal(),Vec3f(1.0f));
}
}
// renderer.renderText3D("#1", coreData.getMenuFontNormal3D(), Vec3f(1.0f), renderer.getVisibleQuad().p[0].x, renderer.getVisibleQuad().p[0].y, false);
// renderer.renderText3D("#2", coreData.getMenuFontNormal3D(), Vec3f(1.0f), renderer.getVisibleQuad().p[1].x, renderer.getVisibleQuad().p[1].y, false);
// renderer.renderText3D("#3", coreData.getMenuFontNormal3D(), Vec3f(1.0f), renderer.getVisibleQuad().p[2].x, renderer.getVisibleQuad().p[2].y, false);
// renderer.renderText3D("#4", coreData.getMenuFontNormal3D(), Vec3f(1.0f), renderer.getVisibleQuad().p[3].x, renderer.getVisibleQuad().p[3].y, false);
}
//network status

View File

@ -202,18 +202,22 @@ Quad2i GameCamera::computeVisibleQuad() const {
//const float farDist= 90.f;
//const float dist= 20.f;
// float nearDist = 20.f;
// float dist = pos.y > 20.f ? pos.y * 1.2f : 20.f;
// float farDist = 90.f * (pos.y > 20.f ? pos.y / 15.f : 1.f);
float nearDist = 20.f;
float dist = pos.y > 20.f ? pos.y * 1.2f : 20.f;
float farDist = 90.f * (pos.y > 20.f ? pos.y / 15.f : 1.f);
float dist = pos.y > nearDist ? pos.y * 1.2f : nearDist;
float farDist = 90.f * (pos.y > nearDist ? pos.y / 15.f : 1.f);
const float viewDegree = 180.f;
#ifdef USE_STREFLOP
Vec2f v(streflop::sinf(degToRad(180 - hAng)), streflop::cosf(degToRad(180 - hAng)));
Vec2f v1(streflop::sinf(degToRad(180 - hAng - fov)), streflop::cosf(degToRad(180 - hAng - fov)));
Vec2f v2(streflop::sinf(degToRad(180 - hAng + fov)), streflop::cosf(degToRad(180 - hAng + fov)));
Vec2f v(streflop::sinf(degToRad(viewDegree - hAng)), streflop::cosf(degToRad(viewDegree - hAng)));
Vec2f v1(streflop::sinf(degToRad(viewDegree - hAng - fov)), streflop::cosf(degToRad(viewDegree - hAng - fov)));
Vec2f v2(streflop::sinf(degToRad(viewDegree - hAng + fov)), streflop::cosf(degToRad(viewDegree - hAng + fov)));
#else
Vec2f v(sinf(degToRad(180 - hAng)), cosf(degToRad(180 - hAng)));
Vec2f v1(sinf(degToRad(180 - hAng - fov)), cosf(degToRad(180 - hAng - fov)));
Vec2f v2(sinf(degToRad(180 - hAng + fov)), cosf(degToRad(180 - hAng + fov)));
Vec2f v(sinf(degToRad(viewDegree - hAng)), cosf(degToRad(viewDegree - hAng)));
Vec2f v1(sinf(degToRad(viewDegree - hAng - fov)), cosf(degToRad(viewDegree - hAng - fov)));
Vec2f v2(sinf(degToRad(viewDegree - hAng + fov)), cosf(degToRad(viewDegree - hAng + fov)));
#endif
v.normalize();
@ -226,19 +230,8 @@ Quad2i GameCamera::computeVisibleQuad() const {
Vec2i p3(static_cast<int>(p.x + v2.x * nearDist), static_cast<int>(p.y + v2.y * nearDist));
Vec2i p4(static_cast<int>(p.x + v2.x * farDist), static_cast<int>(p.y + v2.y * farDist));
const int adjustPerfectSquareX = 15;
const bool adjustQuadToPerfectSquare = true;
Quad2i result;
if (hAng >= 135 && hAng <= 225) {
if(adjustQuadToPerfectSquare) {
//p1.y -= 10;
//p3.y -= 10;
//p2.y += 10;
//p4.y += 10;
//p3.x = p4.x + adjustPerfectSquareX;
//p3.x -= adjustPerfectSquareX;
}
result = Quad2i(p1, p2, p3, p4);
if(MaxVisibleQuadItemCache != 0 &&
(MaxVisibleQuadItemCache < 0 || cacheVisibleQuad[fov][hAng].size() <= MaxVisibleQuadItemCache)) {
@ -246,52 +239,20 @@ Quad2i GameCamera::computeVisibleQuad() const {
}
}
else if (hAng >= 45 && hAng <= 135) {
if(adjustQuadToPerfectSquare) {
//p3.y -= 10;
//p4.y -= 10;
//p1.y += 10;
//p2.y += 10;
//p4.x = p2.x + adjustPerfectSquareX;
//p4.x -= adjustPerfectSquareX;
}
result = Quad2i(p3, p1, p4, p2);
if(MaxVisibleQuadItemCache != 0 &&
(MaxVisibleQuadItemCache < 0 || cacheVisibleQuad[fov][hAng].size() <= MaxVisibleQuadItemCache)) {
cacheVisibleQuad[fov][hAng][pos] = result;
}
}
else if (hAng >= 225 && hAng <= 315) {
if(adjustQuadToPerfectSquare) {
//p2.y -= 10;
//p1.y -= 10;
//p4.y += 10;
//p3.y += 10;
//p1.x = p3.x + adjustPerfectSquareX;
//p1.x -= adjustPerfectSquareX;
}
result = Quad2i(p2, p4, p1, p3);
if(MaxVisibleQuadItemCache != 0 &&
(MaxVisibleQuadItemCache < 0 || cacheVisibleQuad[fov][hAng].size() <= MaxVisibleQuadItemCache)) {
cacheVisibleQuad[fov][hAng][pos] = result;
}
}
else {
if(adjustQuadToPerfectSquare && hAng == 0) {
//p4.y -= 10;
//p2.y -= 10;
//p1.y += 10;
//p3.y += 10;
//p2.x = p1.x + adjustPerfectSquareX;
p2.x -= adjustPerfectSquareX;
}
result = Quad2i(p4, p3, p2, p1);
if(MaxVisibleQuadItemCache != 0 &&
(MaxVisibleQuadItemCache < 0 || cacheVisibleQuad[fov][hAng].size() <= MaxVisibleQuadItemCache)) {

View File

@ -98,7 +98,7 @@ public:
float getVAng() const {return vAng;}
State getState() const {return state;}
const Vec3f &getPos() const {return pos;}
float getFov() const {return fov;}
//set
void setRotate(float rotate){this->rotate= rotate;}
void setPos(Vec2f pos);

View File

@ -714,9 +714,89 @@ void Renderer::loadCameraMatrix(const Camera *camera) {
glTranslatef(-position.x, -position.y, -position.z);
}
static Vec2i _unprojectMap(const Vec2i& pt,const GLdouble* model,const GLdouble* projection,const GLint* viewport,const bool roundDown, const char* label=NULL) {
Vec3d nearClipWorld,farClipWorld;
gluUnProject(pt.x,viewport[3]-pt.y,0,model,projection,viewport,&nearClipWorld.x,&nearClipWorld.y,&nearClipWorld.z);
gluUnProject(pt.x,viewport[3]-pt.y,1,model,projection,viewport,&farClipWorld.x,&farClipWorld.y,&farClipWorld.z);
// junk values if you were looking parallel to the XZ plane; this shouldn't happen as the camera can't do this?
const Vec3f start(nearClipWorld.x,nearClipWorld.y,nearClipWorld.z),
stop(farClipWorld.x,farClipWorld.y,farClipWorld.z),
plane(0,0,0),
norm(0,1,0),
u = stop-start,
w = start-plane;
const float d = norm.x * u.x + norm.y * u.y + norm.z * u.z,
n = -(norm.x * w.x + norm.y * w.y + norm.z * w.z);
const Vec3f i = start + u * (n / d);
//printf("Will stuff: d = %f n = %f\n",d,n);
Vec2i pos(i.x,i.z);
//#ifdef USE_STREFLOP
// if(roundDown == true) {
// pos = Vec2i(streflop::floor(i.x),streflop::floor(i.z));
// }
// else {
// pos = Vec2i(streflop::ceil(i.x),streflop::ceil(i.z));
// }
//#else
// if(roundDown == true) {
// pos = Vec2i(floor(i.x),streflop::floor(i.z));
// }
// else {
// pos = Vec2i(ceil(i.x),streflop::ceil(i.z));
// }
//#endif
if(false) { // print debug info
if(label) printf("%s ",label);
printf("%d,%d -> %f,%f,%f -> %f,%f,%f -> %f,%f,%f -> %d,%d\n",
pt.x,pt.y,
start.x,start.y,start.z,
stop.x,stop.y,stop.z,
i.x,i.y,i.z,
pos.x,pos.y);
}
return pos;
}
void Renderer::computeVisibleQuad() {
const GameCamera *gameCamera = game->getGameCamera();
visibleQuad = gameCamera->computeVisibleQuad();
// const bool debug = false;
// if(debug) {
// visibleQuad = gameCamera->computeVisibleQuad();
// printf("Camera: %d,%d %d,%d %d,%d %d,%d hAng [%f] fov [%f]\n",
// visibleQuad.p[0].x,visibleQuad.p[0].y,
// visibleQuad.p[1].x,visibleQuad.p[1].y,
// visibleQuad.p[2].x,visibleQuad.p[2].y,
// visibleQuad.p[3].x,visibleQuad.p[3].y,
// gameCamera->getHAng(),
// gameCamera->getFov());
// }
// // compute the four corners using OpenGL
// GLdouble model[16], projection[16];
// GLint viewport[4];
// glGetDoublev(GL_MODELVIEW_MATRIX,model);
// glGetDoublev(GL_PROJECTION_MATRIX,projection);
// glGetIntegerv(GL_VIEWPORT,viewport);
// const Vec2i
// tl = _unprojectMap(Vec2i(0,0),model,projection,viewport,true, "tl"),
// tr = _unprojectMap(Vec2i(viewport[2],0),model,projection,viewport,false, "tr"),
// br = _unprojectMap(Vec2i(viewport[2],viewport[3]),model,projection,viewport,false, "br"),
// bl = _unprojectMap(Vec2i(0,viewport[3]),model,projection,viewport,true, "bl");
// // set it as the frustum
// visibleQuad = Quad2i(tl,bl,tr,br); // strange order
// if(debug) {
// printf("Will: %d,%d %d,%d %d,%d %d,%d\n",
// visibleQuad.p[0].x,visibleQuad.p[0].y,
// visibleQuad.p[1].x,visibleQuad.p[1].y,
// visibleQuad.p[2].x,visibleQuad.p[2].y,
// visibleQuad.p[3].x,visibleQuad.p[3].y);
// }
//visibleQuad = gameCamera->computeVisibleQuad();
}
// =======================================
@ -5879,9 +5959,6 @@ Texture2D::Filter Renderer::strToTextureFilter(const string &s){
void Renderer::setAllowRenderUnitTitles(bool value) {
allowRenderUnitTitles = value;
//if(allowRenderUnitTitles == false) {
//renderUnitTitleList.clear();
//}
}
// This method renders titles for units