OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

PositionAttitudeTransform and NodeTrackerManipulator seem confused (I helped)


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgOcean [osgOcean]
View previous topic :: View next topic  
Author Message
tim (tim paige)
User


Joined: 25 Feb 2009
Posts: 31
Location: San Diego

PostPosted: Wed Mar 16, 2011 8:54 pm    Post subject:
PositionAttitudeTransform and NodeTrackerManipulator seem confused (I helped)
Reply with quote

Hi,

I am using oceanExample, and modified the boat transform to use a PositionAttitudeTransform instead of the MatrixTransform just because I wanted to learn a bit more and eventually go underwater with my model and fly around with perspective...

I was successful at orienting my boat and getting it placed at the right level and heading, and then desired to make it move. I used the callback to update the "y" direction in the transform, and my boat casually drifts away into the sunset.
Code:

        if(boat.valid())
        {
            boat->setNodeMask( scene->getOceanScene()->getNormalSceneMask() |
                scene->getOceanScene()->getReflectedSceneMask() |
                scene->getOceanScene()->getRefractedSceneMask() );

            osg::ref_ptr<osg::PositionAttitudeTransform> boatTransform = new osg::PositionAttitudeTransform;
            //Name that NODE!
            boatTransform->setName("BOAT");
            boatTransform->addChild(boat.get());

            const osg::BoundingSphere& bs = boat->getBound();
            boatTransform->setPivotPoint(bs.center());

            osg::Vec3 boatPosit(0,100,1.5);
            boatTransform->setPosition( boatPosit );
            boatTransform->setAttitude(osg::Quat( osg::DegreesToRadians(90.0) , osg::Vec3(0,0,1) ));

            boatTransform->setUpdateCallback( new BoatPositionCallback(scene->getOceanScene()) );

            scene->getOceanScene()->addChild(boatTransform.get());   
        }



Hey... I'm no good at flying after it with my clutzy mouse skills, so I wondered if I could get the camera to do the work for me.

Wanting to follow my boat into the sunset on it's perilous journey, I attempted to "implement" a "FOLLOW_ME" camera mode in the SceneEventHandler. I did what basics I could glean from whatever sources I could, and had limited success... At least I could see water. My boat was traveling perhaps with the camera, but I couldn't find it no matter what position and distance I placed it. I need some clues here...

Code:

else if (_currentCameraMode == TRACKBALL)
{
   osgGA::NodeTrackerManipulator* nt = new osgGA::NodeTrackerManipulator();
   //Find that NODE!                
   osg::Node* trackedNode = _scene->findNamedNode("BOAT",_scene->getScene());    
   if(!trackedNode)
      return false;
   nt->setNode(trackedNode);
   nt->setTrackNode(trackedNode);
   nt->setTrackerMode(osgGA::NodeTrackerManipulator::NODE_CENTER_AND_AZIM);
   nt->setAutoComputeHomePosition(true);
   nt->setMinimumDistance(100);
   nt->setDistance(100);
   nt->setElevation(100);
   _currentCameraMode = FOLLOW_ME;
   //_viewer.getCamera()->setViewMatrixAsLookAt( osg::Vec3f(0.f,0.f,20.f),
        //          osg::Vec3f(0.f,0.f,20.f)+osg::Vec3f(0.f,1.f,0.f), osg::Vec3f(0,0,1) );                     
   _viewer.setCameraManipulator(nt);
   _textHUD->setCameraText("FOLLOW_ME");
}


Please note the commented out setViewMatrixAsLookAt... did not know wether it should be used or not?

I was wondering if perhaps (again) that the nodeTrackerManipulator is incompatible with a node which uses a PositionAttitudeTransform?
The reason I ask is that my mouse controls the position of whatever (the boat and camera presumably) in a very radical means. The slightest touch of the mouse causes wild swings of height, perspective or distance. Once I can find the surface of the water.... zooooooom! What might be going on here?

Thank you!

Cheers,
tim
Code:
Back to top
View user's profile Send private message
tim (tim paige)
User


Joined: 25 Feb 2009
Posts: 31
Location: San Diego

PostPosted: Tue Mar 22, 2011 3:52 pm    Post subject:
Re: NodetrackerManipulator...
Reply with quote

Hi,

I have found my object finally by turning off by NOT relying on setAutoComputeHomePosition, and these other "set" creatures.

Code:

osgGA::NodeTrackerManipulator* nt = new osgGA::NodeTrackerManipulator();
nt->setNode(trackedNode);
nt->setTrackNode(trackedNode);
nt->setTrackerMode(osgGA::NodeTrackerManipulator::NODE_CENTER_AND_AZIM);
nt->setAutoComputeHomePosition(true);
nt->setMinimumDistance(100);
nt->setDistance(100);
nt->setElevation(100);


What HAS worked for me is the (apparently) more direct route...

Code:

nt->setHomePosition( osg::Vec3f(0.f,-40.f,40.f), osg::Vec3f(0.f,20.f,20.f)+osg::Vec3f(0.f,1.f,0.f), osg::Vec3f(0,0,1) );


where ever I was being placed in autocompute wether I set position or not... they were obviously fighting with each other and placed me at the edge of the universe and also upset the scaling of mouse controls. The mouse stabilized somewhat when approaching the object, but was pretty wild for a time on the edge.

I might note that, at the (perceived) edge of the universe, shapes that might relate themselves to the islands would take on darkness, invert themselves and leave remnants behind for the other manipulators to deal with even with their more proper positioning. Like an upside down black mountain over the scene. More stable when positioned first, though... but interesting non-the-less.

Still want to know about the setviewmatrix and such...

Thank you!

Cheers,
tim
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> osgOcean [osgOcean] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts How to get Node object from PositionA... nghien_rbc General 1 Sat Apr 15, 2017 3:05 am View latest post
No new posts confused with setTextureAttributeAndM... mp3butcher General 1 Thu May 26, 2016 10:28 pm View latest post
No new posts PositionAttitudeTransform uniform sca... João General 2 Wed Jun 17, 2015 3:24 pm View latest post
No new posts Fixed potential divide by zero in Nod... filnet Submission 3 Tue Jun 09, 2015 8:22 pm View latest post
No new posts PositionAttitudeTransform operation o... gambr General 6 Tue Sep 02, 2014 2:11 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP