| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/*-------------------------------------------------------------- |
| 38 |
* This is an example from the Inventor Mentor, |
| 39 |
* chapter 12, example 1. |
| 40 |
* |
| 41 |
* Sense changes to a viewer's camera's position. |
| 42 |
*------------------------------------------------------------*/ |
| 43 |
|
| 44 |
#include <cstdlib> |
| 45 |
#include <Inventor/SoDB.h> |
| 46 |
#include <Inventor/Xt/SoXt.h> |
| 47 |
#include <Inventor/Xt/viewers/SoXtExaminerViewer.h> |
| 48 |
#include <Inventor/nodes/SoCamera.h> |
| 49 |
#include <Inventor/nodes/SoSeparator.h> |
| 50 |
#include <Inventor/sensors/SoFieldSensor.h> |
| 51 |
|
| 52 |
// Callback that reports whenever the viewer's position changes. |
| 53 |
static void |
| 54 |
cameraChangedCB(void *data, SoSensor *) |
| 55 |
{ |
| 56 |
SoCamera *viewerCamera = (SoCamera *)data; |
| 57 |
|
| 58 |
SbVec3f cameraPosition = viewerCamera->position.getValue(); |
| 59 |
printf("Camera position: (%g,%g,%g)\n", |
| 60 |
cameraPosition[0], cameraPosition[1], |
| 61 |
cameraPosition[2]); |
| 62 |
} |
| 63 |
|
| 64 |
int |
| 65 |
main(int argc, char **argv) |
| 66 |
{ |
| 67 |
if (argc != 2) { |
| 68 |
fprintf(stderr, "Usage: %s filename.iv\n", argv[0]); |
| 69 |
exit(1); |
| 70 |
} |
| 71 |
|
| 72 |
Widget myWindow = SoXt::init(argv[0]); |
| 73 |
if (myWindow == NULL) exit(1); |
| 74 |
|
| 75 |
SoInput inputFile; |
| 76 |
if (inputFile.openFile(argv[1]) == FALSE) { |
| 77 |
fprintf(stderr, "Could not open file %s\n", argv[1]); |
| 78 |
exit(1); |
| 79 |
} |
| 80 |
|
| 81 |
SoSeparator *root = SoDB::readAll(&inputFile); |
| 82 |
root->ref(); |
| 83 |
|
| 84 |
SoXtExaminerViewer *myViewer = |
| 85 |
new SoXtExaminerViewer(myWindow); |
| 86 |
myViewer->setSceneGraph(root); |
| 87 |
myViewer->setTitle("Camera Sensor"); |
| 88 |
myViewer->show(); |
| 89 |
|
| 90 |
// Get the camera from the viewer, and attach a |
| 91 |
// field sensor to its position field: |
| 92 |
SoCamera *camera = myViewer->getCamera(); |
| 93 |
SoFieldSensor *mySensor = |
| 94 |
new SoFieldSensor(cameraChangedCB, camera); |
| 95 |
mySensor->attach(&camera->position); |
| 96 |
|
| 97 |
SoXt::show(myWindow); |
| 98 |
SoXt::mainLoop(); |
| 99 |
} |