Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r940 - trunk/fox/FManta


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r940 - trunk/fox/FManta
  • Date: Fri, 17 Feb 2006 13:54:36 -0700 (MST)

Author: abe
Date: Fri Feb 17 13:54:36 2006
New Revision: 940

Modified:
   trunk/fox/FManta/FMantaTrackballNav.cc
   trunk/fox/FManta/FMantaTrackballNav.h
Log:

Updated trackball code so that it works with camera path recording.

Added keyboard commands:
'w' dolly forward
's' dolly backward
' ' reset lookat point to center of scene.

M    fox/FManta/FMantaTrackballNav.cc
M    fox/FManta/FMantaTrackballNav.h


Modified: trunk/fox/FManta/FMantaTrackballNav.cc
==============================================================================
--- trunk/fox/FManta/FMantaTrackballNav.cc      (original)
+++ trunk/fox/FManta/FMantaTrackballNav.cc      Fri Feb 17 13:54:36 2006
@@ -5,6 +5,9 @@
 using namespace Manta;
 using namespace fox_manta;
 
+#include <Interface/Scene.h>
+#include <Interface/Context.h>
+#include <Core/Geometry/BBox.h>
 
 void FMantaTrackballNav::projectToSphere( Vector &result, Real x, Real y, 
Real radius ) {
 
@@ -22,10 +25,44 @@
   }
 }
 
+
 // Mouse events.
 long FMantaTrackballNav::onKeyPress   ( FXObject* /*sender*/,
-                                        FXSelector /*sel*/,
-                                        void* /*data*/ ) {
+                                        FXSelector sel,
+                                        void* data ) {
+
+       FXEvent *event = (FXEvent *)data;
+       FXushort sel_type = FXSELTYPE( sel );
+
+  // Determine the image resolution.
+  int xres, yres;
+  bool stereo;
+  manta_interface->getResolution( manta_channel, stereo, xres, yres );
+  
+  Real dolly = ((Real)1.0)/(((Real)0.5*(Real)xres)+control_speed);
+  dolly *= control_speed;
+  
+  // Dollying.
+       if (event->text[0]=='w' || event->code==KEY_Up) {
+    manta_interface->addTransaction("trackball dolly",
+                                   Callback::create( this, 
&FMantaTrackballNav::mantaDolly, dolly ) );
+  }
+
+       else if (event->text[0]=='s' || event->code==KEY_Down) {
+    manta_interface->addTransaction("trackball dolly",
+                                   Callback::create( this, 
&FMantaTrackballNav::mantaDolly, -dolly ) );
+  }
+
+  // Rotation about the up vector.
+       else if (event->text[0]=='a' || event->code==KEY_Left) {
+  }
+       else if (event->text[0]=='d' || event->code==KEY_Right) {
+  }
+  else if (event->text[0]==' ') {
+    manta_interface->addTransaction("trackball center",
+            Callback::create( this, &FMantaTrackballNav::mantaCenterOnScene 
) );
+  }
+    
   return 1;
 }
 
@@ -41,7 +78,8 @@
   
   Real width  = (Real)xres * 0.5;
   Real height = (Real)yres * 0.5;
-       
+
+       
/////////////////////////////////////////////////////////////////////////////
   // Record mouse up and mouse down.
   switch (sel_type) {
   case SEL_LEFTBUTTONPRESS:
@@ -87,7 +125,8 @@
     mouse_down[2] = false;
     break;
   };
-       
+
+       
/////////////////////////////////////////////////////////////////////////////
   // Look for mouse movements.
   if (sel_type == SEL_MOTION && mouse_down[2]) {
                
@@ -111,7 +150,7 @@
                                      Callback::create( this, 
&FMantaTrackballNav::mantaTrackball, rotation ) );
                        
       // Move the from point of the rotation.
-      rotate_from = rotate_to;
+      rotate_from = rotate_to;      
     }
   }
   else if (sel_type == SEL_MOTION && mouse_down[0] && ((event->state & 
SHIFTMASK) == SHIFTMASK)) {
@@ -142,13 +181,54 @@
   return 1;
 }
 
