PDA

View Full Version : Create small coordinate system + Orthographic Camera Problem


Marscr
05-12-2010, 02:01 PM
Hi!

There are 2 Problems on which I hope that someone can help me here:

First Problem:

I want to create some kind of a mini coordinate system for my scene which is always displayed at the same position (in example left bottom corner) of my scene and shows from which direction the camera is looking on the rest of the scene.

By now I created the coordinate system which is all contained by the separator "coordSysSep" and it looks like on the image in the attatchment.
My problem is that I dont know how I can always keep this "mini coordinate System" at the same position(bottom left corner) of my viewer. By now I first translated the whole content of to the camera position. And then I additionally want to translate it to place it in the bottom left corner. But How can I do this? This translation always depends on the current camera position, so I cant translate with the same value all the time.

The relevant code is this:

//combine axes to coordinate system
SoSeparator* coordSysSep = new SoSeparator;
coordSysSep->addChild(xAxesSep);
coordSysSep->addChild(yAxesSep);
coordSysSep->addChild(zAxesSep);

//translate coordinate system to same position as camera at first
SoTranslation* camPosTranslation = new SoTranslation;
camPosTranslation->translation.connectFrom(&camera_->position);

//Then translate it to the desired position relative to the cam (bottom left corner in example)
//How do I do this??? Current attempt only places it to the same relative position. But if camera looks
//in another direction the coordinate system disappears out of the displayed viewingregion
SoTranslation* sideTranslation = new SoTranslation;
sideTranslation->translation.setValue(-1000,-1000,-2000);

//does not really change anything
SoRotation* sideRotation = new SoRotation;
sideRotation->rotation.setValue(camera_->orientation.getValue());

root_->addChild(sideRotation); //this did not help as well
root_->addChild(sideTranslation);
root_->addChild(camPosTranslation);
root_->addChild(coordSysSep);

So how can I position my coordinate system at the right relative position? And/or is there a better way to
do it? Maybe some Inventor class that already does what I want?


Second Problem:
I changed the camera of my scene to SoOrthographicCamera(from SoPerspectiveCamera). Since I did this parts of my scene disappear when I zoom too close or to far away (See image).
I already experianced this problem in other situations with this camera view, however I dont entirely understand why it occurs and whether there is a way to do anything about it. Moreover the my mini coordinate system seems to get smaller and bigger when I zoom, although keep it in a constant distance from the camera (like in the code above with the sideTranslation). With the perspective camera the coordinate system appeard(as expected) in the same size irrespective of the zoom level.

So I hoped that someone can help me understand this occurances here and give me an idea how they can be prevented.

Thanks & Regards

mikeheck
05-12-2010, 04:54 PM
I want to create some kind of a mini coordinate system for my scene which is always displayed at the same position (in example left bottom corner) of my scene and shows from which direction the camera is looking on the rest of the scene.

It sounds like what you need for this problem is a "gnomon". There is an example of how to do this in the forum Resources section here.

Hope it helps.
-Mike

Marscr
05-13-2010, 01:39 PM
Hi Mike, thx for the hint! That looks pretty much like what I need! In the meanwhile I implemented it and basically seems to do what it should. However I have some problems with the interaction in the rest of my scene as soon as I add the gnomon.

Usually I can pan and rotate my scene with LMB and MMB as long as I don't press on a geometry in the scene. Now the gnomon seems to be displayed in the left botton corner like it should, but if I press on certain regions in my scene in order to pan or rotate it, it seems that I press on the gnomon geometry which is not even displayed at that place(I sprayed the area - very approximate since I can only test by clicking and whatching the console output - into the attatched image), instead of pressing on "empty space". Is it possible that the gnomon is displayed in the bottom left corner, but "physically" still is at the origin where I created it? And is there anything I can do about it or work arround? By the way I do not read my gnomongeometry from a file but create it in the scene - could that be the problem?

In code like the following instead of reading from the file:


SoSeparator* gnmGeometry = createGnomonGeometry();
gnmSwitch->addChild(gnmGeometry);

By the way my scene graph looks like this:
SoSeparator = overAllRoot
|
|__SoSelection
| |__ SoSeparator = selectionRoot_
| |__ SoSeparator = sceneRoot_
| | |__ SoTransform
| | |__ ...more nodes..
| | |__ SoCube
| |__ SoSeparator
| | |__ SoTransform
| | |__ ...more nodes..
| | |__ SoCube
| |__ ... and so on
|
|__SoSeparator = gnomonSeparator
|__from here on like in tutorial (just using my own gnomongeometry)

