Re: [osg-users] cross axes

2012-10-12 Thread Gianni Ambrosio
For everyone will need it I'm attaching the code.

Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=50580#50580




Attachments: 
http://forum.openscenegraph.org//files/crossaxes_131.zip


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2011-08-01 Thread ramy panda
Dear Sir,
I still don't know how to settle the scale problem. Would you please help 
me with that. Thank you very much.
 

Jonathan Richard wrote:
 Hi Gianni
 
 Thank you for your reply. It's ok I finally got it working.
 
 Jonathan
 
 On Wed, Aug 11, 2010 at 9:34 AM, Gianni Ambrosio  wrote:
 
  Sorry Jonathan for the delay. Unfortunately I don't remember exactly which 
  modifications I did but if you need I can give you my actual piece of code.
  
  Gianni
  
  --
  Read this topic online here:
  http://forum.openscenegraph.org/viewtopic.php?p=30691#30691
  
  
  
  
  
  ___
  osg-users mailing list
  
  http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
  
  
 ___
 osg-users mailing list
 
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
 
  --
 Post generated by Mail2Forum


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=41755#41755





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-08-22 Thread Jonathan Richard
Hi Gianni

Thank you for your reply. It's ok I finally got it working.

Jonathan

On Wed, Aug 11, 2010 at 9:34 AM, Gianni Ambrosio ga...@vi-grade.com wrote:
 Sorry Jonathan for the delay. Unfortunately I don't remember exactly which 
 modifications I did but if you need I can give you my actual piece of code.

 Gianni

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=30691#30691





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-08-11 Thread Gianni Ambrosio
Anyway, here is basically the code I used to update the axis:

double offset = 80.0;
crosscamera-setProjectionMatrix(osg::Matrix::ortho2D(-offset, iWidth-offset, 
-offset, iHeight-offset));

where offset is hardcoded here and it depends on the length of the axis. 
iWidth and iHeight are the width and height of the viewer (I don't know haw to 
get them I implemented the code for a Qt window where I can easily get them).

HTH
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=30692#30692





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-08-04 Thread Jonathan Richard
Hi Gianni,

I'm trying to get working your example with the modification suggested
by David but the axis appears to be drawn outside of my window. If I
disable

Can you tell me what modification did you perform on your NodeCallback
implementation to get it working?

Thanks
Jonathan

On 7/1/10, Gianni Ambrosio ga...@vi-grade.com wrote:
 OK, I used what Davide suggested + a modification of my NodeCallback
 implementation and now it works fine.

 Thanks
 Gianni

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=29612#29612





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-07-01 Thread Gianni Ambrosio
Thanks Nick,
I implement it but some modifications caused another problem I don't understand.

In the old code I created a cross axes with size=1.5 for each axis. The ortho 
camera was defined as follows:

camera-setProjectionMatrix(osg::Matrix::ortho2D(-1.7, 17.75, -1.7, 13.86));

Then I had to fix the resize problem as you suggested. So, on resize event I 
used the actual viewer width and height. Here is basically the call:

camera-setProjectionMatrix(osg::Matrix::ortho2D(-axisSize, iWidth-axisSize, 
-axisSize, iHeight-axisSize));

but the axis size=1.5 was to small in this case and I had to increase it to 70 
to be seen.

Now the problem.
On top of each axis an osgText to diplays the labels X, Y and Z. When an axis 
points towards out of the screen (more or less) the label disappears. In the 
previous implementation with axis size=1.5 it worked correctly. Can you please 
explain me why?

Regards
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29579#29579





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-07-01 Thread Trajce (Nick) Nikolov
could you post a working code of it? I will have a look at

-Nick