+void FMantaTrackballNav::resetToCamera( const Vector& eye, const Vector& 
lookat, const Vector& up ) {
+
+  // Save the initial state for this trackball.
+  local_camera_lock.lock();
+  
+  camera_eye = eye;
+  camera_lookat = lookat;
+  camera_up = up;
+
+  local_camera_lock.unlock();
+}
+
+void FMantaTrackballNav::getCamera( Vector& eye, Vector& lookat, Vector& up 
) const {
+
+  // Copy out the local copy of the camera state.
+  local_camera_lock.lock();
+  
+  eye    = camera_eye;
+  lookat = camera_lookat;
+  up     = camera_up;
+
+  local_camera_lock.unlock();
+}
+
+void FMantaTrackballNav::updateLocalCamera( Camera *camera ) {
+
+  local_camera_lock.lock();
+
+  camera_eye = camera->getPosition();
+  camera_lookat = camera->getLookAt();
+  camera_up = camera->getUp();  
+  
+  local_camera_lock.unlock();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
 // These functions are called by the manta thread.
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
 void FMantaTrackballNav::mantaLookat( Vector lookat ) {
 
   Camera *camera = manta_interface->getCamera( manta_channel );
        
   // Move the camera.
   camera->reset( camera->getPosition(), camera->getUp(), lookat );
+
+  updateLocalCamera( camera );
 }
 void FMantaTrackballNav::mantaTrackball( AffineTransform rotation ) {
 
@@ -156,6 +236,8 @@
 
   // Apply the rotation.
   camera->transform( rotation, Camera::LookAt );
+
+  updateLocalCamera( camera );
 }
 void FMantaTrackballNav::mantaDolly( Real distance ) {
 
@@ -170,7 +252,21 @@
 
   // Move around the image plane.
   camera->translate( pan );
+
+  updateLocalCamera( camera );
 }
 
+void FMantaTrackballNav::mantaCenterOnScene() {
+
+  Scene *scene = manta_interface->getScene();
 
+  // Compute bounding box.
+  BBox bounds;
+  PreprocessContext context;
+  scene->getObject()->computeBounds( context, bounds );
 
+  // Set the lookat point to the center of the bounding box.
+  Vector center = bounds.center();
+
+  mantaLookat( center );
+}

Modified: trunk/fox/FManta/FMantaTrackballNav.h
==============================================================================
--- trunk/fox/FManta/FMantaTrackballNav.h       (original)
+++ trunk/fox/FManta/FMantaTrackballNav.h       Fri Feb 17 13:54:36 2006
@@ -10,6 +10,8 @@
 #include <FManta/FMantaNavigator.h>
 #include <FManta/FMantaImageFrame.h>
 
+#include <SCIRun/Core/Thread/Mutex.h>
+
 namespace fox_manta {
        
        using namespace Manta;
@@ -37,9 +39,23 @@
 
                // This method is used to implement the trackball.
                // Note that x and y are [-radius,radius]
-               void projectToSphere( Vector &result, Real x, Real y, Real 
radius );            
+               void projectToSphere( Vector &result, Real x, Real y, Real 
radius );
+
+    // Local copy of camera parameters used for camera paths.
+    Vector camera_eye;
+    Vector camera_lookat;
+    Vector camera_up;
+
+    mutable SCIRun::Mutex local_camera_lock;
+
+    void updateLocalCamera( Camera * camera );
+    
 public:
-               FMantaTrackballNav() : control_speed( 1.0 ), 
trackball_radius( 1.0 ) { 
+               FMantaTrackballNav() :
+      control_speed( 1.0 ),
+      trackball_radius( 1.0 ),
+      local_camera_lock( "local_camera_lock" )
+    { 
                        mouse_down[0] = mouse_down[1] = mouse_down[2] = 
false; };
                
                // Mouse events.
@@ -50,15 +66,16 @@
                void setMantaFrame( FMantaImageFrame *frame )     { 
manta_frame = frame; };
                void setTrackballRadius( Real trackball_radius_ ) { 
trackball_radius = trackball_radius_; };
                void setControlSpeed( Real new_speed )            { 
control_speed = new_speed; };
-               void resetToCamera( const Vector& eye, const Vector& lookat,
-                        const Vector& up )
-    {  /* Trackball nav contains no camera state. */ };
+
+               void resetToCamera( const Vector& eye, const Vector& lookat, 
const Vector& up );
+    void getCamera( Vector& eye, Vector& lookat, Vector& up ) const;
                        
                // Methods called by the manta thread.
                void mantaLookat( Vector lookat );
                void mantaTrackball( AffineTransform rotation );
                void mantaDolly( Real distance );
                void mantaPan( Vector pan );
+    void mantaCenterOnScene();
        };
 };
 




  • [MANTA] r940 - trunk/fox/FManta, abe, 02/17/2006

Archive powered by MHonArc 2.6.16.

Top of page