3D wolrd coordinates of the 4 corner of PC screen

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Danny Gilbert
Posts: 54
Joined: Thu Oct 25, 2007 1:38 pm
Location: Montreal, Canada

3D wolrd coordinates of the 4 corner of PC screen

Post by Danny Gilbert »

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.
Frosty Topaz
Posts: 107
Joined: Sat Nov 04, 2006 9:42 pm

Post by Frosty Topaz »

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...
Danny Gilbert
Posts: 54
Joined: Thu Oct 25, 2007 1:38 pm
Location: Montreal, Canada

Post by Danny Gilbert »

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().
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

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
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

Why dont you draw them as 2d images, why does it need to be in 3d?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

It probably doesn't. I've already tried to convince him of this in another thread.

The only reason to do actual 3d here is if you want to see if something is hitting the near plane. Probably not necessary.

Travis
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, with 3d methods you also have more possibilities when it comes to materials, rotation, ...
morris
Posts: 36
Joined: Tue Jul 10, 2007 10:10 am

Post by morris »

you can use the current view matrix to display your quads:

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);
this way you dont have to compute positions. the quads will be displayed parallel to the viewport almost like 2d images.
mk.1
Posts: 76
Joined: Wed Oct 10, 2007 7:37 pm

Post by mk.1 »

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
Danny Gilbert
Posts: 54
Joined: Thu Oct 25, 2007 1:38 pm
Location: Montreal, Canada

well interresting question....

Post by Danny Gilbert »

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 !
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

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
Post Reply