Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r409 - branches/itanium2/fox


Chronological Thread 
  • From: abe@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r409 - branches/itanium2/fox
  • Date: Fri, 24 Jun 2005 00:00:48 -0600 (MDT)

Author: abe
Date: Fri Jun 24 00:00:45 2005
New Revision: 409

Added:
   branches/itanium2/fox/FMantaTrackballNav.cc
   branches/itanium2/fox/FMantaTrackballNav.h
Modified:
   branches/itanium2/fox/CMakeLists.txt
   branches/itanium2/fox/FMantaImageFrame.cc
   branches/itanium2/fox/fox_manta.cc
Log:
Added trackball navigation to tuesday's demo

Modified: branches/itanium2/fox/CMakeLists.txt
==============================================================================
--- branches/itanium2/fox/CMakeLists.txt        (original)
+++ branches/itanium2/fox/CMakeLists.txt        Fri Jun 24 00:00:45 2005
@@ -20,7 +20,9 @@
                            FMantaQuakeNav.h
                            FMantaQuakeNav.cc
                            FMantaUniformNav.h
-                           FMantaUniformNav.cc )
+                           FMantaUniformNav.cc 
+                           FMantaTrackballNav.h
+                           FMantaTrackballNav.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 24 00:00:45 2005
@@ -112,7 +112,7 @@
   Real yoffset = (-yres/2.+0.5)*yscale;
        
        image_x = pixel_x * xscale + xoffset;
-       image_y = pixel_y * yscale + yoffset;
+       image_y = (getHeight() - pixel_y) * yscale + yoffset;
        
        // Create a ray packet.
        RayPacketData data;