On Thu, Jul 1, 2010 at 1:35 PM, Gianni Ambrosio ga...@vi-grade.com wrote:

 Thanks Nick,
 I implement it but some modifications caused another problem I don't
 understand.

 In the old code I created a cross axes with size=1.5 for each axis. The
 ortho camera was defined as follows:

 camera-setProjectionMatrix(osg::Matrix::ortho2D(-1.7, 17.75, -1.7,
 13.86));

 Then I had to fix the resize problem as you suggested. So, on resize event
 I used the actual viewer width and height. Here is basically the call:

 camera-setProjectionMatrix(osg::Matrix::ortho2D(-axisSize,
 iWidth-axisSize, -axisSize, iHeight-axisSize));

 but the axis size=1.5 was to small in this case and I had to increase it to
 70 to be seen.

 Now the problem.
 On top of each axis an osgText to diplays the labels X, Y and Z. When an
 axis points towards out of the screen (more or less) the label disappears.
 In the previous implementation with axis size=1.5 it worked correctly. Can
 you please explain me why?

 Regards
 Gianni

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=29579#29579





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-07-01 Thread Gianni Ambrosio
Nick, here is a working code showing the label disappearing problem:


Code:

#include osgViewer/Viewer
#include osgText/Text
#include osg/LineWidth
#include osg/Geometry
#include osgGA/TrackballManipulator

osgText::Text* createAxisLabel(const std::string iLabel, const osg::Vec3 
iPosition)
{
   osgText::Text* text = new  osgText::Text;
   text-setFont(arial.ttf);
   text-setText(iLabel);
   text-setPosition(iPosition);
   text-setCharacterSize(17);
   text-setAutoRotateToScreen(true);
   text-setColor(osg::Vec4(204, 204, 0, 1));
   text-setCharacterSizeMode(osgText::Text::SCREEN_COORDS);
   return text;
}

osg::Geometry* createArrow(const osg::Matrixd iTransform, const osg::Vec4 
iColor, double iHeight)
{
   osg::Geometry* geometry = new osg::Geometry;

   double pyramidBaseZ = iHeight/3.0*2.0;
   double outerBaseRadius = iHeight/9.0;
   osg::Vec3Array* vertices = new osg::Vec3Array(7);
   (*vertices)[0].set(iTransform.preMult(osg::Vec3d(outerBaseRadius, 0.0, 
pyramidBaseZ)));
   (*vertices)[1].set(iTransform.preMult(osg::Vec3d(0.0, outerBaseRadius, 
pyramidBaseZ)));
   (*vertices)[2].set(iTransform.preMult(osg::Vec3d(-outerBaseRadius, 0.0, 
pyramidBaseZ)));
   (*vertices)[3].set(iTransform.preMult(osg::Vec3d(0.0, -outerBaseRadius, 
pyramidBaseZ)));
   (*vertices)[4].set(iTransform.preMult(osg::Vec3d(0.0, 0.0, iHeight)));
   (*vertices)[5].set(iTransform.preMult(osg::Vec3d(0.0, 0.0, iHeight)));
   (*vertices)[6].set(iTransform.preMult(osg::Vec3d(0.0, 0.0, 0.0)));

   osg::UByteArray* indices = new osg::UByteArray(20);
   (*indices)[0]=0;  (*indices)[1]=1;  (*indices)[2]=4;
   (*indices)[3]=1;  (*indices)[4]=2;  (*indices)[5]=4;
   (*indices)[6]=2;  (*indices)[7]=3;  (*indices)[8]=4;
   (*indices)[9]=3;  (*indices)[10]=0; (*indices)[11]=4;
   (*indices)[12]=1; (*indices)[13]=0; (*indices)[14]=3;
   (*indices)[15]=2; (*indices)[16]=1; (*indices)[17]=3;
   (*indices)[18]=5;
   (*indices)[19]=6;

   geometry-setVertexArray(vertices);
   geometry-setVertexIndices(indices);

   osg::Vec4Array* colors = new osg::Vec4Array;
   colors-push_back(iColor);
   geometry-setColorArray(colors);
   geometry-setColorBinding(osg::Geometry::BIND_OVERALL);

   geometry-addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 
0, indices-size()-2));
   geometry-addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 
indices-size()-2, 2));

   return geometry;
}

osg::Geometry* createXAxis(double iHeight)
{
   osg::Matrixd transform = osg::Matrix::rotate(osg::inDegrees(90.0f), 0.0f, 
1.0f, 0.0f);
   osg::Vec4 color(0.5f,0.125f,0.125f,1.0f);
   osg::Geometry* geometry = createArrow(transform, color, iHeight);
   return geometry;
}

