[osg-users] Really basic question light/material on surface

2019-04-09 Thread Diego Mancilla
Hello,

 I've playing aorund with some examples on the "OpenSceneGraph 3 Cookbook" by 
Wang and Quian. Specifically, with Chapter 10's "Playing with delaunay 
triangulator".

 Here is the official repository code (with one small modification -commented-)


Code:
int main(int argc, char** argv)
{
osg::ref_ptr va = new osg::Vec3Array(9);
(*va)[0].set(-5.0f, -5.0f, 0.4f);
(*va)[1].set(1.0f, -5.6f, 0.0f);
(*va)[2].set(5.0f, -4.0f, -0.5f);
(*va)[3].set(-6.2f, 0.0f, 4.2f);
(*va)[4].set(-1.0f, -0.5f, 4.8f);
(*va)[5].set(4.3f, 1.0f, 3.0f);
(*va)[6].set(-4.8f, 5.4f, 0.3f);
(*va)[7].set(0.6f, 5.1f, -0.8f);
(*va)[8].set(5.2f, 4.5f, 0.1f);

osg::ref_ptr dt = new 
osgUtil::DelaunayTriangulator;
dt->setInputPointArray(va.get());
dt->setOutputNormalArray(new osg::Vec3Array);
dt->triangulate();

osg::ref_ptr geometry = new osg::Geometry;
geometry->setVertexArray(dt->getInputPointArray());
geometry->setNormalArray(dt->getOutputNormalArray());
geometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET); // 
original code setted osg::Geometry::BIND_PER_PRIMITIVE.
geometry->addPrimitiveSet(dt->getTriangles());

osg::ref_ptr geode = new osg::Geode;
geode->addDrawable(geometry.get());

osgViewer::Viewer viewer;
viewer.setSceneData(geode.get());

return viewer.run();
}



