CHAI3DCHAI3D

normal coordinate system of different object

More
14 Mar 2016 15:56 #1

Hi,

I'm using cShapeSphere and cBitmap objects in my application, but they have different coordinate system! For cShapeSphere the origin is at the centre of the window, while for cBitmap the origin is at the bottom left of the window! Why?
Is there a function to switch from one coordinate system to another?


Thanks!

Please Log in or Create an account to join the conversation.

More
15 Mar 2016 00:35 #2

In CHAI3D a 2D widget is defined by its position (x,y), width and height.

The origin of such 2D widget is always located at its bottom left position. This is a very common practice in GUI interface design and makes things very easy when aligning multiple widgets (e.g. a column of labels).

By using the width and height of a widget, you can easily write a function that allows you to control the center point of the widget instead:

  // define a desired widget position of its center
  double cx = 100;
  double cy = 150;

  // compute bottom left position of widget (CHAI3D)
  x = cx - 0.5 * w;
  y = cy - 0.5 * h;

Please Log in or Create an account to join the conversation.

More
15 Mar 2016 09:37 #3

Ok, I know it!
But the question is different, maybe I explained evil!

If I assign a cShapeSphere to the position (0,0), the sphere is put at the centre of the screen; while if I assign a cBitmap to the position (0,0), the image is put at the bottom left of the screen.
In my application I have to put a cShapeSphere object in the same position of a cBitmap object.
Is there a function to switch from one coordinate system to another?


Thanks a lot!

Giulia

Please Log in or Create an account to join the conversation.

More
15 Mar 2016 13:09 #4

They do indeed use different coordinate systems.

The 2D widget uses a two-dimensional system (x,y) with the origin at the bottom left corner of the screen.
The 3D objects (like the cShapeSphere) that populate your scene use a three-dimensional system (x,y,z), explained here : www.chai3d.org/download/doc/html/chapter7-world.html
And if you do cShapeSphere->setLocalPos(0,0), then the function sets the z value to zero by default, so it actually does cShapeSphere->setLocalPos(0,0,0) which places the sphere in the origin of the world coordinates system.

You should understand that the 2D widget acts as a GUI (graphical user interface) that always stays on the top of your screen, while the 3D objects can move around in a 3D virtual world.
So, for example when you move your camera backwards 1 meter, then you will see the sphere get smaller but the widget will stay at exactly the same size.

About what you are asking, I think you want something like that of Unity3d :
docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
but I don't know if that's implemented in chai3d.

I hope I didn't confuse you more.

Please Log in or Create an account to join the conversation.

More
16 Mar 2016 09:04 #5

Giulia,

As you noticed, the convention used for 2D and 3D object is different, and this is what is typically used in the community.

When working with 3D objects, we often like to set the reference frame at the center of mass of the object. One of the reasons being that if you place an object at the world origin and have a camera pointing at that origin, then object will automatically be centered in the scene. If you rotate the object around its reference frame, then you will observe a rotation and not a combined translation/rotation due to the offset.

In your case, since you are combining 2D and 3D objects together, I can understand your frustration, but keep in mind that all you will often need to do is add is a position offset, which in the case of a sphere would simply be its radius.

Please Log in or Create an account to join the conversation.

More
16 Mar 2016 09:19 #6

Thank you so much,
you have been very clear and helpful!!

Please Log in or Create an account to join the conversation.