osg::Geometry* createYAxis(double iHeight)
{
   osg::Matrixd transform = osg::Matrix::rotate(osg::inDegrees(-90.0f), 1.0f, 
0.0f, 0.0f);
   osg::Vec4 color(0.125f,0.5f,0.125f,1.0f);
   osg::Geometry* geometry = createArrow(transform, color, iHeight);
   return geometry;
}

osg::Geometry* createZAxis(double iHeight)
{
   osg::Matrixd transform = osg::Matrix::identity();
   osg::Vec4 color(0.125f,0.125f,0.5f,1.0f);
   osg::Geometry* geometry = createArrow(transform, color, iHeight);
   return geometry;
}

osg::Geode* createAxesGeometry()
{
   osg::Geode* geode = new osg::Geode;

   osg::LineWidth* lineWidth = new osg::LineWidth(2);
   geode-getOrCreateStateSet()-setAttributeAndModes(lineWidth, 
osg::StateAttribute::ON);
   geode-getOrCreateStateSet()-setMode(GL_LIGHTING, osg::StateAttribute::OFF);

   double length = 70.0;
   geode-addDrawable(createXAxis(length));
   geode-addDrawable(createYAxis(length));
   geode-addDrawable(createZAxis(length));
   geode-addDrawable(createAxisLabel(X, osg::Vec3(length*1.05, 0, 0)));
   geode-addDrawable(createAxisLabel(Y, osg::Vec3(0, length*1.05, 0)));
   geode-addDrawable(createAxisLabel(Z, osg::Vec3(0, 0, length*1.05)));

   return geode;
}

class AxisCameraUpdateCallback:public osg::NodeCallback
{
public:
   virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
   {
  if(nv-getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
  {
 osg::Camera* camera = dynamic_castosg::Camera*(node);
 if (camera)
 {
osg::View* view = camera-getView();
if (view  view-getNumSlaves()  0)
{
   osg::View::Slave* slave = view-getSlave(0);
   if(slave-_camera.get() == camera)
   {
  osg::Camera* masterCam = view-getCamera();
  osg::Vec3 eye, center, up;
  masterCam-getViewMatrixAsLookAt(eye, center, up, 30);
  osg::Matrixd matrix;
  matrix.makeLookAt(eye-center, osg::Vec3(0, 0, 0), up); // 
always look at (0, 0, 0)
  camera-setViewMatrix(matrix);
   }
}
 }
  }
  traverse(node,nv);
   }
}; 

osg::Camera* createHUD()
{
   osg::Camera* camera = new osg::Camera;
   camera-setProjectionMatrix(osg::Matrix::ortho2D(-80, 1280-80, 

Re: [osg-users] cross axes

2010-07-01 Thread Trajce (Nick) Nikolov
cool. I ll have a look later today and get back to you

-Nick


On Thu, Jul 1, 2010 at 2:51 PM, Gianni Ambrosio ga...@vi-grade.com wrote:

 Nick, here is a working code showing the label disappearing problem:


 Code:

 #include osgViewer/Viewer
 #include osgText/Text
 #include osg/LineWidth
 #include osg/Geometry
 #include osgGA/TrackballManipulator

 osgText::Text* createAxisLabel(const std::string iLabel, const osg::Vec3
 iPosition)
 {
   osgText::Text* text = new  osgText::Text;
   text-setFont(arial.ttf);
   text-setText(iLabel);
   text-setPosition(iPosition);
   text-setCharacterSize(17);
   text-setAutoRotateToScreen(true);
   text-setColor(osg::Vec4(204, 204, 0, 1));
   text-setCharacterSizeMode(osgText::Text::SCREEN_COORDS);
   return text;
 }

 osg::Geometry* createArrow(const osg::Matrixd iTransform, const osg::Vec4
 iColor, double iHeight)
 {
   osg::Geometry* geometry = new osg::Geometry;

   double pyramidBaseZ = iHeight/3.0*2.0;
   double outerBaseRadius = iHeight/9.0;
   osg::Vec3Array* vertices = new osg::Vec3Array(7);
   (*vertices)[0].set(iTransform.preMult(osg::Vec3d(outerBaseRadius, 0.0,
 pyramidBaseZ)));
   (*vertices)[1].set(iTransform.preMult(osg::Vec3d(0.0, outerBaseRadius,
 pyramidBaseZ)));
   (*vertices)[2].set(iTransform.preMult(osg::Vec3d(-outerBaseRadius, 0.0,
 pyramidBaseZ)));
   (*vertices)[3].set(iTransform.preMult(osg::Vec3d(0.0, -outerBaseRadius,
 pyramidBaseZ)));
   (*vertices)[4].set(iTransform.preMult(osg::Vec3d(0.0, 0.0, iHeight)));
   (*vertices)[5].set(iTransform.preMult(osg::Vec3d(0.0, 0.0, iHeight)));
   (*vertices)[6].set(iTransform.preMult(osg::Vec3d(0.0, 0.0, 0.0)));

   osg::UByteArray* indices = new osg::UByteArray(20);
   (*indices)[0]=0;  (*indices)[1]=1;  (*indices)[2]=4;
   (*indices)[3]=1;  (*indices)[4]=2;  (*indices)[5]=4;
   (*indices)[6]=2;  (*indices)[7]=3;  (*indices)[8]=4;
   (*indices)[9]=3;  (*indices)[10]=0; (*indices)[11]=4;
   (*indices)[12]=1; (*indices)[13]=0; (*indices)[14]=3;
   (*indices)[15]=2; (*indices)[16]=1; (*indices)[17]=3;
   (*indices)[18]=5;
   (*indices)[19]=6;

   geometry-setVertexArray(vertices);
   geometry-setVertexIndices(indices);

   osg::Vec4Array* colors = new osg::Vec4Array;
   colors-push_back(iColor);
   geometry-setColorArray(colors);
   geometry-setColorBinding(osg::Geometry::BIND_OVERALL);

   geometry-addPrimitiveSet(new
 osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, indices-size()-2));
   geometry-addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,
 indices-size()-2, 2));

   return geometry;
 }

