Coordinates of a mesh?

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
Guest

Coordinates of a mesh?

Post by Guest »

Hi,

I was wondering if I am able to get the coordinates of a mesh somehow instead of the vector position in relation to the camera?

I need the position of the mesh in dependance of the resultion or better: I like to set the positon of the mesh in common coordinates instead of vector position.

Is this possible? And if not how any idea how to do something similar?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

The vector is in relation to the origin ( 0,0,0 ), not the camera, or moving the camera would move the world and you wouldn't see anything move. A vector is just an array of numbers with a few added functions, the camera has it's own vector which you will probably see isn't the origin. Try printing the coords of the camera to the console if you want further proof. This is all assuming you haven't made the world a child of the camera of cause.

core::vector3df* pos = node->getPosition();

That is the function you should use to get the absolute position of the mesh.
Guest

Post by Guest »

so the origin is the middle of the screen and (0,10,0) would be 10 units in y-Direction. But how do I know what coordinates that are?

I just believe you that the meshes are independent from the camera. But if I set the camera in (0,0, -10) it is in the middle of the screen but -10 in z-Direction , isn't it?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Yes, the origin would be +10 units on the Z axis to the camera. The units used are just numbers, they could be banana's for all you care because you could use 1 unit as 1mm or 100km, it doesn't matter. Pick a scale and scale your models to that, Irrlicht will use the same units as whatever you save your model in. So if in your modeller a position is 10,10,0 it would be exactly the same in Irrilicht.

I like to use 1 unit as 1m because coords can only go to 3 d.p. That means that the smallest possible value, 0.001, is 0.1mm which is far smaller than you will ever need.
Last edited by Tyn on Tue Apr 27, 2004 9:04 am, edited 1 time in total.
Guest

Post by Guest »

Is it nonetheless possible to set coordinates for meshes?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

On adding your mesh to the world you set the position. That position is the relative origin in your model file.

node->setPosition(core::vector3df(0,0,0));

That's the function to alter the position of the node after creation.
Guest

Post by Guest »

Thank you Tyn for your effort,

but I know the function setPosition. But that was exactly not what I wanted. Because I set there the position with the vector. I know that is useful to be independent from the resolution. But I need that dependency and want to set the coordinates of the mesh.

Someone an idea for that?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

no problem helping, I am currently doing bugger all at work which is when I get to read these forums, so I might as well make myself useful.

I think a little elaboration is probably needed to help you, I seem to have missed exactly what you want. Would I be right in saying that the problem is what models are displayed at 800x600 is not exactly the same on 1280x1024, which is in effect widening the view? So theoretically if you had a grid of blocks that the camera was looking at and at the lower resolution you could see 5x5 blocks but at the higher resolution you could see 10x10. So you want to be able to see the 5x5 blocks no matter the resolution? Or it could be the reverse is true, I can't run Irrlicht at work to check.
Guest

Post by Guest »

I guess my english is very crappy that is why we have some misunderstandings. But still I am very glad, that you try helping me.

Right now I have the screen resolution of 1024x768. I just want to have my mesh at the x/y- screen coordinates 560 (for x) and 300 (for y). But I could only find the fuction setPosition with vector coordinates which are independent from the screen resolution. so I can say irr::core::vector3df(2,2,0) hoping that the mesh is at the place I want it to. so the vector coordinates 2,2,0 are conform to the screen coordinates 560,300.

I need to know that because I have two modes. One is the small mode where the mesh is kind of minimized in a small area but this are should be confrom to full screen mode. thats why I need the screen coordinates to translate the mesh to the right place on the screen.

I am not sure if that mess is getting clearer by this explanation :?
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

This is something you are going to have to code yourself, it is something less vague than I first thought and so is something most people probably haven't even looked at.

A bump in the right direction would be to get a 3D ray from 2D coords, then you have a line that runs through whatever screen coordinate you want. From there you will have to find a way of moving your mesh to do that ( I would write a function for that and post it back here, it may help someone else if they need it ).

Hope that helps.
Guest

Post by Guest »

Thanks a lot Tyn, I will try to write a function that is doing that, but I am not sure if I will succeed.
So may be someone has an idea , maybe even Nico, please post it here.
Guest

viewport

Post by Guest »

I got another idea but because it sound very simple I am not sure if I am right. What excatly does a viewport?
If it moves the origin , it also would be ok. To create a viewport I have to create an rectangle. Is it now the case that the origin is in the middle of this rectangle?
Guest

Post by Guest »

All right!!! The viewport was the right thing to do. If I set the viewport, the origin seems to move in the middle of the rectangle. And the edges of the rectangle is the border of the rendering.

So If I have two modes (one in a minized version and one in full screen mode) I have still the same vector coordinates for the meshes but I have to change the viewport every time.

Still with vectors the right position of a mesh has to be tested at the beginning , I guess it would be easier to have the screen coordinates in extention but it works fine now.

@Tyn: Thank you so much for your effort. Even it was not the right result, you helped me alot
Post Reply