polpoint
Member
Content count
47 
Joined

Last visited
Community Reputation
122 NeutralAbout polpoint

Rank
Member

Problem with SAPI Dynamic Grammars in C++
polpoint replied to polpoint's topic in General and Gameplay Programming
I have broken everything down to its simplest form: [url="http://www.mediafire.com/?xwevgekf8ndrrpv"]http://www.mediafire.com/?xwevgekf8ndrrpv[/url] (should be able to download from above link without having to wait/ enter any captcha) This project contains all the files for a simple WINAPI program utilizing SAPI speech recognition. It was created in VS2010 using the default Win32 project settings. *After compiling and executing the program a window will be displayed with a word (gloves). *After saying the command "START" the program will load the first dynamic grammar word/ rule(which in this case would be the word "GLOVES") *The program is then supposed to start listening for the word displayed. If you say "GLOVES" it will reset the dynamic grammar and load the next word. There are four words in total (gloves, fox, computer, dog). **My issue is that the rules are not consistent. At times I can say "GLOVES" when it is supposed to only accept "COMPUTER" 
Problem with SAPI Dynamic Grammars in C++
polpoint posted a topic in General and Gameplay Programming
Good morning. I have been making a Speech to Text program using SAPI and am having some problems with loading, activating and deactivating dynamic grammars. Basically I am displaying a picture on the screen. If the user states the correct response, as defined by the dynamic grammar rule, then that rule is deactivated, and another picture is displayed and its corresponding grammar rule is activated. I want the dynamic rules to be topLevel, so they just have to state the object without any prefix etc. My problem is the rules activating/ deactivating do not seem to be consistent. Sometimes the grammar will accept any of the rules, sometimes it will accept only the correct rule. Any help would be appreciated. If you need more info/ code please let me know. Thanks! I am pretty sure it is something I am missing when it comes to the grammar rules/ word transition. The other thing I thought might be possible was that I am somehow creating a rule with the memory address of LPCWSTR pikk as opposed to the actual data  but that doesn't seem like it is the problem since the first parameter of GetRule is a LPCWSTR  unless I am converting incorrectly? Loading dynamic grammar rules: [CODE] //curNumb = current number of exercise //curNumbID = curNumb + numOffest (500) so I reserve #1500 for whatever other hardcoded grammar rules I add std::wstring stemp; LPCWSTR pikk; //add in the grammar: //reserve curNumb int reserveNum = curNumb; //loop through all object_data and load dynamic rules into grammar: for(int pip = 0; pip < data.numObjects.size(); pip++) { stemp = s2ws(data.object_data[curNumb].title); pikk = stemp.c_str(); hr = g_cpCmdGrammar>GetRule(pikk, data.object_data[curNumb].programID, SPRAF_TopLevel, TRUE, &hStateTravel); if(FAILED(hr)) { ErrorDescription(hr); } //loop through all words in object_data std::list<std::string>::iterator st_it = data.object_data[curNumb].words.begin(); for(; st_it != data.object_data[curNumb].words.end(); st_it++) { std::cout<<"adding word: "<<(*st_it)<<"\n"; stemp = s2ws((*st_it)); pikk = stemp.c_str(); hr = g_cpCmdGrammar>AddWordTransition(hStateTravel, NULL, pikk, L"", SPWT_LEXICAL, 1, NULL); if(FAILED(hr)) { ErrorDescription(hr); } } curNumb++; } //reset curNumb back to reserveNum curNumb = reserveNum; //activate curNumb grammar rule stemp = s2ws(data.object_data[curNumb].title); pikk = stemp.c_str(); std::cout<<"activate new rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n"; hr = g_cpCmdGrammar>SetRuleIdState(curNumbID, SPRS_ACTIVE); if(FAILED(hr)) { ErrorDescription(hr); std::cout<<"FAILURE at activate previous rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n"; } else { std::cout<<"ruleActivated...\n"; } hr = g_cpCmdGrammar>Commit(0); [/CODE] //deactivate old rule/ activate new rule code: [CODE] std::cout<<"curScore++ ("<<curScore<<">"; curScore++; std::cout<<curScore<<")\n"; //clear old exercise: std::wstring stemp = s2ws(data.object_data[curNumb].title); LPCWSTR pikk = stemp.c_str(); std::cout<<"deactivate previous rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n"; hr = g_cpCmdGrammar>SetRuleIdState(curNumbID, SPRS_INACTIVE); if(FAILED(hr)) { ErrorDescription(hr); std::cout<<"FAILURE at deactivate previous rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n"; } else { std::cout<<"ruleDeactivated...\n"; } curNumb++; if(curNumb > data.numObjects.size()) { curNumb = 1; } curNumbID = curNumb + exerciseOffset; //activate next rule: stemp = s2ws(data.object_data[curNumb].title); pikk = stemp.c_str(); std::cout<<"activate new rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n"; hr = g_cpCmdGrammar>SetRuleIdState(curNumbID, SPRS_ACTIVE); if(FAILED(hr)) { ErrorDescription(hr); std::cout<<"FAILURE at activate previous rules "<<curNumbID<<"/"<<curNumb<<" ("<<data.object_data[curNumb].title<<")\n"; } else { std::cout<<"ruleActivated...\n"; } [/CODE] 
Am I dreaming far too big, even if I know how all of it will work?
polpoint replied to Martuht's topic in Game Design and Theory
Yes, you are dreaming too big. Even the smartest, most dedicated and ____EXPERIENCED____ person would find what you are attempting to be pretty daunting. If you don't want to listen to people try to dissuade you (which is exactly what you just asked everybody to do) you should just jump in and start creating. In a year or two you will figure out what you are doing wrong and correct it, start over, or go in a different direction. Look at how other people are doing the stuff you want to emulate. And it sounds like you are starting from the top, with all the minute details, like voice acting. I would not even worry about that for a looooooong time, and that can _easily_ (comparatively) be bolted on at a later date. You want to make some completely openended, intricately detailed 3d world where you can do anything, attain whatever social status, do almost any action and have all the actors respond appropriately. And you have never made a game before? Good luck! Honestly, don't. Start with a small "snapshot" of what you are attempting. Say, one tiny, isolated hamlet, and see what issues you encounter. 
Need help with some errors in my bilinear interpolation function
polpoint replied to polpoint's topic in General and Gameplay Programming
I've got to thank you for all your help, iMalc! This is what I wound up doing (I broke up the function into a couple of different code quotes because it is kind of long): void smoothifyRegion(int wX, int wY, int aX, int aY) { std::stringstream ddp; //this figures the elevation from the surrounding areamaps and smoothifies everything int quadrant = 1; ACORD cd; cd.wX = wX; cd.wY = wY; cd.aX = aX; cd.aY = aY; //n cd.aY; //if aY < 0 then we need to modify wY until the coords are valid! cd = fixCoordinates(cd); //n is the elevation of the areamap to the north int n = world.wMap[cd.wX][cd.wY].area.aMap[cd.aX][cd.aY].region.baseHt; cd.wX = wX; cd.wY = wY; cd.aX = aX; cd.aY = aY; //ne cd.aY; cd.aX++; cd = fixCoordinates(cd); int ne = world.wMap[cd.wX][cd.wY].area.aMap[cd.aX][cd.aY].region.baseHt; cd.wX = wX; cd.wY = wY; cd.aX = aX; cd.aY = aY; //e cd.aX++; cd = fixCoordinates(cd); int e = world.wMap[cd.wX][cd.wY].area.aMap[cd.aX][cd.aY].region.baseHt; cd.wX = wX; cd.wY = wY; cd.aX = aX; cd.aY = aY; //se cd.aX++; cd.aY++; cd = fixCoordinates(cd); int se = world.wMap[cd.wX][cd.wY].area.aMap[cd.aX][cd.aY].region.baseHt; cd.wX = wX; cd.wY = wY; cd.aX = aX; cd.aY = aY; //s cd.aY++; cd = fixCoordinates(cd); int s = world.wMap[cd.wX][cd.wY].area.aMap[cd.aX][cd.aY].region.baseHt; cd.wX = wX; cd.wY = wY; cd.aX = aX; cd.aY = aY; //sw cd.aY++; cd.aX; cd = fixCoordinates(cd); int sw = world.wMap[cd.wX][cd.wY].area.aMap[cd.aX][cd.aY].region.baseHt; cd.wX = wX; cd.wY = wY; cd.aX = aX; cd.aY = aY; //w cd.aX; cd = fixCoordinates(cd); int w = world.wMap[cd.wX][cd.wY].area.aMap[cd.aX][cd.aY].region.baseHt; cd.wX = wX; cd.wY = wY; cd.aX = aX; cd.aY = aY; //nw cd.aX; cd.aY; cd = fixCoordinates(cd); int nw = world.wMap[cd.wX][cd.wY].area.aMap[cd.aX][cd.aY].region.baseHt; CORD N, NE, E, SE, S, SW, W, NW; //capital directions represent the coordinates of the center of the surrounding areamaps N.X = halfRMAP_X; N.Y = halfRMAP_Y; NE.X = halfRMAP_X + RMAP_X; NE.Y = halfRMAP_Y; E.X = halfRMAP_X + RMAP_X; E.Y = halfRMAP_Y; SE.X = halfRMAP_X + RMAP_X; SE.Y = halfRMAP_Y + RMAP_Y; S.X = halfRMAP_X; S.Y = halfRMAP_Y + RMAP_Y; SW.X = halfRMAP_X; SW.Y = halfRMAP_Y + RMAP_Y; W.X = halfRMAP_X; W.Y = halfRMAP_Y; NW.X = halfRMAP_X; NW.Y = halfRMAP_Y; //haaa less typing! AREAMAP &sourceArea = world.wMap[wX][wY].area; REGIONMAP &destRegion = sourceArea.aMap[aX][aY].region; //do the center of the square first! destRegion.rMap[halfRMAP_X][halfRMAP_Y].elevation = destRegion.baseHt; //ok  do the 8 cardinal directions next! int pix; int piy; //n pix = halfRMAP_X; for(piy = halfRMAP_Y1; piy >= 0; piy) { float nDist = 1 / linearDist(pix,piy,N.X,N.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = nDist + centDist; nDist = nDist / sum; centDist = centDist / sum; destRegion.rMap[pix][piy].elevation = n*nDist + destRegion.baseHt*centDist; } //ne for(pix = halfRMAP_X+1, piy = halfRMAP_Y1; pix < RMAP_X && piy >= 0; pix++, piy) { float neDist = 1 / linearDist(pix,piy,NE.X,NE.Y); float nDist = 1 / linearDist(pix,piy,N.X,N.Y); float eDist = 1 / linearDist(pix,piy,E.X,E.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = neDist + nDist + eDist + centDist; neDist = neDist / sum; nDist = nDist / sum; eDist = eDist / sum; centDist = centDist / sum; destRegion.rMap[pix][piy].elevation = ne*neDist + n*nDist + e*eDist + destRegion.baseHt*centDist; } //e piy = halfRMAP_Y; for(pix = halfRMAP_X+1; pix < RMAP_X; pix++) { float eDist = 1 / linearDist(pix,piy,E.X,E.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = eDist + centDist; eDist = eDist / sum; centDist = centDist / sum; destRegion.rMap[pix][piy].elevation = e*eDist + destRegion.baseHt*centDist; } //se for(pix = halfRMAP_X+1, piy = halfRMAP_Y+1; pix < RMAP_X && piy < RMAP_Y; pix++, piy++) { float seDist = 1 / linearDist(pix,piy,SE.X,SE.Y); float eDist = 1 / linearDist(pix,piy,E.X,E.Y); float sDist = 1 / linearDist(pix,piy,S.X,S.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = seDist + centDist + sDist + eDist; seDist = seDist / sum; eDist = eDist / sum; sDist = sDist / sum; centDist = centDist / sum; destRegion.rMap[pix][piy].elevation = se*seDist + s*sDist + e*eDist + destRegion.baseHt*centDist; } //s pix = halfRMAP_X; for(piy = halfRMAP_Y+1; piy < RMAP_Y; piy++) { float sDist = 1 / linearDist(pix,piy,S.X,S.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = sDist + centDist; sDist = sDist / sum; centDist = centDist / sum; destRegion.rMap[pix][piy].elevation = s*sDist + destRegion.baseHt*centDist; } //sw for(pix = halfRMAP_X1, piy = halfRMAP_Y+1; pix >= 0 && piy < RMAP_Y; pix, piy++) { float swDist = 1 / linearDist(pix,piy,SW.X,SW.Y); float sDist = 1 / linearDist(pix,piy,S.X,S.Y); float wDist = 1 / linearDist(pix,piy,W.X,W.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = swDist + sDist + wDist + centDist; swDist = swDist / sum; sDist = sDist / sum; wDist = wDist / sum; centDist = centDist / sum; destRegion.rMap[pix][piy].elevation = sw*swDist + s*sDist + w*wDist + destRegion.baseHt*centDist; } //w piy = halfRMAP_Y; for(pix = halfRMAP_X1; pix >= 0; pix) { float wDist = 1 / linearDist(pix,piy,W.X,W.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = wDist + centDist; wDist = wDist / sum; centDist = centDist / sum; destRegion.rMap[pix][piy].elevation = w*wDist + destRegion.baseHt*centDist; } //nw for(pix = halfRMAP_X1, piy = halfRMAP_Y1; pix >= 0 && piy >= 0; pix, piy) { float nwDist = 1 / linearDist(pix,piy,NW.X,NW.Y); float wDist = 1 / linearDist(pix,piy,W.X,W.Y); float nDist = 1 / linearDist(pix,piy,N.X,N.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = nwDist + wDist + nDist + centDist; nwDist = nwDist / sum; wDist = wDist / sum; nDist = nDist / sum; centDist = centDist / sum; destRegion.rMap[pix][piy].elevation = nw*nwDist + w*wDist + n*nDist + destRegion.baseHt*centDist; } //octodrants go //\7  0 / // \  / // \  / //6 \/ 1 //+ //5 /\ 2 // /  \ // /  \ /// 4 3 \ //0! //starts at halfRMAP_X+2, halfRMAP_Y2 // int pipY; int pipX; int popp; int counter; //0 //starts at halfRMAP_X+1, halfRMAP_Y2 pipX = halfRMAP_X + 1; counter = 1; for(pipY = halfRMAP_Y  2; pipY >= 0; pipY, counter++) { for(int popp = 0; popp < counter; popp++) { float nDist = 1 / linearDist(pipX + popp, pipY, halfRMAP_X, pipY); float neDist = 1 / linearDist(pipX + popp, pipY, halfRMAP_X + counter + 1, pipY); float sum = nDist + neDist; nDist = nDist / sum; neDist = neDist / sum; destRegion.rMap[pipX + popp][pipY].elevation = destRegion.rMap[halfRMAP_X][pipY].elevation * nDist + destRegion.rMap[halfRMAP_X + counter + 1][pipY].elevation * neDist; } } //1 //starts at halfRMAP_X + 2, halfRMAP_Y 1 pipY = halfRMAP_Y1; counter = 1; for(pipX = halfRMAP_X + 2; pipX < RMAP_X; pipX++, counter++) { for(int popp = 0; popp < counter; popp++) { float eDist = 1 / linearDist(pipX, pipY  popp, pipX, halfRMAP_Y); float neDist = 1 / linearDist(pipX, pipY  popp, pipX, halfRMAP_Y  counter  1); float sum = eDist + neDist; eDist = eDist / sum; neDist = neDist / sum; destRegion.rMap[pipX][pipY  popp].elevation = destRegion.rMap[pipX][halfRMAP_Y].elevation * eDist + destRegion.rMap[pipX][halfRMAP_Y  counter  1].elevation * neDist; } } //2 //starts at halfRMAP_X + 2, halfRMAP_Y+1 pipY = halfRMAP_Y+1; counter = 1; for(pipX = halfRMAP_X + 2; pipX < RMAP_X; pipX++, counter++) { for(int popp = 0; popp < counter; popp++) { float eDist = 1 / linearDist(pipX, pipY + popp, pipX, halfRMAP_Y); float seDist = 1 / linearDist(pipX, pipY + popp, pipX, halfRMAP_Y + counter + 1); float sum = eDist + seDist; eDist = eDist / sum; seDist = seDist / sum; destRegion.rMap[pipX][pipY + popp].elevation = destRegion.rMap[pipX][halfRMAP_Y].elevation * eDist + destRegion.rMap[pipX][halfRMAP_Y + counter + 1].elevation * seDist; } } //3! //starts at halfRMAP_X+1, halfRMAP_Y + 2 pipX = halfRMAP_X+1; counter = 1; for(pipY = halfRMAP_Y + 2; pipY < RMAP_Y; pipY++, counter++) { for(int popp = 0; popp < counter; popp++) { float sDist = 1 / linearDist(pipX + popp, pipY, halfRMAP_X, pipY); float seDist = 1 / linearDist(pipX + popp, pipY, halfRMAP_X + counter + 1, pipY); float sum = sDist + seDist; sDist = sDist / sum; seDist = seDist / sum; destRegion.rMap[pipX + popp][pipY].elevation = destRegion.rMap[halfRMAP_X][pipY].elevation * sDist + destRegion.rMap[halfRMAP_X + counter + 1][pipY].elevation * seDist; } } //4! //starts at halfRMAP_X1, halfRMAP_Y + 2 pipX = halfRMAP_X1; counter = 1; for(pipY = halfRMAP_Y + 2; pipY < RMAP_Y; pipY++, counter++) { for(int popp = 0; popp < counter; popp++) { float sDist = 1 / linearDist(pipX  popp, pipY, halfRMAP_X, pipY); float swDist = 1 / linearDist(pipX  popp, pipY, halfRMAP_X  counter  1, pipY); float sum = sDist + swDist; sDist = sDist / sum; swDist = swDist / sum; destRegion.rMap[pipX  popp][pipY].elevation = destRegion.rMap[halfRMAP_X][pipY].elevation * sDist + destRegion.rMap[halfRMAP_X  counter  1][pipY].elevation * swDist; } } //5 //starts at halfRMAP_X2, halfRMAP_Y1 pipY = halfRMAP_Y + 1; counter = 1; for(pipX = halfRMAP_X  2; pipX >= 0; pipX, counter++) { for(int popp = 0; popp < counter; popp++) { float wDist = 1 / linearDist(pipX, pipY + popp, pipX, halfRMAP_Y); float swDist = 1 / linearDist(pipX, pipY + popp, pipX, halfRMAP_Y + counter + 1); float sum = wDist + swDist; wDist = wDist / sum; swDist = swDist / sum; destRegion.rMap[pipX][pipY + popp].elevation = destRegion.rMap[pipX][halfRMAP_Y].elevation * wDist + destRegion.rMap[pipX][halfRMAP_Y + counter + 1].elevation * swDist; } } //6 //starts at halfRMAP_X2, halfRMAP_Y1 pipY = halfRMAP_Y  1; counter = 1; for(pipX = halfRMAP_X  2; pipX >= 0; pipX, counter++) { for(int popp = 0; popp < counter; popp++) { float wDist = 1 / linearDist(pipX, pipY  popp, pipX, halfRMAP_Y); float nwDist = 1 / linearDist(pipX, pipY  popp, pipX, halfRMAP_Y  counter  1); float sum = wDist + nwDist; wDist = wDist / sum; nwDist = nwDist / sum; destRegion.rMap[pipX][pipY  popp].elevation = destRegion.rMap[pipX][halfRMAP_Y].elevation * wDist + destRegion.rMap[pipX][halfRMAP_Y  counter  1].elevation * nwDist; } } //7 //starts at halfRMAP_X1, halfRMAP_Y2 pipX = halfRMAP_X  1; counter = 1; for(pipY = halfRMAP_Y  2; pipY >= 0; pipY, counter++) { for(int popp = 0; popp < counter; popp++) { float nDist = 1 / linearDist(pipX  popp, pipY, halfRMAP_X, pipY); float nwDist = 1 / linearDist(pipX  popp, pipY, halfRMAP_X  counter  1, pipY); float sum = nDist + nwDist; nDist = nDist / sum; nwDist = nwDist / sum; destRegion.rMap[pipX  popp][pipY].elevation = destRegion.rMap[halfRMAP_X][pipY].elevation * nDist + destRegion.rMap[halfRMAP_X  counter  1][pipY].elevation * nwDist; } } world.wMap[wX][wY].area.aMap[aX][aY].region.reflectREle(wX,wY,aX,aY,3); } and I went from this: to this: Which is good enough for my needs, even though it produces little strips every once in a while  since I am going to be modifying this map slightly, the extra processing will hide whatever little artifacts show up. 
Need help with some errors in my bilinear interpolation function
polpoint replied to polpoint's topic in General and Gameplay Programming
I think I am just missing some minor step in my function somewhere  I need 'e' to only take into account 5 & 2, because at that point, both 4 & 7 and 1 & 8 should have 0% influence on the value I only have odd sized maps at this magnification so I think it might produce the results I want if I calculate the 8 cardinal directions first and then interpolate inbetween those values to fill in the remainder. I'll have to write that up when I get the chance & test it out. ++++ ????????? ?5??1??4? ????????? ++++ ???abc??? ?9?d5e?2? ???fgh??? ++++ ????????? ?3??8??7? ????????? ++++ 
Need help with some errors in my bilinear interpolation function
polpoint replied to polpoint's topic in General and Gameplay Programming
Yeah, that code is pretty funked up  the lowercase n, ne, e, se, s, sw, w & nw are the surrounding big square's base elevation values (or the A, B & D in the example where we try to calculate the values for the C square  the A would be n, the B would be ne and the D would be e) CORD N, NE, E, SE, S, SW, W, NW; N.X = halfRMAP_X; N.Y = halfRMAP_Y; NE.X = halfRMAP_X + RMAP_X; NE.Y = halfRMAP_Y; E.X = halfRMAP_X + RMAP_X; E.Y = halfRMAP_Y; SE.X = halfRMAP_X + RMAP_X; SE.Y = halfRMAP_Y + RMAP_Y; S.X = halfRMAP_X; S.Y = halfRMAP_Y + RMAP_Y; SW.X = halfRMAP_X; SW.Y = halfRMAP_Y + RMAP_Y; W.X = halfRMAP_X; W.Y = halfRMAP_Y; NW.X = halfRMAP_X; NW.Y = halfRMAP_Y; //quadrants go: // 0 1 // 2 3 for(int pix = 0; pix < RMAP_X; pix++) { for(int piy = 0; piy < RMAP_Y; piy++) { quadrant = 1; if(pix < (halfRMAP_X) && piy <(halfRMAP_Y)) { quadrant = 0; } else if(pix >= (halfRMAP_X) && piy < (halfRMAP_Y)) { quadrant = 1; } else if(pix < (halfRMAP_X) && piy >= (halfRMAP_Y)) { quadrant = 2; } else if(pix >= (halfRMAP_X) && piy >= (halfRMAP_Y)) { quadrant = 3; } if(quadrant == 0) { float wDist = 1 / linearDist(pix,piy,W.X,W.Y); float nwDist = 1 / linearDist(pix,piy,NW.X,NW.Y); float nDist = 1 / linearDist(pix,piy,N.X,N.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = nDist + wDist + nwDist + centDist; nDist = nDist / sum; wDist = wDist / sum; nwDist = nwDist / sum; centDist = centDist / sum; world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = n*nDist + w*wDist + nw*nwDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist; } else if(quadrant == 1) { float nDist = 1 / linearDist(pix,piy,N.X,N.Y); float neDist = 1 / linearDist(pix,piy,NE.X,NE.Y); float eDist = 1 / linearDist(pix,piy,E.X,E.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = nDist + eDist + neDist + centDist; nDist = nDist / sum; eDist = eDist / sum; neDist = neDist / sum; centDist = centDist / sum; world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = n*nDist + e*eDist + ne*neDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist; } else if(quadrant == 2) { float sDist = 1 / linearDist(pix,piy,S.X,S.Y); float swDist = 1 / linearDist(pix,piy,SW.X,SW.Y); float wDist = 1 / linearDist(pix,piy,W.X,W.Y); float centDist = 1 / linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); float sum = sDist + wDist + swDist + centDist; sDist = sDist / sum; wDist = wDist / sum; swDist = swDist / sum; centDist = centDist / sum; world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = s*sDist + w*wDist + sw*swDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist; } else if(quadrant == 3) { float eDist = linearDist(pix,piy,E.X,E.Y); float seDist = linearDist(pix,piy,SE.X,SE.Y); float sDist = linearDist(pix,piy,S.X,S.Y); float centDist = linearDist(pix,piy,halfRMAP_X,halfRMAP_Y); eDist = 1 / eDist; seDist = 1 / seDist; sDist = 1 / sDist; if(centDist != 0) { centDist = 1 / centDist; } else { eDist = 0; seDist = 0; sDist = 0; centDist = 1; } float sum = sDist + eDist + seDist + centDist; sDist = sDist / sum; eDist = eDist / sum; seDist = seDist / sum; centDist = centDist / sum; world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = s*sDist + e*eDist + se*seDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist; } } } float linearDist(float x1,float y1,float x2,float y2) { float dx = x2  x1; float dy = y2  y1; dx = dx * dx + dy * dy; if(dx != 0) { return sqrt(dx); } else { return 0; } } 
Need help with some errors in my bilinear interpolation function
polpoint replied to polpoint's topic in General and Gameplay Programming
I don't really understand  so if I do something like your diagram to calculate only the central 5value square: ++++ 5???1???4 ????????? ????????? ++++ ????????? 9???5???2 ????????? ++++ ????????? ????????? 3???8???7 ++++ Then if I move one square to the north and calculate the 1value square like this: ++++ 7???2???3 ????????? ????????? ++++ ????????? 5???1???4 ????????? ++++ ????????? ????????? 9???5???2 ++++ will it line up with the calculated values for the 5value square? It doesn't seem like it would  it seems like it would be missing one row (the three ?'s that are right between the 5 and the 1) 
Need help with some errors in my bilinear interpolation function
polpoint replied to polpoint's topic in General and Gameplay Programming
Thanks for the thorough description iMalc! I don't think I explained the specifics of my problem very well or else I am not completely understanding your explanation. I am not doing anything with graphics, I let openGL handle all of the resampling of my graphics. I am trying to smooth out the elevation of my heightmap after zooming in to a different "magnification" (but it seems that you understand that with the very loose usage of source and destination pixel) I start out with this: ++++ 514 ++++ 952 ++++ 387 ++++ Then increase my magnification to this: ++++ 555111444 555111444 555111444 ++++ 999555222 999555222 999555222 ++++ 333888777 333888777 333888777 ++++ At this point I only have the center 5value square loaded in memory for the new magnification and all of the squares at the previous magnification loaded in memory, so I basically know what the "base" surrounding values are supposed to be. Then I want to smooth out the values so I get something close to this (the values in the center square are a close enough approximation for this example): ++++ 555111444 555111444 555111444 ++++ 999635222 999754222 999566222 ++++ 333888777 333888777 333888777 ++++ So I am coming close to figuring it out, but I don't have access to the extra row & column and it seems like, from your example, I need a specific "start position," which would be the upperleftmost square (or whichever corner). I am using this to smooth out the elevation of a heightmap for a huge area that is divided up into smaller chunks. So the code that I posted above (minus the stupid method I utilized to figure the coordinates for the surrounding center squares) works, but only within one quadrant and the surrounding square's bordering quadrants. I edited one of the pictures above to highlight this. The arrows point to the center of the big squares (the values of that specific tile are messed up because I divided by 0 distance from the center) and the black square is outlining the se, sw, ne, and nw quadrant of 4 adjoining big squares. As you can see everything is lining up within the black square, but it does not line up with that same big square's other 3 quadrants. I tried doing the same thing utilizing all 8 surrounding big square's values along with the central big square that I am modifying but that doesn't work either. Ah! problems that I can not solve are frustrating! 
Need help with some errors in my bilinear interpolation function
polpoint replied to polpoint's topic in General and Gameplay Programming
The code seems to be interpolating correctly within each quadrant, but the 4 quadrants don't line up correctly. And there are those little low elevation squares (the little blue squares evenly spaced around) that mark the exact center of each square. if I take into account all 8 of the surrounding elevation levels (as opposed to how I am doing it now and only taking into account the three closest) will that make everything smooth inbetween the 4 quadrants? 
Need help with some errors in my bilinear interpolation function
polpoint posted a topic in General and Gameplay Programming
Quote: +0,0+1,0+ ? ? ? ? ?? ? ? ? ?... ? ? ? ? ?? ? ? ? ?... ? ? A ? ?? ? B ? ?... ? ? ? ? ?? ? ? ? ?... ? ? ? ? ?? ? ? ? ?... +0,1+1,1+ ? ? ? ? ?? ? ? ? ?... ? ? ? ? ?? ? ? ? ?... ? ? C ? ?? ? D ? ?... ? ? ? ? ?? ? ? ? ?... ? ? ? ? ?? ? ? ? ?... +++  ...  ... ... I know the values of A, B, C & D and I want to interpolate between those values to fill in the rest of the ?'s Below is the source code as I currently have it, but I am doing something wrong somewhere and I can't figure it out. In the code below the NW quadrant == 0 NE quadrant == 1 SW quadrant == 2 SE quadrant == 3 for(int pix = 0; pix < RMAP_X; pix++) { for(int piy = 0; piy < RMAP_Y; piy++) { quadrant = 1; if(pix < (halfRMAP_X) && piy <(halfRMAP_Y)) { quadrant = 0; } else if(pix >= (halfRMAP_X) && piy < (halfRMAP_Y)) { quadrant = 1; } else if(pix < (halfRMAP_X) && piy >= (halfRMAP_Y)) { quadrant = 2; } else if(pix >= (halfRMAP_X) && piy >= (halfRMAP_Y)) { quadrant = 3; } if(quadrant == 0) { //nw quadrant  //pix < halfRMAP_X //piy < halfRMAP_Y float nwDist = 0; float nDist = 0; float wDist = 0; float centDist = 0; nDist = 1 / linearDist(pix,piy,pix + (halfRMAP_X  pix),piy  (halfRMAP_Y + piy)); wDist = 1 / linearDist(pix,piy,pix  (halfRMAP_X + pix),piy + (halfRMAP_Y  piy)); nwDist = 1 / linearDist(pix,piy, pix  (halfRMAP_X + pix), piy  (halfRMAP_Y  piy)); centDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X  pix), piy + (halfRMAP_Y  piy)); float sum = nDist + wDist + nwDist + centDist; nDist = nDist / sum; wDist = wDist / sum; nwDist = nwDist / sum; centDist = centDist / sum; world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = nw*nwDist + n*nDist + w*wDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist; } else if(quadrant == 1) { //ne quadrant //pix >= halfRMAP_X //piy < halfRMAP_Y float neDist = 0; float nDist = 0; float eDist = 0; float centDist = 0; nDist = 1 / linearDist(pix,piy, pix  (pix  halfRMAP_X), piy  (halfRMAP_Y + piy)); eDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X + (RMAP_X  pix)), piy + (halfRMAP_Y  piy)); neDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X + (RMAP_X  pix)), piy  (halfRMAP_Y + piy)); centDist = 1 / linearDist(pix,piy, pix  (pix  halfRMAP_X), piy + (halfRMAP_Y  piy)); float sum = nDist + eDist + neDist + centDist; nDist = nDist / sum; eDist = eDist / sum; neDist = neDist / sum; centDist = centDist / sum; world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = ne*neDist + n*nDist + e*eDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist; } else if(quadrant == 2) { //sw quadrant //pix < halfRMAP_X //piy >= halfRMAP_Y float swDist = 0; float sDist = 0; float wDist = 0; float centDist = 0; wDist = 1 / linearDist(pix,piy,pix  (halfRMAP_X + pix), piy  (piy  halfRMAP_Y)); sDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X  pix), piy + (halfRMAP_Y + (RMAP_Y  piy))); swDist = 1 / linearDist(pix,piy, pix  (halfRMAP_X + pix), piy + (halfRMAP_Y + (RMAP_Y  piy))); centDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X  pix), piy  (piy  halfRMAP_Y)); float sum = sDist + wDist + swDist + centDist; sDist = sDist / sum; wDist = wDist / sum; swDist = swDist / sum; centDist = centDist / sum; world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = sw*swDist + s*sDist + w*wDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist; } else if(quadrant == 3) { //se quadrant //pix >= halfRMAP_X //piy >= halfRMAP_Y float seDist = 0; float sDist = 0; float eDist = 0; float centDist = 0; eDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X + (RMAP_X  pix)), piy  (piy  halfRMAP_Y)); sDist = 1 / linearDist(pix,piy, pix  (pix  halfRMAP_X), piy + (halfRMAP_Y + (RMAP_Y  piy))); seDist = 1 / linearDist(pix,piy, pix + (halfRMAP_X + (RMAP_X  pix)), piy + (halfRMAP_Y + (RMAP_Y  piy))); centDist = 1 / linearDist(pix,piy, pix  (pix  halfRMAP_X), piy  (piy  halfRMAP_Y)); float sum = sDist + eDist + seDist + centDist; sDist = sDist / sum; eDist = eDist / sum; seDist = seDist / sum; centDist = centDist / sum; world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = se*seDist + s*sDist + e*eDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist; } } } My results are below: as you can see, things don't line up correctly and some other stuff isn't working out correctly. It looks like it is something with the se quadrant, because it seems from the shore in the 2nd picture that the sw & ne quadrants will line up, but I'm not sure. [Edited by  polpoint on September 28, 2009 7:08:48 PM] 
ok  now I am having trouble with implementation: for(int pix = 0; pix < RMAP_X; pix++) { for(int piy = 0; piy < RMAP_Y; piy++) { quadrant = 1; if(pix < (halfRMAP_X) && piy <(halfRMAP_Y)) { quadrant = 0; } else if(pix >= (halfRMAP_X) && piy < (halfRMAP_Y)) { quadrant = 1; } else if(pix < (halfRMAP_X) && piy >= (halfRMAP_Y)) { quadrant = 2; } else if(pix >= (halfRMAP_X) && piy >= (halfRMAP_Y)) { quadrant = 3; } //find the percentages ! //now we interpolate between the current square and three of it's neighbors. if(quadrant == 0) { //nw //get the elevations of the west, north & nw float wDist = 1 / (linearDist(pix, piy, halfRMAP_X + pix, halfRMAP_Y  piy)); float nDist = 1 / (linearDist(pix, piy, halfRMAP_X  pix, halfRMAP_Y + piy)); float nwDist = 1 / (linearDist(pix, piy, halfRMAP_X + pix, halfRMAP_Y + piy)); float centDist = 1 / (linearDist(pix, piy ,halfRMAP_X  pix, halfRMAP_Y  piy)); float sum = wDist + nDist + nwDist + centDist; wDist = wDist / sum; nDist = nDist / sum; nwDist = nwDist / sum; centDist = centDist / sum; //this is so I can check on the values ddp.str(""); ddp<<wDist<<","<<nDist<<","<<nwDist<<"["<<centDist<<"]("<<pix<<","<<piy<<")"<<sum; setMess(ddp.str()); //set the elvation world.wMap[wX][wY].area.aMap[aX][aY].region.rMap[pix][piy].elevation = nw*nwDist + n*nDist + w*wDist + world.wMap[wX][wY].area.aMap[aX][aY].region.baseHt*centDist; } } } float linearDist(float x1,float y1,float x2,float y2) { float dx = x2  x1; float dy = y2  y1; return sqrt(dx*dx+dy*dy); } I am getting results like this (in the nw quadrant of square 1,1): if square 1,1's elevation == 4 +0,0+1,0+ ? ? ? ? ?? ? ? ? ?... ? ? ? ? ?? ? ? ? ?... ? ? 3 ? ?? ? 9 ? ?... ? ? ? ? ?? ? ? ? ?... ? ? ? ? ?? ? ? ? ?... +0,1+1,1+ ? ? ? ? ?2 2 2 ? ?... ? ? ? ? ?2 3 2 ? ?... ? ? 5 ? ?2 2 2 ? ?... ? ? ? ? ?? ? ? ? ?... ? ? ? ? ?? ? ? ? ?... +++  ...  ... ...

Hodgman, that is basically what I was picturing, but it seems so much easier the way you wrote it out than the way I was envisioning it. Thanks!

Hey! I have a 2dgrid of squares. Each square contains it's own grid of lets say 11x11 squares. Every square also has an elevation value. I want to average out the elevation of the little squares within one of the larger squares with the surrounding larger squares elevations. Basically I want the middle small square to equal it's large square's elevation and the little squares surrounding that to gradually equal 1/2 the dif between the original big square's elevation and the neighbor big square's elevation while taking into account at least 2 of the other 7 neighboring large square's elevation. What sorts of solutions are available to solve my problem? [Edited by  polpoint on September 28, 2009 6:41:54 PM]

yeah, that is exactly what I am looking for  thanks SriLumpa!

I am sure it is something as simple as that. Now how do I pick which regionTile[pix][piy].var1, var2, or var3 the function edits?