 osg::Geometry* createXAxis(double iHeight)
 {
   osg::Matrixd transform = osg::Matrix::rotate(osg::inDegrees(90.0f), 0.0f,
 1.0f, 0.0f);
   osg::Vec4 color(0.5f,0.125f,0.125f,1.0f);
   osg::Geometry* geometry = createArrow(transform, color, iHeight);
   return geometry;
 }

 osg::Geometry* createYAxis(double iHeight)
 {
   osg::Matrixd transform = osg::Matrix::rotate(osg::inDegrees(-90.0f),
 1.0f, 0.0f, 0.0f);
   osg::Vec4 color(0.125f,0.5f,0.125f,1.0f);
   osg::Geometry* geometry = createArrow(transform, color, iHeight);
   return geometry;
 }

 osg::Geometry* createZAxis(double iHeight)
 {
   osg::Matrixd transform = osg::Matrix::identity();
   osg::Vec4 color(0.125f,0.125f,0.5f,1.0f);
   osg::Geometry* geometry = createArrow(transform, color, iHeight);
   return geometry;
 }

 osg::Geode* createAxesGeometry()
 {
   osg::Geode* geode = new osg::Geode;

   osg::LineWidth* lineWidth = new osg::LineWidth(2);
   geode-getOrCreateStateSet()-setAttributeAndModes(lineWidth,
 osg::StateAttribute::ON);
   geode-getOrCreateStateSet()-setMode(GL_LIGHTING,
 osg::StateAttribute::OFF);

   double length = 70.0;
   geode-addDrawable(createXAxis(length));
   geode-addDrawable(createYAxis(length));
   geode-addDrawable(createZAxis(length));
   geode-addDrawable(createAxisLabel(X, osg::Vec3(length*1.05, 0, 0)));
   geode-addDrawable(createAxisLabel(Y, osg::Vec3(0, length*1.05, 0)));
   geode-addDrawable(createAxisLabel(Z, osg::Vec3(0, 0, length*1.05)));

   return geode;
 }

