Howto transform worldcoordinates into screencoordinates

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
Big-Laser_Gun

Howto transform worldcoordinates into screencoordinates

Post by Big-Laser_Gun »

Hi everyone.
First I want to ask if anyone can become a member in this forum. I tried to register but it keeps telling me that my "Confirm password" is wrong. I have even copy and paste the same word from an external text document and it still complains. Is it me who is doing something wrong? :?

Secound I want to ask if there is any way to transform the world coordinates into screen coordinates.
So if i have an object in the top left corner of the window I want to get the coordinates (0,0) and not the coordinates in the world ex (10,0,200) :?:

Third and last question. Is it possible to transform the mouse coordinats into the 3d world. If the mouse is in the top left corner of the screen, its coordinats is (0,0). Can you get the that coordinat into what polygons it is touching like (10,100,25) depending on the camera :?:
Vox
Posts: 47
Joined: Fri Apr 01, 2005 5:25 pm

Post by Vox »

getScreenCoordinatesFrom3DPosition and getRayFromScreenCoordinates
Big-Laser_Gun

Post by Big-Laser_Gun »

In what .h file do i find getScreenCoordinatesFrom3DPosition()

ISceneNode* ScnNode;
vector2df nodescreenpos = ScnNode->getScreenCoordinatesFrom3DPosition();

that code only gave me a nasty runtime error... :cry:

Any example would be of great help.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

First... What on earth is stopping you from using a search tool [Start | Search | All files and folders on windows or grep on *nix] to look for a method by that name in the include directory? That would only take you like 3 seconds to do and you'd have the answer immediately.

Second... What about the documentation? Given the method name, you can find out information about it there... You can find the docshere. Click Class members and then 'g'.

Third... You most definitely would not get a nasty runtime error from the posted code. It would never compile. You would get a nasty compile error.

Travis
needforhint
Posts: 322
Joined: Tue Aug 30, 2005 10:34 am
Location: slovakia

Post by needforhint »

multiply the world vector with world-view-projection matrix, get the matrix like this:

core::matrix4 matWorldViewProjection;
matWorldViewProjection = driver->getTransform(video::ETS_PROJECTION);
matWorldViewProjection *= driver->getTransform(video::ETS_VIEW);
matWorldViewProjection *= driver->getTransform(video::ETS_WORLD);

and then by doing matWorldViewProjection *= worldvector; you will get a 2 dimension vector beleived to be the screen(projectioin) coordinates ;
what is this thing...
Big-Laser-Gun

Post by Big-Laser-Gun »

To vitec...
If the windows search function lets me search for a frase inside of all text documents then perhaps you can tell me how I do that.

Secound, I DID look in the documentations first but I could not find it there because again, I can't search for a frase in all documenation files.

But I am sorry about the runtime error when I meant compile error... :oops:
hybrid

Post by hybrid »

Big-Laser-Gun wrote:To vitec...
If the windows search function lets me search for a frase inside of all text documents then perhaps you can tell me how I do that.
To all those funny windows users :lol:
Use the advanced search options where the dialogs allows to search for text inside documents :roll:
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

If the windows search function lets me search for a frase inside of all text documents then perhaps you can tell me how I do that.
  1. click Start | Search | All files and folders
  2. Set All or part of the file name to *.h
  3. Set A word or phrase in the file to getScreenCoordinatesFrom3DPosition
  4. Set Look in to the path to the Irrlicht include directory
  5. click Search button
Secound, I DID look in the documentations first but I could not find it there because again, I can't search for a frase in all documenation files.
Why would you need to search. You know the name of the function you are looking for.
  1. click http://irrlicht.sourceforge.net/docu/index.html
  2. click class members near the top of the page
  3. click functions
  4. click g
  5. use the search feature of your web browser [ctrl+f for internet explorer]
  6. search for getScreenCoordinatesFrom3DPosition
  7. click link to irr::scene::ISceneCollisionManager::getScreenCoordinatesFrom3DPosition(...)
.
Big-Laser-Gun

Post by Big-Laser-Gun »

I cant get this code to work. This time i get the runtime error, thanks vitek for clearing that up... :wink:


IAnimatedMesh* mesh = smgr->getMesh(*model*);
node = smgr->addAnimatedMeshSceneNode( mesh );
ICameraSceneNode* camera = smgr->addCameraSceneNode(*numbers*);
ISceneCollisionManager* scmgr = 0;
position2d<s32> pos = scmgr->getScreenCoordinatesFrom3DPosition(node->getPosition(),camera);

PS. Im to lazy to use the debuger...
Please help me anyway...
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

Big-Laser-Gun wrote:ISceneCollisionManager* scmgr = 0;
position2d<s32> pos = scmgr->getScreenCoordinatesFrom3DPosition(node->getPosition(),camera);
The use your brain. ;)

You create a new pointer and initialize it with NULL:

ISceneCollisionManager* scmgr = 0;

In the next line, you want to access a member of the SceneCollisionManager with a nullpointer: CRASH.

Regards - Xaron
Big-Laser-Gun

Post by Big-Laser-Gun »

Yes, I know the problem is with that line.
I guess the question was more of:

ISceneCollisionManager* scmgr = ???;

Wath must I set the ISceneCollisionManager to. The world?, the IrrlichtDevice, the node???

Please help me understand this. Im so confused... :cry:
Xaron
Posts: 310
Joined: Sun Oct 16, 2005 7:39 am
Location: Germany
Contact:

Post by Xaron »

Just do:

Code: Select all

position2d<s32> pos = smgr->getSceneCollisionManager()->getScreenCoordinatesFrom3DPosition(node->getPosition(),camera);
...edited, because of my fault. ;)

Regards - Xaron
Last edited by Xaron on Fri Feb 24, 2006 10:15 am, edited 1 time in total.
Vox
Posts: 47
Joined: Fri Apr 01, 2005 5:25 pm

Post by Vox »

Code: Select all

	scene::ISceneManager* smgr = device->getSceneManager();
	ISceneCollisionManager* scmgr = smgr->getSceneCollisionManager();
You can find this in the Irrlicht collision example. And please next time use beginners help.
Post Reply