Distorted Text Object?
by Gellyware · in Torque Game Builder · 01/16/2007 (12:36 pm) · 5 replies
Why does the text object distort if the cameras width = 800 and height = 600, and design resulution x = 800, y=600?
The text object works fine with the default tgb settings, but I prefer to work with dimension relative to the image pixel size...
Any suggestions?
The text object works fine with the default tgb settings, but I prefer to work with dimension relative to the image pixel size...
Any suggestions?
About the author
#2
Hopefully this text issue gets sorted out. I've also noticed aliasing issues, I wonder if that is going to be addressed.
01/16/2007 (4:17 pm)
Thanks for the response Matthew, I'll look into the conversion to pacify my desire to use pixel coordinates. I really wonder why TGB isn't in pixel coordinates to begin with. Hopefully this text issue gets sorted out. I've also noticed aliasing issues, I wonder if that is going to be addressed.
#3
01/16/2007 (5:47 pm)
Because pixel coordinates are locked to working in a single resolution. Disassociated coordinates make your game object the exact same size (by ratio to the screen) in all resolutions. So if your sprite is 1" at 1024, it will still be 1" at 800.
#4
01/16/2007 (7:35 pm)
I see, thanks for the info Ben.
Torque Owner Matthew "Ashteth" Kee
Default Studio Name
What I did to pretend I'm using pixels is to write a set of console functions that make it easier to convert between pixel and TGB coordinates. I wrote them in C++, because I tend to like C++. If you don't have a pro license, it shouldn't be that difficult to implement this in script either. The function you are most interested in is t2dSceneWindow::getWorldPoint. Below is a version of the pixel to world functions very similar to the ones I use. I've also implemented C++ Console function such as "t2dSceneObject::setPosition_Pixel()" that make life even easier. You could also do something like this in either script or C++. Just a thought. I agree though, the text render should probably be fixed to work at any resolution.
// ----------------------------------------------------------------------------- // Convert pixel width / height to scene width / height. // ----------------------------------------------------------------------------- t2dVector t2dDefaultSize(const t2dVector& vPixelSize) { t2dVector vWindowSize(Platform::getWindowSize().x, Platform::getWindowSize().y); t2dVector vDesignSize(100.0f, 75.0f); t2dVector vWorldSize; vWorldSize.mX = (vDesignSize.mX / vWindowSize.mX) * vPixelSize.mX; vWorldSize.mY = (vDesignSize.mY / vWindowSize.mY) * vPixelSize.mY; return vWorldSize; } ConsoleFunction(t2dDefaultSize, const char*, 2, 2, "Convert height / width in pixels to default TGB height / width.") { t2dVector vPixelSize = t2dSceneObject::getStringElementVector(argv[1]); t2dVector vWorldSize = t2dDefaultSize(vPixelSize); const S32 iElementCount = t2dSceneObject::getStringElementCount(argv[1]); char* rRet = Con::getReturnBuffer(64); dSprintf(rRet, 64, "%7.3f %7.3f", vWorldSize.mX, vWorldSize.mY); return rRet; } // ----------------------------------------------------------------------------- // Convert pixel coordiates to world coordinates. // Note: you must change "WINDOW" to the name of your window. // ----------------------------------------------------------------------------- t2dVector t2dPixelToWorld(const t2dVector& vPixel) { t2dVector vWorld; SimObject* pObj = Sim::findObject("WINDOW"); t2dSceneWindow* pWindow = dynamic_cast<t2dSceneWindow*>(pObj); if(!pWindow) { return vWorld; } pWindow->windowToSceneCoord(vPixel, vWorld); return vWorld; } ConsoleFunction(t2dPixelToWorld, const char*, 2, 2, "Convert pixel coordiates to world coordinates.") { const char* rArg = argv[2]; const S32 iElementCount = t2dSceneObject::getStringElementCount(rArg); if(2 == iElementCount) { t2dVector vPixel = t2dSceneObject::getStringElementVector(rArg, 0); t2dVector vWorld = t2dPixelToWorld(vPixel); dSprintf(rRet, 64, "%7.3f %7.3f", vWorld.mX, vWorld.mY); } return rRet; }