So in the book, they show the following a snapshot of the result of the example 
(attached). The image shows that the "material/color" is responsive to "depth" 
(sorry if I'm using wrong terms).

But when I compile and run the example, the result is no responsive to "depth". 
Clearly it responds to light, as the bottom looks black and when I rotate it 
the surface color begins to show. For instance, I cannot differentiate between 
the faces as is shown on the books snapshot (see attachment).

So my question is really basic. What I'm doing wrong? or what I'm missing?
Bottomline is, how can I create a basic colored material that responds to the 
default light on a osg::Viewer as shown in the book?  


Thank you!

Cheers,

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




Attachments: 
http://forum.openscenegraph.org//files/my_result_121.jpg
http://forum.openscenegraph.org//files/forum_osg_1_466.png


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


Re: [osg-users] Colored Bounding Box over osgText::Text

2019-04-06 Thread Diego Mancilla
Hello,

 I've found a workaround my problem. I had to inherit a class from 
osgText::Text and override the drawImplementation method like so:


Code:
void MyTextNode::drawImplementation(osg::RenderInfo& renderInfo) const
{
osg::Vec4 color = getColor(); # stored custom color
osgText::Text::drawImplementation(*renderInfo.getState(), color);
} 



Cheers,

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





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


[osg-users] Colored Bounding Box over osgText::Text

2019-04-05 Thread Diego Mancilla
Hello,

I'm trying to draw a bounding box around a osgText::Text instance. Setting the 
draw mode to 'osgText::Text::TEXT|osgText::Text::BOUNDINGBOX' draws a white box 
around the text. Does anyone knows a simple way to get this box color match the 
text color? Or, better yet, a way to draw the box myself? The text is dynamic 
in nature, so I need to be able to resize the box as the text changes. 

 I look at the osgText::Text source code but there is too much GL stuff for a 
newbie like me.

 Any help will be very much appreciated.

Thank you!

Cheers.

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





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


[osg-users] osgText::Text dissapears when reparent container window on qt

2019-03-27 Thread Diego Mancilla
Hello,

 This is a mixed OSG/Qt question. I asked first here due to previous 
experiences with the community. 

 I'm following a minimal example of embedding OSG into a Qt5 application from 
https://gist.github.com/vicrucann/874ec3c0a7ba4a814bd84756447bc798. When I 
modify that example, and add a simple osgText::Text to the base Geode 
everything works as expected. But If I ,additionally, encapsulate the OSG 
Widget (a widget derived from QOpenGLWidget) on a QDockWidget and undock it, 
the text dissapears.

 Can someone point me out what could be the problem?

The code:


Code:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#include 
#include 

class QtOSGWidget : public QOpenGLWidget
{
public:
  QtOSGWidget(qreal scaleX, qreal scaleY, QWidget* parent = 0)
  : QOpenGLWidget(parent)
, _mGraphicsWindow(new osgViewer::GraphicsWindowEmbedded( this->x(), 
this->y(),
 this->width(), 
this->height() ) )
, _mViewer(new osgViewer::Viewer)
  , m_scaleX(scaleX)
  , m_scaleY(scaleY)
  {
osg::Cylinder* cylinder= new osg::Cylinder( osg::Vec3( 0.f, 0.f, 
0.f ), 0.25f, 0.5f );
osg::ShapeDrawable* sd = new osg::ShapeDrawable( cylinder );
sd->setColor( osg::Vec4( 0.8f, 0.5f, 0.2f, 1.f ) );
osg::Geode* geode = new osg::Geode;
geode->addDrawable(sd);

// adding text to the visualization
osgText::Text * test = new osgText::Text();
test->setDataVariance(osg::Object::DYNAMIC);

test->setCharacterSize(1.0);
test->setColor(osg::Vec4(0.0, 0.0, 0.0, 1.0));
test->setAlignment(osgText::Text::CENTER_BOTTOM);
test->setAxisAlignment(osgText::TextBase::SCREEN);
test->setCharacterSizeMode(osgText::Text::OBJECT_COORDS);
test->setText("CYLINDER");
geode->addDrawable(test);
// end adding text

osg::Camera* camera = new osg::Camera;
camera->setViewport( 0, 0, this->width(), this->height() );
camera->setClearColor( osg::Vec4( 0.9f, 0.9f, 1.f, 1.f ) );
float aspectRatio = static_cast( this->width()) / 
static_cast( this->height() );
camera->setProjectionMatrixAsPerspective( 30.f, aspectRatio, 1.f, 
1000.f );
camera->setGraphicsContext( _mGraphicsWindow );

_mViewer->setCamera(camera);
_mViewer->setSceneData(geode);
osgGA::TrackballManipulator* manipulator = new 
osgGA::TrackballManipulator;
manipulator->setAllowThrow( false );
this->setMouseTracking(true);
_mViewer->setCameraManipulator(manipulator);
_mViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
   // _mViewer->realize();
  }


  virtual ~QtOSGWidget(){}

  void setScale(qreal X, qreal Y)
  {
  m_scaleX = X;
  m_scaleY = Y;
  this->resizeGL(this->width(), this->height());
  }

protected:

  virtual void paintGL() {
_mViewer->frame();
  }

  virtual void resizeGL( int width, int height ) 
  {
  this->getEventQueue()->windowResize(this->x()*m_scaleX, this->y() * 
m_scaleY, width*m_scaleX, height*m_scaleY);
  _mGraphicsWindow->resized(this->x()*m_scaleX, this->y() * m_scaleY, 
width*m_scaleX, height*m_scaleY);
  osg::Camera* camera = _mViewer->getCamera();
  camera->setViewport(0, 0, this->width()*m_scaleX, this->height()* 
m_scaleY);
  }

  virtual void initializeGL(){
  osg::Geode* geode = dynamic_cast(_mViewer->getSceneData());
  osg::StateSet* stateSet = geode->getOrCreateStateSet();
  osg::Material* material = new osg::Material;
  material->setColorMode( osg::Material::AMBIENT_AND_DIFFUSE );
  stateSet->setAttributeAndModes( material, osg::StateAttribute::ON );
  stateSet->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON );
  }

  virtual void mouseMoveEvent(QMouseEvent* event)
  {
  this->getEventQueue()->mouseMotion(event->x()*m_scaleX, 
event->y()*m_scaleY);
  }

  virtual void mousePressEvent(QMouseEvent* event)
  {
  unsigned int button = 0;
  switch (event->button()){
  case Qt::LeftButton:
  button = 1;
  break;
  case Qt::MiddleButton:
  button = 2;
  break;
  case Qt::RightButton:
  button = 3;
  break;
  default:
  break;
  }
  this->getEventQueue()->mouseButtonPress(event->x()*m_scaleX, 
event->y()*m_scaleY, button);
  }

  virtual void mouseReleaseEvent(QMouseEvent* event)
  {
  unsigned int button = 0;
  switch (event->button()){
  case Qt::LeftButton:
  button = 1;
  break;
  case Qt::MiddleButton:
  button = 2;
  break;
  case Qt::RightButton:
  button = 3;
  break

Re: [osg-users] Get Animation current time

2019-01-08 Thread Diego Mancilla
Hello Robert,

Thank you again.

 It turns out that I forgot to initialize the _timeMultiplier variable on the 
constructor of my AnimationPath class. Also I had a problem with some crazy 
references retrieved wrongly: for some reason on a "for (auto e: stl_map)..." 
loop, &e.second, was not getting the rigth address for the mapped value) so I 
change the loop and everything works now.

 When I use the original approach (filling control points on standard 
AnimationPath) my code took about a minute per mobile object. Now, as the data 
is referenced the time involved is almost zero.

Cheers,

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





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


Re: [osg-users] Get Animation current time

2019-01-07 Thread Diego Mancilla
Hello Robert,

Thank you very much for you complete response.

 I'm trying to do what you suggest and have my on 
AnimationPath/AnimationPathCallback classes that handle my data. But I stumble 
into a problem.

 When I subclass AnimationPath and AnimationPathCallback I have no problems. 
But when I wrote my own classes, from scratch my application crashes.

 In order to achieve what I want, I pass a pointer to a custom data container 
class to my AnimationPath class (I called it MobilesAnimationPath) from my main 
application. I tried to keep most part of the architecture of AnimationPath, 
but I eliminate the TimeControlPointMap container. So, now my class generates 
the control points from the data pointed from custom data pointer class. 


So, for instance, my custom Path class looks like this:


Code:
#include "MobileObject.h"
#include 
#include 

using namespace osg;

class MobilesAnimationPath: public virtual osg::Object
{
public:
MobilesAnimationPath();
MobilesAnimationPath(const MobilesAnimationPath &, const osg::CopyOp & 
copyop = osg::CopyOp::SHALLOW_COPY);
MobilesAnimationPath(MobileObject & mobile);

META_Object(osg, MobilesAnimationPath); //Visual Studio complains about 
this line, but compiles... : "function definition for META_Object not found"

enum LoopMode
{
SWING,
LOOP,
NO_LOOPING
};

void setLoopMode(LoopMode loopMode);
LoopMode getLoopMode() const;

virtual bool getInterpolatedControlPoint(double time, 
osg::AnimationPath::ControlPoint & cp) const;

double getFirstTime() const;
double getLastTime() const;
double getPeriod() const;

protected:
~MobilesAnimationPath(){};

private:
MobileObject * _mobile;
LoopMode _loopMode;

};



And the implementation.


Code:
#include "MobilesAnimationPath.h"

MobilesAnimationPath::MobilesAnimationPath()
:_loopMode(NO_LOOPING)
,_mobile(nullptr)
{
}


MobilesAnimationPath::MobilesAnimationPath(const MobilesAnimationPath& ap, 
const osg::CopyOp& copyop)
:osg::Object(ap, copyop)
,_loopMode(ap._loopMode)
,_mobile(ap._mobile) 
{
}

MobilesAnimationPath::MobilesAnimationPath(MobileObject & mobile)
:_loopMode(NO_LOOPING)
{
_mobile = &mobile;
}

void MobilesAnimationPath::setLoopMode(LoopMode loopMode)
{
_loopMode = loopMode;
}

MobilesAnimationPath::LoopMode MobilesAnimationPath::getLoopMode() const
{
return _loopMode;
}

double MobilesAnimationPath::getFirstTime() const
{
if (_mobile != nullptr)
{
if (_mobile->dataLoaded())
{
return _mobile->getFirstTime();
}
}
return 0.0;
}

double MobilesAnimationPath::getLastTime() const
{
if (_mobile != nullptr)
{
if (_mobile->dataLoaded())
{
return _mobile->getLastTime();
}
}
return 0.0;
}

double MobilesAnimationPath::getPeriod() const
{
if (_mobile != nullptr)
{
if (_mobile->dataLoaded())
{
return _mobile->getFirstTime() - _mobile->getLastTime();
}
}
return 0.0;
}

bool MobilesAnimationPath::getInterpolatedControlPoint(double time, 
osg::AnimationPath::ControlPoint & cp) const
{
if (_mobile == nullptr) return false;
if (!_mobile->dataLoaded()) return false;

// at this point _mobile points something thats not nullptr but returns 
garbage...

switch (_loopMode)
{
case(SWING):
{
double modulated_time = (time - getFirstTime()) / 
(getPeriod()*2.0);
double fraction_part = modulated_time - floor(modulated_time);
if (fraction_part > 0.5) fraction_part = 1.0 - fraction_part;

time = getFirstTime() + (fraction_part*2.0) * getPeriod();
break;
}
case(LOOP):
{
double modulated_time = (time - getFirstTime()) / getPeriod();
double fraction_part = modulated_time - floor(modulated_time);
time = getFirstTime() + fraction_part * getPeriod();
break;
}
case(NO_LOOPING):
// no need to modulate the time.
break;
}

//... here I fill the control point through the data on _mobile.

return true;


}



but at the first call to "getInterpolatedControlPoint" the application crashes. 
Moreover, the _mobile pointer is "corrupted", i.e., when I try to access its 
data it returns garbage (but it not nullptr). Also the "time" value passed is 
random (sometimes huge, sometimes negative, etc...)

As I pointed on the code snippet, MSVS complains about my META_Object call, but 
the code compiles.

Re: [osg-users] Get Animation current time

2019-01-04 Thread Diego Mancilla
Hello Robert,

Thank you again for your answer.

Regarding your question "the AnimationPathCallback::update method)?": yes, from 
the source:


Code:
void AnimationPathCallback::update(osg::Node& node)
{
AnimationPath::ControlPoint cp;
if (_animationPath->getInterpolatedControlPoint(getAnimationTime(),cp))
{
AnimationPathCallbackVisitor apcv(cp,_pivotPoint,_useInverseMatrix);
node.accept(apcv);
}
}




 I ended up writing my own AnimationPathCallback for manipulating the animation 
time though the variables _firstTime, _latestTime and _timeOffset; and exposing 
 AnimationPathCallbackVisitor class to my code in order to force position 
changes. Maybe my solution is rather far-fetched, but for now it works. Also, 
I'm using a dummy AnimationPathCallback in order to expose current animation 
time to Qt.

I have another question rather technical. As per now a have a lot of moving 
objects. I'm using standard AnimationPath instances for each one of them. Also 
y have a lot a control points for each one (20k+). So filling the 
AnimationPaths instances is very slow. Then:

1- Can I using OpenMP or standard Qt threading parallelize the insertion of 
control points?
2- Are osg classes threadsafe? I mean, can I send the generation (filling) of 
each AnimationPath on a different thread (and then use the addChild method)?
3- Is there another alternative to improve performance on this matter? 


Cheers,

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





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


Re: [osg-users] Get Animation current time

2018-12-28 Thread Diego Mancilla
Hello Robert,

First of all, thank you for your answer. I'm just starting to use OSG so I'm 
learning  as I go.

So, my issue is a little more complicated (I think).

I have serveral AnimationPath instances. Each one with a AnimationPathCallback 
derived class attached to it. So, the thing is that I want to retrieve current 
animation time to the main application, ideally without having to traverse each 
animated node.

Context:

I have a Qt app with an osg::Viewer embedded (subclassing QOpenGLWidget), so 
the objective is to handle the "animation timeline" through a QSlider.

So:
1 - Can I, from the osg::FrameStamp instance "reconstruct" the current 
animation time from the AnimationPath instances or from anywhere else?

2- Besides the "while (!viewer.done())..." loop, is there a way to control the 
time sampling of the animation? i.e. the times at which the 
AnimationPath::getInterpolatedControlPoint method is called (from the 
AnimationPathCallback::update method)?

Thank you again, for your help.

Cheers,
Diego

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





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


[osg-users] Get Animation current time

2018-12-27 Thread Diego Mancilla
Hello,

I have several AnimationPath intances for a number of moving objects. Each 
object has the same number of ControlPoints on their path.
 
I need to know if there is a proper way to retrieve the current time of the 
animation (using a callback, for instance). I need this number in order to 
display it on another part of the main application (Qt app). 

Any pointers will be very much appreciated.

Thank you!

Cheers,

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





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


Re: [osg-users] Colors on GL_LINES

2018-12-24 Thread Diego Mancilla
Hello ravidavi,

 Thank you for your answer. Your suuggestion solved my problem.


Cheers,

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





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


[osg-users] Colors on GL_LINES

2018-12-23 Thread Diego Mancilla
Hello,

 I'm drawing some simple lines on osg. So far I have successfully draw the 
lines and set a single color for each of them... but when I rotate the view the 
color is shown only on one direction of the camera, for instance, if rotate on 
180 degrees the view, all lines are shown in black (looking from "down")... how 
can I get that the color of the lines is correctly shown regardless of the 
position/orientation of the camera on the viewer?



Code:
osg::Geode * root = getRoot();
osg::Vec4Array * color = new osg::Vec4Array;
double r, g, b, a;
r = 1.0;
g = 0.0;
b = 0.0;
a = 1.0;
color->push_back(osg::Vec4d(r, g, b, a)); //single color 
osg::Vec3Array* osg_points = new osg::Vec3Array;
...
Here I fill the vertex array
...
osg::Geometry* line_geometry = new osg::Geometry;
line_geometry->setVertexArray(osg_points); //osg_points has the points of the 
lines
line_geometry->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP, 0, 
osg_points->size()));
line_geometry->setColorArray(color);
line_geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
root->addDrawable(line_geometry);



