From: Braden M. <br...@en...> - 2005-11-16 22:05:43
|
vr...@he... wrote: > Hi Braden, > > thanks for the fast response. > > Braden McDaniel <br...@en...> wrote: > >>> i would like to add a new viewport_node to the browser with a given >>> field of >>> view. >>> Or is it possible to change the viewport of the active viewpoint >>> node. I've >>> searched for this topic, but found nothing helpfull. >> >> >> One way is to create a new node with browser::create_vrml_from_stream >> and add it to the scene. > > > The only possibilty i found, was to add the node to the browser so I > tried it > this way, but there must be something wrong, because it crashes later > when the > viewpoint is set with set_viewpoint during the rendering. I'm not knowing > OpenVrml very well, so please give me a hint to the right direction. > Here is my > code: > > vector<node_ptr> nodes = myBrowser->create_vrml_from_stream(nodeStream); > > viewpoint_node* viewpointPtr = node_cast<viewpoint_node*>(nodes[0].get()); At this point you have a viewpoint_node, but it's not part of any scene. node::initialize needs to be called for it to be added to a scene. > myBrowser->add_viewpoint(*viewpointPtr); > myBrowser->active_viewpoint(*viewpointPtr); Unfortunately, browser::add_viewpoint doesn't do what you need. All it does is make the browser aware of a viewpoint_node for the purpose of potentially presenting a list of them in a user interface. This is a part of the API that could really use some more thought, I'm afraid. The bound node stack logic has been deliberately factored out of the core runtime and into the node implementations because I want the potential to provide a less cumbersome implementation of an openvrml::viewpoint_node than what is required for VRML97. Making that compatible with a straightforward API remains a challenge. Suffice it to say that browser::add_viewpoint really shouldn't be part of the public API. It gets called as a side effect of calling node::initialize. Changing nodes after they're created involves sending them events. You need to get the event_listener corresponding to the eventIn you're interested in and call field_value_listener<FieldValue>::process_event. Note that there are typedefs for the field_value_listener instances you might be interested in, so you can do something like this: sfvec3f_listener & listener = dynamic_cast<sfvec3f_listener &>( viewpointPtr->event_listener("set_position")); listener.process_event(new_pos, time); "time" you probably want to get from browser::current_time. Oh, if you're using the CVS version, the first part of the above is a bit tidier: sfvec3f_listener & listener = viewpointPtr->event_listener<sfvec3f>("set_position"); To make the Viewpoint active, you should send a "true" sfbool value to the listener corresponding to "set_bind". (And note that as in VRML, you can elide the "set_" prefix on the eventIn identifiers if you so desire.) > Another solution for my problem, would be to change the position and the > field > of view of the active viewpoint. But I didn't found something to change the > properties of myBrowser->active_viewpoint(). This will be a bit simpler since you don't need to deal with explicitly initializing a node. But as above, you want to send the node events--in this case, to the event_listeners corresponding to "set_position" and "set_fieldOfView". > To be honest for me the > implementation of the nodes is a little bit confusing (i am not such a > CodeGuru)and I am not quit sure how it works. Maybe I will have some > time this > weekend to go through the code to understand it a little bit better. For the moment, I'd actually steer you away from looking too hard at the way the nodes in vrml97node.cpp implement this stuff. There is a good deal of template and pointer-to-member magic that is there to minimize redundant code when implementing a large number of nodes--but it can make it harder to see the Big Picture. I can provide more exposition if necessary. However, I'm inclined to drop useful hints as I tend to be interested in seeing how well the API explains itself. >> PS: The openvrml-develop mailing list permits posting only by >> subscribers in order to curb spam. Please subscribe to the list if you >> intend to continue posting. > > Just used the wrong email address, Sorry for that! Perhaps you have discovered this already; but it is possible to subscribe multiple e-mail addresses and disable mail delivery to all but one of them (using the MailMan Web interface). Braden |