Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[MANTA] r406 - branches/itanium2/fox


Chronological Thread 
  • From: khoff@sci.utah.edu
  • To: manta@sci.utah.edu
  • Subject: [MANTA] r406 - branches/itanium2/fox
  • Date: Tue, 21 Jun 2005 15:47:51 -0600 (MDT)

Author: khoff
Date: Tue Jun 21 15:47:50 2005
New Revision: 406

Modified:
   branches/itanium2/fox/FMantaQuakeNav.cc
   branches/itanium2/fox/FMantaQuakeNav.h
Log:
added left-button translation and resetToCamera

Modified: branches/itanium2/fox/FMantaQuakeNav.cc
==============================================================================
--- branches/itanium2/fox/FMantaQuakeNav.cc     (original)
+++ branches/itanium2/fox/FMantaQuakeNav.cc     Tue Jun 21 15:47:50 2005
@@ -20,12 +20,19 @@
 
 
///////////////////////////////////////////////////////////////////////////////
 // Basic interaction with the class.
-void FMantaQuakeNav::move( Real d ) { 
+void FMantaQuakeNav::moveForwBack( Real d ) { 
   posX += (float)cos(viewDirAngle*TORADS) * (float)cos(viewElevAngle*TORADS) 
* d;
   posY += (float)sin(viewDirAngle*TORADS) * (float)cos(viewElevAngle*TORADS) 
* d;
   if (allowFly) height += (float)sin(viewElevAngle*TORADS) * d; 
 };
 
+void FMantaQuakeNav::moveUpDown( Real d ) { 
+  double UpAngle = (viewElevAngle + 90)*TORADS;
+  posX += (float)cos(viewDirAngle*TORADS) * (float)cos(UpAngle) * d;
+  posY += (float)sin(viewDirAngle*TORADS) * (float)cos(UpAngle) * d;
+  height += (float)sin(UpAngle) * d;
+};
+
 void FMantaQuakeNav::strafe( Real d ) { 
   posX -= (float)sin(viewDirAngle*TORADS) * d;
   posY += (float)cos(viewDirAngle*TORADS) * d;
@@ -52,10 +59,10 @@
 //std::cout << event->time << std::endl;
 
        if (event->text[0]==key_map[UP] || event->code==KEY_Up)
-               move( translateStepSize );
+               moveForwBack( translateStepSize );
 
        else if (event->text[0]==key_map[DOWN] || event->code==KEY_Down)
-               move( -translateStepSize );
+               moveForwBack( -translateStepSize );
                
        else if (event->text[0]==key_map[LEFT] || event->code==KEY_Left)
                strafe( translateStepSize );
@@ -77,24 +84,60 @@
        FXEvent *event = (FXEvent *)data;
        FXushort sel_type = FXSELTYPE( sel );
        
-       if (sel_type == SEL_RIGHTBUTTONPRESS) {
-               mouse_down = true;
-       }
-       else if (sel_type == SEL_RIGHTBUTTONRELEASE) {
-               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;
-               
-               turn( -delta_x * rotateStepSize );
-               tilt( -delta_y * rotateStepSize );
+  if (sel_type == SEL_RIGHTBUTTONPRESS) {
+    right_mouse_down = true;
+  }
+  else if (sel_type == SEL_RIGHTBUTTONRELEASE) {
+    right_mouse_down = false;
+  }
+  else if (sel_type == SEL_MOTION && right_mouse_down) {
+    
+    Real delta_x = event->win_x - event->last_x;
+    Real delta_y = event->win_y - event->last_y;
+    
+    turn( -delta_x * rotateStepSize );
+    tilt( -delta_y * rotateStepSize );
+
+    mantaAddTransaction();
+  }
+
+  if (sel_type == SEL_LEFTBUTTONPRESS) {
+    left_mouse_down = true;
+  }
+  else if (sel_type == SEL_LEFTBUTTONRELEASE) {
+    left_mouse_down = false;
+  }
+  else if (sel_type == SEL_MOTION && left_mouse_down) {
+    
+    Real delta_x = event->win_x - event->last_x;
+    Real delta_y = event->win_y - event->last_y;
+    
+    moveUpDown( delta_y * translateStepSize * 0.1f );
+    strafe( delta_x * translateStepSize * 0.1f );
 
-               mantaAddTransaction();
-       }
+    mantaAddTransaction();
+  }
 
        return 1;
+}
+
+void FMantaQuakeNav::resetToCamera( const Point &eye, const Point &lookat, 
const Vector &up )
+{
+  posX=eye.x();
+  posY=eye.y();
+  height=eye.z();
+  
+  // for now up is assumed to be positive Z
+
+  // use dx and dy to determine the view direction angle  
+  double dx = lookat.x() - eye.x();
+  double dy = lookat.y() - eye.y();
+  viewDirAngle = (float)atan2(dy,dx);
+  
+  // dV and dZ form adjacent edges of a right triangle, use this to 
determine elevation angle
+  double dZ = lookat.z() - eye.z();
+  double dV = sqrt(dx*dx+dy*dy);
+  viewElevAngle = (float)atan2(dZ,dV);
 }
 
 
///////////////////////////////////////////////////////////////////////////////

Modified: branches/itanium2/fox/FMantaQuakeNav.h
==============================================================================
--- branches/itanium2/fox/FMantaQuakeNav.h      (original)
+++ branches/itanium2/fox/FMantaQuakeNav.h      Tue Jun 21 15:47:50 2005
@@ -39,17 +39,18 @@
                char key_map[LAST];
                
                // State.
-               bool mouse_down;
+               bool left_mouse_down, right_mouse_down;
     
     // Timer between movement key polling (zero value means timer hasn't 
started)
     bool timerStarted;
     FXuint lastTime;
                
                // Basic movement.