 class AxisCameraUpdateCallback:public osg::NodeCallback
 {
 public:
   virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
   {
  if(nv-getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
  {
 osg::Camera* camera = dynamic_castosg::Camera*(node);
 if (camera)
 {
osg::View* view = camera-getView();
if (view  view-getNumSlaves()  0)
{
   osg::View::Slave* slave = view-getSlave(0);
   if(slave-_camera.get() == camera)
   {
  osg::Camera* masterCam = view-getCamera();
  osg::Vec3 eye, center, up;
  masterCam-getViewMatrixAsLookAt(eye, center, up, 30);
  osg::Matrixd matrix;
  matrix.makeLookAt(eye-center, osg::Vec3(0, 0, 0), up); //
 always look at (0, 0, 0)
  camera-setViewMatrix(matrix);
   }
}
 }
  }
  

Re: [osg-users] cross axes

2010-07-01 Thread Davide Bacchet
Hi Gianni,

I had a similar problem in the past, and it was related to the camera
clipping.
In my case it was enough to move the axes inside the screen, as shown in
the following code snippet:

// create a camera to set up the projection and model view matrices,
and the subgraph to drawn in the HUD
osg::Camera* camera = new osg::Camera;

// set the projection matrix
camera-setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));

// set the view matrix
camera-setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera-setViewMatrix(osg::Matrix::identity());

// only clear the depth buffer
camera-setClearMask(GL_DEPTH_BUFFER_BIT);

// draw subgraph after main camera view.
camera-setRenderOrder(osg::Camera::POST_RENDER);

// we don't want the camera to grab event focus from the viewers
main camera(s).
camera-setAllowEventFocus(false);

// put the axes under the hud transformation node
hudAxesTransform = new osg::PositionAttitudeTransform();
hudAxesTransform-setPosition(osg::Vec3(80,50,-100)); // put
inside the scren (z=-100) to avoid clipping
hudAxesTransform-addChild(graphics::utils::createAxes(0.5));
osg::StateSet *state = hudAxesTransform-getOrCreateStateSet();
state-setMode(GL_LIGHTING, osg::StateAttribute::OFF);

// add to the hud camera a subgraph to render and add to the main
graph
camera-addChild(hudAxesTransform);
root-addChild(camera);

ciao,
Davide

-- Forwarded message --
 From: Gianni Ambrosio ga...@vi-grade.com
 To: osg-users@lists.openscenegraph.org
 Date: Thu, 01 Jul 2010 09:35:29 +
 Subject: Re: [osg-users] cross axes
 Thanks Nick,
 I implement it but some modifications caused another problem I don't
 understand.

 (...)

 Now the problem.
 On top of each axis an osgText to diplays the labels X, Y and Z. When an
 axis points towards out of the screen (more or less) the label disappears.
 In the previous implementation with axis size=1.5 it worked correctly. Can
 you please explain me why?

 Regards
 Gianni

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-07-01 Thread Gianni Ambrosio
Thanks Davide. I considered that but since I would prefer to fix the axes 
origin to (0,0,0), I tried setting big values for zNear/zFar parameters for 
camera as follows:

setProjectionMatrixAsOrtho(-80, 1280-80, -80, 1024-80,-800, 800);

but nothing changed.

Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29604#29604





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-07-01 Thread Trajce (Nick) Nikolov
Gianni, I would follow Davide's hints and see if it works

-Nick


On Thu, Jul 1, 2010 at 5:36 PM, Gianni Ambrosio ga...@vi-grade.com wrote:

 Thanks Davide. I considered that but since I would prefer to fix the axes
 origin to (0,0,0), I tried setting big values for zNear/zFar parameters for
 camera as follows:

 setProjectionMatrixAsOrtho(-80, 1280-80, -80, 1024-80,-800, 800);

 but nothing changed.

 Gianni

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=29604#29604





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-07-01 Thread Gianni Ambrosio
OK, I used what Davide suggested + a modification of my NodeCallback 
implementation and now it works fine.

Thanks
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29612#29612





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-30 Thread Gianni Ambrosio
Hi Nick,
I'm using Qt and reimplemented the virtual method:

virtual void resizeGL( int width, int height )

that is called on every window resize. I get the ortho camera and called

getProjectionMatrixAsOrtho(left, right, bottom, top, zNear, zFar);

just to verify the values. Do you mean I should change those parameters 
depending on the actual width  height of the window?

Regards
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29528#29528





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-30 Thread Trajce (Nick) Nikolov
exactly. make your ortho with the new window size

-Nick


On Wed, Jun 30, 2010 at 7:21 PM, Gianni Ambrosio ga...@vi-grade.com wrote:

