Text archives Help
- From: abe@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r392 - in branches/itanium2: Engine/Display UserInterface fox
- Date: Fri, 17 Jun 2005 04:13:39 -0600 (MDT)
Author: abe
Date: Fri Jun 17 04:13:31 2005
New Revision: 392
Added:
branches/itanium2/fox/FMantaQuakeNav.cc
branches/itanium2/fox/FMantaQuakeNav.h
Modified:
branches/itanium2/Engine/Display/CMakeLists.txt
branches/itanium2/Engine/Display/GLXImageDisplay.cc
branches/itanium2/Engine/Display/GLXImageDisplay.h
branches/itanium2/UserInterface/XWindowUI.cc
branches/itanium2/fox/CMakeLists.txt
branches/itanium2/fox/FMantaImageFrame.cc
branches/itanium2/fox/FMantaImageFrame.h
branches/itanium2/fox/FMantaWindow.h
branches/itanium2/fox/fox_manta.cc
Log:
Modifications to the GLXImageDisplay and manta embedded in fox example.
Fixed the problem with GLXImageDisplay and my Mac X server. Code now works on
both Altix and powerbook.
Added FMantaQuakeNav based on Kenny's camera navigation system. The code is
there, but it doesn't exactly work yet.
Design of fox example probably isn't the best. Manta seems to get along
reasonably ok, except on exit.
M fox/fox_manta.cc
M fox/FMantaWindow.h
A fox/FMantaQuakeNav.cc
M fox/FMantaImageFrame.cc
A fox/FMantaQuakeNav.h
M fox/FMantaImageFrame.h
M fox/CMakeLists.txt
M UserInterface/XWindowUI.cc
Note that the resolution output doesn't always match the frame buffer size.
M Engine/Display/GLXImageDisplay.cc
M Engine/Display/GLXImageDisplay.h
M Engine/Display/CMakeLists.txt
Modified: branches/itanium2/Engine/Display/CMakeLists.txt
==============================================================================
--- branches/itanium2/Engine/Display/CMakeLists.txt (original)
+++ branches/itanium2/Engine/Display/CMakeLists.txt Fri Jun 17 04:13:31
2005
@@ -10,4 +10,6 @@
Display/FileDisplay.cc
Display/GLXImageDisplay.h
Display/GLXImageDisplay.cc
+ Display/RawImageDisplay.h
+ Display/RawImageDisplay.cc
)
Modified: branches/itanium2/Engine/Display/GLXImageDisplay.cc
==============================================================================
--- branches/itanium2/Engine/Display/GLXImageDisplay.cc (original)
+++ branches/itanium2/Engine/Display/GLXImageDisplay.cc Fri Jun 17 04:13:31
2005
@@ -15,36 +15,46 @@
// Note that the GLXImage display must be passed a GLX context by the
// application it is embedded inside of.
GLXImageDisplay::GLXImageDisplay( XVisualInfo *x_visual_info_,
- GLXContext glx_context_,
-
GLXDrawable
glx_drawable_,
-
Display *x_display_,
-
int x_screen_ )
+
GLXDrawable
glx_drawable_ )
: x_visual_info( x_visual_info_ ),
- glx_context( glx_context_ ),
- glx_drawable( glx_drawable_ ),
- x_display( x_display_ ),
- x_screen( x_screen_ )
+ glx_drawable( glx_drawable_ ),
+ x_display( 0 )
{
}
GLXImageDisplay::~GLXImageDisplay() {
+
+ // Close the X display.
+ if (x_display != 0) {
+
+ // Destroy the gl context.
+ glXDestroyContext( x_display, glx_context );
+
+ // Disconnect from X server.
+ XCloseDisplay( x_display );
+ x_display = 0;
+ }
}
// Manta ImageDisplay interface.
void GLXImageDisplay::setupDisplayChannel( SetupContext &context ) {
// The setup for the window should be done in the driving application.
- std::cout << "setupDisplayChannel" << context.proc << std::endl;
+ std::cout << "setupDisplayChannel " << context.proc << std::endl;
// Only the display processor.
if (context.proc != 0)
return;
- x_display = XOpenDisplay( 0 ); // Open a new connection to the same
display...
+ // Check to see if we are already connected to the X server.
+ if (x_display == 0) {
+ std::cout << "setupDisplayChannel: Connecting to server. " <<
context.proc << std::endl;
+ x_display = XOpenDisplay( 0 ); // Open a new connection to
the same display...
+ }
// Get the default screen for the display.
- x_screen = DefaultScreen( x_display );
+ int x_screen = DefaultScreen( x_display );
// (Like we have a prayer this will work...)
glx_context = glXCreateContext( x_display, x_visual_info, 0, true );
@@ -52,9 +62,7 @@
// Call make current to associate with this thread
// NOTE THIS MUST BE CALLED EACH TIME THE DISPLAY THREAD CHANGES!!
- // glXWaitX();
glXMakeCurrent( x_display, glx_drawable, glx_context );
- // glXWaitGL();
// Copy out the manta channel.
manta_channel = context.channelIndex;
@@ -71,12 +79,6 @@
image->getResolution( stereo, xres, yres );
- // NOTE THIS MUST BE CALLED EACH TIME THE DISPLAY THREAD
CHANGES!!
- // (which is why it's here, until I figure out how to insure
that).
- // XSync( x_display, false );
- // glXWaitX();
- // glXMakeCurrent( x_display, glx_drawable, glx_context );
-
// This code is from OpenGLImageDisplay.
glViewport(0, 0, xres, yres);
glMatrixMode(GL_PROJECTION);
@@ -152,8 +154,5 @@
if(errcode != GL_NO_ERROR) {
std::cerr << "OpenGLDisplay: Error code from OpenGL:
" << gluErrorString(errcode) << std::endl;
}
-
- // glXWaitGL();
- // XSync( x_display, false );
}
}
Modified: branches/itanium2/Engine/Display/GLXImageDisplay.h
==============================================================================
--- branches/itanium2/Engine/Display/GLXImageDisplay.h (original)
+++ branches/itanium2/Engine/Display/GLXImageDisplay.h Fri Jun 17 04:13:31
2005
@@ -20,7 +20,6 @@
GLXDrawable glx_drawable; // Or window id.
Display *x_display;
XVisualInfo *x_visual_info;
- int x_screen;
int manta_channel; // The last channel number to call
setupDisplayChannel.
@@ -28,9 +27,7 @@
// Note that the GLXImage display must be passed a GLX
context by the
// application it is embedded inside of.
GLXImageDisplay( XVisualInfo *x_visual_info_,
-
GLXContext glx_context_,
- GLXDrawable glx_drawable_,
-
Display *x_display_, int x_screen_ );
+
GLXDrawable glx_drawable_ );
~GLXImageDisplay();
// Manta ImageDisplay interface.
Modified: branches/itanium2/UserInterface/XWindowUI.cc
==============================================================================
--- branches/itanium2/UserInterface/XWindowUI.cc (original)
+++ branches/itanium2/UserInterface/XWindowUI.cc Fri Jun 17 04:13:31
2005
@@ -311,6 +311,7 @@
void XWindowUI::changeResolution(int, int, int channel,
int new_xres, int new_yres)
{
+ cerr << "Resolution: " << new_xres << " " << new_yres << endl;
rtrt_interface->changeResolution(channel, new_xres, new_yres, true);
}
Modified: branches/itanium2/fox/CMakeLists.txt
==============================================================================
--- branches/itanium2/fox/CMakeLists.txt (original)
+++ branches/itanium2/fox/CMakeLists.txt Fri Jun 17 04:13:31 2005
@@ -15,7 +15,9 @@
FMantaWidgets.cc
FMantaWidgets.h
FMantaWindow.cc
- FMantaWindow.h )
+ FMantaWindow.h
+ FMantaQuakeNav.h
+ FMantaQuakeNav.cc )
TARGET_LINK_LIBRARIES(fox_manta Manta_Engine
Modified: branches/itanium2/fox/FMantaImageFrame.cc
==============================================================================
--- branches/itanium2/fox/FMantaImageFrame.cc (original)
+++ branches/itanium2/fox/FMantaImageFrame.cc Fri Jun 17 04:13:31 2005
@@ -15,8 +15,8 @@
// Message_Type ID
Message_Handler
FXMAPFUNC(SEL_CONFIGURE, FMantaImageFrame::ID_IMAGE,
FMantaImageFrame::onConfigure ),
FXMAPFUNC(SEL_LEFTBUTTONRELEASE, FMantaImageFrame::ID_IMAGE,
FMantaImageFrame::onMouseChange ),
- FXMAPFUNC(SEL_MIDDLEBUTTONRELEASE, FMantaImageFrame::ID_IMAGE,
FMantaImageFrame::onMouseChange ),
- FXMAPFUNC(SEL_RIGHTBUTTONRELEASE, FMantaImageFrame::ID_IMAGE,
FMantaImageFrame::onMouseChange ),
+ FXMAPFUNC(SEL_LEFTBUTTONPRESS, FMantaImageFrame::ID_IMAGE,
FMantaImageFrame::onMouseChange ),
+ FXMAPFUNC(SEL_MOTION, FMantaImageFrame::ID_IMAGE,
FMantaImageFrame::onMouseChange ),
FXMAPFUNC(SEL_KEYPRESS, FMantaImageFrame::ID_IMAGE,
FMantaImageFrame::onKeyPress )
};
@@ -35,9 +35,9 @@
// Send a transaction to manta, notifying change resolution.
manta_interface->addTransaction("resize",
-
Callback::create(
manta_interface,
-
&RTRTInterface::changeResolution,
-
manta_channel,
+
Callback::create(
manta_interface, // Call on this.
+
&RTRTInterface::changeResolution, // This method.
+
manta_channel, // These
args.
getWidth(),
getHeight(),
true ) );
@@ -50,8 +50,11 @@
FXEvent *event = (FXEvent *)data;
FXushort sel_type = FXSELTYPE( sel );
- std::cerr << "In onMouseChange " << event->win_x << " "
- << event->win_y << std::endl;
+ // std::cerr << "In onMouseChange " << event->win_x << " "
+ // << event->win_y << std::endl;
+
+ // Check to see if a button is pressed.
+ return navigator->onMouseChange( sender, sel, data );
return 1;
}
@@ -66,7 +69,7 @@
manta_interface->finish();
}
- return 1;
+ return navigator->onKeyPress( sender, sel, data );
}
Modified: branches/itanium2/fox/FMantaImageFrame.h
==============================================================================
--- branches/itanium2/fox/FMantaImageFrame.h (original)
+++ branches/itanium2/fox/FMantaImageFrame.h Fri Jun 17 04:13:31 2005
@@ -6,6 +6,8 @@
#include <Interface/RTRTInterface.h>
+#include <fox/FMantaQuakeNav.h>
+
namespace fox_manta {
using namespace FX;
@@ -22,6 +24,9 @@
// Manta channel number.
int manta_channel;
+ // Navigator to send updates to manta's camera.
+ FMantaQuakeNav *navigator;
+
public:
// Message types.
enum {
@@ -30,7 +35,7 @@
};
// Constructors.
- FMantaImageFrame() : manta_interface( 0 ) { };
+ FMantaImageFrame() : manta_interface( 0 ), navigator( 0 ) {
};
FMantaImageFrame( FXComposite *p, FXApp *app, int width, int
height, RTRTInterface *manta_interface_ );
// Fox message handlers for mouse and keyboard.
@@ -41,6 +46,7 @@
// Accessors.
void setMantaInterface( RTRTInterface *manta_interface_, int
manta_channel_ ) {
manta_interface = manta_interface_; manta_channel =
manta_channel_; };
+ void setNavigator( FMantaQuakeNav *navigator_ ) { navigator =
navigator_; }
RTRTInterface *getMantaInterface() { return manta_interface;
};
int getMantaChannel () { return manta_channel;
};
Added: branches/itanium2/fox/FMantaQuakeNav.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/fox/FMantaQuakeNav.cc Fri Jun 17 04:13:31 2005
@@ -0,0 +1,141 @@
+
+#include <fox/FMantaQuakeNav.h>
+
+#include <MantaTypes.h>
+#include <Interface/Camera.h>
+#include <Interface/Callback.h>
+#include <Core/Geometry/PointVector.h>
+#include <Core/Geometry/AffineTransform.h>
+
+using namespace fox_manta;
+using namespace Manta;
+
+///////////////////////////////////////////////////////////////////////////////
+// Basic interaction with the class.
+void FMantaQuakeNav::move( Real d ) {
+
+ posY -= (cos(viewDirAngle) * cos(viewElevAngle)) * d;
+ posX += (sin(viewDirAngle) * cos(viewElevAngle)) * d;
+ if (allowFly) height += sin(viewElevAngle) * d;
+};
+
+void FMantaQuakeNav::strafe( Real d ) {
+ posX += sin( viewDirAngle ) * d;
+ posY += cos( viewDirAngle ) * d;
+};
+
+void FMantaQuakeNav::turn( Real d ) {
+ viewDirAngle += d;
+};
+
+void FMantaQuakeNav::tilt( Real d ) {
+ viewElevAngle += d;
+};
+
+void FMantaQuakeNav::mantaAddTransaction() {
+ manta_interface->addTransaction("Quake Camera",
+
Callback::create(this, &FMantaQuakeNav::manta_transaction ));
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// Fox Mouse and Keyboard.
+long FMantaQuakeNav::onKeyPress ( FXObject *sender, FXSelector sel, void
*data ) {
+
+ FXEvent *event = (FXEvent *)data;
+
+ if (event->text[0] == key_map[UP])
+ move( translateStepSize );
+
+ else if (event->text[0] == key_map[DOWN])
+ move( -translateStepSize );
+
+ else if (event->text[0] == key_map[LEFT])
+ strafe( -translateStepSize );
+
+ else if (event->text[0] == key_map[RIGHT])
+ strafe( translateStepSize );
+
+ else
+ return 1;
+
+ // Add a transaction to manta with new camera state.
+ mantaAddTransaction();
+
+ return 1;
+}
+
+long FMantaQuakeNav::onMouseChange( FXObject *sender, FXSelector sel, void
*data ) {
+
+ FXEvent *event = (FXEvent *)data;
+ FXushort sel_type = FXSELTYPE( sel );
+
+ if (sel_type == SEL_LEFTBUTTONPRESS) {
+ mouse_down = true;
+ }
+ else if (sel_type == SEL_LEFTBUTTONRELEASE) {
+ mouse_down = false;
+ }
+ else if (sel_type == SEL_MOTION && mouse_down) {
+
+ Real delta_x = event->win_x - event->last_x;
+ Real delta_y = event->win_y - event->last_y;
+
+ std::cerr << "delta " << delta_x << " " << delta_y <<
std::endl;
+
+ turn( delta_x * rotateStepSize );
+ tilt( delta_y * rotateStepSize );
+
+ mantaAddTransaction();
+ }
+
+ return 1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Fox interaction with the class.
+// void *data is a pointer to the Real d parameter.
+long FMantaQuakeNav::onMove ( FXObject *sender, FXSelector sel, void *data
) {
+ move( *((Real *)data) );
+ return 1;
+}
+
+long FMantaQuakeNav::onStrafe( FXObject *sender, FXSelector sel, void *data
) {
+ strafe( *((Real *)data) );
+ return 1;
+}
+
+long FMantaQuakeNav::onTurn ( FXObject *sender, FXSelector sel, void *data
) {
+ turn( *((Real *)data) );
+ return 1;
+}
+
+long FMantaQuakeNav::onTilt ( FXObject *sender, FXSelector sel, void *data
) {
+ tilt( *((Real *)data) );
+ return 1;
+}
+
+// Add a transaction in response to a message.
+long FMantaQuakeNav::onMantaAddTransaction( FXObject *sender, FXSelector
sel, void *data ) {
+
+ mantaAddTransaction();
+ return 1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Transaction callback for manta thread.
+// THIS FUNCTION IS NOT CALLED BY THE FOX THREAD.
+void FMantaQuakeNav::manta_transaction() {
+
+ // Create a transformation.
+ AffineTransform affine_transform;
+ affine_transform.initWithIdentity();
+ affine_transform.rotate ( Vector(1.0,0.0,0.0), viewElevAngle );
+ affine_transform.rotate ( Vector(0.0,1.0,0.0), viewDirAngle );
+ affine_transform.translate( Vector( posX, height, posY ) );
+
+ // Apply it to the camera.
+ // Potential problem: Camera isn't initialized with the Identity
matrix.
+ manta_camera->transform( affine_transform, Camera::Origin );
+}
+
+
Added: branches/itanium2/fox/FMantaQuakeNav.h
==============================================================================
--- (empty file)
+++ branches/itanium2/fox/FMantaQuakeNav.h Fri Jun 17 04:13:31 2005
@@ -0,0 +1,121 @@
+#ifndef fox_FMantaQuakeNav__H
+#define fox_FMantaQuakeNav__H
+
+#include <fx.h>
+#include <fx3d.h>
+
+#include <MantaTypes.h>
+#include <Interface/Camera.h>
+#include <Interface/RTRTInterface.h>
+
+namespace fox_manta {
+
+ using namespace Manta;
+
+ // This class contains attributes used to move a "Quake" style viewer
around
+ // the scene.
+ // This class is based on Kenny Hoff's glvu classes (khoff@sgi.com).
+ class FMantaQuakeNav {
+ private:
+ bool allowFly;
+ Real translateStepSize;
+ Real rotateStepSize;
+
+ Real posX, posY;
+ Real viewDirAngle;
+ Real viewElevAngle;
+ Real height;
+
+ // Manta objects.
+ Camera *manta_camera;
+ RTRTInterface *manta_interface;
+
+ public:
+ // Key map.
+ enum { UP, DOWN, LEFT, RIGHT, LAST };
+
+ private:
+ // Default mappings.
+ char key_map[LAST];
+
+ // State.
+ bool mouse_down;
+
+ public:
+ // Constructor with default options.
+ FMantaQuakeNav() : allowFly( false ),
+ translateStepSize( 1.0 ),
+
rotateStepSize ( 1.0 ),
+
posX( 0 ),
+
posY( 0 ),
+
viewDirAngle( 0.0 ),
+
viewElevAngle( 0.0 ),
+
height( 0 ),
+
+
manta_camera( 0 ),
+
manta_interface( 0 ),
+
mouse_down( false )
+
{
+
key_map[0] = 'w';
+
key_map[1] = 's';
+
key_map[2] = 'a';
+
key_map[3] = 'd'; };
+ // Constructor
+ FMantaQuakeNav( bool allowFly_, Real translateStepSize_, Real
rotateStepSize_,
+ Real posX_, Real posY_, Real viewDirAngle_,
Real viewElevAngle_,
+
Real height_ ) :
+
+ allowFly( allowFly_ ),
+ translateStepSize( translateStepSize_ ),
+ rotateStepSize( rotateStepSize_ ),
+ posX( posX_ ),
+ posY( posY_ ),
+ viewDirAngle( viewDirAngle_ ),
+ viewElevAngle( viewElevAngle_ ),
+ height( height_ ),
+
+ manta_camera( 0 ),
+ manta_interface( 0 ),
+ mouse_down( false )
+
+ { key_map[0] = 'w';
+ key_map[1] = 's';
+ key_map[2] = 'a';
+ key_map[3] = 'd'; };
+
+ // Accessors.
+ void setMantaCamera( Camera *manta_camera_ ) {
manta_camera = manta_camera_; };
+ void setMantaInterface( RTRTInterface *manta_interface_ ) {
manta_interface = manta_interface_; };
+
+ void setKeyMap( int map, char k ) { key_map[map] = k; };
+ char getKeyMap( int map ) { return key_map[map]; };
+
+ // Basic interaction with the class.
+ void move ( Real d );
+ void strafe( Real d );
+ void turn ( Real d );
+ void tilt ( Real d );
+
+ // Add a camera update transaction to manta with the current
state
+ // of this Navigator.
+ void mantaAddTransaction();
+
+ // Fox interaction via keyboard and mouse.
+ long onKeyPress ( FXObject *sender, FXSelector sel, void
*data );
+ long onMouseChange( FXObject *sender, FXSelector sel, void
*data );
+
+ // Fox interaction with the class.
+ // void *data is a pointer to the Real d parameter.
+ long onMove ( FXObject *sender, FXSelector sel, void *data );
+ long onStrafe( FXObject *sender, FXSelector sel, void *data );
+ long onTurn ( FXObject *sender, FXSelector sel, void *data );
+ long onTilt ( FXObject *sender, FXSelector sel, void *data );
+ long onMantaAddTransaction( FXObject *sender, FXSelector sel,
void *data );
+
+ // Transaction callback for manta thread.
+ // THIS FUNCTION IS NOT CALLED BY THE FOX THREAD.
+ void manta_transaction();
+ };
+};
+
+#endif
\ No newline at end of file
Modified: branches/itanium2/fox/FMantaWindow.h
==============================================================================
--- branches/itanium2/fox/FMantaWindow.h (original)
+++ branches/itanium2/fox/FMantaWindow.h Fri Jun 17 04:13:31 2005
@@ -61,6 +61,7 @@
// Accessors.
void setMantaInterface( RTRTInterface *manta_interface_, int
manta_channel_ ) {
manta_interface = manta_interface_;
manta_frame->setMantaInterface( manta_interface_, manta_channel_ ); };
+ void setNavigator( FMantaQuakeNav *navigator_ ) {
manta_frame->setNavigator( navigator_ ); };
RTRTInterface *getMantaInterface() { return
manta_interface; };
FMantaImageFrame *getMantaFrame() { return manta_frame; };
Modified: branches/itanium2/fox/fox_manta.cc
==============================================================================
--- branches/itanium2/fox/fox_manta.cc (original)
+++ branches/itanium2/fox/fox_manta.cc Fri Jun 17 04:13:31 2005
@@ -23,6 +23,9 @@
int main( int argc, char *argv[]) {
+ // Don't catch thread exceptions.
+ setenv("THREAD_NO_CATCH_SIGNALS","1",true);
+
// Parse args.
int np = 1;
@@ -62,18 +65,22 @@
manta_interface->selectRenderer ( "raytracer" );
manta_interface->selectShadowAlgorithm( "hard" );
- Camera *camera = manta_interface->createCamera( "pinhole(-eye 3 3 2
-lookat 0 0 0.3 -up 0 0 1 -fov 60)" );
+ Camera *camera = manta_interface->createCamera( "pinhole(-eye 1 1 1
-lookat 0 -1.0 0 -up 0 0 1 -fov 60)" );
- // Create the manta image display.
+ // Create the manta image frame.
FMantaImageFrame *manta_frame = manta_window.getMantaFrame();
// Create a glx image display.
GLXImageDisplay glx_image_display( (XVisualInfo
*)manta_frame->getVisual()->getInfo(),
-
(GLXContext) manta_frame->getContext(),
- (Window) manta_frame->id(),
-
(Display
*) app.getDisplay(),
-
0 );
+ (Window) manta_frame->id() );
+
+ // Create a navigator for the image frame.
+ FMantaQuakeNav *quake_nav = new FMantaQuakeNav();
+ quake_nav->setMantaCamera( camera );
+ quake_nav->setMantaInterface( manta_interface );
+ manta_window.setNavigator( quake_nav );
+
// Create manta channel for the interface.
int manta_channel = 0; // !!! See XWindowUI.cc line: 586
manta_interface->createChannel( &glx_image_display, camera, false,
width, height );
- [MANTA] r392 - in branches/itanium2: Engine/Display UserInterface fox, abe, 06/17/2005
Archive powered by MHonArc 2.6.16.