I need some help.
I have a 512x512 texture floating in front of the camera on a plane. Now I want to setup the camera (distance) so that 1 texture pixel is exactly 1 screen pixel. The screen resolution and FOV is given. How do I calculate the camera distance?
Texture pixel screen pixel
-
- Posts: 109
- Joined: Tue Jan 09, 2007 1:18 pm
Texture pixel screen pixel
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
What I Do - my blog & dev log
Currently developing Link-Dead
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
You can't do it with a perspective camera, since not all parts of the texture will be at the same distance.
If you really need this to be texel/pixel perfect, then you'll have to use an orthographic camera. See matrix4f::buildProjectionMatrixOrthoLH() and ICameraSceneNode::setProjectionMatrix().
If you build the projection matrix using the screen height and width, then your object sizes will correspond 1:1 to pixels, i.e. make your texture object the same height and width as its texture and it will come out close to 1:1 . Note that fp maths may produce some inconsistencies though.
Alternatively, since you have a texture, can't you just use IVideoDriver::draw2DImage() to draw it to screen? If you need the screen position of a 3d object, you can use ISceneCollisionManager::getScreenCoordinatesFrom3DPosition() to get it.
If you really need this to be texel/pixel perfect, then you'll have to use an orthographic camera. See matrix4f::buildProjectionMatrixOrthoLH() and ICameraSceneNode::setProjectionMatrix().
If you build the projection matrix using the screen height and width, then your object sizes will correspond 1:1 to pixels, i.e. make your texture object the same height and width as its texture and it will come out close to 1:1 . Note that fp maths may produce some inconsistencies though.
Alternatively, since you have a texture, can't you just use IVideoDriver::draw2DImage() to draw it to screen? If you need the screen position of a 3d object, you can use ISceneCollisionManager::getScreenCoordinatesFrom3DPosition() to get it.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
If you need to have stuff in front of the texture just use a screen quad with zwriteenable disabled.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
-
- Posts: 109
- Joined: Tue Jan 09, 2007 1:18 pm
It's sort of a 2D/3D engine. Like Duke Nukem Manhattan. So it's 2D but I want it to look as best as possible from a 3D perspective with all the benefits like zooming, maybe slight tilting. So it doesnt have to be perfect but the textures on the map and player should approximate 1:1 correspondence with screen pixels.
--EDIT--
OK works with ortho camera. Thanks a lot!
--EDIT--
OK works with ortho camera. Thanks a lot!
Crimson Glory full Irrlicht game source code!
What I Do - my blog & dev log
Currently developing Link-Dead
What I Do - my blog & dev log
Currently developing Link-Dead
My idea would be to use a vertex shader to place the quad.
I'm using the following shader:
I'm using the following shader:
Code: Select all
varying vec2 vTexCoord;
void main(void)
{
vec2 Position;
Position.xy = sign(gl_Vertex.xy);
gl_Position = vec4(Position.xy, 0.0, 1.0);
vTexCoord = Position.xy *.5 + .5;
}
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.