Thank you!

Cheers,

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





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


Re: [osg-users] Working with osg::Text on animation

2018-12-20 Thread Diego Mancilla
Hello ravidavi,

 Thank you for your your answer.

 What you suggest can be accomplish by the use a visitor or a callback?: Lets 
say that I want to change show/hide the text when the user press a key, 
moreover, if some of the text for  nodes (cessna) should be shown/hidden with 
some key  and others (glider) with another. And at the same time, each text 
varies in time (like if they were their positions)...How can I accomplish this?

Cheers,



ravidavi wrote:
> If you will be dynamically changing your text, then specify that when you 
> first create it:    osgText::Text* text = new osgText::Text;
>     text->setDataVariance(osg::Object::DYNAMIC);
> Note that setting the data variance isimportant for multithreaded Viewers 
> (http://forum.openscenegraph.org/viewtopic.php?t=10441&view=next).
> 
> 
> Then you can change the text easily:
>     text->setText("insert dynamically-generated string here");
> 
> 
> You can show/hide the text with its node mask:
>     text->setNodeMask(0x0); // NodeMask = 0 to hide
>     text->setNodeMask(~0x0); // NodeMask = 0x to show
> 
> 
> Hope that helps,
> Ravi
> 
> 
> 
> On Thu, Dec 20, 2018 at 8:39 AM Diego Mancilla < ()> wrote:
> 
> 
> > Hello,
> > 
> >  I have a couple of doubts regarding the proper way of handling osg::Text 
> > inside an animation.
> > 
> >  For the sake of simplicity lets say we are working on the osganimate 
> > example, and we have multiple cessna moving around.
> > 
> > 1- What is the proper way of changing the text of osg::Text on runtime? For 
> > instance, if I want to display current position of cessna.
> > 
> > 2- How can I hide/show the current value of the text on user request (stoke 
> > of key for example). 
> > 
> > Thank you!
> > 
> > Cheers,
> > 
> > --
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=75329#75329 
> > (http://forum.openscenegraph.org/viewtopic.php?p=75329#75329)
> > 
> > 
> > 
> > 
> > 
> > ___
> > osg-users mailing list
> >  ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 
> > (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=75334#75334





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


Re: [osg-users] Working with osg::Text on animation

2018-12-20 Thread Diego Mancilla
Hello ravi,

 Thank you for your your answer.

 What you suggest can be accomplish by the use a visitor or a callback?: Lets 
say that I want to change show/hide the text when the user press a key, 
moreover, if some of the text for  nodes (cessna) should be shown/hidden with 
some key  and others (glider) with another. And at the same time, each text 
varies in time (like if they were their positions)...How can I accomplish this?

Cheers,



ravidavi wrote:
> If you will be dynamically changing your text, then specify that when you 
> first create it:    osgText::Text* text = new osgText::Text;
>     text->setDataVariance(osg::Object::DYNAMIC);
> Note that setting the data variance isimportant for multithreaded Viewers 
> (http://forum.openscenegraph.org/viewtopic.php?t=10441&view=next).
> 
> 
> Then you can change the text easily:
>     text->setText("insert dynamically-generated string here");
> 
> 
> You can show/hide the text with its node mask:
>     text->setNodeMask(0x0); // NodeMask = 0 to hide
>     text->setNodeMask(~0x0); // NodeMask = 0x to show
> 
> 
> Hope that helps,
> Ravi
> 
> 
> 
> On Thu, Dec 20, 2018 at 8:39 AM Diego Mancilla < ()> wrote:
> 
> 
> > Hello,
> > 
> >  I have a couple of doubts regarding the proper way of handling osg::Text 
> > inside an animation.
> > 
> >  For the sake of simplicity lets say we are working on the osganimate 
> > example, and we have multiple cessna moving around.
> > 
> > 1- What is the proper way of changing the text of osg::Text on runtime? For 
> > instance, if I want to display current position of cessna.
> > 
> > 2- How can I hide/show the current value of the text on user request (stoke 
> > of key for example). 
> > 
> > Thank you!
> > 
> > Cheers,
> > 
> > --
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=75329#75329 
> > (http://forum.openscenegraph.org/viewtopic.php?p=75329#75329)
> > 
> > 
> > 
> > 
> > 
> > ___
> > osg-users mailing list
> >  ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org 
> > (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=75333#75333





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


[osg-users] Working with osg::Text on animation

2018-12-20 Thread Diego Mancilla
Hello,

 I have a couple of doubts regarding the proper way of handling osg::Text 
inside an animation.

 For the sake of simplicity lets say we are working on the osganimate example, 
and we have multiple cessna moving around.

1- What is the proper way of changing the text of osg::Text on runtime? For 
instance, if I want to display current position of cessna.

2- How can I hide/show the current value of the text on user request (stoke of 
key for example). 

Thank you!

Cheers,

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





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


Re: [osg-users] Speeding u/down animation smoothly

2018-12-06 Thread Diego Mancilla
Hi,

Thank you for your answer mp3butcher.

 Regarding the math issue: actually the arithmethic is correct in my code, the 
problem, as I found, was that the _latestTime and _fisrtTime in the 
AnimationPathCallback won't match the ones provided in AnimationPath, so I 
subclassed AnimationPathCallback providing access to mentioned members and 
extract them from the callback (instead of the path) and it finally worked.

 Regarding your second post, to be honest I didnt understand.

 I'm just a newbie on OSG and the lack of proper documentation is becoming 
quite a problem (for me at least). 



Cheers,

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





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


[osg-users] Speeding u/down animation smoothly

2018-12-05 Thread Diego Mancilla
Hello,

I'm trying to sppeding up/down an animation using AnimationPathCallback. The 
idea is to pause/speed/up/down the animation using key strokes, for this I have 
a GuiEventHandler derived class and a NodeVisitor derived class. So far I've 
playing round with the base clases AnimationPath and AnimationPathCallback 
methods get/setStartTime, get/setTimeOffset, get/setLastTime and 
get/settimeMultiplier with no success.

 I found http://forum.openscenegraph.org/viewtopic.php?t=10014 but my 
implementation still jumps around when speeding up/down:


Code:
void AnimationVisitor::apply(osg::Transform& transform)
{
osg::AnimationPathCallback* apc = 
dynamic_cast(transform.getUpdateCallback());

if (apc)
{
osg::AnimationPath * path = apc->getAnimationPath();
int key = getKey();
double lambda;
switch (key)
{
case osgGA::GUIEventAdapter::KEY_Space:
{
bool is_paused = apc->getPause();
apc->setPause(!is_paused);
std::cout << "Animation time: " << 
apc->getAnimationTime() << std::endl;
std::cout << "\tPause: " << !is_paused << std::endl;
std::cout << "---" << std::endl;
break;
}
case osgGA::GUIEventAdapter::KEY_Right:
{
double last = path->getLastTime();
double first = path->getFirstTime();
lambda = apc->getTimeMultiplier();
double simTime = last - first;
double currOffset = apc->getTimeOffset();
double offset = simTime - (simTime - currOffset) / 1.1;
apc->setTimeMultiplier(1.1*lambda);
apc->setTimeOffset(offset);
std::cout << "Animation time: " << 
apc->getAnimationTime() << std::endl;
std::cout << "\tSpeed up: : " << lambda * 1.1 << 
std::endl;
std::cout << "---" << std::endl;
break;
}
case osgGA::GUIEventAdapter::KEY_Left:
{
double last = path->getLastTime();
double first = path->getFirstTime();
lambda = apc->getTimeMultiplier();
double simTime = last - first;
double currOffset = apc->getTimeOffset();
double offset = simTime - (simTime - currOffset) * 0.9;
apc->setTimeMultiplier(0.9*lambda);
apc->setTimeOffset(offset);
std::cout << "Animation time: " << 
apc->getAnimationTime() << std::endl;
std::cout << "\tSpeed up: : " << lambda * 0.9 << 
std::endl;
std::cout << "---" << std::endl;
break;
}
default:
break;
}

}
traverse(transform);
}


   

Can anyone give some pointers about how to achieve a smooth speeding 
transition? I look up in the source code of both classes involved 
(AnimationPath and AnimationPathCallback) but I havent been able to figure out 
a solution. What can I do? or What am I missing?

Thank you!

Cheers

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





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


Re: [osg-users] Update node color on demand

2018-11-26 Thread Diego Mancilla
Hello Trajce,

 The visitor class implementation is on my previous post on this thread. I took 
that code from Gordon Tomlison's OSG Samples, and it works when is used 
previous to the rendering as you can see on my initial post (other thread: 
http://forum.openscenegraph.org/viewtopic.php?p=75209#75209).


 As I said everything gets called when it should, but on runtime, the lines 
wont change color. I you look at the code snippet of my main:

 

Code:
_lines = osgDB::readNodeFile("lines.dxf"); 
_topo->setDataVariance(osg::Object::DYNAMIC); 
osg::Geode* geode = new osg::Geode; 

_mViewer->addEventHandler(new ColorHandler); 

ColorVisitor newColor; 
newColor.setColor( 1.0f, 0.0f, 0.0f ); 
_lines->accept(newColor); 
geode->addChild(_lines); 
_mViewer->realize();



The color of the lines turns red on start. But then, when I try to change it to 
another color on runetime, nothing happens.

Anyway, here is the visitor implementation (.cpp):


Code:
ColorVisitor::ColorVisitor(): 
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) 
{ 
m_color.set(1.0, 1.0, 1.0, 1.0); 
m_colorArrays = new osg::Vec4Array; 
m_colorArrays->push_back(m_color); 
}; 

ColorVisitor::ColorVisitor(const osg::Vec4 &color): 
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) 
{ 
m_color = color; 
m_colorArrays = new osg::Vec4Array; 
m_colorArrays->push_back(m_color); 

}; 

ColorVisitor::~ColorVisitor() 
{ 
}; 

void ColorVisitor::apply(osg::Node &node) { 
//  
// 
//  Handle traversal of osg::Node node types 
// 
//  
traverse(node); 
}; 

void ColorVisitor::apply(osg::Geode &geode) { 
//  
// 
//  Handle traversal of osg::Geode node types 
// 
//  

osg::StateSet *state = NULL; 
unsigned intvertNum = 0; 
//  
//  We need to iterate through all the drawables check if 
//  the contain any geometry that we will need to process 
// 

unsigned int numGeoms = geode.getNumDrawables(); 

for (unsigned int geodeIdx = 0; geodeIdx < numGeoms; geodeIdx++) 
{ 
// 
// Use 'asGeometry' as its supposed to be faster than a dynamic_cast 
// every little saving counts 
// 
osg::Geometry *curGeom = geode.getDrawable(geodeIdx)->asGeometry(); 
// 
// Only process if the drawable is geometry 
// 
if (curGeom) 
{ 
osg::Vec4Array *colorArrays = dynamic_cast(curGeom->getColorArray()); 
if (colorArrays) { 
for (unsigned int i = 0; i < colorArrays->size(); i++) 
{ 
osg::Vec4 *color = &colorArrays->operator [](i); 
// 
// could also use *color = m_color 
// 
color->set(m_color._v[0], m_color._v[1], m_color._v[2], 
m_color._v[3]); 
} 

} 
else 
{ 
curGeom->setColorArray(m_colorArrays.get()); 
curGeom->setColorBinding(osg::Geometry::BIND_OVERALL); 
} 
} 
} 
}; 

void ColorVisitor::setColor(const float r, const float g, const float b, const 
float a) 
{ 
// --- 
// 
// Set the color to change apply to the nodes geometry 
// 
// --- 
osg::Vec4 *c = &m_colorArrays->operator [](0); 
m_color.set(r, g, b, a); 
*c = m_color; 
}; 

void ColorVisitor::setColor(const osg::Vec4 &color) { 
// --- 
// 
// Set the color to change apply to the nodes geometry 
// 
// --- 
osg::Vec4 *c = &m_colorArrays->operator [](0); 
m_color = color; 
*c = m_color; 
};





Cheers,

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





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


Re: [osg-users] Update node color on demand

2018-11-26 Thread Diego Mancilla
Hello,

I have tried Eran's suggestion with no success. I have successfully created the 
handler, and it gets called but no color change...

My current code:

On main:

Code:
_lines = osgDB::readNodeFile("lines.dxf");
_topo->setDataVariance(osg::Object::DYNAMIC);
osg::Geode* geode = new osg::Geode;

_mViewer->addEventHandler(new ColorHandler);

ColorVisitor newColor;
newColor.setColor( 1.0f, 0.0f, 0.0f );
_lines->accept(newColor);
geode->addChild(_lines);
_mViewer->realize();




The handler:


Code:
bool ColorHandler::handle(const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter& aa)
{
if (ea.getEventType() == ea.USER)
{
auto changeColorEvent = dynamic_cast(ea.getUserData());
if (changeColorEvent != nullptr)
{
std::cout << "Hola Handler!!!" << std::endl;
std::cout << "new color: " << changeColorEvent->r<<" 
"<< changeColorEvent->g<< " "<< changeColorEvent->bg, changeColorEvent->b);
changeColorEvent->node->accept(newColor);
return true;
}
}
return false;



Thank you!

Cheers,
Diego

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





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


Re: [osg-users] Update node color on demand

2018-11-26 Thread Diego Mancilla
Hello Eran,

 Thank you again.

 I will try what you suggest. 

Cheers,

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





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


Re: [osg-users] Update node color on demand

2018-11-24 Thread Diego Mancilla
Hello Eran,

 Thank you very much for your answer. I should have been more explicit, due to 
the fact than I'm a newbie on OSG (and 3D development).

 I have an OSG viewer embedded on a Qt5 application. So the idea is that the 
user can change the color of one node (some dxf lines) on demand though the GUI 
(some dialog, pushing buttons, etc). So, bottom line... at some point at 
runtime I have a fresh new color (rgb, for instance) and I need to pass it to 
the viewer towards the "_lines" node. As I previuosly stated I'm new to OSG and 
I'm just digesting the scene graph scheme.

 So, how can I pass this information from the Qt5 environment, to the to the 
node using your suggestions?


Thank you in advance!

Cheers,

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





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


[osg-users] Update node color on demand

2018-11-24 Thread Diego Mancilla
Hello,

I'm trying to change a node color on demand from my application. The idea is 
that the user, once the initial rendering took place can change the color of a 
node by pressing a key (or something similar). I know already hoy to change the 
color using a NodeVisitor (previous to the rendering). 


Code:
ColorVisitor newColor;
newColor.setColor(r, g, b);
_lines->accept(newColor);



Where _lines is a Node reference pointer and ColorVisitor is a subclass of 
NodeVisitor (http://forum.openscenegraph.org/viewtopic.php?p=75209#75209).

I tried to create a callback and attach it to the node but the callback get 
called every time and I cant pass to it the selected color on runtime.

Can anyone give some pointer about this issue?

Thank you!

Cheers,
[/url]

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





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


Re: [osg-users] Change color of node read from dxf file

2018-11-20 Thread Diego Mancilla
Hi,

The suggestion of Chris solve the problem.

The actual code:


Code:
osg::Node* lines = osgDB::readNodeFile("lines.dxf");
osg::Geode* geode = new osg::Geode;

ColorVisitor newColor;
newColor.setColor( 1.0f, 0.0f, 0.0f );
topography->accept(newColor);

geode->addChild(lines); 
_mViewer->setSceneData(geode);
_mViewer->realize();




Where ColorVisitor is a derived class from osg::NodeVistor:


Code:


class ColorVisitor : public osg::NodeVisitor
{
public:
ColorVisitor();
ColorVisitor(const osg::Vec4 &color);
virtual ~ColorVisitor();
virtual void ColorVisitor::apply(osg::Node &node);
virtual void ColorVisitor::apply(osg::Geode &geode);
virtual void ColorVisitor::setColor(const float r, const float g, const float 
b, const float a = 1.0f);
virtual void ColorVisitor::setColor(const osg::Vec4 &color);

private:
osg::Vec4 m_color;
osg::ref_ptr< osg::Vec4Array > m_colorArrays;



and the implementation:


Code:

#include "ColorVisitor.h"

ColorVisitor::ColorVisitor(): 
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {
m_color.set(1.0, 1.0, 1.0, 1.0);
m_colorArrays = new osg::Vec4Array;
m_colorArrays->push_back(m_color);
};

ColorVisitor::ColorVisitor(const osg::Vec4 &color): 
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN){
m_color = color;
m_colorArrays = new osg::Vec4Array;
m_colorArrays->push_back(m_color);
};

ColorVisitor::~ColorVisitor(){};

void ColorVisitor::apply(osg::Node &node) {
traverse(node);
};

void ColorVisitor::apply(osg::Geode &geode) {
osg::StateSet *state = NULL;
unsigned int vertNum = 0;
unsigned int numGeoms = geode.getNumDrawables();

for (unsigned int geodeIdx = 0; geodeIdx < numGeoms; geodeIdx++) {
if (curGeom) {
osg::Vec4Array *colorArrays = dynamic_cast(curGeom->getColorArray());
if (colorArrays) {
for (unsigned int i = 0; i < colorArrays->size(); i++) {
osg::Vec4 *color = &colorArrays->operator [](i);
color->set(m_color._v[0], m_color._v[1], m_color._v[2], m_color._v[3]);
}
}
else {
curGeom->setColorArray(m_colorArrays.get());
curGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
}
}
}
};

void ColorVisitor::setColor(const float r, const float g, const float b, const 
float a) {

osg::Vec4 *c = &m_colorArrays->operator [](0);
m_color.set(r, g, b, a);
*c = m_color;

};

void ColorVisitor::setColor(const osg::Vec4 &color) {

osg::Vec4 *c = &m_colorArrays->operator [](0);
m_color = color;
*c = m_color;
};



The ColorVistor class I took it from Gordon Tomlison's OSG Samples (cant post 
links yet)

One thing stills bother me. If I dont use the line 
Code:
geode->addChild(lines)

 and instead I pass directly the node to the viewer

Code:
_mViewer->setSceneData(lines);

 the application crashes. Can anyone tell why this is happening? 

Thank you!
PS: Sorry I coudnt get the code blocks indented... :(

Cheers,

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





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


Re: [osg-users] Change color of node read from dxf file

2018-11-20 Thread Diego Mancilla
Hello Chris,

Thank you for your answer. 

 My code, actually compiles, nevertheless I was expecting a conceptual error 
from my side.

 I will try what you suggest.

Cheers,

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





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


[osg-users] Change color of node read from dxf file

2018-11-19 Thread Diego Mancilla
I'm a newbie on OpenSceneGraph and 3D development.

 I have a dxf file that contains a bunch of 3DPOLYLINES (with different 
colors). So far I have been able to read and display them on a viewer, but I 
haven been able to change the color of the rendered lines. I believe that I'm 
not understanding properly the graph relationships.

 I'm  using the "Quick Start Guide" as reference and modifying an example that 
I found on the web.

 A code snippet of what I have:


Code:
osg::ref_ptr geom = new osg::Geometry;
osg::ref_ptr c = new osg::Vec4Array;
geom->setColorArray(c.get());
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
c->push_back(osg::Vec4(1.f, 0.f, 0.f, 1.f));

osg::ref_ptr n = new osg::Vec3Array;
geom->setNormalArray(n.get());
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
n->push_back(osg::Vec3(0.f, -1.f, 0.f));

osg::Node* lines = osgDB::readNodeFile("lines.dxf");
osg::Geode* geode = new osg::Geode;

geode->addChild(lines);
geode->addDrawable(geom.get());

std::cout << "Num Drawables in geode: " << geode->getNumDrawables() << 
std::endl;

osg::Camera* camera = new osg::Camera;
camera->setViewport(0, 0, this->width(), this->height());
camera->setClearColor(osg::Vec4(0.9f, 0.9f, 1.f, 1.f));
float aspectRatio = static_cast(this->width()) / 
static_cast(this->height());
camera->setProjectionMatrixAsPerspective(30.f, aspectRatio, 1.f, 1000.f);
camera->setGraphicsContext(_mGraphicsWindow);

_mViewer->setCamera(camera);
_mViewer->setSceneData(geode);
osgGA::TrackballManipulator* manipulator = new osgGA::TrackballManipulator;
manipulator->setAllowThrow(false);
this->setMouseTracking(true);
_mViewer->setCameraManipulator(manipulator);
_mViewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
_mViewer->realize();



Thank you!

Cheers.

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





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