 Hi Nick,
 I'm using Qt and reimplemented the virtual method:

 virtual void resizeGL( int width, int height )

 that is called on every window resize. I get the ortho camera and called

 getProjectionMatrixAsOrtho(left, right, bottom, top, zNear, zFar);

 just to verify the values. Do you mean I should change those parameters
 depending on the actual width  height of the window?

 Regards
 Gianni

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=29528#29528





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-26 Thread Trajce (Nick) Nikolov
if you are doing it thru ortho camera, then you have to change the camera
settings to fit your new window size on resize

-Nick


On Fri, Jun 25, 2010 at 11:50 AM, Gianni Ambrosio ga...@vi-grade.comwrote:

 Another question.

 Now the axes works fine in the left bottom corner but if I resize the
 viewer window (I use QT embedding the viewer inside) the cross axes object
 is deformed accordingly. How can I prevent that? I mean, I agree to resize
 the axes but in a homogeneous way for every axis.

 Regards
 Gianni

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=29405#29405





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-25 Thread Gianni Ambrosio
Another question.

Now the axes works fine in the left bottom corner but if I resize the viewer 
window (I use QT embedding the viewer inside) the cross axes object is deformed 
accordingly. How can I prevent that? I mean, I agree to resize the axes but in 
a homogeneous way for every axis.

Regards
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29405#29405





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-23 Thread Gianni Ambrosio
Thanks Paul, you are right!

Regards
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29287#29287





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-23 Thread Gianni Ambrosio
Since I did't find a complete example for adding a cross axes in a view, here 
is the sample code I roughly implemented. I starded from what Jimmy suggested 
here http://forum.openscenegraph.org/viewtopic.php?t=2205highlight=axis.



Code:

   ViewerQT* viewerWindow = new ViewerQT;
   osg::Group* root = new osg::Group;
   osg::Camera* camera = createHUD();
   viewerWindow-addSlave(camera, false);
   root-addChild(camera);
   root-addChild(loadedModel);
   viewerWindow-setCameraManipulator(new osgGA::TrackballManipulator);
   viewerWindow-setSceneData(root);
   viewerWindow-show();

osg::Camera* createHUD()
{
   osg::Camera* camera = new osg::Camera;
   camera-setProjectionMatrix(osg::Matrix::ortho2D(-1.5, 17.75, -1.5, 13.86));
   camera-setReferenceFrame(osg::Transform::ABSOLUTE_RF);
   camera-setClearMask(GL_DEPTH_BUFFER_BIT);
   camera-setRenderOrder(osg::Camera::POST_RENDER);
   camera-setUpdateCallback(new AxisCameraUpdateCallback);

   osg::Node* axes = osgDB::readNodeFile(axes.osg);
   camera-addChild(axes);

   return camera;
}

class AxisCameraUpdateCallback:public osg::NodeCallback
{
public:
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{
if(nv-getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
{
osg::Camera* camera = dynamic_castosg::Camera*(node);
if (camera)
{
   osg::View* view = camera-getView();
   if (view  view-getNumSlaves()  0)
   {
   osg::View::Slave* slave = view-getSlave(0);
   if(slave-_camera.get() == camera)
   {
   osg::Camera* masterCam = view-getCamera();
   osg::Vec3 eye, center, up;
   masterCam-getViewMatrixAsLookAt(eye, center, up, 30);
   osg::Matrixd matrix;
   matrix.makeLookAt(eye-center, osg::Vec3(0, 0, 0), up); 
// always look at (0, 0, 0)
   camera-setViewMatrix(matrix);
   }
   }
}
}
traverse(node,nv);
}
};




--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29288#29288





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-23 Thread Gianni Ambrosio
I have one question about my posted code. I added

viewerWindow-addSlave(camera, false);

otherwise camera-getView() call in AxisCameraUpdateCallback::operator() 
fails. I didn't find any documentation about that and I tried just intuitively.

Regards
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29289#29289





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-23 Thread Gianni Ambrosio
One more question. Suppose I have two viewers and I would like to show the axes 
just in one of them. Since the camera with the axes model is in the scene, is 
there any flexible way to enable/disable the axes in one viewer?

Regards
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29290#29290





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-23 Thread Jean-Sébastien Guay

Hello Gianni,


One more question. Suppose I have two viewers and I would like to show the axes 
just in one of them. Since the camera with the axes model is in the scene, is 
there any flexible way to enable/disable the axes in one viewer?


You could search the archives for hints of how to display something in 
only one view. It's been discussed before, and there are a few ways to 
do it.


I generally do it by adding the appropriate subgraph (object or HUD 
camera) directly under the master camera of the view in which I want to 
see it (view-getCamera()) instead of under a scene root which is 
visible in all views. I find that easy to manage.


Another way is to add a cull callback which will examine the current 
camera and only traverse the children if it's the right one(s).


Yet another way is with node masks and cull masks in the cullVisitor, 
but you'll run out of bits in a 32-bit node mask pretty fast, especially 
if you use node masks for other things too. Node masks have the 
disadvantage that your whole app needs to know all the node masks in use 
everywhere or else you'll end up with one bit being used for two things 
and will have problems. So they're useful for some things but I wouldn't 
use them for this (personally).


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-23 Thread Gianni Ambrosio
Hi Jean-Sebastien,


Skylark wrote:
 