Added: branches/itanium2/fox/FMantaTrackballNav.cc
==============================================================================
--- (empty file)
+++ branches/itanium2/fox/FMantaTrackballNav.cc Fri Jun 24 00:00:45 2005
@@ -0,0 +1,173 @@
+#include <fox/FMantaTrackballNav.h>
+
+#include <fxkeys.h>
+
+using namespace Manta;
+using namespace fox_manta;
+
+
+void FMantaTrackballNav::projectToSphere( Vector &result, Real x, Real y, 
Real radius ) {
+
+       x /= radius;
+  y /= radius;
+  Real rad2 = x*x+y*y;
+  if(rad2 > 1) {
+    Real rad = sqrt(rad2);
+    x /= rad;
+    y /= rad;
+    result = Vector( x, y, 0 );
+  } else {
+    Real z = sqrt(1-rad2);
+    result = Vector( x, y, z );
+  }
+}
+
+// Mouse events.
+long FMantaTrackballNav::onKeyPress   ( FXObject *sender, FXSelector sel, 
void *data ) {
+
+       FXEvent *event = (FXEvent *)data;
+       return 1;
+}
+
+long FMantaTrackballNav::onMouseChange( FXObject *sender, FXSelector sel, 
void *data ) {
+
+       FXEvent *event = (FXEvent *)data;
+       FXushort sel_type = FXSELTYPE( sel );
+       
+       Real width  = ((FXComposite *)sender)->getWidth() * 0.5;
+       Real height = ((FXComposite *)sender)->getHeight() * 0.5;
+       
+       // Record mouse up and mouse down.
+       switch (sel_type) {
+       case SEL_LEFTBUTTONPRESS:
+               mouse_down[0] = true;
+               break;
+       case SEL_LEFTBUTTONRELEASE:
+               mouse_down[0] = false;
+               break;
+       case SEL_MIDDLEBUTTONPRESS:
+               mouse_down[1] = true;
+               break;
+       case SEL_MIDDLEBUTTONRELEASE:
+               mouse_down[1] = false;
+               break;
+       case SEL_RIGHTBUTTONPRESS:
+               mouse_down[2] = true;
+       
+               // Two clicks of the right button changes the lookat point.
+               if ((event->state & SHIFTMASK) == SHIFTMASK) {
+                       // New center of rotation.
+                       Point lookat;
+                       Vector normal;
+                       
+                       std::cout << "Calling shoot one ray" << std::endl;
+                       
+                       if (manta_frame->shootOneRay( event->win_x, 
event->win_y, lookat, normal )) {
+                               manta_interface->addTransaction("camera 
lookat",
+                                       Callback::create( this, 
&FMantaTrackballNav::mantaLookat, lookat ) );
+                       }
+                       
+                       return 1;
+               }
+               
+               // Update rotate from.
+               projectToSphere( rotate_from, 
+                                                                             
   ((Real)event->win_x-width)/width, 
+                                                                             
   -((Real)event->win_y-height)/height, 
+                                                                             
   trackball_radius );
+               break;
+       case SEL_RIGHTBUTTONRELEASE:
+               mouse_down[2] = false;
+               break;
+       };
+       
+       // Look for mouse movements.
+       if (sel_type == SEL_MOTION && mouse_down[2]) {
+               
+               // Update rotate to.
+               projectToSphere( rotate_to, 
+                                ((Real)event->win_x-width)/width, 
+                                                                             
   -((Real)event->win_y-height)/height, 
+                                                                             
   trackball_radius );
+               
+               // Check to make sure the vectors are far enough apart.
+               Real distance = (rotate_from - rotate_to).length();
+               if (distance > 0.001) {
+                       
+                       // Create a rotation event.
+                       AffineTransform rotation;
+                       
+                       rotation.initWithRotation( rotate_from, rotate_to );
+                       
+                       // Send the rotation to manta.
+                       manta_interface->addTransaction("trackball rotate",
+                               Callback::create( this, 
&FMantaTrackballNav::mantaTrackball, rotation ) );
+                       
+                       // Move the from point of the rotation.
+                       rotate_from = rotate_to;
+               }
+       }
+       else if (sel_type == SEL_MOTION && mouse_down[1]) {
+               
+               // Create a dolly event.
+               Real dolly;
+               
+               dolly = ((Real) (event->win_x - 
event->last_x))/(width+control_speed);
+               dolly *= control_speed;
+
+               manta_interface->addTransaction("trackball dolly",
+                       Callback::create( this, 
&FMantaTrackballNav::mantaDolly, dolly ) );
+       }
+       
+       else if (sel_type == SEL_MOTION && mouse_down[0]) {
+       
+               // Create a pan (translation) event.
+               Vector translation;
+
+               translation[0] = ((Real)-(event->win_x - 
event->last_x))/width;
+               translation[1] = ((Real) (event->win_y - 
event->last_y))/height;
+               translation *= control_speed;
+
+               manta_interface->addTransaction("trackball pan",
+                       Callback::create( this, 
&FMantaTrackballNav::mantaPan, translation ) );
+       }
+       
+       return 1;
+}
+
+// These functions are called by the manta thread.
+void FMantaTrackballNav::mantaLookat( Point lookat ) {
+
+       std::cout << "New lookat: " << lookat << std::endl;
+
+       Camera *camera = manta_interface->getCamera( manta_channel );
+       
+       // Move the camera.
+       camera->reset( camera->getPosition(), camera->getUp(), lookat );
+}
+void FMantaTrackballNav::mantaTrackball( AffineTransform rotation ) {
+
+       std::cout << "Rotation: " << std::endl;
+
+       Camera *camera = manta_interface->getCamera( manta_channel );
+
+       // Apply the rotation.
+       camera->transform( rotation, Camera::LookAt );
+}
+void FMantaTrackballNav::mantaDolly( Real distance ) {
+
+       Camera *camera = manta_interface->getCamera( manta_channel );
+
+       // Dolly the camera.
+       camera->dolly( distance );
+}
+void FMantaTrackballNav::mantaPan( Vector pan ) {
+
+       Camera *camera = manta_interface->getCamera( manta_channel );
+
+       // Move around the image plane.
+       camera->translate( pan );
+}
+
+
+