-               void move  ( Real d );
-               void strafe( Real d );
-               void turn  ( Real d );          
-               void tilt  ( Real d );
+    void moveForwBack( Real d );
+    void moveUpDown( Real d );
+               void strafe( Real d );  // left/right movement
+               void turn( Real d );            
+               void tilt( Real d );
                
                
                void mantaAddTransaction();
@@ -58,14 +59,14 @@
                // Constructor with default options.
                FMantaQuakeNav() : allowFly( true ),
                                   translateStepSize( 0.2 ),
-                                                                             
           rotateStepSize   ( 0.5 ),
+                                                                             
           rotateStepSize   ( 0.75 ),
                                                                              
           posX( 0 ),
                                                                              
           posY( 0 ),
                                                                              
           viewDirAngle( 0.0 ),
                                                                              
           viewElevAngle( 0.0 ),
                                                                              
           height( 0 ),
-                                                                             
           
-                                                                             
           mouse_down( false )
+                       left_mouse_down( false ),
+                       right_mouse_down( false )
                                                                              
           {  
                                                                              
              key_map[0] = 'w';
                                                                              
              key_map[1] = 's';
@@ -84,8 +85,8 @@
                        viewDirAngle( viewDirAngle_ ),
                        viewElevAngle( viewElevAngle_ ),
                        height( height_ ),
-                       
-                       mouse_down( false )
+      left_mouse_down( false ),
+      right_mouse_down( false )
                        
                  { key_map[0] = 'w';
                                key_map[1] = 's';
@@ -103,7 +104,7 @@
                long onMouseChange( FXObject *sender, FXSelector sel, void 
*data );
                
                void setControlSpeed( Real new_speed ) { translateStepSize = 
new_speed; };
-               void resetToCamera( const Point &eye, const Point &lookat, 
const Vector &up );
+    void resetToCamera( const Point &eye, const Point &lookat, const Vector 
&up );
                
                // Transaction callback for manta thread. 
                void mantaThreadCallback() const;




  • [MANTA] r406 - branches/itanium2/fox, khoff, 06/21/2005

Archive powered by MHonArc 2.6.16.

Top of page