Told you!...sbornhof wrote:It's solved. The external window I created had outer dimensions of 640*480, but inner dimensions of only 632*446.
Thanks again.
Stefan

Code: Select all
void OgreViewer::gridScreenshots(int gridSize)
{
mCamera->setCustomProjectionMatrix(false); // reset projection matrix
Ogre::Matrix4 standard = mCamera->getProjectionMatrix();
double nearDist = mCamera->getNearClipDistance();
double nearWidth = (mCamera->getWorldSpaceCorners()[0] - mCamera->getWorldSpaceCorners()[1]).length();
double nearHeight = (mCamera->getWorldSpaceCorners()[1] - mCamera->getWorldSpaceCorners()[2]).length();
int nbScreenshots = 0;
for (int n=0;n<gridSize*gridSize;n++)
{
// use asymmetrical perspective projection.
// check out http://www.cs.kuleuven.ac.be/cwis/research/graphics/INFOTEC/viewing-in-3d/node8.html for more explanations
int y = n / gridSize;
int x = n - y * gridSize;
Ogre::Matrix4 shearing(
1,0,(x-(gridSize-1)*0.5)*nearWidth/nearDist,0,
0,1,-(y-(gridSize-1)*0.5)*nearHeight/nearDist,0,
0,0,1,0,
0,0,0,1);
Ogre::Matrix4 scale(
gridSize,0,0,0,
0,gridSize,0,0,
0,0,1,0,
0,0,0,1);
mCamera->setCustomProjectionMatrix(true,standard*shearing*scale);
mRoot->renderOneFrame();
mWindow->writeContentsToFile(Ogre::String("gridscreenshot")+ Ogre::StringConverter::toString(nbScreenshots++) + Ogre::String(".png"));
}
mCamera->setCustomProjectionMatrix(false); // reset projection matrix
}
Cool.sbornhof wrote:I used a resolution of 640*480 and tested up to a 7*7 grid, which yielded a perfect 4480*3360 pixel screenshot.
Yes, but then I'd rather imagine an oversize version of your screenshots as the project sounded interesting. Could you post a normal sized screenshot, then (or convert to jpeg)?sbornhof wrote:Well, I don't put an example here because not only the number of pixels, but also the file size grows.![]()
Just imagine an oversize version of your own screens.
Code Snippets would be good place I think.sbornhof wrote:Yes, why not put it into the Ogre Wiki, but can you suggest me where the subject fits best? There are so many categories...
I'll put it there, no problem.Code Snippets would be good place I think.
Ok ok, this is one of my plants:Could you post a normal sized screenshot, then (or convert to jpeg)?
Code: Select all
void gridScreenshots(Ogre::Camera* camera, const int& gridSize, const Ogre::String& fileName, const Ogre::String& fileExtention, const bool& stitchGridImages)
{
camera->setCustomProjectionMatrix(false); // reset projection matrix
Ogre::Matrix4 standard = camera->getProjectionMatrix();
double nearDist = camera->getNearClipDistance();
double nearWidth = (camera->getWorldSpaceCorners()[0] - camera->getWorldSpaceCorners()[1]).length();
double nearHeight = (camera->getWorldSpaceCorners()[1] - camera->getWorldSpaceCorners()[2]).length();
Ogre::Image sourceImage;
Ogre::String gridFilename;
Ogre::uchar* stitchedImageData;
int nbScreenshots = 0;
for (int n = 0; n < gridSize * gridSize; n++)
{
// Use asymmetrical perspective projection. For more explanations check out:
// http://www.cs.kuleuven.ac.be/cwis/research/graphics/INFOTEC/viewing-in-3d/node8.html
int y = n / gridSize;
int x = n - y * gridSize;
Ogre::Matrix4 shearing(
1, 0,(x - (gridSize - 1) * 0.5) * nearWidth / nearDist, 0,
0, 1, -(y - (gridSize - 1) * 0.5) * nearHeight / nearDist, 0,
0, 0, 1, 0,
0, 0, 0, 1);
Ogre::Matrix4 scale(
gridSize, 0, 0, 0,
0, gridSize, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
camera->setCustomProjectionMatrix(true, standard * shearing * scale);
Ogre::Root::getSingletonPtr()->renderOneFrame();
gridFilename = fileName + Ogre::StringConverter::toString(nbScreenshots++) + fileExtention;
Ogre::Root::getSingletonPtr()->getAutoCreatedWindow()->writeContentsToFile(gridFilename);
if(stitchGridImages)
{
sourceImage.load(gridFilename, "General");
Ogre::ColourValue colourValue;
int stitchedX, stitchedY, stitchedIndex;
if(n == 0)
stitchedImageData = new Ogre::uchar[sourceImage.getWidth() * gridSize * sourceImage.getHeight() * gridSize * 3]; // 3 colors per pixel
for(int rawY = 0; rawY < (int) sourceImage.getHeight(); rawY++)
{
for(int rawX = 0; rawX < (int) sourceImage.getWidth(); rawX++)
{
colourValue = sourceImage.getColourAt(rawX, rawY, 0);
stitchedY = y * (int) sourceImage.getHeight() + rawY;
stitchedX = x * (int) sourceImage.getWidth() + rawX;
stitchedIndex = stitchedY * (int) sourceImage.getWidth() * gridSize + stitchedX;
Ogre::PixelUtil::packColour(sourceImage.getColourAt(rawX, rawY, 0),
Ogre::PF_R8G8B8,
(void*) &stitchedImageData[stitchedIndex * 3]);
}
}
}
}
camera->setCustomProjectionMatrix(false); // reset projection matrix
if(stitchGridImages)
{
Ogre::Image targetImage;
targetImage.loadDynamicImage(stitchedImageData,
sourceImage.getWidth() * gridSize,
sourceImage.getHeight() * gridSize,
1, // depth
Ogre::PF_R8G8B8,
false);
targetImage.save(fileName + fileExtention);
delete[] stitchedImageData;
}
}
Code: Select all
------------------------------------------------------------------
| | |
| | |
| | |
|___________| |
| |
| |
|______________________________________________|
Code: Select all
frameStarted()
{
if(keypressed == screenshot_key && takingScreenshot == false)
{
takingScreenshot = true;
gridScreenshots();
takingScreenshot = false;
}
}
Code: Select all
frameStarted()
{
if(mInputDevice->isKeyDown(KC_B))
{
gridScreenshots(3);
}
}