Added: branches/itanium2/fox/FMantaTrackballNav.h
==============================================================================
--- (empty file)
+++ branches/itanium2/fox/FMantaTrackballNav.h  Fri Jun 24 00:00:45 2005
@@ -0,0 +1,64 @@
+#ifndef fox_FMantaTrackballNav__H
+#define fox_FMantaTrackballNav__H
+
+#include <MantaTypes.h>
+#include <Core/Geometry/PointVector.h>
+#include <Core/Geometry/AffineTransform.h>
+#include <Core/Math/MiscMath.h>
+#include <Core/Math/Trig.h>
+
+#include <fox/FMantaNavigator.h>
+#include <fox/FMantaImageFrame.h>
+
+namespace fox_manta {
+       
+       using namespace Manta;
+       
+       // This navigator provides uniform panning, dolly, and rotation.
+       // The center of rotation by default is the camera itself, however 
+       // the user may "freeze" the center of rotation at a point and then 
+       // rotate the camera about that point.
+       
+       class FMantaTrackballNav : public FMantaNavigator {
+private:
+               
+               // Attributes.
+               Real control_speed;
+               Real trackball_radius; // Radius of trackball, 1.0 is half 
width of window.
+               
+               Vector rotate_from; // Trackball vectors.
+               Vector rotate_to;
+               
+               // Image frame to shoot helper rays into.
+               FMantaImageFrame *manta_frame;
+               
+               // Mouse buttons up and down.
+               bool mouse_down[3];
+
+               // 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 );            
+public:
+               FMantaTrackballNav() : control_speed( 1.0 ), 
trackball_radius( 1.0 ) { 
+                       mouse_down[0] = mouse_down[1] = mouse_down[2] = 
false; };
+               
+               // Mouse events.
+               long onKeyPress   ( FXObject *sender, FXSelector sel, void 
*data );
+               long onMouseChange( FXObject *sender, FXSelector sel, void 
*data );
+       
+               // Accessors.
+               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 Point &eye, const Point &lookat, 
const Vector &up ) { 
+                       /* Trackball nav contains no camera state. */ };
+                       
+               // Methods called by the manta thread.
+               void mantaLookat( Point lookat );
+               void mantaTrackball( AffineTransform rotation );
+               void mantaDolly( Real distance );
+               void mantaPan( Vector pan );
+       };
+};
+
+#endif
\ No newline at end of file

Modified: branches/itanium2/fox/fox_manta.cc
==============================================================================
--- branches/itanium2/fox/fox_manta.cc  (original)
+++ branches/itanium2/fox/fox_manta.cc  Fri Jun 24 00:00:45 2005
@@ -12,6 +12,8 @@
 
 #include <fox/FMantaWindow.h>
 #include <fox/FMantaUniformNav.h>
+#include <fox/FMantaQuakeNav.h>
+#include <fox/FMantaTrackballNav.h>
 
 #include <string>
 #include <stdlib.h>
@@ -90,6 +92,13 @@
        quake_nav->setMantaInterface( manta_interface );
        manta_window.addNavigatorOption( "Video Game", quake_nav );
 
+       // Create a navigator for the image frame.
+       FMantaTrackballNav *trackball_nav = new FMantaTrackballNav();
+       trackball_nav->setMantaInterface( manta_interface );
+       trackball_nav->setMantaFrame( manta_frame );
+       trackball_nav->setMantaChannel( 0 );    
+       manta_window.addNavigatorOption("Trackball", trackball_nav );   
+       
        // Create a navigator for the image frame.
        FMantaUniformNav *uniform_nav = new FMantaUniformNav();
        uniform_nav->setMantaInterface( manta_interface );




  • [MANTA] r409 - branches/itanium2/fox, abe, 06/24/2005

Archive powered by MHonArc 2.6.16.

Top of page