 So they're useful for some things but I wouldn't 
 use them for this (personally).
 


I agree, if I understood correctly it doesn't make much sense in my case.

Thanks fot the other ways you suggested.

Regards
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29311#29311





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-22 Thread Gianni Ambrosio
Looking around I found a topic that could help but I will ask some help about 
that later.

Now, can anybody explain me please why I don't see the axes object in the 
bottom left corner of the viewer using the following code? I can see the cessna 
plane only in the viewer.

   ViewerQT* viewerWindow = new ViewerQT;
   osg::Group* root = new osg::Group;
   osg::Node* loadedModel = osgDB::readNodeFiles(cessna.osg);
   root-addChild(loadedModel);
   root-addChild(createHUD());
   viewerWindow-setCameraManipulator(new osgGA::TrackballManipulator);
   viewerWindow-setSceneData(root);
   viewerWindow-show();

osg::Camera* createHUD()
{
   osg::Camera* camera = new osg::Camera;
   camera-setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
   camera-setReferenceFrame(osg::Transform::ABSOLUTE_RF);
   camera-setViewMatrix(osg::Matrix::identity());
   camera-setClearMask(GL_DEPTH_BUFFER_BIT);
   camera-setRenderOrder(osg::Camera::POST_RENDER);
   camera-setAllowEventFocus(false);
   osg::Node* axes = osgDB::readNodeFile(axes.osg);
   camera-addChild(axes);
   return camera;
}

Regards
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29260#29260





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] cross axes

2010-06-22 Thread Paul Martz

Gianni Ambrosio wrote:

Looking around I found a topic that could help but I will ask some help about 
that later.

Now, can anybody explain me please why I don't see the axes object in the 
bottom left corner of the viewer using the following code? I can see the cessna 
plane only in the viewer.

 ...

osg::Camera* createHUD()
{
   osg::Camera* camera = new osg::Camera;
   camera-setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
   camera-setReferenceFrame(osg::Transform::ABSOLUTE_RF);
   camera-setViewMatrix(osg::Matrix::identity());
   camera-setClearMask(GL_DEPTH_BUFFER_BIT);
   camera-setRenderOrder(osg::Camera::POST_RENDER);
   camera-setAllowEventFocus(false);
   osg::Node* axes = osgDB::readNodeFile(axes.osg);
   camera-addChild(axes);
   return camera;
}


The axes.osg model has a bounding volume that extends from approximately (0, 0, 
0) to (1, 1, 1). With the transformation you've specified, the model will 
subtend less that one pixel of screen space.


--
  -Paul Martz  Skew Matrix Software
   http://www.skew-matrix.com/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org