home *** CD-ROM | disk | FTP | other *** search
-
- //////////////////////////////////////////////////////////////
- //
- // Source file for glrduckMainWindow
- //
- // This class is a subclass of VkWindow
- //
- //
- // Normally, very little in this file should need to be changed.
- // Create/add/modify menus using RapidApp.
- //
- // Try to restrict any changes to the bodies of functions
- // corresponding to menu items, the constructor and destructor.
- //
- // Restrict changes to those sections between
- // the "//--- Start/End editable code block" markers
- //
- // Doing so will allow you to make changes using RapidApp
- // without losing any changes you may have made manually
- //
- // Avoid gratuitous reformatting and other changes that might
- // make it difficult to integrate changes made using RapidApp
- //////////////////////////////////////////////////////////////
- #include "glrduckMainWindow.h"
-
- #include <Vk/VkApp.h>
- #include <Vk/VkFileSelectionDialog.h>
- #include <Vk/VkSubMenu.h>
- #include <Vk/VkRadioSubMenu.h>
- #include <Vk/VkMenuItem.h>
- #include <Vk/VkMenuBar.h>
- #include <Vk/VkResource.h>
-
-
- // Externally defined classes referenced by this class:
-
- //---- Start editable code block: headers and declarations
- #include <Inventor/nodes/SoSeparator.h>
- #include <Inventor/actions/SoGLRenderAction.h>
- #include <Inventor/nodes/SoCylinder.h>
- #include <Inventor/nodes/SoDirectionalLight.h>
- #include <Inventor/nodes/SoEventCallback.h>
- #include <Inventor/nodes/SoMaterial.h>
- #include <Inventor/nodes/SoPerspectiveCamera.h>
- #include <Inventor/nodes/SoRotationXYZ.h>
- #include <Inventor/nodes/SoTransform.h>
- #include <Inventor/nodes/SoTranslation.h>
- #include <Inventor/nodes/SoComplexity.h>
- #include "SoXtGLRRenderArea.h"
- //---- End editable code block: headers and declarations
-
-
-
- // These are default's resources for widgets in objects of this class
- // All resources will be prepended by *<name> at instantiation,
- // where <name> is the name of the specific instance, as well as the
- // name of the baseWidget. These are only defaults, and may be overriden
- // in a resource file by providing a more specific resource name
-
- String glrduckMainWindow::_defaultglrduckMainWindowResources[] = {
- "*exitButton.accelerator: Ctrl<Key>Q",
- "*exitButton.acceleratorText: Ctrl+Q",
- "*exitButton.labelString: Exit",
- "*exitButton.mnemonic: x",
- "*filePane.labelString: File",
- "*filePane.mnemonic: F",
- "*helpPane.labelString: Help",
- "*helpPane.mnemonic: H",
- //---- Start editable code block: glrduckMainWindow Default Resources
-
-
- //---- End editable code block: glrduckMainWindow Default Resources
-
- (char*)NULL
- };
-
-
- //---- Class declaration
-
- glrduckMainWindow::glrduckMainWindow ( const char *name,
- ArgList args,
- Cardinal argCount) :
- VkWindow ( name, args, argCount ), _moving(FALSE)
- {
- int attrs[] = {GLR_RGBA, GLR_RED_SIZE, 1, GLR_GREEN_SIZE, 1,
- GLR_BLUE_SIZE, 1, GLR_DEPTH_SIZE, 16,
- GLR_SAMPLES_SGIS, 4, 0};
-
- // Load any class-default resources for this object
-
- setDefaultResources ( baseWidget(), _defaultglrduckMainWindowResources );
-
-
- // Create the view component contained by this window
-
- _render= new SoXtGLRRenderArea (attrs, mainWindowWidget(), "render");
-
-
- XtVaSetValues ( _render->getWidget(),
- XmNwidth, 500,
- XmNheight, 500,
- (XtPointer) NULL );
-
- // Add the component as the main view
- // Inventor components are not really VkComponents,
- // so we have to add them by their widgets
-
- addView ( _render->getWidget() );
-
- // Create the panes of this window's menubar. The menubar itself
- // is created automatically by ViewKit
-
-
- // The filePane menu pane
-
- _filePane = addMenuPane ( "filePane" );
-
- _exitButton = _filePane->addAction ( "exitButton",
- &glrduckMainWindow::quitCallback,
- (XtPointer) this );
-
-
- //---- Start editable code block: glrduckMainWindow constructor
- _root = new SoSeparator;
- _root->ref();
-
- _complexity = new SoComplexity;
- _complexity->value = 0.4;
- _root->addChild(_complexity);
-
- // Add a camera and light
- SoPerspectiveCamera *myCamera = new SoPerspectiveCamera;
- myCamera->position.setValue(0., -4., 8.0);
- myCamera->heightAngle = M_PI/2.5;
- myCamera->nearDistance = 1.0;
- myCamera->farDistance = 15.0;
-
- _root->addChild(myCamera);
- _root->addChild(new SoDirectionalLight);
-
- // Rotate scene slightly to get better view
- SoRotationXYZ *globalRotXYZ = new SoRotationXYZ;
- globalRotXYZ->axis = SoRotationXYZ::X;
- globalRotXYZ->angle = M_PI/9;
- _root->addChild(globalRotXYZ);
-
- // Pond group
- SoSeparator *pond = new SoSeparator;
- _root->addChild(pond);
-
- SoMaterial *cylMaterial = new SoMaterial;
- cylMaterial->diffuseColor.setValue(0., 0.3, 0.8);
- pond->addChild(cylMaterial);
-
- SoTranslation *cylTranslation = new SoTranslation;
- cylTranslation->translation.setValue(0., -6.725, 0.);
- pond->addChild(cylTranslation);
-
- SoCylinder *myCylinder = new SoCylinder;
- myCylinder->radius.setValue(4.0);
- myCylinder->height.setValue(0.5);
- pond->addChild(myCylinder);
-
- // Duck group
- SoSeparator *duck = new SoSeparator;
- _root->addChild(duck);
-
- // Read the duck object from a file and add to the group
- SoInput myInput;
- if (!myInput.openFile("duck.iv")) {
- if (!myInput.openFile("/usr/share/src/Inventor/examples/data/duck.iv")) {
- exit(1);
- }
- }
- SoSeparator *duckObject = SoDB::readAll(&myInput);
- if (duckObject == NULL) exit(1);
-
- // Set up the duck transformations
- _duckRotXYZ = new SoRotationXYZ;
- duck->addChild(_duckRotXYZ);
- _duckRotXYZ->angle = _angle = 0.0;
- _duckRotXYZ->axis = SoRotationXYZ::Y; // rotate about Y axis
-
- SoTransform *initialTransform = new SoTransform;
- initialTransform->translation.setValue(0., 0., 3.);
- initialTransform->scaleFactor.setValue(6., 6., 6.);
- duck->addChild(initialTransform);
-
- duck->addChild(duckObject);
-
- _render->setSceneGraph(_root);
- _render->setEventCallback(myEventCB, this);
- //---- End editable code block: glrduckMainWindow constructor
-
-
- } // End Constructor
-
-
- glrduckMainWindow::~glrduckMainWindow()
- {
- delete _render;
- //---- Start editable code block: glrduckMainWindow destructor
-
-
- //---- End editable code block: glrduckMainWindow destructor
- } // End destructor
-
-
- const char *glrduckMainWindow::className()
- {
- return ("glrduckMainWindow");
- } // End className()
-
-
- Boolean glrduckMainWindow::okToQuit()
- {
- //---- Start editable code block: glrduckMainWindow okToQuit
-
-
-
- // This member function is called when the user quits by calling
- // theApplication->terminate() or uses the window manager close protocol
- // This function can abort the operation by returning FALSE, or do some.
- // cleanup before returning TRUE. The actual decision is normally passed on
- // to the view object
-
-
- // The view object is an Inventor component, which does
- // not currently support the okToQuit protocol
-
- return ( TRUE );
- //---- End editable code block: glrduckMainWindow okToQuit
- } // End okToQuit()
-
-
-
- ///////////////////////////////////////////////////////////////
- // The following functions are static member functions used to
- // interface with Motif.
- ///////////////////////////////////
-
- void glrduckMainWindow::quitCallback ( Widget w,
- XtPointer clientData,
- XtPointer callData )
- {
- glrduckMainWindow* obj = ( glrduckMainWindow * ) clientData;
- obj->quit ( w, callData );
- }
-
-
-
-
-
- ///////////////////////////////////////////////////////////////
- // The following functions are called from callbacks
- ///////////////////////////////////
-
- void glrduckMainWindow::quit ( Widget, XtPointer )
- {
- // Exit via quitYourself() to allow the application
- // to go through its normal shutdown routines, checking with
- // all windows, views, and so on.
-
- theApplication->quitYourself();
-
- } // End glrduckMainWindow::quit()
-
-
-
-
- //---- Start editable code block: End of generated code
-
- SbBool glrduckMainWindow::myEventCB(void *userData, XAnyEvent *event)
- {
- SbBool done= NULL;;
-
- if (userData)
- done = ((glrduckMainWindow*)userData)->myRealEventCB(event);
-
- return done;
- }
-
- SbBool
- glrduckMainWindow::myRealEventCB(XAnyEvent *anyevent)
- {
- XButtonEvent *myButtonEvent;
- XMotionEvent *myMotionEvent;
- SbVec3f vec;
- SbBool handled = FALSE;
-
- switch (anyevent->type) {
- case ButtonPress:
- myButtonEvent = (XButtonEvent *) anyevent;
- if (myButtonEvent->button == Button1) {
- motionStart(myButtonEvent->x, myButtonEvent->y);
- handled = TRUE;
- }
- break;
- case ButtonRelease:
- myButtonEvent = (XButtonEvent *) anyevent;
- if (myButtonEvent->button == Button1) {
- if (_moving) {
- motionStop();
- handled = TRUE;
- }
- }
- break;
- case MotionNotify:
- myMotionEvent = (XMotionEvent *) anyevent;
- if (myMotionEvent->state & Button1Mask) {
- motion(myMotionEvent->x, myMotionEvent->y);
- }
- break;
- default:
- break;
- }
-
- return handled;
- }
-
- void glrduckMainWindow::motionStart(int x, int y)
- {
- _complexity->value = 0.4;
- _begin = x;
- }
-
- void glrduckMainWindow::motion(int x, int)
- {
- _moving = TRUE;
- _angle = _angle + .01 * (x - _begin);
- _begin = x;
- _duckRotXYZ->angle = _angle;
- _render->render(SoXtGLRRenderArea::LOW);
- }
-
- void glrduckMainWindow::motionStop()
- {
- extern VkApp *theApplication;
-
- _moving = FALSE;
- _complexity->value = 1.0;
- theApplication->busy();
- _render->render(SoXtGLRRenderArea::HIGH);
- theApplication->notBusy();
- _render->setAutoRedraw(FALSE);
- _complexity->value = 0.4;
- }
-
-
- //---- End editable code block: End of generated code
-
-
-