- adjust camera angle for more properly unit visibility calc

- more accurate unit titles when debugging
This commit is contained in:
Mark Vejvoda 2011-04-18 16:51:30 +00:00
parent 1b68053397
commit 016771ed81
5 changed files with 91 additions and 22 deletions

View File

@ -472,11 +472,12 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(i < pathFindRefresh) {
path->add(nodePos);
}
else if(tryLastPathCache == false) {
break;
}
//else if(tryLastPathCache == false) {
// break;
//}
if(tryLastPathCache == true && basicPathFinder) {
//if(tryLastPathCache == true && basicPathFinder) {
if(basicPathFinder) {
basicPathFinder->addToLastPathCache(nodePos);
}
}
@ -923,11 +924,12 @@ TravelState PathFinder::aStar(Unit *unit, const Vec2i &targetPos, bool inBailout
if(i < pathFindRefresh) {
path->add(nodePos);
}
else if(tryLastPathCache == false) {
break;
}
//else if(tryLastPathCache == false) {
// break;
//}
if(tryLastPathCache == true && basicPathFinder) {
//if(tryLastPathCache == true && basicPathFinder) {
if(basicPathFinder) {
basicPathFinder->addToLastPathCache(nodePos);
}
}

View File

@ -80,6 +80,12 @@ GameCamera::~GameCamera() {
cacheVisibleQuad.clear();
}
std::string GameCamera::getCameraMovementKey() const {
char szBuf[1024]="";
sprintf(szBuf,"%s_%f_%f_%f_%s,%f",pos.getString().c_str(),hAng,vAng,rotate,move.getString().c_str(),fov);
return szBuf;
}
void GameCamera::setMaxHeight(float value) {
if(value < 0) {
maxHeight = Config::getInstance().getFloat("CameraMaxDistance","20");
@ -177,6 +183,8 @@ void GameCamera::update(){
}
Quad2i GameCamera::computeVisibleQuad() const {
//printf("\n@@@ hAng [%f] vAng [%f] fov [%f]\n",hAng,vAng,fov);
if(MaxVisibleQuadItemCache != 0) {
std::map<float, std::map<float, std::map<Vec3f, Quad2i> > >::const_iterator iterFind = cacheVisibleQuad.find(fov);
if(iterFind != cacheVisibleQuad.end()) {
@ -189,6 +197,11 @@ Quad2i GameCamera::computeVisibleQuad() const {
}
}
}
//const float nearDist= 20.f;
//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);
@ -213,8 +226,19 @@ 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)) {
@ -222,6 +246,16 @@ 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 &&
@ -230,6 +264,16 @@ Quad2i GameCamera::computeVisibleQuad() const {
}
}
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 &&
@ -238,6 +282,16 @@ Quad2i GameCamera::computeVisibleQuad() const {
}
}
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)) {
@ -245,9 +299,6 @@ Quad2i GameCamera::computeVisibleQuad() const {
}
}
if(result.p[0].x < -1000) {
int ii = 0;
}
return result;
}

View File

@ -113,6 +113,8 @@ public:
destAng.y = hAng;
}
std::string getCameraMovementKey() const;
//other
void update();
Quad2i computeVisibleQuad() const;

View File

@ -162,6 +162,8 @@ Renderer::Renderer() {
particleRenderer = NULL;
saveScreenShotThread = NULL;
mapSurfaceData.clear();
visibleFrameUnitList.clear();
visibleFrameUnitListCameraKey = "";
lastRenderFps=MIN_FPS_NORMAL_RENDERING;
shadowsOffDueToMinRender=false;
@ -337,7 +339,7 @@ void Renderer::initGame(const Game *game){
SurfaceData::nextUniqueId = 1;
mapSurfaceData.clear();
this->game= game;
worldToScreenPosCache.clear();
//worldToScreenPosCache.clear();
//check gl caps
checkGlOptionalCaps();
@ -494,7 +496,7 @@ void Renderer::endGame() {
glDeleteLists(list3d, 1);
worldToScreenPosCache.clear();
//worldToScreenPosCache.clear();
ReleaseSurfaceVBOs();
mapSurfaceData.clear();
}
@ -2553,7 +2555,13 @@ void Renderer::renderUnits(const int renderFps) {
//assert
assertGl();
visibleFrameUnitList.clear();
if(visibleFrameUnitList.empty() == false) {
visibleFrameUnitList.clear();
//visibleFrameUnitListCameraKey = "";
//if(visibleFrameUnitListCameraKey != game->getGameCamera()->getCameraMovementKey()) {
// worldToScreenPosCache.clear();
//}
}
bool modelRenderStarted = false;
@ -2621,8 +2629,13 @@ void Renderer::renderUnits(const int renderFps) {
glPopMatrix();
unit->setVisible(true);
unit->setScreenPos(computeScreenPosition(unit->getCurrVectorFlat()));
visibleFrameUnitList.push_back(unit);
if( showDebugUI == true &&
(showDebugUILevel & debugui_unit_titles) == debugui_unit_titles) {
//unit->setScreenPos(computeScreenPosition(unit->getCurrVectorFlat()));
unit->setScreenPos(computeScreenPosition(unit->getCurrVector()));
visibleFrameUnitList.push_back(unit);
visibleFrameUnitListCameraKey = game->getGameCamera()->getCameraMovementKey();
}
//if(allowRenderUnitTitles == true) {
// Add to the pending render unit title list
@ -3571,9 +3584,9 @@ bool Renderer::computePosition(const Vec2i &screenPos, Vec2i &worldPos){
// This method takes world co-ordinates and translates them to screen co-ords
Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) {
if(worldToScreenPosCache.find(worldPos) != worldToScreenPosCache.end()) {
return worldToScreenPosCache[worldPos];
}
//if(worldToScreenPosCache.find(worldPos) != worldToScreenPosCache.end()) {
// return worldToScreenPosCache[worldPos];
//}
assertGl();
const Metrics &metrics= Metrics::getInstance();
@ -3601,7 +3614,7 @@ Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) {
&screenX, &screenY, &screenZ);
Vec3f screenPos(screenX,screenY,screenZ);
worldToScreenPosCache[worldPos]=screenPos;
//worldToScreenPosCache[worldPos]=screenPos;
return screenPos;
}
@ -4801,7 +4814,7 @@ void Renderer::renderUnitTitles(Font2D *font, Vec3f color) {
unitRenderedList[unit->getId()] = true;
}
else {
string str = unit->getFullName() + " - " + intToStr(unit->getId());
string str = unit->getFullName() + " - " + intToStr(unit->getId()) + " [" + unit->getPos().getString() + "]";
Vec3f screenPos = unit->getScreenPos();
#ifdef USE_STREFLOP
renderText(str, font, color, streflop::fabs(screenPos.x) + 5, streflop::fabs(screenPos.y) + 5, false);

View File

@ -245,6 +245,7 @@ private:
bool allowRenderUnitTitles;
//std::vector<std::pair<Unit *,Vec3f> > renderUnitTitleList;
std::vector<Unit *> visibleFrameUnitList;
string visibleFrameUnitListCameraKey;
bool no2DMouseRendering;
bool showDebugUI;
@ -258,7 +259,7 @@ private:
Mutex saveScreenShotThreadAccessor;
std::list<std::pair<string,Pixmap2D *> > saveScreenQueue;
std::map<Vec3f,Vec3f> worldToScreenPosCache;
//std::map<Vec3f,Vec3f> worldToScreenPosCache;
std::map<uint32,VisibleQuadContainerVBOCache > mapSurfaceVBOCache;