The code vor creating my gnomon geometry:
SoSeparator* myClass::createGnomonGeometry()
{
//create a generall axes for the coordinate system
SoSeparator* axesSeparator = new SoSeparator;

SoBaseColor* axesColor = new SoBaseColor;
axesColor->rgb = SbColor(0, 0.5, 0);
axesSeparator->addChild(axesColor);

SoCube* axesBaseCube = new SoCube;
axesBaseCube->depth = 0.1f;
axesBaseCube->width = 0.1f;
axesBaseCube->height = 0.01f;
axesSeparator->addChild(axesBaseCube);

SoCylinder* axesCylinder = new SoCylinder;
axesCylinder->radius = 0.1f;
axesCylinder->height = 1.0f;

SoTranslation* cylinderTranslation = new SoTranslation;
cylinderTranslation->translation.setValue(0, (axesCylinder->height.getValue())/2, 0);

axesSeparator->addChild(cylinderTranslation);
axesSeparator->addChild(axesCylinder);

SoCone* axesCone = new SoCone;
axesCone->bottomRadius = 0.2f;
axesCone->height = 0.2f;

SoTranslation* coneTranslation = new SoTranslation;
coneTranslation->translation.setValue(0, (axesCone->height.getValue())/2, 0);

axesSeparator->addChild(cylinderTranslation); //cone needs to be translated by full cylinder height (2 times half height)
axesSeparator->addChild(coneTranslation);
axesSeparator->addChild(axesCone);

//x axes
SoSeparator* xAxesSep = new SoSeparator;
SoRotation* xAxesRot = new SoRotation();
xAxesRot->rotation.setValue(SbRotation(SbVec3f(0,0,1), -1.5707963f));
xAxesSep->addChild(xAxesRot);
xAxesSep->addChild(axesSeparator);

//y axes
SoSeparator* yAxesSep = new SoSeparator;
SoRotation* yAxesRot = new SoRotation();
yAxesSep->addChild(axesSeparator);

//z axes
SoSeparator* zAxesSep = new SoSeparator;
SoRotation* zAxesRot = new SoRotation();
zAxesRot->rotation.setValue(SbRotation(SbVec3f(1,0,0), 1.5707963f));
zAxesSep->addChild(zAxesRot);
zAxesSep->addChild(axesSeparator);

//combine axes to coordinate system
SoSeparator* coordSysSep = new SoSeparator;
coordSysSep->addChild(xAxesSep);
coordSysSep->addChild(yAxesSep);
coordSysSep->addChild(zAxesSep);

return coordSysSep;
}

Thanks again for the help!

mikeheck
05-13-2010, 03:35 PM
Usually I can pan and rotate my scene with LMB and MMB as long as I don't press on a geometry in the scene. Now the gnomon seems to be displayed in the left botton corner like it should, but if I press on certain regions in my scene in order to pan or rotate it, it seems that I press on the gnomon geometry which is not even displayed at that place(I sprayed the area - very approximate since I can only test by clicking and whatching the console output - into the attatched image), instead of pressing on "empty space". Is it possible that the gnomon is displayed in the bottom left corner, but "physically" still is at the origin where I created it?

Yes, that's possible. The image of the gnomon appears in the corner because the viewport is modified. This doesn't change where the geometry is located in 3D space.

However the problem you're seeing may be a "feature" of Coin. By default Open Inventor's viewers ignore geometry when in viewing mode. That's why you have to press ESC (or equivalent) to switch to selection mode before you can select geometry, interact with draggers, etc.

And is there anything I can do about it or work arround? By the way I do not read my gnomongeometry from a file but create it in the scene - could that be the problem?

How the geometry is created isn't relevant to this issue. But you may be able to solve the problem by adding an SoPickStyle node with style = UNPICKABLE at the top of the gnomon sub-graph. (I'm not sure since we're apparently working around a Coin behavior.)

-Mike

Marscr
05-13-2010, 03:47 PM
Ok thanks for the information! I ll try your to fix it and report back :)

Regards scr

EDIT: Thanks a lot!!! The SoPickStyle solution works! (at least I did not find the geometry after some clicking :))