3D wolrd coordinates of the 4 corner of PC screen
-
- Posts: 54
- Joined: Thu Oct 25, 2007 1:38 pm
- Location: Montreal, Canada
3D wolrd coordinates of the 4 corner of PC screen
Suppose the game is a 3D game with one camera (FPS). Is there any way to know the 3D world coordinates of the 4 corner of the PC screen ????
Is it the Near Plan of the Camera ???
Thanks.
Is it the Near Plan of the Camera ???
Thanks.
-
- Posts: 107
- Joined: Sat Nov 04, 2006 9:42 pm
Well, since you're working in a 3D world the world coordinates of the screen's corners are actually rays. So there are infinite possibilities for each. What exactly do you need them for? Depending on why you need them there may be a good way to get them.
Frosty Topaz
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
=========
It isn't easy being ice-encrusted aluminum silicate fluoride hydroxide...
-
- Posts: 54
- Joined: Thu Oct 25, 2007 1:38 pm
- Location: Montreal, Canada
The screen shows what the camera see in is FOV. So if the camera doesn't move, there is no INFINITE value. There are only one "projected" position for each corner of the screen.
I am looking for something around NEAR PLAN of the FOV of the camera to see if there is a possibility to know what are the position of each corner.
My Problem: I want to show some BLOOD SPLASHING on the screen and I use a QUAD (a mesh composed of 4 vertex). I will show this Mesh Buffer (quad) with a texture (material) on it. But when the SPLASH occurs, I stop the movement of the camera (or of the player). I drawMeshBuffer directly on driver after the SceneManager->drawAll() and GuiEnvironment->drawAll().
I am looking for something around NEAR PLAN of the FOV of the camera to see if there is a possibility to know what are the position of each corner.
My Problem: I want to show some BLOOD SPLASHING on the screen and I use a QUAD (a mesh composed of 4 vertex). I will show this Mesh Buffer (quad) with a texture (material) on it. But when the SPLASH occurs, I stop the movement of the camera (or of the player). I drawMeshBuffer directly on driver after the SceneManager->drawAll() and GuiEnvironment->drawAll().
You can ask the camera for its SViewFrustum. The frustum is made up of 6 planes. You can use them and the methods of core::plane3df to find the position of the coordinates you are looking for.
You could also use the scene collision manager to do a ray cast to the corner of the screen. You could use the ray to get a point that is a given distance away from the camera.
You could also use the view and projection matrices directly to find these points.
Travis
You could also use the scene collision manager to do a ray cast to the corner of the screen. You could use the ray to get a point that is a given distance away from the camera.
You could also use the view and projection matrices directly to find these points.
Travis
-
- Posts: 914
- Joined: Fri Aug 03, 2007 12:43 pm
- Location: South Africa
- Contact:
you can use the current view matrix to display your quads:
this way you dont have to compute positions. the quads will be displayed parallel to the viewport almost like 2d images.
Code: Select all
ICameraSceneNode *camera = SMGR->getActiveCamera();
matrix4 mv = camera->getViewMatrix();
mv.makeInverse();
// translate the quad on screen
// play around with x,y values to find out where they show your quad
// try 0,0 first
// z value should be bigger than the Near value of the camera, i set it to 1
matrix4 t;
t.setTranslation(vector3df(x,y,1));
mv *= t;
SMGR->getVideoDriver()->setTransform(ETS_WORLD, mv);
Create your own projection matrix (in your case identity matrix) and set it via
IVideoDriver::setTransform(ETS_PROJECTION, yourMatrix);
vertex coordinates range from -1 to 1 for both x and y coordinates. Choose any z coordinate you want (it doesn't matter because it's an orthogonal matrix). Maybe you need to set the world matrix etc as well, I haven't tested it. But that should work very well
IVideoDriver::setTransform(ETS_PROJECTION, yourMatrix);
vertex coordinates range from -1 to 1 for both x and y coordinates. Choose any z coordinate you want (it doesn't matter because it's an orthogonal matrix). Maybe you need to set the world matrix etc as well, I haven't tested it. But that should work very well
-
- Posts: 54
- Joined: Thu Oct 25, 2007 1:38 pm
- Location: Montreal, Canada
well interresting question....
My original problem was that I cannot splash/splatter something like blood or water in the screen and hiding GUI objets. I use some GUI elements like the statistics of the player, the score, the time, also a mini-map, etc. The game is in 3D environment and I show some stuff on screen with IGUIEnvironment.
So, when I "drawAll()" my Scene Manager and after that I "drawAll()" my Gui Environment, I did not see the Splash like I want. First of all, it must cover all the screen (the size of the near plan) and it must be over the GUI elements.
The proposal of Vitek was very good.
I did it with a QUAD using coordinates of the 4 corners of the near plan. It works fine for now..... maybe there is something easier of faster, I will take a look to all your proposal.
Thank !
So, when I "drawAll()" my Scene Manager and after that I "drawAll()" my Gui Environment, I did not see the Splash like I want. First of all, it must cover all the screen (the size of the near plan) and it must be over the GUI elements.
The proposal of Vitek was very good.
I did it with a QUAD using coordinates of the 4 corners of the near plan. It works fine for now..... maybe there is something easier of faster, I will take a look to all your proposal.
Thank !
Uh, I already gave you code showing exactly how to do that a few days ago in your other thread... http://irrlicht.sourceforge.net/phpBB2/ ... p?p=146010.
Travis
Travis